NestedIters#
-
class numpy::NestedIters#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use NestedIters
NestedIters obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_NDITER.H:597 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
NestedIterLevel<T>& |
NP_NDITER.H:622 |
|
|
const NestedIterLevel<T>& |
NP_NDITER.H:630 |
Logical#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_NDITER.H:643 |
Other Methods#
Code Examples#
The following examples are extracted from the test suite.
num_levels (np_test_2_all.cpp:22928)
22918 void np_test_nested_iters_multi_level() {
22919 std::cout << "========= nested_iters: multi-level nesting (3 levels) =======================";
22920
22921 // Create 3D array
22922 numpy::NDArray<int> arr({ 2, 3, 4 });
22923
22924 // Create 3-level nested iteration: each axis gets its own level
22925 auto iters = numpy::nested_iters(arr, { {0}, {1}, {2} });
22926
22927 if (iters.num_levels() != 3) {
22928 std::cout << " [FAIL] : Should have 3 levels";
22929 throw std::runtime_error("np_test_nested_iters_multi_level failed");
22930 }
22931
22932 auto& level0 = iters[0];
22933 auto& level1 = iters[1];
22934 auto& level2 = iters[2];
22935
22936 if (level0.size() != 2 || level1.size() != 3 || level2.size() != 4) {
22937 std::cout << " [FAIL] : Level sizes incorrect";
reset_all (np_test_2_all.cpp:22742)
22732 // Reset outer
22733 outer.reset();
22734 if (outer.iteration() != 0 || outer.is_finished()) {
22735 std::cout << " [FAIL] : Outer reset failed";
22736 throw std::runtime_error("np_test_nested_iters_reset failed");
22737 }
22738
22739 // Test reset_all on NestedIters object
22740 ++outer;
22741 ++inner;
22742 iters.reset_all();
22743 if (outer.iteration() != 0 || inner.iteration() != 0) {
22744 std::cout << " [FAIL] : reset_all() failed";
22745 throw std::runtime_error("np_test_nested_iters_reset failed");
22746 }
22747
22748 std::cout << " -> tests passed" << std::endl;
22749 }
22750
22751 // ============================================================================
22752 // VALUE ACCESS TESTS