BroadcastView#

class numpy::BroadcastView#

View class for array data access.

Example#

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

// Use BroadcastView
BroadcastView obj;
// ... operations ...

Constructors#

Signature

Location

Example

BroadcastView(const NDArray<T>&source, const std::vector<size_t>&target_shape)

NP_BROADCASTING_UTILS.H:127

Indexing / Selection#

Signature

Return Type

Location

Example

T getElementAt(const std::vector<size_t>&indices)

T

NP_BROADCASTING_UTILS.H:165

View

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

const std::vector<size_t>&

NP_BROADCASTING_UTILS.H:162

View

const std::vector<ssize_t>& getStrides()

const std::vector<ssize_t>&

NP_BROADCASTING_UTILS.H:163

View

Code Examples#

The following examples are extracted from the test suite.

getElementAt (np_test_1_all.cpp:49)
39using namespace numpy::benchmark;
40using namespace numpy::char_;
41
42// Helper functions for array comparison tests
43namespace {
44    const double TOLERANCE = 1e-10;
45
46    bool allTrue(const NDArray<bool>& arr) {
47        std::vector<size_t> indices(arr.getShape().size(), 0);
48        do {
49            if (!arr.getElementAt(indices)) {
50                return false;
51            }
52        } while (incrementIndices(indices, arr.getShape()));
53        return true;
54    }
55
56    bool allFalse(const NDArray<bool>& arr) {
57        std::vector<size_t> indices(arr.getShape().size(), 0);
58        do {
59            if (arr.getElementAt(indices)) {
getShape (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);
getStrides (np_test_1_all.cpp:13373)
13363namespace numpy_tests {
13364
13365  using namespace numpy;
13366
13367
13368  void testBasicStrides() {
13369    std::cout << "========= testBasicStrides =======================";
13370
13371    // Test 1D array
13372    auto array1d = createInt32Array({ 5 }, 10);
13373    const auto& strides1d = array1d.getStrides();
13374
13375    // std::cout << "1D array shape: (" << array1d.getShape()[0] << ")" << std::endl;
13376    // std::cout << "1D array strides: (" << strides1d[0] << ")" << std::endl;
13377
13378    if (!(strides1d.size() == 1)) {
13379        std::string description = std::string("testBasicStrides():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(strides1d.size() == 1)";
13380        std::cout << std::string("[FAIL] ") + description << std::endl;
13381        throw std::runtime_error(description);
13382    }
13383    if (!(strides1d[0] == 1)) {