VTK-m  2.2
ArrayHandleRandomStandardNormal.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_count_ArrayHandleRandomStandardNormal_h
11 #define vtk_m_count_ArrayHandleRandomStandardNormal_h
12 
13 #include <vtkm/Math.h>
17 
18 namespace vtkm
19 {
20 namespace cont
21 {
22 namespace detail
23 {
24 struct BoxMuller
25 {
27  {
28  // We take two U(0, 1) and return one N(0, 1)
29  return vtkm::Sqrt(-2.0f * vtkm::Log(uv.first)) * vtkm::Cos(2.0f * vtkm::TwoPif() * uv.second);
30  }
31 
33  {
34  // We take two U(0, 1) and return one N(0, 1)
35  return vtkm::Sqrt(-2.0 * vtkm::Log(uv.first)) * vtkm::Cos(2 * vtkm::TwoPi() * uv.second);
36  }
37 };
38 } //detail
39 
56 template <typename Real = vtkm::Float64>
59  vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandleRandomUniformReal<Real>,
60  vtkm::cont::ArrayHandleRandomUniformReal<Real>>,
61  detail::BoxMuller>
62 {
63 public:
66 
73  detail::BoxMuller>));
74 
83  SeedType seed = { std::random_device{}() })
84  : Superclass(vtkm::cont::make_ArrayHandleZip(UniformReal{ length, seed },
85  UniformReal{ length, { ~seed[0] } }),
86  detail::BoxMuller{})
87  {
88  }
89 };
90 }
91 }
92 #endif // vtk_m_count_ArrayHandleRandomStandardNormal_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Sqrt
vtkm::Float32 Sqrt(vtkm::Float32 x)
Definition: Math.h:943
VTKM_ARRAY_HANDLE_SUBCLASS
#define VTKM_ARRAY_HANDLE_SUBCLASS(classname, fullclasstype, superclass)
Macro to make default methods in ArrayHandle subclasses.
Definition: ArrayHandle.h:243
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
ArrayHandleTransform.h
vtkm::cont::ArrayHandleRandomUniformReal
An ArrayHandle that provides a source of random numbers with uniform distribution.
Definition: ArrayHandleRandomUniformReal.h:66
ArrayHandleZip.h
vtkm::cont::make_ArrayHandleZip
vtkm::cont::ArrayHandleZip< FirstHandleType, SecondHandleType > make_ArrayHandleZip(const FirstHandleType &first, const SecondHandleType &second)
A convenience function for creating an ArrayHandleZip.
Definition: ArrayHandleZip.h:290
vtkm::cont::ArrayHandleZip
ArrayHandleZip is a specialization of ArrayHandle.
Definition: ArrayHandleZip.h:253
Math.h
vtkm::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:50
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::ArrayHandleTransform
Implicitly transform values of one array to another with a functor.
Definition: ArrayHandleTransform.h:447
ArrayHandleRandomUniformReal.h
vtkm::cont::ArrayHandleRandomStandardNormal::ArrayHandleRandomStandardNormal
ArrayHandleRandomStandardNormal(vtkm::Id length, SeedType seed={ std::random_device{}() })
Construct an ArrayHandleRandomStandardNormal.
Definition: ArrayHandleRandomStandardNormal.h:82
vtkm::Vec
A short fixed-length array.
Definition: Types.h:357
vtkm::Log
vtkm::Float32 Log(vtkm::Float32 x)
Definition: Math.h:1456
vtkm::Float32
float Float32
Base type to use for 32-bit floating-point numbers.
Definition: Types.h:157
vtkm::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:161
vtkm::cont::ArrayHandleRandomStandardNormal
An ArrayHandle that provides a source of random numbers with a standard normal distribution.
Definition: ArrayHandleRandomStandardNormal.h:57
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
vtkm::Cos
vtkm::Float32 Cos(vtkm::Float32 x)
Definition: Math.h:227
vtkm::Pair
A vtkm::Pair is essentially the same as an STL pair object except that the methods (constructors and ...
Definition: Pair.h:29
vtkm::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:55