MCPcopy Create free account
hub / github.com/numpy/numpy / scalar_instances

Function scalar_instances

numpy/core/tests/test_array_coercion.py:81–134  ·  view source on GitHub ↗
(times=True, extended_precision=True, user_dtype=True)

Source from the content-addressed store, hash-verified

79
80
81def scalar_instances(times=True, extended_precision=True, user_dtype=True):
82 # Hard-coded list of scalar instances.
83 # Floats:
84 yield param(np.sqrt(np.float16(5)), id="float16")
85 yield param(np.sqrt(np.float32(5)), id="float32")
86 yield param(np.sqrt(np.float64(5)), id="float64")
87 if extended_precision:
88 yield param(np.sqrt(np.longdouble(5)), id="longdouble")
89
90 # Complex:
91 yield param(np.sqrt(np.complex64(2+3j)), id="complex64")
92 yield param(np.sqrt(np.complex128(2+3j)), id="complex128")
93 if extended_precision:
94 yield param(np.sqrt(np.longcomplex(2+3j)), id="clongdouble")
95
96 # Bool:
97 # XFAIL: Bool should be added, but has some bad properties when it
98 # comes to strings, see also gh-9875
99 # yield param(np.bool_(0), id="bool")
100
101 # Integers:
102 yield param(np.int8(2), id="int8")
103 yield param(np.int16(2), id="int16")
104 yield param(np.int32(2), id="int32")
105 yield param(np.int64(2), id="int64")
106
107 yield param(np.uint8(2), id="uint8")
108 yield param(np.uint16(2), id="uint16")
109 yield param(np.uint32(2), id="uint32")
110 yield param(np.uint64(2), id="uint64")
111
112 # Rational:
113 if user_dtype:
114 yield param(rational(1, 2), id="rational")
115
116 # Cannot create a structured void scalar directly:
117 structured = np.array([(1, 3)], "i,i")[0]
118 assert isinstance(structured, np.void)
119 assert structured.dtype == np.dtype("i,i")
120 yield param(structured, id="structured")
121
122 if times:
123 # Datetimes and timedelta
124 yield param(np.timedelta64(2), id="timedelta64[generic]")
125 yield param(np.timedelta64(23, "s"), id="timedelta64[s]")
126 yield param(np.timedelta64("NaT", "s"), id="timedelta64[s](NaT)")
127
128 yield param(np.datetime64("NaT"), id="datetime64[generic](NaT)")
129 yield param(np.datetime64("2020-06-07 12:43", "ms"), id="datetime64[ms]")
130
131 # Strings and unstructured void:
132 yield param(np.bytes_(b"1234"), id="bytes")
133 yield param(np.str_("2345"), id="unicode")
134 yield param(np.void(b"4321"), id="unstructured_void")
135
136
137def is_parametric_dtype(dtype):

Calls 1

dtypeMethod · 0.45

Tested by

no test coverage detected