Skip to content

Instantly share code, notes, and snippets.

@bbbales2
bbbales2 / timeseries.py
Last active January 10, 2023 16:08
Timeseries model
View timeseries.py
from functools import reduce
from sortedcontainers import SortedSet, SortedDict
from typing import List, Callable, TypeVar, Any, Generic, Optional, Tuple, Dict
from collections import namedtuple, defaultdict
import haiku
import jax
import jax.scipy
import numpy.random
View gist:43ce7fc4adc1503bcfddd8c24afc45eb
--- Translating Stan model to C++ code ---
bin/stanc --o=lv.hpp lv.stan
--- Compiling, linking C++ code ---
clang++ -std=c++1y -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.75.0 -I stan/lib/stan_math/lib/sundials_5.7.0/include -DBOOST_DISABLE_ASSERTS -c -include-pch stan/src/stan/model/model_header.hpp.gch -x c++ -o lv.o lv.hpp
In file included from lv.hpp:1:
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from /home/bbales2/tmp/cmdstan-ode-adjoint-v3/stan/lib/stan_math/stan/math.hpp:19:
In file included from /home/bbales2/tmp/cmdstan-ode-adjoint-v3/stan/lib/stan_math/stan/math/rev.hpp:11:
In file included from /home/bbales2/tmp/cmdstan-ode-adjoint-v3/stan/lib/stan_math/stan/math/rev/functor.hpp:20:
@bbbales2
bbbales2 / constrain.hpp
Created March 5, 2021 22:47
Constrain model
View constrain.hpp
// Code generated by stanc 4f8f010
#include <stan/model/model_header.hpp>
namespace constrain_model_namespace {
inline void validate_positive_index(const char* var_name, const char* expr,
int val) {
if (val < 1) {
std::stringstream msg;
@bbbales2
bbbales2 / vector_sum.cpp
Created December 29, 2020 19:01
Benchmark column/row sums varmat vs. matvar
View vector_sum.cpp
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
static void toss_me(benchmark::State& state) {
using stan::math::var;
Eigen::Matrix<double, -1, -1> x_vals = Eigen::MatrixXd::Random(256, 256);
Eigen::Matrix<double, -1, -1> y_vals = Eigen::MatrixXd::Random(256, 256);
using stan::math::var;
using stan::math::sum;
@bbbales2
bbbales2 / scalar_bench2.cpp
Created December 16, 2020 19:22
Benchmark scalar operations on varmat and matvar
View scalar_bench2.cpp
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
static void toss_me(benchmark::State& state) {
using stan::math::var;
Eigen::Matrix<double, -1, -1> x_vals = Eigen::MatrixXd::Random(256, 256);
Eigen::Matrix<double, -1, -1> y_vals = Eigen::MatrixXd::Random(256, 256);
using stan::math::var;
using stan::math::sum;
@bbbales2
bbbales2 / scalar_bench.cpp
Created December 15, 2020 21:44
Benchmark scalar read/write of varmat/matvar
View scalar_bench.cpp
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
static void toss_me(benchmark::State& state) {
using stan::math::var;
Eigen::Matrix<double, -1, -1> x_vals = Eigen::MatrixXd::Random(256, 256);
Eigen::Matrix<double, -1, -1> y_vals = Eigen::MatrixXd::Random(256, 256);
using stan::math::var;
using stan::math::sum;
View scalar_adj_jac.cpp
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
// Just to kick off the stack allocation
static void geometric_series(benchmark::State& state) {
using stan::math::var;
for (auto _ : state) {
auto start = std::chrono::high_resolution_clock::now();
var r = 1.0;
@bbbales2
bbbales2 / prim_fun
Created May 11, 2020 20:30
Functions in stan/math/prim/fun that reference matrices
View prim_fun
MatrixExponential
accumulator
add
add_diag
append_col
append_row
assign
autocorrelation
autocovariance
block
@bbbales2
bbbales2 / apply_x_unary
Created May 11, 2020 20:29
Functions in stan/math/prim using apply_scalar_unary or apply_vector_unary
View apply_x_unary
These are all the files in stan/math/prim/fun that reference apply_scalar_unity:
acosh.hpp
acos.hpp
approx.hpp
asinh.hpp
asin.hpp
atanh.hpp
atan.hpp
cbrt.hpp
@bbbales2
bbbales2 / rev_fun.txt
Last active September 23, 2020 23:55
List of functions in stan/math/rev/fun that need reverse mode implementations for var_type<Eigen::MatrixXd>
View rev_fun.txt
adj_jac_apply - deprecated
# Fully converted to var<mat>
softmax
dot_self
columns_dot_self
determinant
inverse
sum
multiply