NestedIterLevel#
-
class numpy::NestedIterLevel#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use NestedIterLevel
NestedIterLevel obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_NDITER.H:455 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
T |
NP_NDITER.H:521 |
|
|
NestedIterLevel & |
NP_NDITER.H:526 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_NDITER.H:495 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
const std::vector<size_t>& |
NP_NDITER.H:505 |
|
|
size_t |
NP_NDITER.H:500 |
|
|
void |
NP_NDITER.H:566 |
|
|
size_t |
NP_NDITER.H:581 |
|
|
T |
NP_NDITER.H:513 |
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);
indices (np_test_1_all.cpp:47)
37using namespace numpy;
38using namespace numpy::benchmark;
39using namespace numpy::char_;
40
41// Helper functions for array comparison tests
42namespace {
43 const double TOLERANCE = 1e-10;
44
45 bool allTrue(const NDArray<bool>& arr) {
46 std::vector<size_t> indices(arr.getShape().size(), 0);
47 do {
48 if (!arr.getElementAt(indices)) {
49 return false;
50 }
51 } while (incrementIndices(indices, arr.getShape()));
52 return true;
53 }
54
55 bool allFalse(const NDArray<bool>& arr) {
56 std::vector<size_t> indices(arr.getShape().size(), 0);
iteration (np_test_2_all.cpp:22720)
22710 numpy::NDArray<double> arr({ 3, 4 });
22711 auto iters = numpy::nested_iters(arr, { {0}, {1} });
22712 auto& outer = iters[0];
22713 auto& inner = iters[1];
22714
22715 // Iterate partway
22716 ++outer;
22717 ++inner;
22718 ++inner;
22719
22720 if (outer.iteration() != 1 || inner.iteration() != 2) {
22721 std::cout << " [FAIL] : Iteration state incorrect before reset";
22722 throw std::runtime_error("np_test_nested_iters_reset failed");
22723 }
22724
22725 // Reset inner
22726 inner.reset();
22727 if (inner.iteration() != 0 || inner.is_finished()) {
22728 std::cout << " [FAIL] : Inner reset failed";
22729 throw std::runtime_error("np_test_nested_iters_reset failed");
22730 }
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 }
size (np_test_1_all.cpp:47)
37using namespace numpy;
38using namespace numpy::benchmark;
39using namespace numpy::char_;
40
41// Helper functions for array comparison tests
42namespace {
43 const double TOLERANCE = 1e-10;
44
45 bool allTrue(const NDArray<bool>& arr) {
46 std::vector<size_t> indices(arr.getShape().size(), 0);
47 do {
48 if (!arr.getElementAt(indices)) {
49 return false;
50 }
51 } while (incrementIndices(indices, arr.getShape()));
52 return true;
53 }
54
55 bool allFalse(const NDArray<bool>& arr) {
56 std::vector<size_t> indices(arr.getShape().size(), 0);
value (np_test_1_all.cpp:7786)
7776}
7777
7778void testFloat16PrecisionFloat16() {
7779 std::cout << "========= testFloat16PrecisionFloat16 =======================";
7780
7781 // Test precision limits
7782 float16 small_val(0.0001f);
7783 float16 large_val(30000.0f);
7784 float16 very_small(1e-8f); // This might underflow to zero
7785
7786 // std::cout << "Small value (0.0001): " << small_val << std::endl;
7787 // std::cout << "Large value (30000): " << large_val << std::endl;
7788 // std::cout << "Very small value (1e-8): " << very_small << std::endl;
7789
7790 // Test conversion accuracy
7791 float original = 1.234f;
7792 float16 converted(original);
7793 float back_converted = static_cast<float>(converted);
7794
7795 // std::cout << "Original float: " << std::setprecision(10) << original << std::endl;
7796 // std::cout << "Float16 version: " << converted << std::endl;