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

[WIP] Use auto and more general template types #1309

Closed
wants to merge 60 commits into from
Closed
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6d0bc8a
Use auto in multiply, subtract, and add
SteveBronder Aug 14, 2019
11132f2
Merge commit '2b87cca584fe033bafb069cd375a77bb9a63a7b3' into HEAD
yashikno Aug 14, 2019
ca4b0aa
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Aug 14, 2019
057b37b
Move eigen stuff to prim/mat/meta.hpp
SteveBronder Aug 14, 2019
ac745e4
Merge branch 'code-cleanup/auto' of github.com:bstatcomp/math into co…
SteveBronder Aug 14, 2019
cca759a
Fix protect header for enable_eigen and enable_eigen_vector
SteveBronder Aug 14, 2019
af1c270
Update metaprogramming so they work with generic Eigen types
SteveBronder Aug 14, 2019
26e3b1a
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Aug 14, 2019
e16e8fa
update to make sure type_traits is in the meta headers
SteveBronder Aug 14, 2019
a72e685
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 14, 2019
3243df1
Changed apply_scalar_unary tests from hpp to cpp so that they execute…
SteveBronder Aug 14, 2019
d4dd472
Merge branch 'code-cleanup/auto' of github.com:bstatcomp/math into co…
SteveBronder Aug 14, 2019
5587834
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 14, 2019
e6141f5
Remove old apply_scaler_unary for int
SteveBronder Aug 14, 2019
f2980fd
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 14, 2019
193f649
Update docs for apply_scalar_unary
SteveBronder Aug 14, 2019
270cff3
Merge branch 'code-cleanup/auto' of github.com:bstatcomp/math into co…
SteveBronder Aug 14, 2019
4d0396c
fix headers to pull in meta structs correctly
SteveBronder Aug 14, 2019
ff8b194
Cleanup is_vector template specialization
SteveBronder Aug 14, 2019
b39b397
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Aug 14, 2019
219627f
Cleanup is_vector template specialization
SteveBronder Aug 14, 2019
3876030
Forgot > in arr is_vector
SteveBronder Aug 14, 2019
3cb3bcd
Add header for enable_if_eigen in prim/mat/meta/is_vector_like
SteveBronder Aug 14, 2019
96d9ffd
Add header for enable_if_eigen in prim/mat/meta/is_vector_like
SteveBronder Aug 14, 2019
55295b0
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 14, 2019
17e8375
Update functions in prim to use enable_ifs for Eigen types
SteveBronder Aug 14, 2019
8fa189d
Merge branch 'code-cleanup/auto' of github.com:bstatcomp/math into co…
SteveBronder Aug 14, 2019
7813d5a
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 14, 2019
f7a3d33
standardize templates for prim functions
SteveBronder Aug 15, 2019
a4e3017
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 15, 2019
702c636
fixup more of prim and start removing fwd
SteveBronder Aug 15, 2019
956d0e7
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 15, 2019
8a9211d
Update error checks to handle new eigen types
SteveBronder Aug 15, 2019
cbb2745
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 15, 2019
5c3c7b0
use abs instead of fabs in check_symmetric
SteveBronder Aug 15, 2019
09254d7
fix for scalar_type of fvar
SteveBronder Aug 15, 2019
4ffd3c5
fix is_fvar in fwd scalar_type
SteveBronder Aug 15, 2019
cc42424
fix scalar_type for fvar
SteveBronder Aug 16, 2019
45522ed
Fix OpenCL Multiply
SteveBronder Aug 16, 2019
a17c405
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Aug 16, 2019
a6c1845
move enable_if functions to a generic folder and fixup opencl/rev mul…
SteveBronder Aug 16, 2019
a230871
merge clang-format
SteveBronder Aug 16, 2019
dc3b639
Merge commit '915b7896841ebca22b414838b7a4a33ac30029a8' into HEAD
yashikno Aug 16, 2019
6117e70
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Aug 16, 2019
ed7ef25
fix for cpplint
SteveBronder Aug 16, 2019
8690c13
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Aug 16, 2019
1d95ef4
fix names so doxygen does not get mad
SteveBronder Aug 16, 2019
7bae8d9
Merge branch 'code-cleanup/auto' of github.com:bstatcomp/math into co…
SteveBronder Aug 16, 2019
24d865f
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Aug 16, 2019
4f00232
fix names so doxygen does not get mad
SteveBronder Aug 16, 2019
8fe5d40
Merge branch 'code-cleanup/auto' of github.com:bstatcomp/math into co…
SteveBronder Aug 16, 2019
b26394f
update to fix tempalte instational error in multiply
SteveBronder Aug 16, 2019
2b24ad5
[Jenkins] auto-formatting by clang-format version 5.0.2-svn328729-1~e…
stan-buildbot Aug 16, 2019
14575b2
fix cpplint error
SteveBronder Aug 16, 2019
6b6f27d
remove eigen_helpers
SteveBronder Aug 16, 2019
9fd6746
remove enable_if_fvar in fwd folder
SteveBronder Aug 16, 2019
6d27722
put back multiply fvar
SteveBronder Aug 17, 2019
5a18142
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Aug 17, 2019
89293df
revert changes to fvar
SteveBronder Aug 17, 2019
ef0b68d
revert changes to_fvar
SteveBronder Aug 17, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -5,10 +5,10 @@
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
#include <stan/math/fwd/mat/fun/typedefs.hpp>
#include <stan/math/fwd/core.hpp>

#include <stan/math/prim/mat/fun/columns_dot_product.hpp>
namespace stan {
namespace math {

#ifdef NOOO
template <typename T, int R1, int C1, int R2, int C2>
inline Eigen::Matrix<fvar<T>, 1, C1> columns_dot_product(
const Eigen::Matrix<fvar<T>, R1, C1>& v1,
@@ -50,7 +50,7 @@ inline Eigen::Matrix<fvar<T>, 1, C1> columns_dot_product(
}
return ret;
}

#endif
} // namespace math
} // namespace stan
#endif
@@ -4,10 +4,10 @@
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/mat/fun/dot_self.hpp>

#include <stan/math/prim/mat.hpp>
namespace stan {
namespace math {

#ifdef NOOOO
template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, 1, C> columns_dot_self(
const Eigen::Matrix<fvar<T>, R, C>& x) {
@@ -18,6 +18,7 @@ inline Eigen::Matrix<fvar<T>, 1, C> columns_dot_self(
}
return ret;
}
#endif
} // namespace math
} // namespace stan
#endif
@@ -5,17 +5,4 @@
#include <stan/math/fwd/mat/fun/multiply.hpp>
#include <stan/math/prim/mat/fun/transpose.hpp>

namespace stan {
namespace math {

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, C, C> crossprod(
const Eigen::Matrix<fvar<T>, R, C>& m) {
if (m.rows() == 0)
return Eigen::Matrix<fvar<T>, C, C>(0, 0);
return multiply(transpose(m), m);
}

} // namespace math
} // namespace stan
#endif
@@ -3,60 +3,5 @@

#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/fwd/core.hpp>

namespace stan {
namespace math {

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> divide(
const Eigen::Matrix<fvar<T>, R, C>& v, const fvar<T>& c) {
Eigen::Matrix<fvar<T>, R, C> res(v.rows(), v.cols());
for (int i = 0; i < v.rows(); i++) {
for (int j = 0; j < v.cols(); j++)
res(i, j) = v(i, j) / c;
}
return res;
}

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> divide(
const Eigen::Matrix<fvar<T>, R, C>& v, double c) {
Eigen::Matrix<fvar<T>, R, C> res(v.rows(), v.cols());
for (int i = 0; i < v.rows(); i++) {
for (int j = 0; j < v.cols(); j++)
res(i, j) = v(i, j) / c;
}
return res;
}

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> divide(const Eigen::Matrix<double, R, C>& v,
const fvar<T>& c) {
Eigen::Matrix<fvar<T>, R, C> res(v.rows(), v.cols());
for (int i = 0; i < v.rows(); i++) {
for (int j = 0; j < v.cols(); j++)
res(i, j) = v(i, j) / c;
}
return res;
}

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> operator/(
const Eigen::Matrix<fvar<T>, R, C>& v, const fvar<T>& c) {
return divide(v, c);
}

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> operator/(
const Eigen::Matrix<fvar<T>, R, C>& v, double c) {
return divide(v, c);
}

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> operator/(
const Eigen::Matrix<double, R, C>& v, const fvar<T>& c) {
return divide(v, c);
}
} // namespace math
} // namespace stan
#include <stan/math/prim/mat.hpp>
#endif
@@ -5,146 +5,7 @@
#include <stan/math/prim/mat/err/check_vector.hpp>
#include <stan/math/prim/arr/err/check_matching_sizes.hpp>
#include <stan/math/fwd/mat/fun/typedefs.hpp>
#include <stan/math/prim/mat.hpp>
#include <vector>

namespace stan {
namespace math {

template <typename T, int R1, int C1, int R2, int C2>
inline fvar<T> dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
check_vector("dot_product", "v1", v1);
check_vector("dot_product", "v2", v2);
check_matching_sizes("dot_product", "v1", v1, "v2", v2);

fvar<T> ret(0, 0);
for (size_type i = 0; i < v1.size(); i++)
ret += v1(i) * v2(i);
return ret;
}

template <typename T, int R1, int C1, int R2, int C2>
inline fvar<T> dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
const Eigen::Matrix<double, R2, C2>& v2) {
check_vector("dot_product", "v1", v1);
check_vector("dot_product", "v2", v2);
check_matching_sizes("dot_product", "v1", v1, "v2", v2);

fvar<T> ret(0, 0);
for (size_type i = 0; i < v1.size(); i++)
ret += v1(i) * v2(i);
return ret;
}

template <typename T, int R1, int C1, int R2, int C2>
inline fvar<T> dot_product(const Eigen::Matrix<double, R1, C1>& v1,
const Eigen::Matrix<fvar<T>, R2, C2>& v2) {
check_vector("dot_product", "v1", v1);
check_vector("dot_product", "v2", v2);
check_matching_sizes("dot_product", "v1", v1, "v2", v2);

fvar<T> ret(0, 0);
for (size_type i = 0; i < v1.size(); i++)
ret += v1(i) * v2(i);
return ret;
}

template <typename T, int R1, int C1, int R2, int C2>
inline fvar<T> dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
const Eigen::Matrix<fvar<T>, R2, C2>& v2,
size_type& length) {
check_vector("dot_product", "v1", v1);
check_vector("dot_product", "v2", v2);

fvar<T> ret(0, 0);
for (size_type i = 0; i < length; i++)
ret += v1(i) * v2(i);
return ret;
}

template <typename T, int R1, int C1, int R2, int C2>
inline fvar<T> dot_product(const Eigen::Matrix<fvar<T>, R1, C1>& v1,
const Eigen::Matrix<double, R2, C2>& v2,
size_type& length) {
check_vector("dot_product", "v1", v1);
check_vector("dot_product", "v2", v2);

fvar<T> ret(0, 0);
for (size_type i = 0; i < length; i++)
ret += v1(i) * v2(i);
return ret;
}

template <typename T, int R1, int C1, int R2, int C2>
inline fvar<T> dot_product(const Eigen::Matrix<double, R1, C1>& v1,
const Eigen::Matrix<fvar<T>, R2, C2>& v2,
size_type& length) {
check_vector("dot_product", "v1", v1);
check_vector("dot_product", "v2", v2);

fvar<T> ret(0, 0);
for (size_type i = 0; i < length; i++)
ret += v1(i) * v2(i);
return ret;
}

template <typename T>
inline fvar<T> dot_product(const std::vector<fvar<T> >& v1,
const std::vector<fvar<T> >& v2) {
check_matching_sizes("dot_product", "v1", v1, "v2", v2);
fvar<T> ret(0, 0);
for (size_t i = 0; i < v1.size(); i++)
ret += v1.at(i) * v2.at(i);
return ret;
}

template <typename T>
inline fvar<T> dot_product(const std::vector<double>& v1,
const std::vector<fvar<T> >& v2) {
check_matching_sizes("dot_product", "v1", v1, "v2", v2);
fvar<T> ret(0, 0);
for (size_t i = 0; i < v1.size(); i++)
ret += v1.at(i) * v2.at(i);
return ret;
}

template <typename T>
inline fvar<T> dot_product(const std::vector<fvar<T> >& v1,
const std::vector<double>& v2) {
check_matching_sizes("dot_product", "v1", v1, "v2", v2);
fvar<T> ret(0, 0);
for (size_t i = 0; i < v1.size(); i++)
ret += v1.at(i) * v2.at(i);
return ret;
}

template <typename T>
inline fvar<T> dot_product(const std::vector<fvar<T> >& v1,
const std::vector<fvar<T> >& v2, size_type& length) {
fvar<T> ret(0, 0);
for (size_type i = 0; i < length; i++)
ret += v1.at(i) * v2.at(i);
return ret;
}

template <typename T>
inline fvar<T> dot_product(const std::vector<double>& v1,
const std::vector<fvar<T> >& v2, size_type& length) {
fvar<T> ret(0, 0);
for (size_type i = 0; i < length; i++)
ret += v1.at(i) * v2.at(i);
return ret;
}

template <typename T>
inline fvar<T> dot_product(const std::vector<fvar<T> >& v1,
const std::vector<double>& v2, size_type& length) {
fvar<T> ret(0, 0);
for (size_type i = 0; i < length; i++)
ret += v1.at(i) * v2.at(i);
return ret;
}

} // namespace math
} // namespace stan
#endif
@@ -5,16 +5,5 @@
#include <stan/math/prim/mat/err/check_vector.hpp>
#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/mat/fun/dot_product.hpp>

namespace stan {
namespace math {

template <typename T, int R, int C>
inline fvar<T> dot_self(const Eigen::Matrix<fvar<T>, R, C>& v) {
check_vector("dot_self", "v", v);
return dot_product(v, v);
}

} // namespace math
} // namespace stan
#include <stan/math/prim/mat.hpp>
#endif
@@ -8,32 +8,4 @@
#include <stan/math/fwd/mat/fun/multiply.hpp>
#include <stan/math/prim/mat/fun/inverse.hpp>
#include <stan/math/prim/mat/err/check_square.hpp>

namespace stan {
namespace math {

template <typename T, int R, int C>
inline Eigen::Matrix<fvar<T>, R, C> inverse(
const Eigen::Matrix<fvar<T>, R, C>& m) {
check_square("inverse", "m", m);
Eigen::Matrix<T, R, C> m_deriv(m.rows(), m.cols());
Eigen::Matrix<T, R, C> m_inv(m.rows(), m.cols());

for (size_type i = 0; i < m.rows(); i++) {
for (size_type j = 0; j < m.cols(); j++) {
m_inv(i, j) = m(i, j).val_;
m_deriv(i, j) = m(i, j).d_;
}
}

m_inv = inverse(m_inv);

m_deriv = multiply(multiply(m_inv, m_deriv), m_inv);
m_deriv = -m_deriv;

return to_fvar(m_inv, m_deriv);
}

} // namespace math
} // namespace stan
#endif
@@ -7,17 +7,17 @@
#include <stan/math/fwd/scal/fun/fabs.hpp>
#include <stan/math/fwd/scal/fun/log.hpp>
#include <stan/math/prim/mat/err/check_square.hpp>

#include <stan/math/prim/mat.hpp>
namespace stan {
namespace math {

#ifdef NOOOO
template <typename T, int R, int C>
inline fvar<T> log_determinant(const Eigen::Matrix<fvar<T>, R, C>& m) {
check_square("log_determinant", "m", m);

return log(fabs(determinant(m)));
}

#endif
} // namespace math
} // namespace stan
#endif
@@ -9,7 +9,7 @@

namespace stan {
namespace math {

#ifdef NOOOOO
template <typename T>
inline Eigen::Matrix<fvar<T>, Eigen::Dynamic, 1> log_softmax(
const Eigen::Matrix<fvar<T>, Eigen::Dynamic, 1>& alpha) {
@@ -43,7 +43,7 @@ inline Eigen::Matrix<fvar<T>, Eigen::Dynamic, 1> log_softmax(

return log_softmax_alpha;
}

#endif
} // namespace math
} // namespace stan
#endif
@@ -5,10 +5,10 @@
#include <stan/math/prim/mat/err/check_matching_dims.hpp>
#include <stan/math/fwd/mat/fun/dot_product.hpp>
#include <stan/math/fwd/core.hpp>

#include <stan/math/prim/mat.hpp>
namespace stan {
namespace math {

#ifdef NOOOO
template <typename T, int R1, int C1, int R2, int C2>
inline Eigen::Matrix<fvar<T>, R1, 1> rows_dot_product(
const Eigen::Matrix<fvar<T>, R1, C1>& v1,
@@ -50,7 +50,7 @@ inline Eigen::Matrix<fvar<T>, R1, 1> rows_dot_product(
}
return ret;
}

#endif
} // namespace math
} // namespace stan
#endif
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.