Skip to content

Instantly share code, notes, and snippets.

View unixpickle's full-sized avatar

Alex Nichol unixpickle

View GitHub Profile
@unixpickle
unixpickle / bitonic.py
Created November 8, 2023 00:22
Bitonic sequences
import numpy as np
from tqdm.auto import tqdm
def is_bitonic(xs):
results = []
for seq in xs:
prev = seq[0]
direction = 0
num_changes = 0
for x1 in seq:
@unixpickle
unixpickle / reductions.md
Last active October 30, 2023 21:28
Global reduction speed

Benchmarking global reductions with varying numbers of SMs and warps per SM. We find interesting facts, like that using one warp across more SMs is more efficient than more warps across a single SM.

These were computed on an NVIDIA Titan X GPU.

Code for the benchmark is here and the kernel is here.

1 warps
@unixpickle
unixpickle / guess_the_number.ipynb
Created August 12, 2023 22:57
Guess the number
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@unixpickle
unixpickle / char_poly.py
Created May 17, 2022 16:34
Characteristic polynomial
"""
Compute the closed-form characteristic polynomial of a 4x4 matrix.
"""
import sympy
syms = sympy.symbols('a b c d e f g h i j k l m n o p')
mat = sympy.Matrix([[syms[i+j*4] for i in range(4)] for j in range(4)])
print(sympy.collect((mat - sympy.eye(4)*sympy.symbols('x')).det(), 'x'))
# a*f*k*p - a*f*l*o - a*g*j*p + a*g*l*n + a*h*j*o - a*h*k*n - b*e*k*p + b*e*l*o + b*g*i*p - b*g*l*m - b*h*i*o + b*h*k*m + c*e*j*p - c*e*l*n - c*f*i*p + c*f*l*m + c*h*i*n - c*h*j*m - d*e*j*o + d*e*k*n + d*f*i*o - d*f*k*m - d*g*i*n + d*g*j*m + x**4 + x**3*(-a - f - k - p) + x**2*(a*f + a*k + a*p - b*e - c*i - d*m + f*k + f*p - g*j - h*n + k*p - l*o) + x*(-a*f*k - a*f*p + a*g*j + a*h*n - a*k*p + a*l*o + b*e*k + b*e*p - b*g*i - b*h*m - c*e*j + c*f*i + c*i*p - c*l*m - d*e*n + d*f*m - d*i*o + d*k*m - f*k*p + f*l*o + g*j*p - g*l*n - h*j*o + h*k*n)
@unixpickle
unixpickle / egg_balance.py
Created November 21, 2021 14:33
Egg balance
import numpy as np
rows = 3
cols = 6
# Create all 2^(rows*cols) combinations of egg matrices.
all_combos = np.zeros([1] * (rows * cols + 2), dtype=np.float32)
for i in range(rows * cols):
m = np.zeros([2, rows * cols], dtype=np.float32)
m[1, i] = 1
@unixpickle
unixpickle / center_window.sh
Created September 28, 2021 13:42
Center window in GNOME
#!/bin/bash
#
# Center a GNOME window, given its title. All windows with the given title are
# moved to the center of their respective displays.
#
# Example:
#
# bash center_window.sh "foo.png - image editor"
#
@unixpickle
unixpickle / main.go
Created July 10, 2021 18:41
Split audio files into constant-length chunks
package main
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"github.com/unixpickle/essentials"
@unixpickle
unixpickle / go.mod
Last active February 28, 2021 18:41
Minimize the maximum of a mesh's SDF
module github.com/unixpickle/heart3d
go 1.15
require (
github.com/unixpickle/essentials v1.3.0
github.com/unixpickle/ffmpego v0.1.3
github.com/unixpickle/model3d v0.2.12
)
@unixpickle
unixpickle / decimate.go
Created July 23, 2020 01:39
2D decimation
func DecimateMesh(m *model2d.Mesh, maxVertices int) *model2d.Mesh {
m = model2d.NewMeshSegments(m.SegmentsSlice())
areas := map[model2d.Coord]float64{}
for _, v := range m.VertexSlice() {
areas[v] = VertexArea(m, v)
}
for len(areas) > maxVertices {
var next model2d.Coord
nextArea := math.Inf(1)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.