NestedIters =========== .. cpp:class:: numpy::NestedIters numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use NestedIters NestedIters obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``NestedIters(const std::vector\*>&arrays, const std::vector>&axes_list)`` - NP_NDITER.H:597 - Operators --------- .. list-table:: :widths: 40 25 15 20 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``NestedIterLevel& operator[](size_tlevel)`` - NestedIterLevel& - NP_NDITER.H:622 - * - ``const NestedIterLevel& operator[](size_tlevel)`` - const NestedIterLevel& - NP_NDITER.H:630 - Logical ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool all_finished()`` - bool - NP_NDITER.H:643 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t num_levels()`` - size_t - NP_NDITER.H:638 - :ref:`View ` * - ``void reset_all()`` - void - NP_NDITER.H:653 - :ref:`View ` * - ``const std::vector>& shared_indices()`` - const std::vector>& - NP_NDITER.H:666 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-nestediters-num_levels-0: .. dropdown:: num_levels (np_test_2_all.cpp:22928) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22918 :emphasize-lines: 11 void np_test_nested_iters_multi_level() { std::cout << "========= nested_iters: multi-level nesting (3 levels) ======================="; // Create 3D array numpy::NDArray arr({ 2, 3, 4 }); // Create 3-level nested iteration: each axis gets its own level auto iters = numpy::nested_iters(arr, { {0}, {1}, {2} }); if (iters.num_levels() != 3) { std::cout << " [FAIL] : Should have 3 levels"; throw std::runtime_error("np_test_nested_iters_multi_level failed"); } auto& level0 = iters[0]; auto& level1 = iters[1]; auto& level2 = iters[2]; if (level0.size() != 2 || level1.size() != 3 || level2.size() != 4) { std::cout << " [FAIL] : Level sizes incorrect"; .. _example-nestediters-reset_all-1: .. dropdown:: reset_all (np_test_2_all.cpp:22742) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22732 :emphasize-lines: 11 // Reset outer outer.reset(); if (outer.iteration() != 0 || outer.is_finished()) { std::cout << " [FAIL] : Outer reset failed"; throw std::runtime_error("np_test_nested_iters_reset failed"); } // Test reset_all on NestedIters object ++outer; ++inner; iters.reset_all(); if (outer.iteration() != 0 || inner.iteration() != 0) { std::cout << " [FAIL] : reset_all() failed"; throw std::runtime_error("np_test_nested_iters_reset failed"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // VALUE ACCESS TESTS