Skip to content

Instantly share code, notes, and snippets.

View proger's full-sized avatar
🎯
Focusing

Volodymyr Kyrylov proger

🎯
Focusing
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@proger
proger / bfs.py
Last active September 30, 2023 19:07
breadth first search (flood fill) in torch
class BFS(nn.Module):
def __init__(self):
super().__init__()
# convolutional kernel to connect with neighbors on the grid
self.step = nn.Conv2d(1, 1, kernel_size=3, padding=1, bias=False)
self.step.weight.data = 0.3 * torch.tensor([[1, 1, 1],
[1, 2, 1],
[1, 1, 1]]).view(1,1,3,3)
self.steps = 4
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@proger
proger / prior_likelihood_conflict.r
Created September 12, 2023 10:09 — forked from rmcelreath/prior_likelihood_conflict.r
Demonstration of how normal and student-t distributions interact in Bayesian updating
# prior - likelihood conflict
library(rethinking)
yobs <- 0
mtt <- ulam(
alist(
y ~ dstudent(2,mu,1),
mu ~ dstudent(2,10,1)
@proger
proger / dual_linear.py
Last active July 31, 2023 21:31
Two independent linear maps using Conv1d
"Two independent linear maps using grouped Conv1d"
import torch
import torch.nn as nn
class DualLinearSerial(nn.Module):
def __init__(self, in_channels, out_channels, bias=True):
super().__init__()
self.left = nn.Linear(in_channels // 2, out_channels // 2, bias=bias)
self.right = nn.Linear(in_channels // 2, out_channels // 2, bias=bias)
diff --git a/cuda/practicals/tree-ex1/findneighbors.hpp b/cuda/practicals/tree-ex1/findneighbors.hpp
index 7ba7329..412e6cd 100644
--- a/cuda/practicals/tree-ex1/findneighbors.hpp
+++ b/cuda/practicals/tree-ex1/findneighbors.hpp
@@ -16,7 +16,7 @@ namespace cstone
//! @brief generic depth-first traversal of an octree that works on CPU and GPU with customizable descent criteria
template<class C, class A>
-void depthFirstTraversal(const TreeNodeIndex* childOffsets, C&& continuationCriterion, A&& endpointAction)
+__host__ __device__ void depthFirstTraversal(const TreeNodeIndex* childOffsets, C&& continuationCriterion, A&& endpointAction)
import torch
import torch.nn as nn
import math
input_dim = 80
head_dim = 64
heads = 12
p_drop = 0.1
layers = 6
context = 128
import argparse
from pathlib import Path
from hashlib import sha1
import math
import torch
parser = argparse.ArgumentParser(description='compute nll/bpc/bpb on a text dataset')
parser.add_argument('--device', type=str, default='cuda:0')
parser.add_argument('ckpt_path')
@proger
proger / hue.py
Last active May 26, 2023 10:17
homography H via inverse mapping with bilinear interpolation and numba jit
import numpy as np
def rgb_to_hue(image):
"""Compute hue value from BGR image.
Uses Hue definition from https://mattlockyer.github.io/iat455/documents/rgb-hsv.pdf
"""
image = image / 255
m_max = np.max(image, axis=-1) # (W,H,C) -> (W,H)
m_min = np.min(image, axis=-1) # (W,H,C) -> (W,H)