Viskores  1.0
ArrayHandleRandomStandardNormal.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_count_ArrayHandleRandomStandardNormal_h
19 #define viskores_count_ArrayHandleRandomStandardNormal_h
20 
21 #include <viskores/Math.h>
25 
26 namespace viskores
27 {
28 namespace cont
29 {
30 namespace detail
31 {
32 struct BoxMuller
33 {
36  {
37  // We take two U(0, 1) and return one N(0, 1)
38  return viskores::Sqrt(-2.0f * viskores::Log(uv.first)) *
39  viskores::Cos(2.0f * viskores::TwoPif() * uv.second);
40  }
41 
44  {
45  // We take two U(0, 1) and return one N(0, 1)
46  return viskores::Sqrt(-2.0 * viskores::Log(uv.first)) *
47  viskores::Cos(2 * viskores::TwoPi() * uv.second);
48  }
49 };
50 } //detail
51 
68 template <typename Real = viskores::Float64>
69 class VISKORES_ALWAYS_EXPORT ArrayHandleRandomStandardNormal
71  viskores::cont::ArrayHandleZip<viskores::cont::ArrayHandleRandomUniformReal<Real>,
72  viskores::cont::ArrayHandleRandomUniformReal<Real>>,
73  detail::BoxMuller>
74 {
75 public:
78 
85  detail::BoxMuller>));
86 
95  SeedType seed = { std::random_device{}() })
96  : Superclass(viskores::cont::make_ArrayHandleZip(UniformReal{ length, seed },
97  UniformReal{ length, { ~seed[0] } }),
98  detail::BoxMuller{})
99  {
100  }
101 };
102 }
103 }
104 #endif // viskores_count_ArrayHandleRandomStandardNormal_h
viskores::cont::make_ArrayHandleZip
viskores::cont::ArrayHandleZip< FirstHandleType, SecondHandleType > make_ArrayHandleZip(const FirstHandleType &first, const SecondHandleType &second)
A convenience function for creating an ArrayHandleZip.
Definition: ArrayHandleZip.h:300
ArrayHandleTransform.h
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::cont::ArrayHandleZip
ArrayHandleZip is a specialization of ArrayHandle.
Definition: ArrayHandleZip.h:263
viskores::Sqrt
viskores::Float32 Sqrt(viskores::Float32 x)
Definition: Math.h:951
ArrayHandleZip.h
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores::cont::ArrayHandleRandomStandardNormal
An ArrayHandle that provides a source of random numbers with a standard normal distribution.
Definition: ArrayHandleRandomStandardNormal.h:69
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:58
viskores::Float32
float Float32
Base type to use for 32-bit floating-point numbers.
Definition: Types.h:165
viskores::Pair
A viskores::Pair is essentially the same as an STL pair object except that the methods (constructors ...
Definition: Pair.h:37
viskores::Cos
viskores::Float32 Cos(viskores::Float32 x)
Definition: Math.h:235
ArrayHandleRandomUniformReal.h
viskores::cont::ArrayHandleRandomUniformReal
An ArrayHandle that provides a source of random numbers with uniform distribution.
Definition: ArrayHandleRandomUniformReal.h:76
viskores::Log
viskores::Float32 Log(viskores::Float32 x)
Definition: Math.h:1464
VISKORES_ARRAY_HANDLE_SUBCLASS
#define VISKORES_ARRAY_HANDLE_SUBCLASS(classname, fullclasstype, superclass)
Macro to make default methods in ArrayHandle subclasses.
Definition: ArrayHandle.h:256
viskores::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:63
viskores::cont::ArrayHandleRandomStandardNormal::ArrayHandleRandomStandardNormal
ArrayHandleRandomStandardNormal(viskores::Id length, SeedType seed={ std::random_device{}() })
Construct an ArrayHandleRandomStandardNormal.
Definition: ArrayHandleRandomStandardNormal.h:94
viskores::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:169
viskores::cont::ArrayHandleTransform
Implicitly transform values of one array to another with a functor.
Definition: ArrayHandleTransform.h:461
viskores::Vec
A short fixed-length array.
Definition: Types.h:365