IndexExpr ========= .. cpp:class:: numpy::IndexExpr numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use IndexExpr IndexExpr obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``IndexExpr(std::initializer_listindices)`` - NP_INDEX_TYPES.H:117 - * - ``IndexExpr(const std::vector&indices)`` - NP_INDEX_TYPES.H:118 - Operators --------- .. list-table:: :widths: 40 25 15 20 :header-rows: 1 * - 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 -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool empty()`` - bool - NP_INDEX_TYPES.H:127 - :ref:`View ` Math Operations --------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void add(const IndexElement &idx)`` - void - NP_INDEX_TYPES.H:121 - :ref:`View ` * - ``IndexExpr expand_ellipsis(const std::vector&shape)`` - IndexExpr - NP_INDEX_TYPES.H:167 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - 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& indices()`` - const std::vector& - NP_INDEX_TYPES.H:124 - :ref:`View ` * - ``std::vector& indices()`` - std::vector& - NP_INDEX_TYPES.H:125 - :ref:`View ` * - ``size_t size()`` - size_t - NP_INDEX_TYPES.H:126 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-indexexpr-empty-0: .. dropdown:: empty (np_test_1_all.cpp:6316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6306 :emphasize-lines: 11 } void test_data_generator_emptyBenchmarkSorting() { std::cout << "========= test_data_generator_empty ======================="; DataGenerator gen(42); // Test empty data generation std::vector data = gen.generate(0, DataPattern::RANDOM); if (!(data.empty())) { std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Empty data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-indexexpr-add-1: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-indexexpr-indices-2: .. dropdown:: indices (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-indexexpr-indices-3: .. dropdown:: indices (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-indexexpr-size-4: .. dropdown:: size (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);