Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / dig_torch_mlir.py
Last active May 12, 2023 09:42
dig into torch-mlir
import torch
from torch import nn
# import torch_mlir
from torch_mlir.passmanager import PassManager
from torch_mlir.dialects.torch.importer.jit_ir import ClassAnnotator, ModuleBuilder
torch.manual_seed(42)
@scturtle
scturtle / im2col.py
Last active May 6, 2023 07:28
conv2d forward and backward implementation
import torch
from torch import nn
import numpy as np
# https://github.com/arasdar/DL/blob/master/uri-dl/uri-dl-hw-2/assignment2/cs231n/layers.py
# https://github.com/brandontrabucco/conv-python/blob/master/main.py
def get_output_shape(x, kernel, stride):
(_, _, ih, iw), (kh, kw) = x.shape, kernel
oh = (ih - kh) // stride + 1
#include <algorithm>
#include <cassert>
#include <random>
#include <vector>
constexpr unsigned int bit_floor(unsigned int num) {
return num == 0 ? 0 : 1 << (31 - __builtin_clz(num));
}
template <typename It, typename T, typename Cmp>
@scturtle
scturtle / arguments.cc
Created October 30, 2022 14:15
c++ argparser (adapted from Corrade)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <optional>
#include <iomanip>
enum class Type {
PositionalArgument,
@scturtle
scturtle / slab.rs
Created October 11, 2022 12:17
slab
enum Entry<T> {
Vacant(usize),
Occupied(T),
}
pub struct Slab<T> {
entries: Vec<Entry<T>>,
next: usize,
}
@scturtle
scturtle / rbtree.cc
Last active September 21, 2022 07:53
red black tree
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <random>
#include <vector>
enum Color { Black, Red };
enum Leaf { Left, Right };
@scturtle
scturtle / list.cc
Last active September 10, 2022 17:02
double linked list
#include <iostream>
struct ListNode {
void *m_prev = nullptr;
void *m_next = nullptr;
};
template <typename T> struct List {
private:
T *m_head = nullptr;
@scturtle
scturtle / build.sh
Last active October 23, 2023 03:06
build minimal emacs
# ubuntu/debian
# sudo apt install libjansson-dev texinfo gnutls-bin
# homebrew
brew install jansson texinfo
# build
CFLAGS="-O2 -DNDEBUG" ./configure \
--without-all --without-x --without-ns --without-libgmp \
--with-json --with-modules --with-threads \
@scturtle
scturtle / xrandr.sh
Created January 14, 2022 09:18
xrandr.sh
#!/bin/bash
# xrandr # to see infos
# arandr # gui
echo -n "builtin(1) external(2) sidebyside(3) mirror(4): "
read choice
BUI=`xrandr | grep ' connected' | awk 'NR==1 {print $1}'`
BUIMODE=`xrandr | grep $BUI -A1 | awk 'FNR==2 {print $1}'`
@scturtle
scturtle / qlocktwo.py
Last active August 11, 2021 15:26
qlocktwo in python
from datetime import datetime
t = datetime.now()
H, M = t.hour % 12, t.minute
HL, DK = '\033[0m', '\033[2m'
RESET = HL
MM = lambda *rgs: HL if any(a <= M < b for a, b in rgs) else DK
HH = lambda h: HL if (M < 35 and H == h) or (M >= 35 and H + 1 == h) else DK
print(f'''\
{HL}I T{DK} L {HL}I S{DK} A S T I M E
{MM((15, 20), (45, 50))}A{DK} C {MM((15, 20), (45, 50))}Q U A R T E R{DK} D C