Skip to content

Instantly share code, notes, and snippets.

@bbbales2
bbbales2 / test_jacobian.cpp
Created September 9, 2017 18:30
File for benchmarking different ways to compute Jacobians
#include <iostream>
#include "stan/math.hpp"
#include "stan/math/fwd/mat.hpp"
using namespace stan::math;
template<typename T1, typename T2>
std::vector<typename stan::return_type<T1, T2>::type > ode(const double& t,
const std::vector<T1>& u,
const std::vector<T2>& D,
@bbbales2
bbbales2 / adj_jac_apply_benchmark_test.cpp
Last active September 4, 2018 14:17
adj_jac_apply additiion benchmarks
#include <stan/math/rev/core.hpp>
#include <test/unit/math/rev/mat/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <vector>
#include <chrono>
namespace stan {
@bbbales2
bbbales2 / solve_functor_test.cpp
Last active September 4, 2018 17:22
Example use of adj_jac_apply to solve Ax = b
#include <stan/math/rev/core.hpp>
#include <test/unit/math/rev/mat/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
#include <random>
#include <sstream>
#include <tuple>
namespace stan {
namespace math {
@bbbales2
bbbales2 / apply_x_unary
Created May 11, 2020 20:29
Functions in stan/math/prim using apply_scalar_unary or apply_vector_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 / prim_fun
Created May 11, 2020 20:30
Functions in stan/math/prim/fun that reference matrices
MatrixExponential
accumulator
add
add_diag
append_col
append_row
assign
autocorrelation
autocovariance
block
#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 / 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>
adj_jac_apply - deprecated
# Fully converted to var<mat>
softmax
dot_self
columns_dot_self
determinant
inverse
sum
multiply
@bbbales2
bbbales2 / scalar_bench.cpp
Created December 15, 2020 21:44
Benchmark scalar read/write of varmat/matvar
#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
#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 / vector_sum.cpp
Created December 29, 2020 19:01
Benchmark column/row sums varmat vs. matvar
#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;