UfuncWithMethods#
-
class numpy::UfuncWithMethods#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use UfuncWithMethods
UfuncWithMethods obj;
// ... operations ...
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_UFUNC_METHODS.H:334 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::any |
NP_UFUNC_METHODS.H:300 |
Code Examples#
The following examples are extracted from the test suite.
at (np_test_1_all.cpp:144)
134 array.setElementAt({0, 0}, 1);
135 array.setElementAt({0, 1}, 2);
136 array.setElementAt({0, 2}, 3);
137 array.setElementAt({1, 1}, 5);
138 array.setElementAt({2, 2}, 9);
139
140 // std::cout << "Array after setting elements:" << std::endl;
141 //array.printArray();
142
143 // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl;
144 // std::cout << "Element at (2,2): " << array.getElementAt({2, 2});
145
146 std::cout << " -> tests passed" << std::endl;
147}
148
149void testArithmetic() {
150 std::cout << "========= testArithmeticOperations =======================";
151
152 auto array1 = createFloat32Array({2, 2}, 5.0f);
153 auto array2 = createFloat32Array({2, 2}, 3.0f);
reduce (np_test_3_all.cpp:946)
936 sum_arr.setElementAt({ 1 }, 2.0);
937 sum_arr.setElementAt({ 2 }, 3.0);
938 sum_arr.setElementAt({ 3 }, 4.0);
939
940 // Convert to object array for reduce
941 numpy::NDArray<std::any> obj_sum_arr({ 4 });
942 for (size_t i = 0; i < 4; ++i) {
943 obj_sum_arr.setElementAt({ i }, std::any{ sum_arr.getElementAt({i}) });
944 }
945
946 auto reduce_result = ufunc_sum.reduce(obj_sum_arr);
947 double final_sum = std::any_cast<double>(reduce_result);
948
949 if (std::abs(final_sum - 10.0) > 1e-10) {
950 std::cout << "[FAIL] Reduce method failed";
951 return 1;
952 }
953
954 // std::cout << "[OK] Reduce method works correctly" << std::endl;
955 std::cout << " -> tests passed" << std::endl;
956 return 0;