NDArrayBackedExtensionIndex =========================== .. cpp:class:: numpy::NDArrayBackedExtensionIndex numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use NDArrayBackedExtensionIndex NDArrayBackedExtensionIndex obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``explicit NDArrayBackedExtensionIndex(const ArrayType& array, const std::optional& name = std::nullopt, bool copy = false)`` - df_ndarray_backed_extension_index.h:139 - * - ``explicit NDArrayBackedExtensionIndex(ArrayType&& array, const std::optional& name = std::nullopt)`` - df_ndarray_backed_extension_index.h:149 - * - ``NDArrayBackedExtensionIndex(const NDArrayBackedExtensionIndex& other)`` - df_ndarray_backed_extension_index.h:158 - * - ``NDArrayBackedExtensionIndex(NDArrayBackedExtensionIndex&& other) noexcept`` - df_ndarray_backed_extension_index.h:166 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string get_value_str(size_t index) const override`` - std::string - df_ndarray_backed_extension_index.h:667 - I/O --- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string to_string() const override`` - std::string - df_ndarray_backed_extension_index.h:611 - :ref:`View ` Type Handling ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``NDArrayBackedExtensionIndex copy() const`` - NDArrayBackedExtensionIndex - df_ndarray_backed_extension_index.h:712 - :ref:`View ` Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool is_all_dates() const`` - bool - df_ndarray_backed_extension_index.h:486 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DatetimeArray arr(data, mask)`` - DatetimeArray - df_ndarray_backed_extension_index.h:276 - :ref:`View ` * - ``TimedeltaArray arr(data, mask)`` - TimedeltaArray - df_ndarray_backed_extension_index.h:293 - :ref:`View ` * - ``DatetimeArray arr(data, mask)`` - DatetimeArray - df_ndarray_backed_extension_index.h:346 - :ref:`View ` * - ``TimedeltaArray arr(data, mask)`` - TimedeltaArray - df_ndarray_backed_extension_index.h:362 - :ref:`View ` * - ``PeriodArray arr(data, mask, "D")`` - PeriodArray - df_ndarray_backed_extension_index.h:376 - :ref:`View ` * - ``PeriodArray arr(data, mask, freq)`` - PeriodArray - df_ndarray_backed_extension_index.h:402 - :ref:`View ` * - ``size_t cache_memory_usage() const override`` - size_t - df_ndarray_backed_extension_index.h:897 - * - ``\* Clears both the base class caches (from ExtensionIndex) and`` - \* Clears both the base class - df_ndarray_backed_extension_index.h:875 - * - ``void clear_cache() const override`` - void - df_ndarray_backed_extension_index.h:878 - * - ``std::unique_ptr clone() const override`` - std::unique_ptr - df_ndarray_backed_extension_index.h:604 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:263 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:281 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:298 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:334 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:350 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:366 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:393 - :ref:`View ` * - ``static std::string format_datetime(const numpy::datetime64& val)`` - static std::string - df_ndarray_backed_extension_index.h:733 - * - ``std::string format_period(numpy::int64 ordinal) const`` - std::string - df_ndarray_backed_extension_index.h:832 - * - ``static std::string format_timedelta(const numpy::timedelta64& val)`` - static std::string - df_ndarray_backed_extension_index.h:793 - * - ``std::string freq_string() const`` - std::string - df_ndarray_backed_extension_index.h:563 - * - ``bool has_cached_values() const override`` - bool - df_ndarray_backed_extension_index.h:888 - * - ``std::string inferred_type() const override`` - std::string - df_ndarray_backed_extension_index.h:590 - * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:264 - :ref:`View ` * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:282 - :ref:`View ` * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:299 - :ref:`View ` * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:335 - :ref:`View ` * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:351 - :ref:`View ` * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:367 - :ref:`View ` * - ``numpy::NDArray mask(std::vector`` - numpy::NDArray - df_ndarray_backed_extension_index.h:394 - :ref:`View ` * - ``PeriodArray arr(data, mask, period_freq_to_string(current_arr.freq()))`` - PeriodArray arr(data, mask, - df_ndarray_backed_extension_index.h:309 - * - ``NDArrayBackedExtensionIndex rename(const std::optional& new_name) const`` - NDArrayBackedExtensionIndex - df_ndarray_backed_extension_index.h:719 - * - ``std::string repr() const override`` - std::string - df_ndarray_backed_extension_index.h:660 - * - ``std::string resolution() const`` - std::string - df_ndarray_backed_extension_index.h:424 - :ref:`View ` * - ``NDArrayBackedExtensionIndex result(\*this)`` - NDArrayBackedExtensionIndex - df_ndarray_backed_extension_index.h:720 - :ref:`View ` * - ``std::string unit() const`` - std::string - df_ndarray_backed_extension_index.h:525 - * - ``static std::string unit_to_string(numpy::DateTimeUnit unit)`` - static std::string - df_ndarray_backed_extension_index.h:540 - * - ``\* int64 values (nanoseconds since epoch, timedelta values, or period ordinals).`` - \* int64 - df_ndarray_backed_extension_index.h:214 - :ref:`View ` Internal Methods ---------------- *6 internal methods (prefixed with underscore)* Code Examples ------------- The following examples are extracted from the test suite. .. _example-ndarraybackedextensionindex-to_string-0: .. 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-ndarraybackedextensionindex-copy-1: .. 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-ndarraybackedextensionindex-arr-2: .. 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-ndarraybackedextensionindex-arr-3: .. 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-ndarraybackedextensionindex-arr-4: .. 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-ndarraybackedextensionindex-arr-5: .. 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-ndarraybackedextensionindex-arr-6: .. 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-ndarraybackedextensionindex-arr-7: .. 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-ndarraybackedextensionindex-clone-8: .. 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-ndarraybackedextensionindex-data-9: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-data-10: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-data-11: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-data-12: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-data-13: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-data-14: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-data-15: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-ndarraybackedextensionindex-mask-16: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-mask-17: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-mask-18: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-mask-19: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-mask-20: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-mask-21: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-mask-22: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-ndarraybackedextensionindex-resolution-23: .. dropdown:: resolution (np_test_5_all.cpp:21200) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21190 :emphasize-lines: 11 std::cout << "[FAIL] np_test_timedelta_constructors: Timedelta(30, 's') expected 30 seconds, got " << td_sec.total_seconds() << std::endl; errors++; } numpy::Timedelta td_ms(500, "ms"); // 500 milliseconds std::cout << " Timedelta(500, 'ms') = " << td_ms.value() << " nanoseconds" << std::endl; int64_t expected_ms = 500 * numpy::Timedelta::NANOS_PER_MILLISECOND; if (td_ms.value() != expected_ms) { std::cout << "[FAIL] np_test_timedelta_constructors: Timedelta(500, 'ms') expected " << expected_ms << " ns, got " << td_ms.value() << std::endl; errors++; } numpy::Timedelta td_us(1000, "us"); // 1000 microseconds std::cout << " Timedelta(1000, 'us') = " << td_us.value() << " nanoseconds" << std::endl; int64_t expected_us = 1000 * numpy::Timedelta::NANOS_PER_MICROSECOND; if (td_us.value() != expected_us) { std::cout << "[FAIL] np_test_timedelta_constructors: Timedelta(1000, 'us') expected " << expected_us << " ns, got " << td_us.value() << std::endl; errors++; .. _example-ndarraybackedextensionindex-result-24: .. 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-ndarraybackedextensionindex-values-25: .. dropdown:: values (np_test_1_all.cpp:15133) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15123 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } else { std::cout << "[FAIL] Where function failed" << std::endl; errors++; } // Test 8: Clip function std::cout << "========= test_clip_function =======================" ; numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val);