cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
random.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_RANDOM_H
4#define pRC_CORE_TENSOR_VIEWS_RANDOM_H
5
10
11namespace pRC::TensorViews
12{
13 template<class T, class N, template<class...> class D>
14 class Random : public View<T, N, Random<T, N, D>>
15 {
16 private:
18
19 public:
21 : mRNG(rng)
22 , mDistribution(distribution)
23 {
24 }
25
26 template<class... Is, If<All<IsConvertible<Is, Index>...>> = 0,
27 If<IsSatisfied<(sizeof...(Is) == typename Base::Dimension())>> = 0>
28 constexpr decltype(auto) operator()(Is const... indices)
29 {
30 return operator()(typename Base::Subscripts(indices...));
31 }
32
33 constexpr decltype(auto) operator()(
34 [[maybe_unused]] typename Base::Subscripts const &subscripts)
35 {
36 if constexpr(cDebugLevel >= DebugLevel::Mid)
37 {
38 if(subscripts.isOutOfRange())
39 {
41 "Tensor View Random subscripts out of range.");
42 }
43 }
44
45 return random<T>(mRNG, mDistribution);
46 }
47
48 constexpr decltype(auto) operator[]([[maybe_unused]] Index const index)
49 {
50 if constexpr(cDebugLevel >= DebugLevel::Mid)
51 {
52 if(!(index < Base::size()))
53 {
54 Logging::error("Tensor View Random index out of range.");
55 }
56 }
57
58 return random<T>(mRNG, mDistribution);
59 }
60
61 private:
62 RandomEngine &mRNG;
63 D<typename T::Value> &mDistribution;
64 };
65}
66#endif // pRC_CORE_TENSOR_VIEWS_RANDOM_H
pRC::Size const D
Definition CalculatePThetaTests.cpp:9
Definition random.hpp:15
constexpr decltype(auto) operator()(Is const ... indices)
Definition random.hpp:28
Random(RandomEngine &rng, D< typename T::Value > &distribution)
Definition random.hpp:20
Definition type_traits.hpp:32
Definition threefry.hpp:24
pRC::Float<> T
Definition externs_nonTT.hpp:1
static void error(Xs &&...args)
Definition log.hpp:14
Definition diagonal.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
constexpr auto cDebugLevel
Definition config.hpp:46