cMHN 1.2
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, class URNG, template<class...> class D>
14 class Random : public View<T, N, Random<T, N, URNG, D>>
15 {
16 private:
18
19 public:
20 Random(URNG &rng, D<Value<T>> &distribution)
21 : mRNG(rng)
22 , mDistribution(distribution)
23 {
24 }
25
26 template<IsConvertible<Index>... Is>
27 requires(sizeof...(Is) == Base::Dimension)
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 URNG &mRNG;
63 D<Value<T>> &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(URNG &rng, D< Value< T > > &distribution)
Definition random.hpp:20
Definition declarations.hpp:20
pRC::Float<> T
Definition externs_nonTT.hpp:1
static void error(Xs &&...args)
Definition log.hpp:14
Definition declarations.hpp:18
Size Index
Definition basics.hpp:32
typename ValueType< T >::Type Value
Definition value.hpp:72
constexpr auto cDebugLevel
Definition config.hpp:48
static constexpr auto random(URNG &rng, D &distribution)
Definition random.hpp:13