NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
nan_to_num.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <utility>
31
37#include "NumCpp/NdArray.hpp"
38
39namespace nc
40{
41 //============================================================================
42 // Method Description:
54 template<typename dtype>
56 dtype nan = static_cast<dtype>(0.),
57 dtype posInf = DtypeInfo<dtype>::max(),
58 dtype negInf = DtypeInfo<dtype>::min())
59 {
61
63 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.))
73 {
74 value = posInf;
75 }
76 else
77 {
78 value = negInf;
79 }
80 }
81 });
82
83 return inArray;
84 }
85} // namespace nc
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:50
Holds info about the dtype.
Definition: DtypeInfo.hpp:41
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
iterator end() noexcept
Definition: NdArrayCore.hpp:1623
iterator begin() noexcept
Definition: NdArrayCore.hpp:1315
const double nan
NaN.
Definition: Core/Constants.hpp:41
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:225
Definition: Cartesian.hpp:40
bool isinf(dtype inValue) noexcept
Definition: isinf.hpp:49
NdArray< dtype > nan_to_num(NdArray< dtype > inArray, dtype nan=static_cast< dtype >(0.), dtype posInf=DtypeInfo< dtype >::max(), dtype negInf=DtypeInfo< dtype >::min())
Definition: nan_to_num.hpp:55