NumCpp  1.0
A C++ implementation of the Python Numpy library
lognormal.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Core/Shape.hpp"
37 
38 #include "boost/random/lognormal_distribution.hpp"
39 
40 #include <string>
41 
42 namespace nc
43 {
44  namespace random
45  {
46  //============================================================================
47  // Method Description:
57  template<typename dtype>
58  dtype lognormal(dtype inMean = 0, dtype inSigma = 1)
59  {
61 
62  if (inSigma <= 0)
63  {
64  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
65  }
66 
67  boost::random::lognormal_distribution<dtype> dist(inMean, inSigma);
68  return dist(generator_);
69  }
70 
71  //============================================================================
72  // Method Description:
84  template<typename dtype>
85  NdArray<dtype> lognormal(const Shape& inShape, dtype inMean = 0, dtype inSigma = 1)
86  {
88 
89  if (inSigma <= 0)
90  {
91  THROW_INVALID_ARGUMENT_ERROR("input sigma must be greater than zero.");
92  }
93 
94  NdArray<dtype> returnArray(inShape);
95 
96  boost::random::lognormal_distribution<dtype> dist(inMean, inSigma);
97 
98  stl_algorithms::for_each(returnArray.begin(), returnArray.end(),
99  [&dist](dtype& value) -> void
100  {
101  value = dist(generator_);
102  });
103 
104  return returnArray;
105  }
106  }
107 }
StaticAsserts.hpp
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::random::lognormal
dtype lognormal(dtype inMean=0, dtype inSigma=1)
Definition: lognormal.hpp:58
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f) noexcept
Definition: StlAlgorithms.hpp:214
generator.hpp
nc::NdArray< dtype >
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::random::generator_
static std::mt19937_64 generator_
generator function
Definition: generator.hpp:40
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091