Skip to content

Instantly share code, notes, and snippets.

View SteveBronder's full-sized avatar
⚔️
Chillin

Steve Bronder SteveBronder

⚔️
Chillin
View GitHub Profile

Stan 2.15 Release Notes

This release cycle is dedicated to some nice "slice of life" features for Stan users and developers.

First, for users we've started adding vectorized binary functions to the language. This means that users can now right code such as

 matrix[17, 93] u[12];
 matrix[17, 93] z[12];
 z = pow(u, 2.0);
--------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
--------------------------------------------------------------------------------------------
toss_me<mem_size> 521658152 ns 521655319 ns 1
dot_product_test<var, var>/2/manual_time 34.8 ns 85.3 ns 20068728
dot_product_test<var, var>/4/manual_time 43.0 ns 109 ns 16041541
dot_product_test<var, var>/8/manual_time 50.3 ns 143 ns 13898465
dot_product_test<var, var>/16/manual_time 68.5 ns 218 ns 10655759
dot_product_test<var, var>/32/manual_time 124 ns 380 ns 5482916
dot_product_test<var, var>/64/manual_time 231 ns 725 ns 3029805
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
static bool needs_done = true;
// Just to fill up the stack allocator
template <int max_alloc>
static void toss_me(benchmark::State& state) {
using stan::math::var;
if (needs_done) {
#ifndef STAN_MATH_REV_FUN_DOT_PRODUCT_HPP
#define STAN_MATH_REV_FUN_DOT_PRODUCT_HPP
#include <stan/math/rev/meta.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/rev/fun/value_of.hpp>
#include <stan/math/rev/fun/to_arena.hpp>
#include <stan/math/rev/core/arena_matrix.hpp>
#include <stan/math/rev/functor/reverse_pass_callback.hpp>
#include <stan/math/prim/meta.hpp>
valgrind -s --show-leak-kinds=all --leak-check=full test/unit/math/mix/fun/tcrossprod_test
==1151514== Memcheck, a memory error detector
==1151514== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1151514== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==1151514== Command: test/unit/math/mix/fun/tcrossprod_test
==1151514==
Running main() from lib/benchmark_1.5.1/googletest/googletest/src/gtest_main.cc
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from MathMixMatFun
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
#include <utility>
#include "toss_me.hpp"
#include "callback_bench_impl.hpp"
static void tcrossprod(benchmark::State& state) {
using stan::math::var;
using stan::math::promote_scalar;
using stan::math::tcrossprod;
benchmark size grain time cpu iteration
exp_ParMap_var 128 16 17651 26609 39833
exp_ParMap_var 256 16 26033 44690 26965
exp_ParMap_var 512 16 36565 82138 18701
exp_ParMap_var 1024 16 56113 128538 12465
exp_ParMap_var 2048 16 75671 221892 9356
exp_ParMap_var 4096 16 105999 395385 6540
exp_ParMap_var 8192 16 166110 731292 4309
exp_ParMap_var 16384 16 329069 1457103 2147
exp_ParMap_var 32768 16 570971 2736153 1249
#include <benchmark/benchmark.h>
#include <stan/math.hpp>
static void exp_ParMap_dbl(benchmark::State &state) {
Eigen::Matrix<double, -1, 1> m_d = Eigen::VectorXd::Random(state.range(0));
Eigen::Matrix<double, -1, 1> m_res(state.range(0));
// Functor defining how inputs should be indexed
auto ind_f = [](auto&& i, auto&& j, auto&& fun, auto&& x) {
return fun(x.segment(i, j));
};
# -*- coding: utf-8 -*-
# This file is part of Eigen, a lightweight C++ template library
# for linear algebra.
#
# Copyright (C) 2009 Benjamin Schindler <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
https://godbolt.org/z/MYscsE