Vectorize ========= .. cpp:class:: numpy::Vectorize numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use Vectorize Vectorize obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``Vectorize(Funcfunc, const VectorizeOptions &opts = VectorizeOptions{})`` - NP_VECTORIZE.H:76 - Operators --------- .. list-table:: :widths: 40 25 15 20 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``auto -> NDArray> operator()(const NDArray&arr)`` - auto -> NDArray> - NP_VECTORIZE.H:92 - * - ``auto -> NDArray> operator()(const NDArray&arr1, const NDArray&arr2)`` - auto -> NDArray> - NP_VECTORIZE.H:111 - * - ``auto -> NDArray> operator()(const NDArray&arr1, const NDArray&arr2, const NDArray&arr3)`` - auto -> NDArray> - NP_VECTORIZE.H:145 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t getCacheSize()`` - size_t - NP_VECTORIZE.H:193 - :ref:`View ` * - ``const VectorizeOptions & getOptions()`` - const VectorizeOptions & - NP_VECTORIZE.H:187 - * - ``const Signature & getSignature()`` - const Signature & - NP_VECTORIZE.H:182 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void clearCache()`` - void - NP_VECTORIZE.H:192 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-vectorize-getcachesize-0: .. dropdown:: getCacheSize (np_test_1_all.cpp:15260) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15250 :emphasize-lines: 11 // Verify results are identical for (size_t i = 0; i < 3; ++i) { if (std::abs(result_1.getElementAt({ i }) - result_2.getElementAt({ i })) > 1e-15) { test11_pass = false; break; } } if (test11_pass) { // std::cout << "[OK] Caching performance works correctly (cache hits: " // << cached_vectorized.getCacheSize() << ")" << std::endl; std::cout << " -> tests passed" << std::endl; } else { std::cout << "[FAIL] Caching performance failed" << std::endl; errors++; } // Test 12: Error handling std::cout << "========= test_error_handling =======================" ; .. _example-vectorize-getsignature-1: .. dropdown:: getSignature (np_test_1_all.cpp:15167) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15157 :emphasize-lines: 11 errors++; } // Test 9: Signature parsing std::cout << "========= test_signature_parsing =======================" ; auto dot_product = [](double x, double y) { return x * y; }; auto vectorized_dot = numpy::vectorize(dot_product, "(n),(n)->()"); // Test that signature is parsed correctly auto info = vectorized_dot.getSignature(); std::cout << info.isValid() << "," << info.numInputs() << "," << info.numOutputs() << ""; bool test9_pass = info.isValid() && info.numInputs() == 2 && info.numOutputs() == 1; if (test9_pass) { // std::cout << "[OK] Signature parsing works correctly"; std::cout << " -> tests passed" << std::endl; } else { std::cout << "[FAIL] Signature parsing failed" << std::endl; errors++;