NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
nansum.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/Functions/sum.hpp"
36 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
51  template<typename dtype>
53  {
54  STATIC_ASSERT_FLOAT(dtype);
55 
56  NdArray<dtype> arrayCopy(inArray);
57  stl_algorithms::for_each(arrayCopy.begin(),
58  arrayCopy.end(),
59  [](dtype& value) noexcept -> void
60  {
61  if (std::isnan(value))
62  {
63  value = static_cast<dtype>(0);
64  };
65  });
66 
67  return sum(arrayCopy, inAxis);
68  }
69 } // namespace nc
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:45
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:227
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:47
NdArray< dtype > nansum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: nansum.hpp:52
NdArray< dtype > sum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: sum.hpp:46