Skip to content

Instantly share code, notes, and snippets.

View SteveBronder's full-sized avatar
⚔️
Chillin

Steve Bronder SteveBronder

⚔️
Chillin
View GitHub Profile
#include <cstdio>
#include <stdexcept>
#include <sstream>
#include <string>
#include <typeinfo>
#include <sstream>
#include <stdexcept>
#include <benchmark/benchmark.h>
#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
#include "toss_me.hpp"
template <typename T1, typename T2>
static void multiply_vector_vector(benchmark::State& state) {
using stan::math::var;
using stan::math::promote_scalar;
Eigen::MatrixXd x_val = Eigen::VectorXd::Random(state.range(0));
// Code generated by stanc 51d1957
#include <stan/model/model_header.hpp>
namespace glmr_model_namespace {
inline void validate_positive_index(const char* var_name, const char* expr,
int val) {
if (val < 1) {
std::stringstream msg;

Note on Sparse Matrices in Stan

Below we compare the cost of how we currently handle compressed data in Stan vs. how we would handle compressed data if Stan had a sparse matrix type.

The stan model below is a relatively common model form where we are calculating coefficients for several groups.

data {
  int N = 50,000; // # of rows
  int N_1 = 1000; // # of coefficients in group 1

Sparse Matrices, they are good!@

Below we compare the cost of how we currently handle compressed data in Stan vs. how we would handle compressed data if Stan had a sparse matrix type.

The stan model below is a relatively common model form where we are calculating coefficients for several groups.

data {
  int N = 50,000; // # of rows
  int N_1 = 1000; // # of coefficients in group 1
#ifndef STAN_MATH_REV_FUN_AENERALIZED_INVERSE_HPP
#define STAN_MATH_REV_FUN_AENERALIZED_INVERSE_HPP
auto f = [](const auto& a) {
return stan::math::generalized_inverse(a);
};
Eigen::MatrixXd A = Eigen::MatrixXd::Random(10, 10);
test_ad(f, A);
#include <stan/math/rev/core.hpp>
#include <stan/math/prim/err.hpp>
make: 'test/unit/math/mix/fun/acos_test' is up to date.
Running main() from lib/benchmark_1.5.1/googletest/googletest/src/gtest_main.cc
[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from mathMixMatFun
[ RUN ] mathMixMatFun.acos
[ OK ] mathMixMatFun.acos (356 ms)
[----------] 1 test from mathMixMatFun (356 ms total)
[----------] 1 test from MathMixMatFun
In file included from test/prob/poisson/poisson_00000_generated_ffd_test.cpp:3:
In file included from ./test/prob/test_fixture_distr.hpp:4:
In file included from ./stan/math/mix.hpp:6:
In file included from ./stan/math/rev.hpp:9:
In file included from ./stan/math/prim.hpp:12:
In file included from ./stan/math/prim/prob.hpp:276:
In file included from ./stan/math/prim/prob/poisson_log.hpp:5:
./stan/math/prim/prob/poisson_lpmf.hpp:68:28: error: no matching function for call to 'sum'
T_partials_return logp = stan::math::sum(multiply_log(n_val, lambda_val));
^~~~~~~~~~~~~~~
// Code generated by stanc 3ce704a2
#include <stan/model/model_header.hpp>
namespace bernoulli_model_namespace {
inline void validate_positive_index(const char* var_name, const char* expr,
int val) {
if (val < 1) {
std::stringstream msg;
msg << "Found dimension size less than one in simplex declaration"
https://godbolt.org/z/o693Pn