IndexExpr#

class numpy::IndexExpr#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use IndexExpr
IndexExpr obj;
// ... operations ...

Constructors#

Signature

Location

Example

IndexExpr(std::initializer_list<IndexElement>indices)

NP_INDEX_TYPES.H:117

IndexExpr(const std::vector<IndexElement>&indices)

NP_INDEX_TYPES.H:118

Operators#

Signature

Return Type

Location

Example

const IndexElement & operator[](size_ti)

const IndexElement &

NP_INDEX_TYPES.H:129

IndexElement & operator[](size_ti)

IndexElement &

NP_INDEX_TYPES.H:130

Array Creation#

Signature

Return Type

Location

Example

bool empty()

bool

NP_INDEX_TYPES.H:127

View

Math Operations#

Signature

Return Type

Location

Example

void add(const IndexElement &idx)

void

NP_INDEX_TYPES.H:121

View

IndexExpr expand_ellipsis(const std::vector<size_t>&shape)

IndexExpr

NP_INDEX_TYPES.H:167

Other Methods#

Signature

Return Type

Location

Example

size_t count_newaxis()

size_t

NP_INDEX_TYPES.H:156

bool has_advanced_indexing()

bool

NP_INDEX_TYPES.H:133

bool has_ellipsis()

bool

NP_INDEX_TYPES.H:146

const std::vector<IndexElement>& indices()

const std::vector<IndexElement>&

NP_INDEX_TYPES.H:124

View

std::vector<IndexElement>& indices()

std::vector<IndexElement>&

NP_INDEX_TYPES.H:125

View

size_t size()

size_t

NP_INDEX_TYPES.H:126

View

Code Examples#

The following examples are extracted from the test suite.

empty (np_test_1_all.cpp:6316)
6306}
6307
6308void test_data_generator_emptyBenchmarkSorting() {
6309    std::cout << "========= test_data_generator_empty =======================";
6310
6311    DataGenerator<int> gen(42);
6312
6313    // Test empty data generation
6314    std::vector<int> data = gen.generate(0, DataPattern::RANDOM);
6315
6316    if (!(data.empty())) {
6317        std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())";
6318        std::cout << std::string("[FAIL] ") + description << std::endl;
6319        throw std::runtime_error(description);
6320    }
6321
6322    // std::cout << "Empty data generation test passed" << std::endl;
6323
6324    std::cout << " -> tests passed" << std::endl;
6325}
add (np_test_1_all.cpp:6410)
6400void testCharArrayStringOperationsCharArray() {
6401    std::cout << "========= testStringOperations =======================";
6402
6403    // Test string concatenation
6404    std::vector<std::string> words1 = {"Hello", "Good", "Nice"};
6405    std::vector<std::string> words2 = {" World", " Day", " Work"};
6406
6407    auto arr1 = array<32>(words1);
6408    auto arr2 = array<32>(words2);
6409
6410    auto result = add(arr1, arr2);
6411    // std::cout << "String concatenation (add):" << std::endl;
6412    for (size_t i = 0; i < result.size(); ++i) {
6413        // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'";
6414    }
6415
6416    // Test scalar addition
6417    auto scalar_result = add(arr1, "!");
6418    // std::cout << "Scalar concatenation:" << std::endl;
6419    for (size_t i = 0; i < scalar_result.size(); ++i) {
6420        // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
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);
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);
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);