Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds require_* template type traits #1344

Merged
merged 74 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
40335ed
Adds require_* template type traits
SteveBronder Sep 7, 2019
3cb3cfd
Run clang-format
SteveBronder Sep 7, 2019
0c9e8d9
cpplint fixes
SteveBronder Sep 7, 2019
c76fe5f
fixup is_var_or_arithmetic tests
SteveBronder Sep 7, 2019
242fdda
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 7, 2019
9d95ef5
add is_vector_like header to require_generics header
SteveBronder Sep 7, 2019
790c0b9
Merge branch 'feature/require-templates' of github.com:stan-dev/math …
SteveBronder Sep 7, 2019
ce53688
move value_type from math namespace to stan namespace like the rest o…
SteveBronder Sep 7, 2019
ead4ff0
Show template style with add function
SteveBronder Sep 8, 2019
c804df3
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Sep 8, 2019
9f44861
Revert "[Jenkins] auto-formatting by clang-format version 5.0.2-svn32…
SteveBronder Sep 8, 2019
989b127
Revert "Show template style with add function"
SteveBronder Sep 8, 2019
ee140cb
merge to develop
SteveBronder Sep 10, 2019
40b27e4
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 10, 2019
346d61b
fix scalar_type_pre
SteveBronder Sep 10, 2019
67a73f5
Merge branch 'feature/require-templates' of github.com:stan-dev/math …
SteveBronder Sep 10, 2019
ca57760
fix bad merge to origin
SteveBronder Sep 10, 2019
c8c698d
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 10, 2019
cc7cc27
Have normal distribution functions in prim/scal use the requires and …
SteveBronder Sep 11, 2019
fc01589
Merge branch 'feature/require-templates' of github.com:stan-dev/math …
SteveBronder Sep 11, 2019
9bd747c
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 11, 2019
5f08c37
fix cpplint
SteveBronder Sep 11, 2019
9888994
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 11, 2019
fec06ac
Revert "fix cpplint"
SteveBronder Sep 11, 2019
8f9410b
Revert "[Jenkins] auto-formatting by clang-format version 6.0.0 (tags…
SteveBronder Sep 11, 2019
9053d80
Revert "Have normal distribution functions in prim/scal use the requi…
SteveBronder Sep 11, 2019
8ac529a
revert normal stuff until I fix operands_and_partials
SteveBronder Sep 11, 2019
cd3c7a8
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 11, 2019
d825cc3
update to develop, change not_any/all to any/all_not, update the assi…
SteveBronder Sep 25, 2019
cad97d2
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 25, 2019
8e0e903
fix cpplint whitespace
SteveBronder Sep 25, 2019
8581611
Merge branch 'feature/require-templates' of github.com:stan-dev/math …
SteveBronder Sep 25, 2019
16a9047
add back the explicit rvalue methods and constructors for matrix_cl
SteveBronder Sep 26, 2019
981b5aa
remove the .eval()s
SteveBronder Sep 26, 2019
7cb1f79
accidentally removed empty constructor
SteveBronder Sep 26, 2019
3601a64
add tests for matrix_cl assignment
SteveBronder Sep 27, 2019
d1896c9
forgot to also copy the read and write events in copy assignment
SteveBronder Sep 27, 2019
7a82301
Add back deep copy for ref assignment plus a test to make sure new me…
SteveBronder Sep 27, 2019
b34ac2c
Merge commit 'b6676952f244d6a6f90017af5b83221cd02988de' into HEAD
yashikno Sep 27, 2019
af4ee05
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 27, 2019
80d0d18
Adds vt and st to the requires for container checks
SteveBronder Sep 27, 2019
c380d9d
Merge branch 'feature/require-templates' of github.com:stan-dev/math …
SteveBronder Sep 27, 2019
a01b150
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 27, 2019
0dcd1d2
forgot a & when looking at read events
SteveBronder Sep 27, 2019
56a75a6
Merge remote-tracking branch 'origin/develop' into feature/require-te…
SteveBronder Sep 27, 2019
3d13a38
Merge remote-tracking branch 'origin/develop' into feature/require-te…
SteveBronder Oct 1, 2019
a057458
started cleaning up tests
SteveBronder Oct 1, 2019
946b095
Adds testing framework for require aliases
SteveBronder Oct 3, 2019
8e0ec57
merge to develop
SteveBronder Oct 3, 2019
9c610aa
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Oct 3, 2019
e6ca17d
use require instead of enable_if
SteveBronder Oct 3, 2019
a334b93
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Oct 3, 2019
481af84
forget to include vector in mat/meta/require tests
SteveBronder Oct 3, 2019
4e97c8f
rename all requires to use _t, _vt, or _st
SteveBronder Oct 3, 2019
88d9901
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Oct 3, 2019
934d530
forgot _t for require_same tests
SteveBronder Oct 3, 2019
3fc6b8f
fix fvar test
SteveBronder Oct 3, 2019
bd6379e
cleanup testing so we don't need one struct for ad_types and another …
SteveBronder Oct 3, 2019
906a24a
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Oct 3, 2019
5f22013
Merge remote-tracking branch 'origin/develop' into feature/require-te…
SteveBronder Oct 4, 2019
15ff684
change double with T in vector<eigen> matrix_cl constructor
SteveBronder Oct 4, 2019
408c1cd
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Oct 4, 2019
ed464f3
remove this->read_events() from constructors and add _st and _vt requ…
SteveBronder Oct 5, 2019
76dfde3
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Oct 5, 2019
a973fa7
Merge remote-tracking branch 'origin/develop' into feature/require-te…
SteveBronder Oct 7, 2019
b298924
add wait for write events when copying from matrix_cl
SteveBronder Oct 7, 2019
d2a8fa3
fix so that require_same is used to check the types match in matrix_c…
SteveBronder Oct 7, 2019
1eb2b75
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Oct 7, 2019
ef8ff87
add require for converting to string
SteveBronder Oct 8, 2019
9a5be1b
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Oct 8, 2019
a0eb72e
make a requires for checking if type T is convertible to S
SteveBronder Oct 8, 2019
b186221
make a requires for checking if type T is convertible to S
SteveBronder Oct 8, 2019
6992f07
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Oct 8, 2019
5e73b0f
remove tbb stuff
SteveBronder Oct 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Show template style with add function
  • Loading branch information
SteveBronder committed Sep 8, 2019
commit ead4ff085bb392bdfa3cd7d63c8fe56fe5a5eead
32 changes: 17 additions & 15 deletions stan/math/prim/mat/fun/add.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef STAN_MATH_PRIM_MAT_FUN_ADD_HPP
#define STAN_MATH_PRIM_MAT_FUN_ADD_HPP

#include <boost/math/tools/promotion.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/meta.hpp>
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
#include <boost/math/tools/promotion.hpp>

namespace stan {
namespace math {
Expand All @@ -21,41 +22,42 @@ namespace math {
* @throw std::invalid_argument if m1 and m2 do not have the same
* dimensions.
*/
template <typename T1, typename T2, int R, int C>
inline Eigen::Matrix<return_type_t<T1, T2>, R, C> add(
const Eigen::Matrix<T1, R, C>& m1, const Eigen::Matrix<T2, R, C>& m2) {
template <typename Mat1, typename Mat2, require_all_eigen_t<is_stan_scalar, Mat1, Mat2>...>
inline auto add(Mat1&& m1, Mat2&& m2) {
check_matching_dims("add", "m1", m1, "m2", m2);
return m1 + m2;
return (m1 + m2).eval();
}

/**
* Return the sum of the specified matrix and specified scalar.
*
* @tparam T1 Scalar type of matrix.
* @tparam T1 Type of matrix.
* @tparam T2 Type of scalar.
* @param m Matrix.
* @param c Scalar.
* @return The matrix plus the scalar.
*/
template <typename T1, typename T2, int R, int C>
inline Eigen::Matrix<return_type_t<T1, T2>, R, C> add(
const Eigen::Matrix<T1, R, C>& m, const T2& c) {
return m.array() + c;
template <typename T1, typename T2,
require_eigen_t<is_stan_scalar, T1>...,
require_not_eigen_t<is_stan_scalar, T2>...>
inline auto add(T1&& m, T2&& c) {
return (m.array() + c).eval();
}

/**
* Return the sum of the specified scalar and specified matrix.
*
* @tparam T1 Type of scalar.
* @tparam T2 Scalar type of matrix.
* @tparam T2 Type of matrix.
* @param c Scalar.
* @param m Matrix.
* @return The scalar plus the matrix.
*/
template <typename T1, typename T2, int R, int C>
inline Eigen::Matrix<return_type_t<T1, T2>, R, C> add(
const T1& c, const Eigen::Matrix<T2, R, C>& m) {
return c + m.array();
template <typename T1, typename T2,
require_not_eigen_t<is_stan_scalar, T1>...,
require_eigen_t<is_stan_scalar, T2>...>
inline auto add(T1&& c, T2& m) {
return (c + m.array()).eval();
}

} // namespace math
Expand Down
9 changes: 6 additions & 3 deletions test/unit/math/rev/mat/util.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#ifndef TEST_UNIT_MATH_REV_MAT_UTIL_HPP
#define TEST_UNIT_MATH_REV_MAT_UTIL_HPP

#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/rev/mat.hpp>
#include <gtest/gtest.h>
#include <stan/math/prim/meta.hpp>
#include <test/unit/math/rev/arr/util.hpp>
#include <gtest/gtest.h>

namespace test {

template <int R, int C>
void check_varis_on_stack(const Eigen::Matrix<stan::math::var, R, C>& x) {
template <typename Mat, stan::require_eigen_t<stan::is_var, Mat>...>
void check_varis_on_stack(Mat&& x) {
x.eval();
for (int j = 0; j < x.cols(); ++j)
for (int i = 0; i < x.rows(); ++i)
EXPECT_TRUE(stan::math::ChainableStack::instance_->memalloc_.in_stack(
Expand Down