Skip to content

Instantly share code, notes, and snippets.

View alecjacobson's full-sized avatar

Alec Jacobson alecjacobson

View GitHub Profile
@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)
{
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8801572..a4ab77b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,9 +21,11 @@ include(FeatureSummary) # More verbose Output for libraries using set_package_pr
# Look for supporting libraries
# -----------------------------
-find_package(Eigen3 NO_MODULE REQUIRED)
-set_package_properties(Eigen3 PROPERTIES TYPE REQUIRED PURPOSE "C++ vector data structures")