NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
var.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/NdArray.hpp"
33 
34 #include <algorithm>
35 #include <complex>
36 
37 namespace nc
38 {
39  //============================================================================
40  // Method Description:
51  template<typename dtype>
52  NdArray<double> var(const NdArray<dtype>& inArray, Axis inAxis = Axis::NONE)
53  {
55 
56  NdArray<double> stdValues = stdev(inArray, inAxis);
57  const auto function = [](double& value) -> void
58  {
59  value *= value;
60  };
61 
62  stl_algorithms::for_each(stdValues.begin(), stdValues.end(), function);
63  return stdValues;
64  }
65 
66  //============================================================================
67  // Method Description:
78  template<typename dtype>
79  NdArray<std::complex<double>> var(const NdArray<std::complex<dtype>>& inArray, Axis inAxis = Axis::NONE)
80  {
82 
83  NdArray<std::complex<double>> stdValues = stdev(inArray, inAxis);
84  const auto function = [](std::complex<double>& value) -> void
85  {
86  value *= value;
87  };
88 
89  stl_algorithms::for_each(stdValues.begin(), stdValues.end(), function);
90  return stdValues;
91  }
92 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
iterator end() noexcept
Definition: NdArrayCore.hpp:1558
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:46
NdArray< double > stdev(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: stdev.hpp:53
NdArray< double > var(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: var.hpp:52