NDEnumerate#
-
class numpy::NDEnumerate#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use NDEnumerate
NDEnumerate obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_NDITER.H:257 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
IndexValuePair |
NP_NDITER.H:260 |
|
|
NDEnumerate & |
NP_NDITER.H:265 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_NDITER.H:271 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_NDITER.H:276 |
Code Examples#
The following examples are extracted from the test suite.
is_finished (np_test_2_all.cpp:3824)
3814 for (size_t i = 0; i < 2; ++i) {
3815 for (size_t j = 0; j < 3; ++j) {
3816 arr.setElementAt({ i, j }, static_cast<double>(i * 3 + j));
3817 }
3818 }
3819
3820 auto iter = nditer(arr);
3821 size_t count = 0;
3822 double expected_values[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
3823
3824 for (; !iter.is_finished(); ++iter, ++count) {
3825 if (!(isApproxEqualMCO(*iter, expected_values[count]))) {
3826 std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(*iter, expected_values[count]))";
3827 std::cout << std::string("[FAIL] ") + description << std::endl;
3828 throw std::runtime_error(description);
3829 }
3830 }
3831 if (!(count == 6)) {
3832 std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(count == 6)";
3833 std::cout << std::string("[FAIL] ") + description << std::endl;
3834 throw std::runtime_error(description);
reset (np_test_2_all.cpp:22610)
22600 // Count iterations
22601 size_t outer_count = 0;
22602 size_t total_inner_count = 0;
22603 for (; !outer.is_finished(); ++outer) {
22604 size_t inner_count = 0;
22605 for (; !inner.is_finished(); ++inner) {
22606 inner_count++;
22607 total_inner_count++;
22608 }
22609 outer_count++;
22610 inner.reset();
22611 }
22612
22613 if (outer_count != 3 || total_inner_count != 12) {
22614 std::cout << " [FAIL] : Iteration counts incorrect";
22615 throw std::runtime_error("np_test_nested_iters_basic failed");
22616 }
22617
22618 std::cout << " -> tests passed" << std::endl;
22619 }