NumCpp  2.1.0
A C++ implementation of the Python Numpy library
nansum.hpp
Go to the documentation of this file.
1 #pragma once
30 
33 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/Functions/sum.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 #include <cmath>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
53  template<typename dtype>
54  NdArray<dtype> nansum(const NdArray<dtype>& inArray, Axis inAxis = Axis::NONE)
55  {
56  STATIC_ASSERT_FLOAT(dtype);
57 
58  NdArray<dtype> arrayCopy(inArray);
59  stl_algorithms::for_each(arrayCopy.begin(), arrayCopy.end(),
60  [](dtype& value) noexcept -> void
61  {
62  if (std::isnan(value)) { value = static_cast<dtype>(0); };
63  });
64 
65  return sum(arrayCopy, inAxis);
66  }
67 } // namespace nc
StaticAsserts.hpp
nc::Axis::NONE
@ NONE
nc::nansum
NdArray< dtype > nansum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: nansum.hpp:54
nc::NdArray< dtype >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:214
NdArray.hpp
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:44
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
nc::sum
NdArray< dtype > sum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: sum.hpp:48
nc::Axis
Axis
Enum To describe an axis.
Definition: Types.hpp:47
nc
Definition: Coordinate.hpp:45
sum.hpp
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091