TimedeltaDtype ============== .. cpp:class:: numpy::TimedeltaDtype numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use TimedeltaDtype TimedeltaDtype obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``explicit TimedeltaDtype(numpy::DateTimeUnit unit)`` - df_timedelta_dtype.h:43 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t itemsize() const override`` - size_t - df_timedelta_dtype.h:69 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string kind() const override`` - std::string - df_timedelta_dtype.h:77 - * - ``bool matches(const std::string& dtype_name) const`` - bool - df_timedelta_dtype.h:119 - :ref:`View ` * - ``std::string name() const override`` - std::string - df_timedelta_dtype.h:53 - :ref:`View ` * - ``numpy::DType numpy_dtype() const override`` - numpy::DType - df_timedelta_dtype.h:62 - * - ``std::string repr() const override`` - std::string - df_timedelta_dtype.h:130 - * - ``const std::type_info& type() const override`` - const std::type_info& - df_timedelta_dtype.h:84 - :ref:`View ` * - ``numpy::DateTimeUnit unit() const`` - numpy::DateTimeUnit - df_timedelta_dtype.h:91 - * - ``std::string unit_string() const`` - std::string - df_timedelta_dtype.h:98 - * - ``TimedeltaDtype with_unit(numpy::DateTimeUnit new_unit) const`` - TimedeltaDtype - df_timedelta_dtype.h:139 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-timedeltadtype-itemsize-0: .. dropdown:: itemsize (np_test_2_all.cpp:3540) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3530 :emphasize-lines: 11 } // Test size if (!(size(arr) == 24)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(size(arr) == 24)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // 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); .. _example-timedeltadtype-matches-1: .. dropdown:: matches (np_test_1_all.cpp:26699) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26689 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ load_library() (stub)" << std::endl; } // Test ndpointer { auto ptr_desc = numpy::ctypeslib::ndpointer(2, { 10, 10 }); auto arr = NDArray({ 10, 10 }, 0.0); bool matches = ptr_desc.matches(arr); if (!(matches)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(matches)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ ndpointer()" << std::endl; } // std::cout << " [PASS] Sub-phase 6D complete (4 functions tested)" << std::endl; } .. _example-timedeltadtype-name-2: .. 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-timedeltadtype-type-3: .. dropdown:: type (np_test_1_all.cpp:2240) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2230 :emphasize-lines: 11 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 1}).is_type())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(multi_array.getElementAt({0, 2}).is_type())) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 2}).is_type())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 4: Arrays with all same type (homogeneous) NDArray homo_array = createObjectZeros({5}); for (size_t i = 0; i < 5; ++i) { homo_array.setElementAt({i}, object_(static_cast(i * 10))); } // Verify all are same type for (size_t i = 0; i < 5; ++i) { object_ obj = homo_array.getElementAt({i}); if (!(obj.is_type())) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())";