NDIndex#
-
class numpy::NDIndex#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use NDIndex
NDIndex obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_NDITER.H:197 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
const std::vector<size_t>& |
NP_NDITER.H:209 |
|
|
NDIndex & |
NP_NDITER.H:214 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_NDITER.H:227 |
Other Methods#
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);
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 }