-
-
Notifications
You must be signed in to change notification settings - Fork 190
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] Parallel Prototype #1616
[WIP] Parallel Prototype #1616
Changes from 122 commits
8099c90
7027c12
302cd71
9740b45
e47ca13
e94be85
9565db9
6faa614
acbb3dc
ca762fe
bc2a601
eec7472
2d696c8
8a1d99e
6d8ad8a
1a54bde
f689c93
0da9de0
73fb5ae
e7a83c6
2a370e7
bd13907
e1deb4f
358525c
13641ea
5f76ca2
d9e5276
5e01bf0
f2ed8a9
a3b4ad4
f3b37ae
940fc82
8b66f94
e56cdf2
2cece58
71c0196
e2b20d7
c0c118a
ff0f582
96e8c8e
3d62fa8
cbcf42f
8f90d8c
617d6e2
fbfa9ba
008255e
00e5743
623ed9e
16db0f2
9305fb0
bb9a1b2
430ba3f
0248bcb
b2c1dec
cf8b530
a27047f
2dd8881
5e3e078
92fe766
2d1d57e
906c262
747c73a
3da42ff
70001ac
be1ff0c
7a6b558
d440aab
89bad42
c1ac292
4ea5f1c
6075dcc
af7791e
103333c
ab1e653
29f1f71
37b516f
b76cd8c
6b93f93
e804157
66acef6
906d7b0
71d8c71
d05d452
658755d
4e18f1e
d834a4f
145ae95
9957909
3ecf79e
94989a0
c9ac276
70546f4
4cfcfe8
d46c022
ccc82e7
144bb9c
4adf05d
80ae1bf
7a1a27b
9e15292
b6b215b
66ba573
a5a50e2
55171a4
bc3b7c6
a017619
2561972
3e36ba8
38aa2af
b99d299
cc37f22
b64fe87
7d27f90
c53d29d
fb9f25a
ee1e0d7
7aa19ce
cb57e75
09d3f52
558c4ba
5dd3481
5089039
59d23cb
d6e2c00
3d03855
2c3a65d
5f64b49
6025286
4c30bc1
c702bd7
c1fd34f
1dcad2a
564ec5e
6743ff6
da8332b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef STAN_MATH_PRIM_SCAL_FUNCTOR_APPLY_HPP | ||
#define STAN_MATH_PRIM_SCAL_FUNCTOR_APPLY_HPP | ||
|
||
#include <functional> | ||
#include <tuple> | ||
#include <utility> | ||
|
||
namespace stan { | ||
namespace math { | ||
/* | ||
* Invoke the functor f with arguments given in t and indexed in the index | ||
* sequence I | ||
* | ||
* @tparam F Type of functor | ||
* @tparam Tuple Type of tuple containing arguments | ||
* @tparam I Index sequence going from 0 to std::tuple_size<T>::value - 1 | ||
* inclusive | ||
* @param f functor callable | ||
* @param t tuple of arguments | ||
* @param i placeholder variable for index sequence | ||
*/ | ||
template <class F, class Tuple, std::size_t... I> | ||
constexpr decltype(auto) apply_impl(F&& f, Tuple&& t, | ||
std::index_sequence<I...> i) { | ||
return f(std::forward<decltype(std::get<I>(t))>(std::get<I>(t))...); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be internal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I don't think so. It's meant to be used by any function in math (currently used by adj_jac_apply and here). It's not intended to be exposed to the Stan language. It'll get replaced by std::apply as soon as we get the next C++ stuff. I'll leave this decision to you. Certainly easy enough to just add an internal:: if we want. |
||
|
||
/* | ||
* Call the functor f with the tuple of arguments t, like: | ||
* | ||
* f(std::get<0>(t), std::get<1>(t), ...) | ||
* | ||
* TODO: replace this with implementation in C++ std when C++17 is available | ||
* | ||
* @tparam F Type of functor | ||
* @tparam Tuple Type of tuple containing arguments | ||
* @param f functor callable | ||
* @param t tuple of arguments | ||
*/ | ||
template <class F, class Tuple> | ||
constexpr decltype(auto) apply(F&& f, Tuple&& t) { | ||
return apply_impl(std::forward<F>(f), std::forward<Tuple>(t), | ||
std::make_index_sequence< | ||
std::tuple_size<std::remove_reference_t<Tuple>>{}>{}); | ||
} | ||
|
||
} // namespace math | ||
} // namespace stan | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef STAN_MATH_PRIM_SCAL_FUNCTOR_LEFT_FOLD_HPP | ||
#define STAN_MATH_PRIM_SCAL_FUNCTOR_LEFT_FOLD_HPP | ||
|
||
#include <stan/math/prim/meta.hpp> | ||
#include <functional> | ||
#include <tuple> | ||
#include <utility> | ||
|
||
namespace stan { | ||
namespace math { | ||
|
||
/** | ||
* Performs a left fold on a tuple with a given operation | ||
* @tparam index The index in this recursion for accessing tuple elemenTypes | ||
* @tparam Op An operation to perform on the tuple elemenTypes | ||
* @tparam Types types of tuple elements | ||
* @param op operation to perform on individual tuple elements | ||
* @param t A tuple to iterate over | ||
*/ | ||
template <size_t index, class Op, class... Types> | ||
constexpr auto left_fold(Op op, const std::tuple<Types...>& t) { | ||
if (index == sizeof...(Types) - 1) { | ||
return std::get<index>(t); | ||
} else { | ||
return op(std::get<index>(t), left_fold<1 + index>(op, t)); | ||
} | ||
} | ||
|
||
/** | ||
* Sum the elements of a tuple | ||
* @tparam Types types of the tuple's elements | ||
* @param t tuple whose elements are to be summed | ||
*/ | ||
template <typename... Types, require_stan_scalar_t<Types>...> | ||
constexpr auto sum(const std::tuple<Types...>& t) { | ||
return left_fold<0>(std::plus<>{}, t); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just get rid of this? it's cool but idt we use it anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's not needed... then it should go away. |
||
|
||
} // namespace math | ||
} // namespace stan | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.