NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
nan_to_num.hpp
Go to the documentation of this file.
1
28#pragma once
29
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
52 template<typename dtype>
54 dtype nan = static_cast<dtype>(0.),
55 dtype posInf = DtypeInfo<dtype>::max(),
56 dtype negInf = DtypeInfo<dtype>::min())
57 {
59
61 inArray.end(),
62 [nan, posInf, negInf](dtype& value)
63 {
64 if (isnan(value))
65 {
66 value = nan;
67 }
68 else if (isinf(value))
69 {
70 if (value > static_cast<dtype>(0.))
71 {
72 value = posInf;
73 }
74 else
75 {
76 value = negInf;
77 }
78 }
79 });
80
81 return inArray;
82 }
83} // namespace nc
#define STATIC_ASSERT_FLOAT(dtype)
Definition StaticAsserts.hpp:50
static constexpr dtype max() noexcept
Definition DtypeInfo.hpp:110
static constexpr dtype min() noexcept
Definition DtypeInfo.hpp:98
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
iterator end() noexcept
Definition NdArrayCore.hpp:1619
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition StlAlgorithms.hpp:226
Definition Cartesian.hpp:39
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:53