Vectorize#
-
class numpy::Vectorize#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use Vectorize
Vectorize obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_VECTORIZE.H:76 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
auto -> NDArray<std::invoke_result_t<Func, T>> |
NP_VECTORIZE.H:92 |
|
|
auto -> NDArray<std::invoke_result_t<Func, T1, T2>> |
NP_VECTORIZE.H:111 |
|
|
auto -> NDArray<std::invoke_result_t<Func, T1, T2, T3>> |
NP_VECTORIZE.H:145 |
Indexing / Selection#
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_VECTORIZE.H:192 |
Code Examples#
The following examples are extracted from the test suite.
getCacheSize (np_test_1_all.cpp:15260)
15250 // Verify results are identical
15251 for (size_t i = 0; i < 3; ++i) {
15252 if (std::abs(result_1.getElementAt({ i }) - result_2.getElementAt({ i })) > 1e-15) {
15253 test11_pass = false;
15254 break;
15255 }
15256 }
15257
15258 if (test11_pass) {
15259 // std::cout << "[OK] Caching performance works correctly (cache hits: "
15260 // << cached_vectorized.getCacheSize() << ")" << std::endl;
15261 std::cout << " -> tests passed" << std::endl;
15262 }
15263 else {
15264 std::cout << "[FAIL] Caching performance failed" << std::endl;
15265 errors++;
15266 }
15267
15268 // Test 12: Error handling
15269 std::cout << "========= test_error_handling =======================" ;
getSignature (np_test_1_all.cpp:15167)
15157 errors++;
15158 }
15159
15160 // Test 9: Signature parsing
15161 std::cout << "========= test_signature_parsing =======================" ;
15162
15163 auto dot_product = [](double x, double y) { return x * y; };
15164 auto vectorized_dot = numpy::vectorize(dot_product, "(n),(n)->()");
15165
15166 // Test that signature is parsed correctly
15167 auto info = vectorized_dot.getSignature();
15168 std::cout << info.isValid() << "," << info.numInputs() << "," << info.numOutputs() << "";
15169 bool test9_pass = info.isValid() && info.numInputs() == 2 && info.numOutputs() == 1;
15170
15171 if (test9_pass) {
15172 // std::cout << "[OK] Signature parsing works correctly";
15173 std::cout << " -> tests passed" << std::endl;
15174 }
15175 else {
15176 std::cout << "[FAIL] Signature parsing failed" << std::endl;
15177 errors++;