UfuncBase ========= .. cpp:class:: numpy::UfuncBase numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use UfuncBase UfuncBase obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::any getIdentity()`` - std::any - NP_UFUNC.H:41 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool hasIdentity()`` - bool - NP_UFUNC.H:40 - :ref:`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. .. _example-ufuncbase-getidentity-0: .. dropdown:: getIdentity (np_test_3_all.cpp:1055) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1045 :emphasize-lines: 11 try { auto mult_func = [](double a, double b) { return a * b; }; auto ufunc_mult = numpy::frompyfunc(mult_func, 2, 1, std::any{ 1.0 }); if (!ufunc_mult.hasIdentity()) { std::cout << "[FAIL] Identity value failed"; return 1; } double identity = std::any_cast(ufunc_mult.getIdentity()); if (std::abs(identity - 1.0) > 1e-10) { std::cout << "[FAIL] Identity value failed"; return 1; } // std::cout << "[OK] Identity value works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; return 0; } catch (const std::exception& e) { .. _example-ufuncbase-hasidentity-1: .. dropdown:: hasIdentity (np_test_3_all.cpp:1050) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1040 :emphasize-lines: 11 } // Test 8: Identity value int np_test_frompyfunc_identity_value() { std::cout << "========= np_test_frompyfunc_identity_value ======================="; try { auto mult_func = [](double a, double b) { return a * b; }; auto ufunc_mult = numpy::frompyfunc(mult_func, 2, 1, std::any{ 1.0 }); if (!ufunc_mult.hasIdentity()) { std::cout << "[FAIL] Identity value failed"; return 1; } double identity = std::any_cast(ufunc_mult.getIdentity()); if (std::abs(identity - 1.0) > 1e-10) { std::cout << "[FAIL] Identity value failed"; return 1; }