UfuncBase#

class numpy::UfuncBase#

numpy C++ class.

Example#

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

// Use UfuncBase
UfuncBase obj;
// ... operations ...

Indexing / Selection#

Signature

Return Type

Location

Example

std::any getIdentity()

std::any

NP_UFUNC.H:41

View

Other Methods#

Signature

Return Type

Location

Example

bool hasIdentity()

bool

NP_UFUNC.H:40

View

size_t nin()

size_t

NP_UFUNC.H:38

size_t nout()

size_t

NP_UFUNC.H:39

std::string signature()

std::string

NP_UFUNC.H:42

Code Examples#

The following examples are extracted from the test suite.

getIdentity (np_test_3_all.cpp:1055)
1045      try {
1046        auto mult_func = [](double a, double b) { return a * b; };
1047        auto ufunc_mult = numpy::frompyfunc(mult_func, 2, 1, std::any{ 1.0 });
1048
1049        if (!ufunc_mult.hasIdentity()) {
1050          std::cout << "[FAIL] Identity value failed";
1051          return 1;
1052        }
1053
1054        double identity = std::any_cast<double>(ufunc_mult.getIdentity());
1055        if (std::abs(identity - 1.0) > 1e-10) {
1056          std::cout << "[FAIL] Identity value failed";
1057          return 1;
1058        }
1059
1060        // std::cout << "[OK] Identity value works correctly" << std::endl;
1061        std::cout << " -> tests passed" << std::endl;
1062        return 0;
1063      }
1064      catch (const std::exception& e) {
hasIdentity (np_test_3_all.cpp:1050)
1040    }
1041
1042    // Test 8: Identity value
1043    int np_test_frompyfunc_identity_value() {
1044      std::cout << "========= np_test_frompyfunc_identity_value =======================";
1045
1046      try {
1047        auto mult_func = [](double a, double b) { return a * b; };
1048        auto ufunc_mult = numpy::frompyfunc(mult_func, 2, 1, std::any{ 1.0 });
1049
1050        if (!ufunc_mult.hasIdentity()) {
1051          std::cout << "[FAIL] Identity value failed";
1052          return 1;
1053        }
1054
1055        double identity = std::any_cast<double>(ufunc_mult.getIdentity());
1056        if (std::abs(identity - 1.0) > 1e-10) {
1057          std::cout << "[FAIL] Identity value failed";
1058          return 1;
1059        }