Skip to content

Instantly share code, notes, and snippets.

View alecjacobson's full-sized avatar

Alec Jacobson alecjacobson

View GitHub Profile
@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 sys
import os
s2_api_key = 'replaceme'
sch = SemanticScholar(timeout=10,api_key=s2_api_key)
print("Connected to SemanticScholar")
@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")
# HG changeset patch
# User Torbjorn Granlund <[email protected]>
# Date 1606685500 -3600
# Node ID 5f32dbc41afc1f8cd77af1614f0caeb24deb7d7b
# Parent 94c84d919f83ba963ed1809f8e80c7bef32db55c
Avoid the x18 register since it is reserved on Darwin.
diff -r 94c84d919f83 -r 5f32dbc41afc mpn/arm64/aors_n.asm
--- a/mpn/arm64/aors_n.asm Sat Nov 28 23:38:32 2020 +0100
@alecjacobson
alecjacobson / say.py
Last active March 5, 2023 23:54
Quick replacement for mac os `say` using Google Text To Speech
# https://stackoverflow.com/a/51164950/148668
#
# python3 -m pip install gtts playsound pyobjc
from gtts import gTTS
import sys
from io import BytesIO
import objc
import playsound
import tempfile
import argparse