TimedeltaDtype#

class numpy::TimedeltaDtype#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use TimedeltaDtype
TimedeltaDtype obj;
// ... operations ...

Constructors#

Signature

Location

Example

explicit TimedeltaDtype(numpy::DateTimeUnit unit)

df_timedelta_dtype.h:43

Indexing / Selection#

Signature

Return Type

Location

Example

size_t itemsize() const override

size_t

df_timedelta_dtype.h:69

View

Other Methods#

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

View

std::string name() const override

std::string

df_timedelta_dtype.h:53

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

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.

itemsize (np_test_2_all.cpp:3540)
3530      }
3531
3532      // Test size
3533      if (!(size(arr) == 24)) {
3534          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(size(arr) == 24)";
3535          std::cout << std::string("[FAIL] ") + description << std::endl;
3536          throw std::runtime_error(description);
3537      }
3538
3539      // Test itemsize
3540      if (!(itemsize(arr) == sizeof(double))) {
3541          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(itemsize(arr) == sizeof(double))";
3542          std::cout << std::string("[FAIL] ") + description << std::endl;
3543          throw std::runtime_error(description);
3544      }
3545
3546      // Test nbytes
3547      if (!(nbytes(arr) == 24 * sizeof(double))) {
3548          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))";
3549          std::cout << std::string("[FAIL] ") + description << std::endl;
3550          throw std::runtime_error(description);
matches (np_test_1_all.cpp:26699)
26689            std::cout << std::string("[FAIL] ") + description << std::endl;
26690            throw std::runtime_error(description);
26691        }
26692        // std::cout << "  ✓ load_library() (stub)" << std::endl;
26693      }
26694
26695      // Test ndpointer
26696      {
26697        auto ptr_desc = numpy::ctypeslib::ndpointer<double>(2, { 10, 10 });
26698        auto arr = NDArray<double>({ 10, 10 }, 0.0);
26699        bool matches = ptr_desc.matches(arr);
26700        if (!(matches)) {
26701            std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(matches)";
26702            std::cout << std::string("[FAIL] ") + description << std::endl;
26703            throw std::runtime_error(description);
26704        }
26705        // std::cout << "  ✓ ndpointer()" << std::endl;
26706      }
26707
26708      // std::cout << "  [PASS] Sub-phase 6D complete (4 functions tested)" << std::endl;
26709    }
name (np_test_1_all.cpp:24865)
24855      uint64_t before_restore = rng.next_uint64();
24856      rng.set_state(state);
24857      uint64_t after_restore = rng.next_uint64();
24858
24859      if (before_restore != after_restore) {
24860        std::cout << "  [FAIL] : in np_test_bitgen_mt19937() : state restore failed";
24861        throw std::runtime_error("np_test_bitgen_mt19937 failed: state");
24862      }
24863
24864      // Test name
24865      if (rng.name() != "MT19937") {
24866        std::cout << "  [FAIL] : in np_test_bitgen_mt19937() : incorrect name";
24867        throw std::runtime_error("np_test_bitgen_mt19937 failed: name");
24868      }
24869
24870      std::cout << " -> tests passed" << std::endl;
24871    }
24872
24873    // ============================================================================
24874    // PCG64 TESTS
24875    // ============================================================================
type (np_test_1_all.cpp:2240)
2230        std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 1}).is_type<std::string>())";
2231        std::cout << std::string("[FAIL] ") + description << std::endl;
2232        throw std::runtime_error(description);
2233    }
2234    if (!(multi_array.getElementAt({0, 2}).is_type<double>())) {
2235        std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 2}).is_type<double>())";
2236        std::cout << std::string("[FAIL] ") + description << std::endl;
2237        throw std::runtime_error(description);
2238    }
2239
2240    // Test 4: Arrays with all same type (homogeneous)
2241    NDArray<object_> homo_array = createObjectZeros({5});
2242    for (size_t i = 0; i < 5; ++i) {
2243        homo_array.setElementAt({i}, object_(static_cast<int>(i * 10)));
2244    }
2245
2246    // Verify all are same type
2247    for (size_t i = 0; i < 5; ++i) {
2248        object_ obj = homo_array.getElementAt({i});
2249        if (!(obj.is_type<int>())) {
2250            std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";