Unverified Commit d291281c authored by Steve Bronder's avatar Steve Bronder
Browse files

Merge branch 'gpu_matrix_multiply' of https://github.com/bstatcomp/math into gpu_matrix_multiply

parents f0f5b8fa d413f207
No related merge requests found
Showing with 19 additions and 10 deletions
+19 -10
......@@ -77,7 +77,7 @@ $(BOOST)/user-config.jam:
$(BOOST_LIB)/mpi.so: $(BOOST)/user-config.jam
@mkdir -p $(dir $@)
cd $(BOOST); ./bootstrap.sh
cd $(BOOST); ./b2 --user-config=user-config.jam --layout=system --with-mpi --with-serialization -j$(BOOST_PARALLEL_BUILD) variant=release link=shared threading=multi runtime-link=shared
cd $(BOOST); ./b2 --user-config=user-config.jam --layout=system --with-mpi --with-serialization -j$(BOOST_PARALLEL_BUILD) variant=release link=shared threading=multi runtime-link=shared hardcode-dll-paths=true dll-path="$(BOOST_LIB_ABS)"
$(BOOST_LIB)/libboost_serialization.so: $(BOOST_LIB)/mpi.so
......
......@@ -81,7 +81,7 @@ class kernel_functor {
* functor to access the kernel compiler.
* @param name The name for the kernel.
* @param source A string literal containing the code for the kernel.
* @param options The values of macros to be passed at compile time.
* @param options The values of macros to be passed at compile time.
*/
kernel_functor(const char* name, const char* source,
std::map<const char*, int> options)
......@@ -135,7 +135,7 @@ struct local_range_kernel {
* Creates kernels that only need access to defining the global work size.
* @param name The name for the kernel
* @param source A string literal containing the code for the kernel.
* @param options The values of macros to be passed at compile time.
* @param options The values of macros to be passed at compile time.
*/
local_range_kernel(const char* name, const char* source,
std::map<const char*, int> options = {{"NO_OPT", 0}})
......
......@@ -3,6 +3,7 @@
#include <cstddef>
#include <vector>
#include <numeric>
namespace stan {
namespace math {
......@@ -16,12 +17,7 @@ namespace math {
*/
template <typename T>
inline T sum(const std::vector<T>& xs) {
if (xs.size() == 0)
return 0;
T sum(xs[0]);
for (size_t i = 1; i < xs.size(); ++i)
sum += xs[i];
return sum;
return std::accumulate(xs.begin(), xs.end(), T{0});
}
} // namespace math
......
......@@ -19,7 +19,7 @@ namespace math {
* @return Sum of coefficients of vector.
*/
template <typename T, int R, int C>
inline double sum(const Eigen::Matrix<T, R, C>& v) {
inline T sum(const Eigen::Matrix<T, R, C>& v) {
return v.sum();
}
......
#include <stan/math/prim/mat.hpp>
#include <gtest/gtest.h>
#include <test/unit/util.hpp>
#include <type_traits>
#include <vector>
TEST(MathMatrix, sumVector) {
using Eigen::Dynamic;
......@@ -54,3 +57,13 @@ TEST(MathMatrix, sumMatrix) {
m << 1, 2, 3, 4, 5, 6;
EXPECT_FLOAT_EQ(21.0, sum(m));
}
template <typename T>
using sum_return_t = decltype(stan::math::sum(std::declval<T>()));
TEST(MathMatrix, sumIsTemplated) {
using Eigen::Matrix;
test::expect_same_type<int, sum_return_t<Matrix<int, 2, 3>>>();
test::expect_same_type<double, sum_return_t<Matrix<double, 4, 2>>>();
test::expect_same_type<float, sum_return_t<std::vector<float>>>();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment