NaNHandler#

class numpy::NaNHandler#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use NaNHandler
NaNHandler obj;
// ... operations ...

Type Checking#

Signature

Return Type

Location

Example

bool is_nan(Tvalue)

bool

NP_SORTING_ALGORITHMS.H:76

Other Methods#

Signature

Return Type

Location

Example

void handle_nans(std::vector<T>&values, NaNPolicypolicy)

void

NP_SORTING_ALGORITHMS.H:83

View

Code Examples#

The following examples are extracted from the test suite.

handle_nans (np_test_1_all.cpp:17382)
17372  }
17373
17374  void test_nan_handling() {
17375    std::cout << "========= test_nan_handling =======================";
17376
17377    // Test with float arrays containing NaN
17378    std::vector<float> data_with_nans = { 3.0f, std::numeric_limits<float>::quiet_NaN(), 1.0f, 2.0f, std::numeric_limits<float>::quiet_NaN() };
17379
17380    // Test LAST policy (default) - NaNs at end
17381    std::vector<float> last_policy = data_with_nans;
17382    NaNHandler<float>::handle_nans(last_policy, NaNPolicy::LAST);
17383    // Should be: [1.0, 2.0, 3.0, NaN, NaN] (but not necessarily sorted yet)
17384    if (!(last_policy.size() == 5)) {
17385        std::string description = std::string("test_nan_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(last_policy.size() == 5)";
17386        std::cout << std::string("[FAIL] ") + description << std::endl;
17387        throw std::runtime_error(description);
17388    }
17389    if (!(!std::isnan(last_policy[0]) && !std::isnan(last_policy[1]) && !std::isnan(last_policy[2]))) {
17390        std::string description = std::string("test_nan_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(last_policy[0]) && !std::isnan(last_policy[1]) && !std::isnan(last_policy[2]))";
17391        std::cout << std::string("[FAIL] ") + description << std::endl;
17392        throw std::runtime_error(description);