Skip to content

Instantly share code, notes, and snippets.

@0x0L
0x0L / lib.rs
Last active January 13, 2025 09:25
arrow chunked_binary_search
use arrow::array::{make_array, ArrayData, Int64Array};
use arrow::pyarrow::PyArrowType;
use pyo3::prelude::*;
fn chunked_binary_search(chunks: Vec<&[i64]>, val: i64, left: bool) -> usize {
let val = if left { val } else { val + 1 };
let chunks: Vec<&[i64]> = chunks.into_iter().filter(|x| !x.is_empty()).collect();
if chunks.is_empty() {
return 0;
@0x0L
0x0L / ogita_aishima.py
Created December 20, 2024 18:36
Ogita Aishima
import numpy as np
def estimate_eigeinvalues(A, X, extra=False):
"""From estimated eigenvectors X of A, compute estimated eigenvalues of A."""
n, _ = A.shape
R = np.eye(n) - X.T @ X
S = X.T @ A @ X
w = np.diag(S) / (1 - np.diag(R))
if extra:
@0x0L
0x0L / gen.py
Last active June 12, 2024 20:38
parallel_unique_merge.cpp
import numpy as np
N = 200
L = 10_000_000
p = 0.2
r = np.arange(L / p, dtype=int)
s = [
r[np.random.rand(r.shape[0]) > 1 - p]
for _ in range(N)
#include <algorithm>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include <future>
#include <queue>
#include <condition_variable>
#include <mutex>
#include <functional>
from pathlib import Path
import numpy as np
import pandas as pd
class RaggedIndexer:
def __init__(self, counts):
self.stops = np.r_[0, np.cumsum(counts)]
self.starts = self.stops[:-1]
@0x0L
0x0L / root.sh
Last active July 7, 2023 07:59
Setup P3 EC2 Rocky 9
# https://rockylinux.org/cloud-images/
# AMI 0951577d22b8e8dd4 rocky 9.1
# Instance p3.2xlarge
dnf install -y epel-release
crb enable
dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64/cuda-rhel9.repo
dnf module install -y nvidia-driver:latest
reboot
@0x0L
0x0L / DRE.py
Last active June 28, 2022 07:46
Deep Regression Ensembles
import numpy as np
from opt_einsum import contract
class DRE:
"""Deep Regression Ensemble
Parameters
----------
n_layers : int
Number of hidden layers.
@0x0L
0x0L / t.ipynb
Last active November 8, 2021 09:40
asyncpg / apache arrow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@0x0L
0x0L / test.py
Created September 28, 2021 15:17
import os
from multiprocessing import get_context
from concurrent.futures import ProcessPoolExecutor
from concurrent.futures.thread import _global_shutdown_lock as L
os.register_at_fork(
before=L.acquire,
after_in_child=L._at_fork_reinit,
after_in_parent=L.release
@0x0L
0x0L / generic_linkage.py
Last active November 12, 2021 19:59
Clustering algorithms
import heapq
import numpy as np
def generic_linkage(D, method='single'):
N = D.shape[0]
S = set(range(N))
size = {i: 1 for i in range(N)}
d = {}