IndexedArray#

class numpy::IndexedArray#

numpy C++ class.

Example#

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

// Use IndexedArray
IndexedArray obj;
// ... operations ...

Constructors#

Signature

Location

Example

IndexedArray(const NDArray<T>\*source, const IndexExpr &expr)

NP_ADVANCED_INDEXING.H:59

Linear Algebra#

Signature

Return Type

Location

Example

size_t normalize_array_index(IndexTypeidx, size_tdim_size)

size_t

NP_ADVANCED_INDEXING.H:223

Type Handling#

Signature

Return Type

Location

Example

void copy_with_slices(NDArray<T>&result, const std::vector<Slice>&slices, const std::vector<ssize_t>&fixed_indices, const std::vector<size_t>&fixed_dims, const std::vector<size_t>&newaxis_positions)

void

NP_ADVANCED_INDEXING.H:149

Other Methods#

Signature

Return Type

Location

Example

void apply_boolean_indexing(NDArray<T>&result, const std::vector<NDArray<bool\_>\*>&bool_masks)

void

NP_ADVANCED_INDEXING.H:197

void apply_fancy_indexing(NDArray<T>&result, const std::vector<std::variant<ssize_t,Slice,NDArray<size_t>,NDArray<int32_t>,NDArray<int64_t>>>&indices)

void

NP_ADVANCED_INDEXING.H:233

void apply_mixed_basic_indexing(NDArray<T>&result, const std::vector<std::variant<ssize_t,Slice,NDArray<size_t>,NDArray<int32_t>,NDArray<int64_t>>>&indices)

void

NP_ADVANCED_INDEXING.H:324

void materialize_advanced(NDArray<T>&result)

void

NP_ADVANCED_INDEXING.H:117

void materialize_basic(NDArray<T>&result)

void

NP_ADVANCED_INDEXING.H:81

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

const std::vector<size_t>&

NP_ADVANCED_INDEXING.H:64

View

Code Examples#

The following examples are extracted from the test suite.

shape (np_test_1_all.cpp:3751)
3741    }
3742
3743    for (size_t j = 0; j < 3; ++j) {
3744        arr3.setElementAt({0, j}, static_cast<double>((j + 1) * 100));  // [100, 200, 300]
3745    }
3746
3747    // Broadcast all arrays together
3748    std::vector<NDArray<double>> arrays = {arr1, arr2, arr3};
3749    auto broadcasted = broadcast_arrays(arrays);
3750
3751    // All should have shape (2, 3)
3752    for (const auto& arr : broadcasted) {
3753        if (!((arr.getShape() == std::vector<size_t>{2, 3}))) {
3754            std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((arr.getShape() == std::vector<size_t>{2, 3}))";
3755            std::cout << std::string("[FAIL] ") + description << std::endl;
3756            throw std::runtime_error(description);
3757        }
3758    }
3759
3760    // Check values
3761    if (!(broadcasted[0].getElementAt({0, 1}) == 2.0)) {