FloatingDtype#
-
class numpy::FloatingDtype#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use FloatingDtype
FloatingDtype obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_floating_dtype.h:31 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
size_t |
df_floating_dtype.h:53 |
Statistics#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
T |
df_floating_dtype.h:82 |
|
|
T |
df_floating_dtype.h:75 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static bool |
df_floating_dtype.h:96 |
|
|
static bool |
df_floating_dtype.h:110 |
|
|
static bool |
df_floating_dtype.h:103 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
T |
df_floating_dtype.h:89 |
|
|
std::string |
df_floating_dtype.h:61 |
|
|
bool |
df_floating_dtype.h:119 |
|
|
std::string |
df_floating_dtype.h:38 |
|
|
numpy::DType |
df_floating_dtype.h:46 |
|
|
const std::type_info& |
df_floating_dtype.h:68 |
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);
epsilon (np_test_1_all.cpp:7822)
7812 // std::cout << " float16: " << sizeof(float16) << " bytes" << std::endl;
7813 // std::cout << " float32: " << sizeof(float32) << " bytes" << std::endl;
7814 // std::cout << " float64: " << sizeof(float64) << " bytes" << std::endl;
7815 // std::cout << " float128: " << sizeof(float128) << " bytes" << std::endl;
7816
7817 // Test numeric limits
7818 // std::cout << "Numeric limits:" << std::endl;
7819 // std::cout << " min: " << std::numeric_limits<float16>::min() << std::endl;
7820 // std::cout << " max: " << std::numeric_limits<float16>::max() << std::endl;
7821 // std::cout << " lowest: " << std::numeric_limits<float16>::lowest() << std::endl;
7822 // std::cout << " epsilon: " << std::numeric_limits<float16>::epsilon() << std::endl;
7823 // std::cout << " digits: " << std::numeric_limits<float16>::digits << std::endl;
7824 // std::cout << " digits10: " << std::numeric_limits<float16>::digits10 << std::endl;
7825
7826 std::cout << " -> tests passed" << std::endl;
7827}
7828
7829void testFloat16BitPatternsFloat16() {
7830 std::cout << "========= testFloat16BitPatternsFloat16 =======================";
7831
7832 // Test some known bit patterns
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>())";