BroadcastView ============= .. cpp:class:: numpy::BroadcastView View class for array data access. Example ------- .. code-block:: cpp #include using namespace numpy; // Use BroadcastView BroadcastView obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``BroadcastView(const NDArray&source, const std::vector&target_shape)`` - NP_BROADCASTING_UTILS.H:127 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T getElementAt(const std::vector&indices)`` - T - NP_BROADCASTING_UTILS.H:165 - :ref:`View ` * - ``const std::vector& getShape()`` - const std::vector& - NP_BROADCASTING_UTILS.H:162 - :ref:`View ` * - ``const std::vector& getStrides()`` - const std::vector& - NP_BROADCASTING_UTILS.H:163 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-broadcastview-getelementat-0: .. dropdown:: getElementAt (np_test_1_all.cpp:49) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 39 :emphasize-lines: 11 using namespace numpy::benchmark; using namespace numpy::char_; // Helper functions for array comparison tests namespace { const double TOLERANCE = 1e-10; bool allTrue(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (!arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } bool allFalse(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (arr.getElementAt(indices)) { .. _example-broadcastview-getshape-1: .. dropdown:: getShape (np_test_1_all.cpp:47) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 37 :emphasize-lines: 11 using namespace numpy; using namespace numpy::benchmark; using namespace numpy::char_; // Helper functions for array comparison tests namespace { const double TOLERANCE = 1e-10; bool allTrue(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (!arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } bool allFalse(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); .. _example-broadcastview-getstrides-2: .. dropdown:: getStrides (np_test_1_all.cpp:13373) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13363 :emphasize-lines: 11 namespace numpy_tests { using namespace numpy; void testBasicStrides() { std::cout << "========= testBasicStrides ======================="; // Test 1D array auto array1d = createInt32Array({ 5 }, 10); const auto& strides1d = array1d.getStrides(); // std::cout << "1D array shape: (" << array1d.getShape()[0] << ")" << std::endl; // std::cout << "1D array strides: (" << strides1d[0] << ")" << std::endl; if (!(strides1d.size() == 1)) { std::string description = std::string("testBasicStrides():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(strides1d.size() == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(strides1d[0] == 1)) {