28 template <vector_mode_t V>
35 static constexpr
bool gpu_computable = (is_single_precision_t<T> && impl::egblas::has_sbernoulli_sample_seed)
36 || (is_double_precision_t<T> && impl::egblas::has_dbernoulli_sample_seed);
53 static std::uniform_real_distribution<double> distribution(0.0, 1.0);
55 return x > distribution(rand_engine) ? 1.0 : 0.0;
65 template <
typename X,
typename Y>
69 std::uniform_int_distribution<long> seed_dist;
76 impl::egblas::bernoulli_sample_seed(
etl::size(y), alpha, t1.gpu_memory(), 1, t2.gpu_memory(), 1, seed_dist(rand_engine));
87 template <
typename X,
typename Y>
91 std::uniform_int_distribution<long> seed_dist;
96 impl::egblas::bernoulli_sample_seed(
etl::size(y), alpha, t1.gpu_memory(), 1, y.gpu_memory(), 1, seed_dist(rand_engine));
108 static std::string
desc() noexcept {
117 template <
typename G,
typename T>
119 static constexpr
bool linear =
true;
120 static constexpr
bool thread_safe =
false;
138 template <vector_mode_t V>
139 static constexpr
bool vectorizable =
false;
144 template <
typename E>
145 static constexpr
bool gpu_computable = (is_single_precision_t<T> && impl::egblas::has_sbernoulli_sample_seed)
146 || (is_double_precision_t<T> && impl::egblas::has_dbernoulli_sample_seed);
154 std::uniform_real_distribution<double> distribution(0.0, 1.0);
156 return x > distribution(rand_engine) ? 1.0 : 0.0;
166 template <
typename X,
typename Y>
168 std::uniform_int_distribution<long> seed_dist;
175 impl::egblas::bernoulli_sample_seed(
etl::size(y), alpha, t1.gpu_memory(), 1, t2.gpu_memory(), 1, seed_dist(rand_engine));
186 template <
typename X,
typename Y>
188 std::uniform_int_distribution<long> seed_dist;
193 impl::egblas::bernoulli_sample_seed(
etl::size(y), alpha, t1.gpu_memory(), 1, y.gpu_memory(), 1, seed_dist(rand_engine));
205 static std::string
desc() noexcept {
214 template <
typename T>
216 static constexpr
bool linear =
true;
217 static constexpr
bool thread_safe =
false;
224 template <vector_mode_t V>
225 static constexpr
bool vectorizable =
false;
230 template <
typename E>
231 static constexpr
bool gpu_computable = (is_single_precision_t<T> && impl::egblas::has_bernoulli_sample_prepare)
232 || (is_double_precision_t<T> && impl::egblas::has_bernoulli_sample_prepare);
236 std::shared_ptr<void*> states;
243 if constexpr (impl::egblas::has_bernoulli_sample_prepare) {
244 states = std::make_shared<void*>();
245 *states = impl::egblas::bernoulli_sample_prepare();
253 if constexpr (impl::egblas::has_bernoulli_sample_prepare) {
254 this->states = states;
256 if (!*this->states) {
257 std::uniform_int_distribution<long> seed_dist;
258 *this->states = impl::egblas::bernoulli_sample_prepare_seed(seed_dist(rand_engine));
269 std::uniform_real_distribution<double> distribution(0.0, 1.0);
271 return x > distribution(rand_engine) ? 1.0 : 0.0;
281 template <
typename X,
typename Y>
288 impl::egblas::bernoulli_sample_states(
etl::size(y), alpha, t1.gpu_memory(), 1, t2.gpu_memory(), 1, *states);
298 template <
typename X,
typename Y>
303 impl::egblas::bernoulli_sample_states(
etl::size(y), alpha, t1.gpu_memory(), 1, y.gpu_memory(), 1, *states);
315 static std::string
desc() noexcept {
324 template <
typename G,
typename T>
326 static constexpr
bool linear =
true;
327 static constexpr
bool thread_safe =
false;
334 template <vector_mode_t V>
335 static constexpr
bool vectorizable =
false;
340 template <
typename E>
341 static constexpr
bool gpu_computable = (is_single_precision_t<T> && impl::egblas::has_sbernoulli_sample_seed)
342 || (is_double_precision_t<T> && impl::egblas::has_dbernoulli_sample_seed);
346 std::shared_ptr<void*> states;
353 if constexpr (impl::egblas::has_bernoulli_sample_prepare) {
354 std::uniform_int_distribution<long> seed_dist;
356 states = std::make_shared<void*>();
357 *states = impl::egblas::bernoulli_sample_prepare_seed(seed_dist(rand_engine));
365 if constexpr (impl::egblas::has_bernoulli_sample_prepare) {
366 this->states = states;
368 if (!*this->states) {
369 std::uniform_int_distribution<long> seed_dist;
370 *this->states = impl::egblas::bernoulli_sample_prepare_seed(seed_dist(rand_engine));
381 std::uniform_real_distribution<double> distribution(0.0, 1.0);
383 return x > distribution(rand_engine) ? 1.0 : 0.0;
393 template <
typename X,
typename Y>
400 impl::egblas::bernoulli_sample_states(
etl::size(y), alpha, t1.gpu_memory(), 1, t2.gpu_memory(), 1, *states);
410 template <
typename X,
typename Y>
415 impl::egblas::bernoulli_sample_states(
etl::size(y), alpha, t1.gpu_memory(), 1, y.gpu_memory(), 1, *states);
427 static std::string
desc() noexcept {
436 template <
typename T>
438 static constexpr
bool linear =
true;
439 static constexpr
bool thread_safe =
false;
446 template <vector_mode_t V>
447 static constexpr
bool vectorizable =
false;
452 template <
typename E>
453 static constexpr
bool gpu_computable =
false;
462 static std::uniform_real_distribution<double> distribution(0.0, 1.0);
464 return x > distribution(rand_engine) ? 0.0 : 1.0;
471 static std::string
desc() noexcept {
472 return "bernoulli_reverse";
480 template <
typename G,
typename T>
482 static constexpr
bool linear =
true;
483 static constexpr
bool thread_safe =
false;
501 template <vector_mode_t V>
502 static constexpr
bool vectorizable =
false;
507 template <
typename E>
508 static constexpr
bool gpu_computable =
false;
516 std::uniform_real_distribution<double> distribution(0.0, 1.0);
518 return x > distribution(rand_engine) ? 0.0 : 1.0;
525 static std::string
desc() noexcept {
526 return "bernoulli_reverse";
Unary operation sampling with a reverse Bernoulli distribution.
Definition: bernoulli.hpp:437
state_bernoulli_unary_g_op(G &rand_engine, const std::shared_ptr< void *> &states)
Construct a new state_bernoulli_unary_g_op.
Definition: bernoulli.hpp:364
T apply(const T &x) const
Apply the unary operator on x.
Definition: bernoulli.hpp:515
static T apply(const T &x)
Apply the unary operator on x.
Definition: bernoulli.hpp:460
Unary operation sampling with a Bernoulli distribution.
Definition: bernoulli.hpp:118
static auto gpu_compute_hint(const X &x, Y &y) noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:66
Y & gpu_compute(const X &x, Y &y) const noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:411
auto gpu_compute_hint(const X &x, Y &y) const noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:394
state_bernoulli_unary_g_op(G &rand_engine)
Construct a new state_bernoulli_unary_g_op.
Definition: bernoulli.hpp:352
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: bernoulli.hpp:525
decltype(auto) select_smart_gpu_compute(X &x, Y &y)
Compute the expression into a representation that is GPU up to date and possibly store this represent...
Definition: helpers.hpp:434
bernoulli_unary_g_op(G &rand_engine)
Construct a new bernoulli_unary_g_op.
Definition: bernoulli.hpp:129
static constexpr bool linear
Indicates if the operator is linear.
Definition: bernoulli.hpp:20
T apply(const T &x) const
Apply the unary operator on x.
Definition: bernoulli.hpp:153
EGBLAS wrappers for the bernoulli_sample operation.
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: bernoulli.hpp:315
static constexpr bool thread_safe
Indicates if the operator is thread safe or not.
Definition: bernoulli.hpp:21
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: bernoulli.hpp:205
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr bool vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: bernoulli.hpp:29
T apply(const T &x) const
Apply the unary operator on x.
Definition: bernoulli.hpp:268
Y & gpu_compute(const X &x, Y &y) const noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:187
state_bernoulli_unary_op(const std::shared_ptr< void *> states)
Construct a new operator.
Definition: bernoulli.hpp:252
Unary operation sampling with a reverse Bernoulli distribution.
Definition: bernoulli.hpp:481
T apply(const T &x) const
Apply the unary operator on x.
Definition: bernoulli.hpp:380
state_bernoulli_unary_op()
Construct a new operator.
Definition: bernoulli.hpp:242
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: bernoulli.hpp:471
decltype(auto) force_temporary_gpu_dim_only(E &&expr)
Force a temporary out of the expression, without copying its content.
Definition: temporary.hpp:223
static constexpr int complexity()
Estimate the complexity of operator.
Definition: bernoulli.hpp:42
auto gpu_compute_hint(const X &x, Y &y) const noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:167
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
Unary operation sampling with a Bernoulli distribution.
Definition: bernoulli.hpp:19
Unary operation sampling with a Bernoulli distribution.
Definition: bernoulli.hpp:325
auto gpu_compute_hint(const X &x, Y &y) const noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:282
Unary operation sampling with a Bernoulli distribution.
Definition: bernoulli.hpp:215
static Y & gpu_compute(const X &x, Y &y) noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:88
static T apply(const T &x)
Apply the unary operator on x.
Definition: bernoulli.hpp:51
Y & gpu_compute(const X &x, Y &y) const noexcept
Compute the result of the operation using the GPU.
Definition: bernoulli.hpp:299
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: bernoulli.hpp:35
reverse_bernoulli_unary_g_op(G &rand_engine)
Construct a new reverse_bernoulli_unary_g_op.
Definition: bernoulli.hpp:492
std::mt19937_64 random_engine
The random engine used by the library.
Definition: random.hpp:22
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: bernoulli.hpp:108
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: bernoulli.hpp:427
decltype(auto) smart_gpu_compute_hint(E &expr, Y &y)
Compute the expression into a representation that is GPU up to date.
Definition: helpers.hpp:368