NDEnumerate =========== .. cpp:class:: numpy::NDEnumerate numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use NDEnumerate NDEnumerate obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``NDEnumerate(const NDArray&array)`` - NP_NDITER.H:257 - Operators --------- .. list-table:: :widths: 40 25 15 20 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``IndexValuePair operator\*()`` - IndexValuePair - NP_NDITER.H:260 - * - ``NDEnumerate & operator++()`` - NDEnumerate & - NP_NDITER.H:265 - Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool is_finished()`` - bool - NP_NDITER.H:271 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void reset()`` - void - NP_NDITER.H:276 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-ndenumerate-is_finished-0: .. dropdown:: is_finished (np_test_2_all.cpp:3824) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3814 :emphasize-lines: 11 for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { arr.setElementAt({ i, j }, static_cast(i * 3 + j)); } } auto iter = nditer(arr); size_t count = 0; double expected_values[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; for (; !iter.is_finished(); ++iter, ++count) { if (!(isApproxEqualMCO(*iter, expected_values[count]))) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(*iter, expected_values[count]))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } if (!(count == 6)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(count == 6)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-ndenumerate-reset-1: .. dropdown:: reset (np_test_2_all.cpp:22610) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22600 :emphasize-lines: 11 // Count iterations size_t outer_count = 0; size_t total_inner_count = 0; for (; !outer.is_finished(); ++outer) { size_t inner_count = 0; for (; !inner.is_finished(); ++inner) { inner_count++; total_inner_count++; } outer_count++; inner.reset(); } if (outer_count != 3 || total_inner_count != 12) { std::cout << " [FAIL] : Iteration counts incorrect"; throw std::runtime_error("np_test_nested_iters_basic failed"); } std::cout << " -> tests passed" << std::endl; }