NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
nan_to_num.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include "NumCpp/NdArray.hpp"
36 
37 #include <utility>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
55  template<typename dtype>
57  dtype nan = static_cast<dtype>(0.0),
58  dtype posInf = DtypeInfo<dtype>::max(),
59  dtype negInf = DtypeInfo<dtype>::min())
60  {
61  STATIC_ASSERT_FLOAT(dtype);
62 
63  stl_algorithms::for_each(inArray.begin(), inArray.end(),
64  [nan, posInf, negInf](dtype& value)
65  {
66  if (isnan(value))
67  {
68  value = nan;
69  }
70  else if (isinf(value))
71  {
72  if (value > static_cast<dtype>(0.0))
73  {
74  value = posInf;
75  }
76  else
77  {
78  value = negInf;
79  }
80  }
81  }
82  );
83 
84  return inArray;
85  }
86 } // namespace nc
StaticAsserts.hpp
nc::NdArray< dtype >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
NdArray.hpp
STATIC_ASSERT_FLOAT
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1431
isnan.hpp
nc::nan_to_num
NdArray< dtype > nan_to_num(NdArray< dtype > inArray, dtype nan=static_cast< dtype >(0.0), dtype posInf=DtypeInfo< dtype >::max(), dtype negInf=DtypeInfo< dtype >::min())
Definition: nan_to_num.hpp:56
nc::isinf
bool isinf(dtype inValue) noexcept
Definition: isinf.hpp:51
nc::constants::nan
const double nan
NaN.
Definition: Constants.hpp:44
nc
Definition: Coordinate.hpp:44
isinf.hpp
nc::DtypeInfo
Holds info about the dtype.
Definition: DtypeInfo.hpp:40
DtypeInfo.hpp
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087