VTK-m  2.0
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 
40 template <typename Real = vtkm::Float64>
43  vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandleRandomUniformReal<Real>,
44  vtkm::cont::ArrayHandleRandomUniformReal<Real>>,
45  detail::BoxMuller>
46 {
47 public:
50 
57  detail::BoxMuller>));
58 
60  SeedType seed = { std::random_device{}() })
61  : Superclass(vtkm::cont::make_ArrayHandleZip(UniformReal{ length, seed },
62  UniformReal{ length, { ~seed[0] } }),
63  detail::BoxMuller{})
64  {
65  }
66 };
67 }
68 }
69 #endif // vtk_m_count_ArrayHandleRandomStandardNormal_h
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Cos
VTKM_EXEC_CONT vtkm::Float32 Cos(vtkm::Float32 x)
Compute the cosine of x.
Definition: Math.h:269
VTKM_ARRAY_HANDLE_SUBCLASS
#define VTKM_ARRAY_HANDLE_SUBCLASS(classname, fullclasstype, superclass)
Macro to make default methods in ArrayHandle subclasses.
Definition: ArrayHandle.h:226
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
ArrayHandleTransform.h
vtkm::cont::ArrayHandleRandomUniformReal
Definition: ArrayHandleRandomUniformReal.h:54
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ArrayHandleZip.h
vtkm::cont::ArrayHandleZip
ArrayHandleZip is a specialization of ArrayHandle.
Definition: ArrayHandleZip.h:251
Math.h
vtkm::cont::make_ArrayHandleZip
VTKM_CONT vtkm::cont::ArrayHandleZip< FirstHandleType, SecondHandleType > make_ArrayHandleZip(const FirstHandleType &first, const SecondHandleType &second)
A convenience function for creating an ArrayHandleZip.
Definition: ArrayHandleZip.h:288
vtkm::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:50
vtkm::cont::ArrayHandleTransform
Implicitly transform values of one array to another with a functor.
Definition: ArrayHandleTransform.h:437
ArrayHandleRandomUniformReal.h
vtkm::cont::ArrayHandleRandomStandardNormal::ArrayHandleRandomStandardNormal
ArrayHandleRandomStandardNormal(vtkm::Id length, SeedType seed={ std::random_device{}() })
Definition: ArrayHandleRandomStandardNormal.h:59
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::cont::ArrayHandleRandomStandardNormal
Definition: ArrayHandleRandomStandardNormal.h:41
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
vtkm::Log
VTKM_EXEC_CONT vtkm::Float32 Log(vtkm::Float32 x)
Computes the natural logarithm of x.
Definition: Math.h:1455
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