RangeIndex ========== .. cpp:class:: numpy::RangeIndex numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use RangeIndex RangeIndex obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``explicit RangeIndex(int64_t stop, const std::optional& name = std::nullopt)`` - df_range_index.h:101 - * - ``RangeIndex(const RangeIndex& other)`` - df_range_index.h:134 - * - ``RangeIndex(RangeIndex&& other) noexcept`` - df_range_index.h:143 - Construction ------------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static RangeIndex from_range(int64_t start, int64_t stop, int64_t step = 1, const std::optional& name = std::nullopt)`` - static RangeIndex - df_range_index.h:182 - Array Creation -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool empty() const override`` - bool - df_range_index.h:220 - :ref:`View ` Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``int64_t at(size_t i) const`` - int64_t - df_range_index.h:311 - :ref:`View ` * - ``numpy::NDArray get_indexer(const std::vector& target) const`` - numpy::NDArray - df_range_index.h:404 - * - ``numpy::NDArray get_indexer(const RangeIndex& target) const`` - numpy::NDArray - df_range_index.h:419 - * - ``numpy::NDArray get_indexer_for(const std::vector& target) const`` - numpy::NDArray - df_range_index.h:1607 - * - ``get_indexer_non_unique(const std::vector& target) const`` - - df_range_index.h:1617 - * - ``RangeIndex get_level_values(int level) const`` - RangeIndex - df_range_index.h:2158 - * - ``RangeIndex get_level_values(const std::string& level_name) const`` - RangeIndex - df_range_index.h:2174 - * - ``size_t get_loc(int64_t key) const`` - size_t - df_range_index.h:380 - * - ``int64_t get_loc_str(const std::string& key_str) const override`` - int64_t - df_range_index.h:390 - * - ``std::vector> get_names() const`` - std::vector> - df_range_index.h:2330 - :ref:`View ` * - ``size_t get_slice_bound(int64_t label, const std::string& side) const`` - size_t - df_range_index.h:1649 - * - ``std::string get_value_str(size_t index) const override`` - std::string - df_range_index.h:1229 - * - ``int64_t item() const`` - int64_t - df_range_index.h:1754 - :ref:`View ` * - ``Index putmask(const numpy::NDArray& mask, int64_t value) const`` - Index - df_range_index.h:1832 - :ref:`View ` * - ``size_t searchsorted(int64_t value, const std::string& side = "left") const`` - size_t - df_range_index.h:1277 - :ref:`View ` * - ``Index take(const std::vector& indices) const`` - Index - df_range_index.h:491 - :ref:`View ` * - ``Index where(const numpy::NDArray& cond, const std::vector& other) const`` - Index - df_range_index.h:1958 - :ref:`View ` Shape Manipulation ------------------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``numpy::NDArray ravel() const`` - numpy::NDArray - df_range_index.h:1818 - :ref:`View ` * - ``RangeIndex transpose() const`` - RangeIndex - df_range_index.h:1802 - :ref:`View ` Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``int64_t max() const`` - int64_t - df_range_index.h:1033 - :ref:`View ` * - ``double mean() const`` - double - df_range_index.h:1075 - :ref:`View ` * - ``int64_t min() const`` - int64_t - df_range_index.h:1023 - :ref:`View ` * - ``int64_t sum() const`` - int64_t - df_range_index.h:1063 - :ref:`View ` Sorting ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``numpy::NDArray argsort(bool ascending = true) const`` - numpy::NDArray - df_range_index.h:1090 - :ref:`View ` * - ``RangeIndex sort(bool ascending = true) const`` - RangeIndex - df_range_index.h:2369 - :ref:`View ` * - ``RangeIndex sort_values(bool ascending = true) const`` - RangeIndex - df_range_index.h:1111 - * - ``std::pair> sortlevel( int level = 0, bool ascending = true, bool sort_remaining = true, const std::string& na_position = "first") const`` - std::pair> - df_range_index.h:2219 - Math Operations --------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::variant> abs() const`` - std::variant> - df_range_index.h:765 - :ref:`View ` * - ``RangeIndex round(int decimals = 0) const`` - RangeIndex - df_range_index.h:1914 - :ref:`View ` Comparison ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool equals(const RangeIndex& other) const`` - bool - df_range_index.h:1198 - Logical ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool all(bool skipna = true) const`` - bool - df_range_index.h:1497 - :ref:`View ` * - ``bool any(bool skipna = true) const`` - bool - df_range_index.h:1511 - :ref:`View ` Set Operations -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``numpy::NDArray isin(const std::vector& values) const`` - numpy::NDArray - df_range_index.h:505 - :ref:`View ` * - ``Index unique() const`` - Index - df_range_index.h:2362 - :ref:`View ` I/O --- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``numpy::NDArray to_array() const`` - numpy::NDArray - df_range_index.h:321 - * - ``RangeIndex to_flat_index() const`` - RangeIndex - df_range_index.h:1794 - * - ``FrameData to_frame(bool index = true, const std::optional& name = std::nullopt) const`` - FrameData - df_range_index.h:2254 - * - ``Index to_index() const`` - Index - df_range_index.h:1263 - * - ``std::vector to_list() const`` - std::vector - df_range_index.h:336 - * - ``numpy::NDArray to_numpy() const`` - numpy::NDArray - df_range_index.h:1786 - :ref:`View ` * - ``SeriesData to_series(const std::optional& index = std::nullopt, const std::optional& name = std::nullopt) const`` - SeriesData - df_range_index.h:2294 - * - ``std::string to_string() const override`` - std::string - df_range_index.h:1243 - :ref:`View ` * - ``std::vector to_string_vector() const override`` - std::vector - df_range_index.h:1216 - * - ``std::vector tolist() const`` - std::vector - df_range_index.h:1778 - :ref:`View ` Joining / Splitting ------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::variant> append(const RangeIndex& other) const`` - std::variant> - df_range_index.h:997 - :ref:`View ` * - ``std::variant> delete\_(size_t loc) const`` - std::variant> - df_range_index.h:558 - :ref:`View ` * - ``std::variant> delete\_(const std::vector& locs) const`` - std::variant> - df_range_index.h:584 - :ref:`View ` * - ``std::variant> insert(size_t loc, int64_t item) const`` - std::variant> - df_range_index.h:528 - :ref:`View ` * - ``Index repeat(size_t repeats) const`` - Index - df_range_index.h:1870 - :ref:`View ` * - ``Index repeat(const std::vector& repeats) const`` - Index - df_range_index.h:1889 - :ref:`View ` Type Handling ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``RangeIndex copy() const`` - RangeIndex - df_range_index.h:679 - :ref:`View ` * - ``numpy::NDArray view() const`` - numpy::NDArray - df_range_index.h:1810 - :ref:`View ` Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool is\_(const RangeIndex& other) const`` - bool - df_range_index.h:2112 - * - ``bool is_aligned(int64_t value) const`` - bool - df_range_index.h:81 - * - ``bool is_boolean() const`` - bool - df_range_index.h:1390 - * - ``bool is_categorical() const`` - bool - df_range_index.h:1398 - * - ``bool is_floating() const`` - bool - df_range_index.h:1406 - * - ``bool is_integer() const`` - bool - df_range_index.h:1414 - * - ``bool is_interval() const`` - bool - df_range_index.h:1422 - * - ``bool is_monotonic_decreasing() const`` - bool - df_range_index.h:288 - * - ``bool is_monotonic_increasing() const`` - bool - df_range_index.h:281 - * - ``bool is_numeric() const`` - bool - df_range_index.h:1430 - :ref:`View ` * - ``bool is_object() const`` - bool - df_range_index.h:1438 - * - ``bool is_unique() const override`` - bool - df_range_index.h:255 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t argmax() const`` - size_t - df_range_index.h:1053 - :ref:`View ` * - ``size_t argmin() const`` - size_t - df_range_index.h:1043 - :ref:`View ` * - ``numpy::NDArray arr(std::vector`` - numpy::NDArray - df_range_index.h:324 - :ref:`View ` * - ``std::optional asof(int64_t label) const`` - std::optional - df_range_index.h:1542 - * - ``numpy::NDArray asof_locs(const std::vector& where) const`` - numpy::NDArray - df_range_index.h:1587 - * - ``size_t cache_memory_usage() const override`` - size_t - df_range_index.h:1366 - * - ``void clear_cache() const override`` - void - df_range_index.h:1348 - * - ``std::unique_ptr clone() const override`` - std::unique_ptr - df_range_index.h:1236 - :ref:`View ` * - ``numpy::NDArray codes(std::vector`` - numpy::NDArray - df_range_index.h:1332 - * - ``size_t compute_size() const`` - size_t - df_range_index.h:56 - * - ``bool contains(int64_t value) const`` - bool - df_range_index.h:355 - :ref:`View ` * - ``bool contains_str(const std::string& key_str) const override`` - bool - df_range_index.h:365 - * - ``numpy::NDArray counts(std::vector`` - numpy::NDArray - df_range_index.h:2350 - :ref:`View ` * - ``Index diff(int64_t periods = 1) const`` - Index - df_range_index.h:1666 - :ref:`View ` * - ``std::variant> difference(const RangeIndex& other) const`` - std::variant> - df_range_index.h:911 - :ref:`View ` * - ``std::variant> drop(const std::vector& labels) const`` - std::variant> - df_range_index.h:634 - * - ``RangeIndex drop_duplicates(const std::string& keep = "first") const`` - RangeIndex - df_range_index.h:1708 - * - ``RangeIndex droplevel(int level = 0) const`` - RangeIndex - df_range_index.h:2142 - * - ``RangeIndex dropna() const`` - RangeIndex - df_range_index.h:1699 - * - ``std::string dtype_name() const override`` - std::string - df_range_index.h:227 - :ref:`View ` * - ``numpy::NDArray duplicated(const std::string& keep = "first") const`` - numpy::NDArray - df_range_index.h:1718 - * - ``std::pair, RangeIndex> factorize() const`` - std::pair, RangeIndex> - df_range_index.h:1330 - * - ``RangeIndex fillna(int64_t value) const`` - RangeIndex - df_range_index.h:1690 - * - ``std::vector format(const std::string& na_rep = "NaN") const`` - std::vector - df_range_index.h:1737 - :ref:`View ` * - ``std::unordered_map> groupby( const std::vector& values) const`` - std::unordered_map> - df_range_index.h:2193 - * - ``bool has_cached_values() const override`` - bool - df_range_index.h:1357 - * - ``bool has_duplicates() const override`` - bool - df_range_index.h:262 - * - ``bool holds_integer() const`` - bool - df_range_index.h:1382 - * - ``bool identical(const RangeIndex& other) const`` - bool - df_range_index.h:1205 - * - ``bool in_bounds(int64_t value) const`` - bool - df_range_index.h:70 - * - ``numpy::NDArray indexer_arr(std::vector`` - numpy::NDArray - df_range_index.h:1630 - * - ``RangeIndex infer_objects() const`` - RangeIndex - df_range_index.h:1746 - * - ``std::string inferred_type() const override`` - std::string - df_range_index.h:248 - * - ``std::variant> intersection(const RangeIndex& other) const`` - std::variant> - df_range_index.h:847 - * - ``numpy::NDArray isna() const`` - numpy::NDArray - df_range_index.h:1450 - * - ``numpy::NDArray isnull() const`` - numpy::NDArray - df_range_index.h:1463 - * - ``join(const RangeIndex& other, const std::string& how = "left", bool sort = false) const`` - - df_range_index.h:1988 - :ref:`View ` * - ``numpy::NDArray left_arr(std::vector`` - numpy::NDArray - df_range_index.h:2083 - * - ``size_t memory_usage(bool deep = false) const`` - size_t - df_range_index.h:1766 - * - ``numpy::NDArray missing_arr(std::vector`` - numpy::NDArray - df_range_index.h:1635 - * - ``std::optional name() const override`` - std::optional - df_range_index.h:234 - :ref:`View ` * - ``name\_(other.name\_)`` - - df_range_index.h:136 - * - ``name\_(std::move(other.name\_)), cached_array\_(std::move(other.cached_array\_))`` - - df_range_index.h:145 - * - ``size_t nbytes() const override`` - size_t - df_range_index.h:273 - :ref:`View ` * - ``size_t nlevels() const`` - size_t - df_range_index.h:2322 - * - ``numpy::NDArray notna() const`` - numpy::NDArray - df_range_index.h:1471 - * - ``numpy::NDArray notnull() const`` - numpy::NDArray - df_range_index.h:1484 - * - ``size_t nunique(bool dropna = true) const`` - size_t - df_range_index.h:1528 - * - ``std::pair> reindex( const RangeIndex& target, const std::string& method = "") const`` - std::pair> - df_range_index.h:1857 - * - ``RangeIndex rename(const std::optional& new_name) const`` - RangeIndex - df_range_index.h:686 - * - ``std::string repr() const override`` - std::string - df_range_index.h:1256 - * - ``RangeIndex result(\*this)`` - RangeIndex - df_range_index.h:687 - :ref:`View ` * - ``numpy::NDArray right_arr(std::vector`` - numpy::NDArray - df_range_index.h:2084 - * - ``void set_name(const std::optional& name) override`` - void - df_range_index.h:241 - * - ``RangeIndex set_names(const std::optional& name) const`` - RangeIndex - df_range_index.h:2099 - * - ``Index shift(int64_t periods = 1, int64_t fill_value = 0) const`` - Index - df_range_index.h:1925 - :ref:`View ` * - ``size_t size() const override`` - size_t - df_range_index.h:213 - :ref:`View ` * - ``RangeIndex slice(size_t start_idx, size_t stop_idx, int64_t step_idx = 1) const`` - RangeIndex - df_range_index.h:434 - :ref:`View ` * - ``std::pair slice_indexer(std::optional start = std::nullopt, std::optional stop = std::nullopt, size_t step = 1) const`` - std::pair - df_range_index.h:2123 - * - ``std::pair slice_locs( std::optional start = std::nullopt, std::optional stop = std::nullopt) const`` - std::pair - df_range_index.h:455 - * - ``int64_t start() const`` - int64_t - df_range_index.h:194 - :ref:`View ` * - ``int64_t step() const`` - int64_t - df_range_index.h:204 - :ref:`View ` * - ``int64_t stop() const`` - int64_t - df_range_index.h:199 - * - ``std::variant> symmetric_difference(const RangeIndex& other) const`` - std::variant> - df_range_index.h:950 - * - ``std::variant> union\_(const RangeIndex& other) const`` - std::variant> - df_range_index.h:796 - * - ``std::pair, numpy::NDArray> value_counts( bool normalize = false, bool sort = true, bool ascending = false, bool dropna = true) const`` - std::pair, numpy::NDArray> - df_range_index.h:2338 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-rangeindex-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-rangeindex-at-1: .. dropdown:: at (np_test_1_all.cpp:144) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 134 :emphasize-lines: 11 array.setElementAt({0, 0}, 1); array.setElementAt({0, 1}, 2); array.setElementAt({0, 2}, 3); array.setElementAt({1, 1}, 5); array.setElementAt({2, 2}, 9); // std::cout << "Array after setting elements:" << std::endl; //array.printArray(); // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl; // std::cout << "Element at (2,2): " << array.getElementAt({2, 2}); std::cout << " -> tests passed" << std::endl; } void testArithmetic() { std::cout << "========= testArithmeticOperations ======================="; auto array1 = createFloat32Array({2, 2}, 5.0f); auto array2 = createFloat32Array({2, 2}, 3.0f); .. _example-rangeindex-get_names-2: .. dropdown:: get_names (np_test_1_all.cpp:21728) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21718 :emphasize-lines: 11 RecordArray base(dtype, { 2 }); base.setFieldValue({ 0 }, "name", std::string("Alice")); base.setFieldValue({ 0 }, "score", static_cast(85)); base.setFieldValue({ 1 }, "name", std::string("Bob")); base.setFieldValue({ 1 }, "score", static_cast(92)); // std::cout << "Base array:" << std::endl; //base.printArray(); std::vector names = get_names(base); // std::cout << "Field names: "; for (const auto& name : names) { // std::cout << name << " "; } // std::cout << std::endl; // std::cout << "Field structure: " << get_fieldstructure(base) << std::endl; auto dropped = drop_fields(base, { "score" }); // std::cout << "After dropping 'score' field:"; .. _example-rangeindex-item-3: .. dropdown:: item (np_test_4_all.cpp:20048) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20038 :emphasize-lines: 11 /** * @file np_test_phase6.cpp * @brief Test suite for Phase 6A - HIGH PRIORITY NDArray methods and masked array utilities * * Tests: * - ndarray.nonzero() - Return indices of non-zero elements * - ndarray.tobytes() - Convert to bytes representation * - ndarray.tolist() - Convert to nested list string * - ndarray.fill() - Fill with scalar value (in-place) * - ndarray.item() - Get single element as scalar * - ndarray.itemset() - Set single element value * - ma.masked_all_like() - Create masked array with all elements masked * * Created: 2025-10-28 * Status: Phase 6A Implementation - HIGH PRIORITY functions */ #include "../numpy/np_ndarray.h" #include "../numpy/np_masked_array.h" #include .. _example-rangeindex-putmask-4: .. dropdown:: putmask (np_test_5_all.cpp:4659) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4649 :emphasize-lines: 11 mask.setElementAt({ 1 }, false); mask.setElementAt({ 2 }, true); mask.setElementAt({ 3 }, false); mask.setElementAt({ 4 }, true); // Create value array numpy::NDArray values({ 1 }); values.setElementAt({ 0 }, 99); // Apply putmask numpy::putmask(arr, mask, values); // Expected: [99, 2, 99, 4, 99] if (arr.getElementAt({ 0 }) != 99 || arr.getElementAt({ 1 }) != 2 || arr.getElementAt({ 2 }) != 99 || arr.getElementAt({ 3 }) != 4 || arr.getElementAt({ 4 }) != 99) { std::cout << " [FAIL] : in np_test_putmask() : Incorrect result"; throw std::runtime_error("Test failed"); } // Test with multiple values .. _example-rangeindex-searchsorted-5: .. dropdown:: searchsorted (np_test_2_all.cpp:8204) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8194 :emphasize-lines: 11 // Test missing NumPy functions void test_numpy_functions() { std::cout << "========= NumPy Functions Test =========================="; // Test searchsorted { std::vector sorted_arr = { 1, 3, 5, 7, 9 }; std::vector values = { 2, 6, 8 }; auto result = numpy::searchsorted(sorted_arr, values, "left"); std::vector expected = { 1, 3, 4 }; if (result != expected) { std::cout << " searchsorted (left): -> [FAIL]"; throw std::runtime_error("searchsorted (left): FAILED - incorrect result indices"); } // std::cout << "[OK] searchsorted (left): PASSED" << std::endl; auto result_right = numpy::searchsorted(sorted_arr, values, "right"); std::vector expected_right = { 1, 3, 4 }; .. _example-rangeindex-take-6: .. dropdown:: take (np_test_5_all.cpp:4313) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4303 :emphasize-lines: 11 for (size_t i = 0; i < 6; ++i) { arr.setElementAt({ i }, static_cast(i * 10)); // [0, 10, 20, 30, 40, 50] } // Take specific indices numpy::NDArray indices({ 3 }); indices.setElementAt({ 0 }, 5); // 50 indices.setElementAt({ 1 }, 2); // 20 indices.setElementAt({ 2 }, 0); // 0 auto result = numpy::take(arr, indices); if (result.getSize() != 3) { std::cout << " [FAIL] : in np_test_take_basic() : Wrong result size"; throw std::runtime_error("Test failed"); } if (result.getElementAt({ 0 }) != 50 || result.getElementAt({ 1 }) != 20 || result.getElementAt({ 2 }) != 0) { std::cout << " [FAIL] : in np_test_take_basic() : Wrong values extracted"; throw std::runtime_error("Test failed"); } .. _example-rangeindex-where-7: .. dropdown:: where (np_test_3_all.cpp:15253) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15243 :emphasize-lines: 11 auto y_data = createInt32Array({ 4 }, 0); y_data.setElementAt({ 0 }, 100); y_data.setElementAt({ 1 }, 200); y_data.setElementAt({ 2 }, 300); y_data.setElementAt({ 3 }, 400); auto y_mask = createBoolArray({ 4 }, false); MaskedArray y(y_data, y_mask, -999); // Test where() selection auto result = where(condition, x, y); if (!(result.getElementAt({ 0 }) == 10)) { std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 200)) { std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-rangeindex-ravel-8: .. dropdown:: ravel (np_test_1_all.cpp:4082) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4072 :emphasize-lines: 11 std::cout << "Testing ravel function...\n"; // Test with 2-D array auto arr_2d = createFloat64Array({ 2, 3 }); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { arr_2d.setElementAt({ i, j }, static_cast(i * 3 + j)); } } auto raveled = ravel(arr_2d); if (!(raveled.getShape() == std::vector({ 6 }))) { std::string description = std::string("testRavelFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(raveled.getShape() == std::vector({ 6 }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 6; ++i) { if (!(isApproxEqualExt(raveled.getElementAt({ i }), static_cast(i)))) { std::string description = std::string("testRavelFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualExt(raveled.getElementAt({ i }), static_cast(i)))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-rangeindex-transpose-9: .. dropdown:: transpose (np_test_2_all.cpp:4973) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4963 :emphasize-lines: 11 } /** * Test matrix properties and methods */ void testMatrixProperties() { std::cout << "========= testMatrixProperties ======================="; // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); .. _example-rangeindex-max-10: .. dropdown:: max (np_test_1_all.cpp:7274) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7264 :emphasize-lines: 11 if (sizeof(uintp) == sizeof(void*)) { // std::cout << " -> uintp size matches pointer size"; } else { // std::cout << " ✗ uintp size doesn't match pointer size" << std::endl; } // Test range limits // std::cout << "Range Information:" << std::endl; // std::cout << " intp min: " << std::numeric_limits::min() << std::endl; // std::cout << " intp max: " << std::numeric_limits::max() << std::endl; // std::cout << " uintp max: " << std::numeric_limits::max() << std::endl; // std::cout << " longdouble digits: " << std::numeric_limits::digits << std::endl; std::cout << " -> tests passed" << std::endl; } void testComplexArithmeticExtendedTypes() { std::cout << "========= testComplexArithmeticExtendedTypes ======================="; clongdouble c1(3.0L, 4.0L); // 3 + 4i .. _example-rangeindex-mean-11: .. dropdown:: mean (np_test_1_all.cpp:11714) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11704 :emphasize-lines: 11 // Create test array auto array = createInt32Array({ 2, 3 }, 0); array.setElementAt({ 0, 0 }, 1); array.setElementAt({ 0, 1 }, 2); array.setElementAt({ 0, 2 }, 3); array.setElementAt({ 1, 0 }, 4); array.setElementAt({ 1, 1 }, 5); array.setElementAt({ 1, 2 }, 6); // Test mean without axis auto mean_all = mean(array); if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean (all elements) works correctly\n"; // Test mean along axis 0 auto mean_axis0 = mean(array, 0); if (!(mean_axis0.getShape()[0] == 3)) { .. _example-rangeindex-min-12: .. dropdown:: min (np_test_1_all.cpp:2350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2340 :emphasize-lines: 11 if (i % 3 == 0) { large_array.setElementAt({i}, object_(static_cast(i))); } else if (i % 3 == 1) { large_array.setElementAt({i}, object_(static_cast(i) * 0.5)); } else { large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i))); } } // Verify pattern for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) { // Check first 100 object_ obj = large_array.getElementAt({i}); if (i % 3 == 0) { if (!(obj.is_type())) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } else if (i % 3 == 1) { if (!(obj.is_type())) { std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())"; .. _example-rangeindex-sum-13: .. dropdown:: sum (np_test_1_all.cpp:11766) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11756 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean along axis 1 works correctly\n"; // Test sum auto sum_all = sum(array); if (!(sum_all.getElementAt({ 0 }) == 21)) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sum_all.getElementAt({ 0 }) == 21)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] sum works correctly\n"; // Test min and max auto min_all = min(array); auto max_all = max(array); .. _example-rangeindex-argsort-14: .. dropdown:: argsort (np_test_1_all.cpp:16841) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16831 :emphasize-lines: 11 std::cout << "========= test_argsort ======================="; // Test 1D array argsort NDArray arr1d({ 5 }); arr1d.setElementAt({ 0 }, 30); // index 0 arr1d.setElementAt({ 1 }, 10); // index 1 arr1d.setElementAt({ 2 }, 40); // index 2 arr1d.setElementAt({ 3 }, 20); // index 3 arr1d.setElementAt({ 4 }, 50); // index 4 auto indices = argsort(arr1d); // Expected order: 10(idx1), 20(idx3), 30(idx0), 40(idx2), 50(idx4) if (!(indices.getElementAt({ 0 }) == 1)) { std::string description = std::string("test_argsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(indices.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(indices.getElementAt({ 1 }) == 3)) { std::string description = std::string("test_argsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(indices.getElementAt({ 1 }) == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-rangeindex-sort-15: .. dropdown:: sort (np_test_1_all.cpp:6258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6248 :emphasize-lines: 11 std::vector data = gen.generate(100, DataPattern::FEW_UNIQUE); if (!(data.size() == 100)) { std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Count unique values std::vector sorted_copy = data; std::sort(sorted_copy.begin(), sorted_copy.end()); auto unique_end = std::unique(sorted_copy.begin(), sorted_copy.end()); size_t unique_count = std::distance(sorted_copy.begin(), unique_end); // Should have significantly fewer unique values than total elements if (!(unique_count < data.size() / 2)) { std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_count < data.size() / 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-rangeindex-abs-16: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-rangeindex-round-17: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-rangeindex-all-18: .. dropdown:: all (np_test_4_all.cpp:23928) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23918 :emphasize-lines: 11 } } } auto result = numpy::einsum("ijk->ik", {A}); if (result.getShape()[0] != 2 || result.getShape()[1] != 2) { throw std::runtime_error("einsum partial sum shape wrong"); } // Sum over j: 1+2+3 = 6 for all (i,k) positions if (std::abs(result.getElementAt({0, 0}) - 6.0) > 1e-10 || std::abs(result.getElementAt({1, 1}) - 6.0) > 1e-10) { throw std::runtime_error("einsum partial sum values wrong"); } // std::cout << " OK: Partial sum: 'ijk->ik'\n"; } // Test 5: Size-1 dimension handling { .. _example-rangeindex-any-19: .. dropdown:: any (np_test_2_all.cpp:16758) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16748 :emphasize-lines: 11 // ANY() TESTS - SCALAR RESULT // ============================================================================ void np_test_logic_any_scalar_all_false() { std::cout << "========= any: all false elements ======================="; // Create array with all false/zero elements std::vector data = { 0.0, 0.0, 0.0 }; numpy::NDArray arr = numpy::createArrayFromVector({ 3 }, data); bool result = numpy::any(arr); if (result != false) { std::cout << " [FAIL] : in np_test_logic_any_scalar_all_false() : expected false for all-zero array"; throw std::runtime_error("np_test_logic_any_scalar_all_false failed: expected false"); } std::cout << " -> tests passed" << std::endl; } void np_test_logic_any_scalar_all_true() { .. _example-rangeindex-isin-20: .. dropdown:: isin (np_test_1_all.cpp:19434) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19424 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(membership.getElementAt({ 5 }) == false)) { std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(membership.getElementAt({ 5 }) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Membership testing (in1d) works correctly\n"; // Test isin (alias for in1d) auto isin_result = isin(test_array, test_values); // Should be identical to in1d result for (size_t i = 0; i < membership.getSize(); ++i) { if (!(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))) { std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-rangeindex-unique-21: .. dropdown:: unique (np_test_1_all.cpp:6259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6249 :emphasize-lines: 11 if (!(data.size() == 100)) { std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Count unique values std::vector sorted_copy = data; std::sort(sorted_copy.begin(), sorted_copy.end()); auto unique_end = std::unique(sorted_copy.begin(), sorted_copy.end()); size_t unique_count = std::distance(sorted_copy.begin(), unique_end); // Should have significantly fewer unique values than total elements if (!(unique_count < data.size() / 2)) { std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_count < data.size() / 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Few unique data generation test passed. Unique values: " << unique_count << std::endl; .. _example-rangeindex-to_numpy-22: .. dropdown:: to_numpy (np_test_5_all.cpp:21373) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21363 :emphasize-lines: 11 if (errors == 0) { std::cout << "np_test_timedelta_components -> tests passed" << std::endl; } return errors; } // ============================================================================= // Test 4: Total Conversion Properties // ============================================================================= int np_test_timedelta_total_conversions() { int errors = 0; numpy::Timedelta td(1, 12, 0); // 1 day 12 hours = 1.5 days = 36 hours // total_seconds { double secs = td.total_seconds(); double expected = (24 + 12) * 3600.0; if (std::abs(secs - expected) > 0.0001) { std::cout << "[FAIL] np_test_timedelta_total_conversions: total_seconds expected " << expected << ", got " << secs << std::endl; .. _example-rangeindex-to_string-23: .. dropdown:: to_string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)"; .. _example-rangeindex-tolist-24: .. dropdown:: tolist (np_test_4_all.cpp:20046) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20036 :emphasize-lines: 11 } // namespace numpy_tests /** * @file np_test_phase6.cpp * @brief Test suite for Phase 6A - HIGH PRIORITY NDArray methods and masked array utilities * * Tests: * - ndarray.nonzero() - Return indices of non-zero elements * - ndarray.tobytes() - Convert to bytes representation * - ndarray.tolist() - Convert to nested list string * - ndarray.fill() - Fill with scalar value (in-place) * - ndarray.item() - Get single element as scalar * - ndarray.itemset() - Set single element value * - ma.masked_all_like() - Create masked array with all elements masked * * Created: 2025-10-28 * Status: Phase 6A Implementation - HIGH PRIORITY functions */ #include "../numpy/np_ndarray.h" .. _example-rangeindex-append-25: .. dropdown:: append (np_test_2_all.cpp:7028) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7018 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(deleted_dups.getElementAt({ 2 }) == 3)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(deleted_dups.getElementAt({ 2 }) == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Delete with duplicate indices works correctly\n"; // Test append auto appended = append(array, 100); if (!(appended.getSize() == array.getSize() + 1)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getSize() == array.getSize() + 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(appended.getElementAt({ appended.getSize() - 1 }) == 100)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getElementAt({ appended.getSize() - 1 }) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-rangeindex-delete_-26: .. dropdown:: delete_ (np_test_4_all.cpp:18411) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18401 :emphasize-lines: 11 } // ============================================================================ // SPRINT 1.2: ESSENTIAL OPERATIONS TESTS // ============================================================================ void np_test_phase1_delete() { std::cout << "========= delete_: element deletion ===="; auto arr = numpy::array({10, 20, 30, 40, 50}); auto result = numpy::delete_(arr, 2); // Delete index 2 (value 30) // Verify size reduced if (result.getSize() != 4) { std::cout << " [FAIL] : delete_ result size is " << result.getSize() << ", expected 4\n"; throw std::runtime_error("delete_ failed: wrong size"); } // Verify correct element was removed if (result.getElementAt({0}) != 10 || result.getElementAt({1}) != 20 || result.getElementAt({2}) != 40 || result.getElementAt({3}) != 50) { .. _example-rangeindex-delete_-27: .. dropdown:: delete_ (np_test_4_all.cpp:18411) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18401 :emphasize-lines: 11 } // ============================================================================ // SPRINT 1.2: ESSENTIAL OPERATIONS TESTS // ============================================================================ void np_test_phase1_delete() { std::cout << "========= delete_: element deletion ===="; auto arr = numpy::array({10, 20, 30, 40, 50}); auto result = numpy::delete_(arr, 2); // Delete index 2 (value 30) // Verify size reduced if (result.getSize() != 4) { std::cout << " [FAIL] : delete_ result size is " << result.getSize() << ", expected 4\n"; throw std::runtime_error("delete_ failed: wrong size"); } // Verify correct element was removed if (result.getElementAt({0}) != 10 || result.getElementAt({1}) != 20 || result.getElementAt({2}) != 40 || result.getElementAt({3}) != 50) { .. _example-rangeindex-insert-28: .. dropdown:: insert (np_test_1_all.cpp:6990) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6980 :emphasize-lines: 11 } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday datetime64 end("2024-03-22"); // Friday (2 weeks later) // Create holidays set std::set holidays; holidays.insert(datetime64("2024-03-15")); // Friday holiday auto business_dates = createBusinessDateRange(start, end, holidays); // std::cout << "Business dates from " << start.toString() // << " to " << end.toString() << " (excluding 2024-03-15):" << std::endl; //business_dates.printArray(); std::cout << " -> tests passed" << std::endl; } void testMonthRangeDateTime() { .. _example-rangeindex-repeat-29: .. dropdown:: repeat (np_test_1_all.cpp:18268) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18258 :emphasize-lines: 11 // Create test array auto array = createInt32Array({ 2, 3 }, 0); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { array.setElementAt({ i, j }, static_cast(i * 3 + j + 1)); } } // Test repeat without axis (flattened) auto repeated_flat = repeat(array, 2); if (!(repeated_flat.getShape()[0] == 12)) { std::string description = std::string("testRepeat():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repeated_flat.getShape()[0] == 12)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(repeated_flat.getElementAt({ 0 }) == 1)) { std::string description = std::string("testRepeat():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repeated_flat.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-rangeindex-repeat-30: .. dropdown:: repeat (np_test_1_all.cpp:18268) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18258 :emphasize-lines: 11 // Create test array auto array = createInt32Array({ 2, 3 }, 0); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { array.setElementAt({ i, j }, static_cast(i * 3 + j + 1)); } } // Test repeat without axis (flattened) auto repeated_flat = repeat(array, 2); if (!(repeated_flat.getShape()[0] == 12)) { std::string description = std::string("testRepeat():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repeated_flat.getShape()[0] == 12)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(repeated_flat.getElementAt({ 0 }) == 1)) { std::string description = std::string("testRepeat():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repeated_flat.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-rangeindex-copy-31: .. dropdown:: copy (np_test_1_all.cpp:9812) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9802 :emphasize-lines: 11 //original.printArray(); // The modification should be at position (1,1) in original if (!(original.getElementAt({1, 1}) == 9999)) { std::string description = std::string("testSliceCopyVsViewMemoryOwnership():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 9999)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Slice view shares memory with original"; // Test slice copy (should be independent) auto slice_copy = original.sliceArray({{2, 4}, {2, 4}}); // std::cout << "Slice copy [2:4, 2:4]:"; //slice_copy.printArray(); slice_copy.setElementAt({0, 0}, 7777); // std::cout << "After modifying slice copy at (0,0):" << std::endl; // std::cout << "Original array:" << std::endl; //original.printArray(); // std::cout << "Slice copy:" << std::endl; .. _example-rangeindex-view-32: .. dropdown:: view (np_test_1_all.cpp:440) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 430 :emphasize-lines: 11 for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 3; ++j) { original.setElementAt({i, j}, static_cast(i * 3 + j)); } } // std::cout << "Original array:" << std::endl; //original.printArray(); // Create multiple views auto view1 = original.view(); auto view2 = original.transposeView(); auto view3 = original.sliceView({{1, 3}, {1, 3}}); // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); .. _example-rangeindex-is_numeric-33: .. dropdown:: is_numeric (np_test_1_all.cpp:7511) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7501 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testNumericConversionStringTypes() { std::cout << "========= testNumericStringOperationsStringTypes ======================="; str32 num_str1("123.45"); str32 num_str2("67.89"); str32 not_num("hello"); // std::cout << "String '" << num_str1 << "' is numeric: " << is_numeric(num_str1) << std::endl; // std::cout << "String '" << not_num << "' is numeric: " << is_numeric(not_num) << std::endl; if (is_numeric(num_str1)) { double val1 = to_numeric(num_str1); // std::cout << "Numeric value of '" << num_str1 << "': " << val1 << std::endl; } if (is_numeric(num_str2)) { double val2 = to_numeric(num_str2); // std::cout << "Numeric value of '" << num_str2 << "': " << val2 << std::endl; .. _example-rangeindex-is_unique-34: .. dropdown:: is_unique (np_test_1_all.cpp:19676) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19666 :emphasize-lines: 11 unique_array.setElementAt({ 1 }, 2); unique_array.setElementAt({ 2 }, 3); unique_array.setElementAt({ 3 }, 4); auto duplicate_array = createInt32Array({ 4 }, 0); duplicate_array.setElementAt({ 0 }, 1); duplicate_array.setElementAt({ 1 }, 2); duplicate_array.setElementAt({ 2 }, 2); // Duplicate duplicate_array.setElementAt({ 3 }, 4); if (!(set_ops::is_unique(unique_array) == true)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::is_unique(unique_array) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(set_ops::is_unique(duplicate_array) == false)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::is_unique(duplicate_array) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] is_unique function works correctly\n"; .. _example-rangeindex-argmax-35: .. dropdown:: argmax (np_test_3_all.cpp:20521) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20511 :emphasize-lines: 11 auto result = numpy::argmin(arr); // Should return 1 (index of (1,5)) if (result.getElementAt({0}) != 1) { throw std::runtime_error("argmin() failed: expected index 1"); } std::cout << "PASSED\n"; } void test_argmax_complex128() { std::cout << " Testing argmax() with complex128... "; numpy::NDArray arr({3}); arr.setElementAt({0}, complex128(3.0, 1.0)); // index 0 - largest arr.setElementAt({1}, complex128(1.0, 5.0)); // index 1 arr.setElementAt({2}, complex128(2.0, 2.0)); // index 2 auto result = numpy::argmax(arr); // Should return 0 (index of (3,1)) if (result.getElementAt({0}) != 0) { throw std::runtime_error("argmax() failed: expected index 0"); } .. _example-rangeindex-argmin-36: .. dropdown:: argmin (np_test_3_all.cpp:20506) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20496 :emphasize-lines: 11 if (min_result.getElementAt({0}).real() != 2.0 || min_result.getElementAt({0}).imag() != 1.0) { throw std::runtime_error("min() tie-breaking failed: expected (2,1)"); } if (max_result.getElementAt({0}).real() != 2.0 || max_result.getElementAt({0}).imag() != 5.0) { throw std::runtime_error("max() tie-breaking failed: expected (2,5)"); } std::cout << "PASSED\n"; } void test_argmin_complex128() { std::cout << " Testing argmin() with complex128... "; numpy::NDArray arr({3}); arr.setElementAt({0}, complex128(3.0, 1.0)); // index 0 arr.setElementAt({1}, complex128(1.0, 5.0)); // index 1 - smallest arr.setElementAt({2}, complex128(2.0, 2.0)); // index 2 auto result = numpy::argmin(arr); // Should return 1 (index of (1,5)) if (result.getElementAt({0}) != 1) { throw std::runtime_error("argmin() failed: expected index 1"); } .. _example-rangeindex-arr-37: .. dropdown:: arr (np_test_1_all.cpp:1388) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1378 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(*str_obj.get_as() == "hello")) { std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as() == \"hello\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test NDArray construction NDArray arr({2, 2}, 3.14); object_ arr_obj(arr); if (!(!arr_obj.is_null())) { std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(arr_obj.is_array())) { std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-rangeindex-clone-38: .. dropdown:: clone (np_test_1_all.cpp:24942) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24932 :emphasize-lines: 11 } // Test reproducibility numpy::random::PCG64DXSM rng2(11111); if (rng2.next_uint64() != val) { std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : not reproducible"; throw std::runtime_error("np_test_bitgen_pcg64dxsm failed"); } // Test clone auto cloned = rng.clone(); if (cloned->name() != "PCG64DXSM") { std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : clone name incorrect"; throw std::runtime_error("np_test_bitgen_pcg64dxsm failed"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // PHILOX TESTS .. _example-rangeindex-contains-39: .. dropdown:: contains (np_test_2_all.cpp:10521) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10511 :emphasize-lines: 11 auto npz_file = load_npz(TEMP_DIR + "test_multiple.npz"); // Verify keys auto keys = npz_file.keys(); if (!(keys.size() == 3)) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(keys.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(npz_file.contains("integers"))) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(npz_file.contains(\"integers\"))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(npz_file.contains("floats"))) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(npz_file.contains(\"floats\"))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(npz_file.contains("complex_nums"))) { .. _example-rangeindex-counts-40: .. dropdown:: counts (np_test_1_all.cpp:19042) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19032 :emphasize-lines: 11 std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_full_result.values.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_full_result.counts.getSize() == 4)) { std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_full_result.counts.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Check counts (1 appears 2 times, 2 appears 2 times, 3 appears 2 times, 4 appears 1 time) if (!(unique_full_result.counts.getElementAt({ 0 }) == 2)) { std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_full_result.counts.getElementAt({ 0 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_full_result.counts.getElementAt({ 1 }) == 2)) { std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_full_result.counts.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-rangeindex-diff-41: .. dropdown:: diff (np_test_2_all.cpp:4947) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4937 :emphasize-lines: 11 // Test matrix addition and subtraction numpy::Matrix a("1 2; 3 4"); numpy::Matrix b("5 6; 7 8"); auto sum = a + b; assert_test(std::abs(sum(0, 0) - 6.0) < 1e-10, "Matrix addition"); assert_test(std::abs(sum(1, 1) - 12.0) < 1e-10, "Matrix addition"); auto diff = b - a; assert_test(std::abs(diff(0, 0) - 4.0) < 1e-10, "Matrix subtraction"); assert_test(std::abs(diff(1, 1) - 4.0) < 1e-10, "Matrix subtraction"); // Test matrix multiplication (not element-wise!) auto product = a * b; assert_test(std::abs(product(0, 0) - 19.0) < 1e-10, "Matrix multiplication 0,0"); assert_test(std::abs(product(0, 1) - 22.0) < 1e-10, "Matrix multiplication 0,1"); assert_test(std::abs(product(1, 0) - 43.0) < 1e-10, "Matrix multiplication 1,0"); assert_test(std::abs(product(1, 1) - 50.0) < 1e-10, "Matrix multiplication 1,1"); // Test scalar multiplication .. _example-rangeindex-difference-42: .. dropdown:: difference (np_test_1_all.cpp:19333) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19323 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(difference.getElementAt({ 2 }) == 5)) { std::string description = std::string("testSetDifferenceOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(difference.getElementAt({ 2 }) == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Set difference works correctly\n"; // Test symmetric difference (XOR) auto xor_result = setxor1d(arr1, arr2); if (!(xor_result.getSize() == 4)) { std::string description = std::string("testSetDifferenceOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(xor_result.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(xor_result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testSetDifferenceOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(xor_result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-rangeindex-dtype_name-43: .. dropdown:: dtype_name (np_test_2_all.cpp:3567) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3557 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(flags_info.writeable == true)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.writeable == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test dtype functions if (!(dtype_name(arr) == "float64")) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_name(arr) == \"float64\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(dtype_itemsize(arr) == sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_itemsize(arr) == sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-rangeindex-format-44: .. dropdown:: format (main.cpp:22) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12 :emphasize-lines: 11 int main() { // Automatically log all output to temp/test_output.log numpy::TestLogger logger("temp/test_output.log"); int res = 0; int res1 = 0; std::string resS = ""; // call all the tests res1 = numpy_tests::np_test_main(); resS += std::format(" np_test_main: {} errors\n", res1); res += res1; std::cout << "\n------------------------- main --------------------------------------------\n"; std::cout << std::endl << "All tests completed. Nb errors = " << res << std::endl; std::cout << "Details: \n" << resS; std::cout << "\n---------------------------------------------------------------------------\n"; return res; } .. _example-rangeindex-join-45: .. dropdown:: join (np_test_5_all.cpp:1341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1331 :emphasize-lines: 11 // ============================================================================ void np_test_string_join() { std::cout << "========= join operation ======================="; // Join takes a separator string and vector of CharArrays std::vector> arrays; arrays.push_back(numpy::char_::array<32>({ "a", "b", "c" })); arrays.push_back(numpy::char_::array<32>({ "x", "y", "z" })); auto result = numpy::char_::join("-", arrays); bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_join() : join operation failed"; throw std::runtime_error("np_test_string_join failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-rangeindex-name-46: .. dropdown:: name (np_test_1_all.cpp:24865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24855 :emphasize-lines: 11 uint64_t before_restore = rng.next_uint64(); rng.set_state(state); uint64_t after_restore = rng.next_uint64(); if (before_restore != after_restore) { std::cout << " [FAIL] : in np_test_bitgen_mt19937() : state restore failed"; throw std::runtime_error("np_test_bitgen_mt19937 failed: state"); } // Test name if (rng.name() != "MT19937") { std::cout << " [FAIL] : in np_test_bitgen_mt19937() : incorrect name"; throw std::runtime_error("np_test_bitgen_mt19937 failed: name"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // PCG64 TESTS // ============================================================================ .. _example-rangeindex-nbytes-47: .. dropdown:: nbytes (np_test_2_all.cpp:3547) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3537 :emphasize-lines: 11 } // Test itemsize if (!(itemsize(arr) == sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(itemsize(arr) == sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test nbytes if (!(nbytes(arr) == 24 * sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test flags auto flags_info = flags(arr); if (!(flags_info.owndata == true)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.owndata == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-rangeindex-result-48: .. dropdown:: result (np_test_1_all.cpp:6090) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6080 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "Timer restart test passed. Second: " << second_elapsed << " ms" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_benchmark_result_storageBenchmarkSorting() { std::cout << "========= test_benchmark_result_storage ======================="; BenchmarkResult result("TestAlgorithm", 1000, 15.5, true, 4096); if (!(result.algorithm_name == "TestAlgorithm")) { std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.algorithm_name == \"TestAlgorithm\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.array_size == 1000)) { std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.array_size == 1000)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-rangeindex-shift-49: .. dropdown:: shift (np_test_1_all.cpp:2761) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2751 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(left_array.getElementAt({3}) == 16384)) { std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(left_array.getElementAt({3}) == 16384)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Left shift by array\n"; // Test excessive shift (should result in 0) auto excessive_left = left_shift(arr, 20); // More than 16 bits if (!(excessive_left.getElementAt({0}) == 0)) { std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({0}) == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(excessive_left.getElementAt({1}) == 0)) { std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({1}) == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-rangeindex-size-50: .. 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); .. _example-rangeindex-slice-51: .. dropdown:: slice (np_test_1_all.cpp:13009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12999 :emphasize-lines: 11 // Test substr valid start but excessive length auto result3 = str1.substr(2, 10); // start=2, len=10 on string of length 5 if (!(result3.to_string() == "llo")) { std::string description = std::string("test_variable_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result3.to_string() == \"llo\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] vstring_ substr(2, 10) on 'hello' returns 'llo'\n"; // Test slice method with out-of-bounds auto result4 = str1.slice(10, 15); // slice[10:15] on string of length 5 if (!(result4.to_string() == "")) { std::string description = std::string("test_variable_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result4.to_string() == \"\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] vstring_ slice(10, 15) on 'hello' returns empty string\n"; // Test slice with negative indices auto result5 = str1.slice(-2, -1); // slice[-2:-1] should be "l" if (!(result5.to_string() == "l")) { .. _example-rangeindex-start-52: .. dropdown:: start (np_test_1_all.cpp:6043) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6033 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ------ merging np_test_benchmark_sorting.cpp -- number of functions merged= 11 -------------------------------- void test_timer_accuracyBenchmarkSorting() { std::cout << "========= test_timer_accuracy ======================="; Timer timer; timer.start(); // Sleep for a known duration (10ms) std::this_thread::sleep_for(std::chrono::milliseconds(10)); double elapsed = timer.elapsed_milliseconds(); // Timer should be approximately 10ms (allow 5ms tolerance for system variance) if (!(elapsed >= 3.0 && elapsed <= 105.0)) { std::string description = std::string("test_timer_accuracyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(elapsed >= 3.0 && elapsed <= 105.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-rangeindex-step-53: .. dropdown:: step (np_test_1_all.cpp:6929) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6919 :emphasize-lines: 11 // Create array of dates datetime64 start("2024-01-01"); auto date_array = createDateTimeArray({5}, start); // std::cout << "Array of 5 dates initialized to 2024-01-01:" << std::endl; //date_array.printArray(); // Create date range datetime64 range_start("2024-01-01"); datetime64 range_end("2024-01-10"); timedelta64 step(1, DateTimeUnit::Day); auto date_range = createDateRange(range_start, range_end, step); // std::cout << "Date range from 2024-01-01 to 2024-01-10:" << std::endl; //date_range.printArray(); // Create timedelta array timedelta64 one_day(1, DateTimeUnit::Day); auto timedelta_array = createTimeDeltaArray({3}, one_day); // std::cout << "Array of 3 timedeltas (1 day each):" << std::endl;