Skip to content

Instantly share code, notes, and snippets.

View alecjacobson's full-sized avatar

Alec Jacobson alecjacobson

View GitHub Profile
@alecjacobson
alecjacobson / dense-block64.csv
Last active November 5, 2026 04:14
Warp tile_ldlt benchmarks on NVIDIA L40: original sweep plus 1,170 dense-sweep cases (Codex)
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 12 columns, instead of 11 in line 8.
n,batches,precision,family,matrix_seed,algorithm,block_dim,residual,two_by_two,median_us,min_us,max_us
63,256,float32,random,47,ldlt,64,6.707963203594388e-07,17.1328125,96.33050113916397,96.30150347948074,96.65949642658234
63,256,float32,random,47,lu_native,64,3.189055865353508e-07,0.0,100.5605012178421,100.55000334978104,100.87499767541885
63,256,float32,random,47,lu_mathdx,64,3.2291812076664263e-07,0.0,114.64650183916092,114.3840029835701,114.75600302219391
63,256,float32,kkt,47,ldlt,64,1.2501164973987116e-07,0.0,101.26599669456482,101.2440025806427,101.52450203895569
63,256,float32,kkt,47,lu_native,64,1.2385266135232413e-07,0.0,98.1760025024414,98.1459990143776,98.41199964284897
63,256,float32,kkt,47,lu_mathdx,64,1.2459839498130073e-07,0.0,113.07749897241592,113.05750161409378,113.30349743366241
63,256,float64,random,47,ldlt,64,1.3131718636163956e-15,17.1328125,241.8615072965622,241.6595071554184,242.34150350093842
63,256,float64,random,47,lu_native,64,6.097520334641678e-16,0.0,381.60398602485657,381.59048
@alecjacobson
alecjacobson / nasoq_crash_H.mtx
Created September 8, 2026 15:06
Matrix triggering SIGSEGV in NASOQ's symbolic_analysis() via structurally-zero-diagonal-block KKT system
%%MatrixMarket matrix coordinate real general
1200 1200 4963
1 1 6.92520775623268483e-04
801 1 -1.00000000000000022e+00
802 1 5.00000000000000111e-01
821 1 5.00000000000000111e-01
2 2 1.38504155124653697e-03
801 2 5.00000000000000111e-01
802 2 -2.00000000000000044e+00
803 2 5.00000000000000111e-01
#!/bin/sh
# https://stackoverflow.com/questions/13719122/how-to-use-opendiff-as-default-mergetool/36841553#36841553
# https://apple.stackexchange.com/questions/476348/use-apples-filemerge-from-command-line-and-have-it-wait-instead-of-exiting-imme
file1=$(readlink -f "$1")
file2=$(readlink -f "$2")
open -a FileMerge -n -W --args -left "$file1" -right "$file2"
@alecjacobson
alecjacobson / ElasticModuli.cpp
Created October 26, 2024 17:51
ElasticModuli class implementing the conversion table at https://en.wikipedia.org/wiki/Elastic_modulus . Setting any two input parameters will calculate the remaining four.
#include <optional>
#include <cmath>
//////////////////////////////////////////////////////////////////////////
/// ElasticModuli class implementing the conversion table at
/// https://en.wikipedia.org/wiki/Elastic_modulus
///
/// Setting any two input parameters will calculate the remaining four.
///
//////////////////////////////////////////////////////////////////////////
from semanticscholar import SemanticScholar
from collections import defaultdict
from tqdm import tqdm
import os
import builtins
import re
import unicodedata
from collections import defaultdict
@alecjacobson
alecjacobson / sparse_hessian_adolc.cpp
Created April 23, 2024 16:34
Sparse Hessian of a mass-spring system
// Adapted from ADOL-C/examples/additional_examples/sparse/sparse_hessian.cpp
#include <math.h>
#include <cstdlib>
#include <cstdio>
#include <adolc/adolc.h>
#include <adolc/adolc_sparse.h>
#define tag 1
# May need to have python 3.10 or higher installed
# Use blender to convert .gltf file to .obj file
#
import bpy
import sys
# Get the arguments passed to the script, skipping the first three
# sys.argv[0] is blender's executable, sys.argv[1] is '-P', sys.argv[2] is the script name
args = sys.argv[1:]
// https://github.com/autodiff/autodiff/issues/179
#define FORWARD
#ifdef FORWARD
#include <autodiff/forward/dual.hpp>
#else
#include <autodiff/reverse/var.hpp>
#endif
#include <complex>
template <typename T> T f(const T & x)
@alecjacobson
alecjacobson / scalar_descent_test.cpp
Last active October 15, 2023 15:14
Use C++17 auto lambdas to pass a templated function to an optimizer that will call it with both double and autodiff::real types.
// requires -std=c++17
#include <stdio.h>
#include <autodiff/forward/real.hpp> // https://github.com/autodiff/autodiff/
/// Take a gradient descent step at a given function
///
/// @tparam FuncType should be an auto-lambda (i.e., `[](auto x)->auto{…}`)
/// @param[in] func scalar function
/// @param[in] initial_guess initial input to func
/// @return initial_guess - dfdx where dfdx is the derivative of func at initial_guess
#include <cmath>
#include <cstdio>
float angle_via_law_of_cosines(float a, float b, float c)
{
return std::acos( (b+a-c) / (float(2)*std::sqrt(b*a)) );
}
float angle_via_kahan(float a, float b, float c)
{