PeriodDtype =========== .. cpp:class:: numpy::PeriodDtype numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use PeriodDtype PeriodDtype obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``explicit PeriodDtype(PeriodFrequency freq)`` - df_period_dtype.h:123 - * - ``explicit PeriodDtype(const std::string& freq_str)`` - df_period_dtype.h:131 - 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_period_dtype.h:156 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``PeriodFrequency freq() const`` - PeriodFrequency - df_period_dtype.h:178 - * - ``std::string freq_string() const`` - std::string - df_period_dtype.h:185 - * - ``std::string kind() const override`` - std::string - df_period_dtype.h:164 - * - ``bool matches(const std::string& dtype_name) const`` - bool - df_period_dtype.h:194 - :ref:`View ` * - ``std::string name() const override`` - std::string - df_period_dtype.h:141 - :ref:`View ` * - ``numpy::DType numpy_dtype() const override`` - numpy::DType - df_period_dtype.h:149 - * - ``std::string repr() const override`` - std::string - df_period_dtype.h:205 - * - ``const std::type_info& type() const override`` - const std::type_info& - df_period_dtype.h:171 - :ref:`View ` * - ``PeriodDtype with_freq(PeriodFrequency new_freq) const`` - PeriodDtype - df_period_dtype.h:212 - * - ``PeriodDtype with_freq(const std::string& new_freq) const`` - PeriodDtype - df_period_dtype.h:219 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-perioddtype-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-perioddtype-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-perioddtype-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-perioddtype-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())";