Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
#!/usr/bin/env python3
import re
from pathlib import Path
from typing import List
MARK = "// -----// IR Dump"
PAT = re.compile(r'IR Dump \w+ (\w+)')
def main(infile: Path, outdir: Path):
assert infile.exists(), f'{infile} not exists'
@scturtle
scturtle / emutool.py
Created May 16, 2023 16:22
emuiibo data generator
import json
import time
import random
import struct
import urllib.request
from pathlib import Path
# https://www.amiiboapi.com/api/amiibo/
database = json.load(open("amiibos.json"))
@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 1, 2025 02:40
build minimal emacs
# ubuntu/debian
# sudo apt install autoconf texinfo gnutls-bin -y
# homebrew
brew install texinfo tree-sitter
# build
CFLAGS="-O2 -DNDEBUG" ./configure --prefix $HOME/.local \
--without-all --without-x --without-ns --without-libgmp \
--with-modules --with-threads --with-tree-sitter --without-compress-install