Skip to content

Instantly share code, notes, and snippets.

View wisnunugroho21's full-sized avatar
🎯
Focusing

Nugroho Dewantoro wisnunugroho21

🎯
Focusing
View GitHub Profile
find_grade <- function(score) {
if (score >= 90 && score <= 100) {
return("A")
} else if (score >= 85 && score <= 89) {
return("A-")
} else if (score >= 80 && score <= 84) {
return("B+")
} else if (score >= 75 && score <= 79) {
return("B")
#install library gapminder dan tidyverse jika belum diinstall
#install.packages("gapminder")
#install.packages("tidyverse)
library(tidyverse)
library(gapminder)
gapminder_subset <- gapminder %>%
filter(year == 2007)
getNumberFromArray <- function(x, idx) {
return(x[idx])
}
milisecondToTime <- function(x) {
x <- x / 1000
result = as.POSIXct(x, origin = "1970-01-01")
return(result)
}
@wisnunugroho21
wisnunugroho21 / masked_softmax_pytorch.py
Last active August 22, 2021 08:49
Masked Softmax PyTorch
import torch
from torch.nn.functional import softmax
def masked_softmax(input: torch.Tensor, bool_mask: torch.Tensor, dim: int = -1, dtype: torch.dtype = None) -> torch.Tensor:
min_type_value = torch.finfo(input.dtype).min
masked_value = input.masked_fill(bool_mask, min_type_value)
return softmax(masked_value, dim = dim, dtype = dtype)
## Example
@wisnunugroho21
wisnunugroho21 / hungarian_algorithm.py
Last active October 12, 2024 13:45
Pytorch implementation of Hungarian Algorithm
# Pytorch implementation of Hungarian Algorithm
# Inspired from here : https://python.plainenglish.io/hungarian-algorithm-introduction-python-implementation-93e7c0890e15
# Despite my effort to parallelize the code, there is still some sequential workflows in this code
from typing import Tuple
import torch
from torch import Tensor
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')