This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
def least_squares(A, b): | |
b = list(map(Fraction, b)) | |
m = len(A) | |
n = len(A[0]) if m else 0 | |
R = [[Fraction(0) for _ in range(n)] for _ in range(n)] | |
Q_cols = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binomial_filter_fft(filter_size, fft_size): | |
k = np.arange(fft_size) | |
z = -2j * np.pi * k / fft_size | |
L = np.log1p(np.exp(z)) - np.log(2) | |
logH = (filter_size - 1) * L | |
return np.exp(logH) | |
def conv_separable_fft(img2d, filter_size, filter): | |
H, W, C = img2d.shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
eigh6.py — Fast symmetric 3×3 eigen‐decomposition with Numba | |
This module provides a highly optimized, stand-alone (no Numpy) implementation | |
of the eigenvalue decomposition for real symmetric 3×3 matrices. It returns the | |
three real eigenvalues in ascending order along with an orthonormal basis of | |
eigenvectors. The implementation is designed for use with Numba’s @njit | |
decorator and features: | |
- Analytic solution for eigenvalues via closed‐form formulas (trigonometric |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Pcg32 = struct { | |
state: u64, | |
fn next_u32(self: *Pcg32) u32 { | |
const s = self.state; | |
self.state = s *% 0x5851f42d4c957f2d +% 0x14057b7ef767814f; | |
const xorshifted: u32 = @truncate((s ^ (s >> 18)) >> 27); | |
const rot: u5 = @intCast(s >> 59); | |
return (xorshifted >> rot) | (xorshifted << -% rot); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
static inline uint64_t multiply_mix(uint64_t x, uint64_t y) { | |
__uint128_t m = (__uint128_t)x * (__uint128_t)y; | |
uint64_t hi = m >> 64; | |
uint64_t lo = m; | |
return lo ^ hi; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const seeder = @import("seeder.zig"); | |
const Xoshiro256 = struct { | |
s: [4]u64, | |
pub fn next(self: *Xoshiro256) u64 { | |
const S = struct { | |
inline fn rotl(data: u64, rot: u6) u64 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from base64 import urlsafe_b64encode | |
from hashlib import sha384 | |
import os | |
import aiofiles | |
from aiohttp.client import ClientSession | |
# Fake user agent to trick the google font api to give us the .woff2 fonts | |
# Retrive one by typing `navigator.userAgent` in the browser's console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <string_view> | |
#include <memory> | |
constexpr uint32_t fnv_1a(std::string_view sv) { | |
uint32_t hash = 0x811c9dc5; | |
for (char c : sv) { | |
hash ^= (uint8_t)c; | |
hash *= 0x01000193; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
char *read_line_malloc(void) { | |
size_t sz = 64; | |
char *buf = malloc(sz); | |
if (!fgets(buf, sz, stdin)) { | |
*buf = '\0'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <cstring> | |
#include <charconv> | |
#include <iostream> | |
template<const int N> | |
struct BigInt { | |
static constexpr size_t digit_count = 9; | |
static constexpr uint32_t base = 1000000000; | |
uint32_t limbs[N]; |
NewerOlder