Skip to content

Any*Array and Any*DType

The Any{Scalar}Array type aliases describe array-likes that are coercible to an numpy.ndarray with specific dtype.

Unlike numpy.typing.ArrayLike, these optype.numpy aliases don't accept "bare" scalar types such as float and np.float64. However, arrays of "zero dimensions" like onp.Array[tuple[()], np.float64] will be accepted. This is in line with the behavior of numpy.isscalar on numpy >= 2.

import numpy.typing as npt
import optype.numpy as onp

v_np: npt.ArrayLike = 3.14  # accepted
v_op: onp.AnyArray = 3.14  # rejected

sigma1_np: npt.ArrayLike = [[0, 1], [1, 0]]  # accepted
sigma1_op: onp.AnyArray = [[0, 1], [1, 0]]  # accepted

Info

The numpy.dtypes docs exists since NumPy 1.26, but its type annotations were incorrect before NumPy 2.1 (see numpy/numpy#27008)

See the docs for more info on the NumPy scalar type hierarchy.

Abstract types

numpy._ optype.numpy._
scalar scalar base array-like dtype-like
generic AnyArray AnyDType
number generic AnyNumberArray AnyNumberDType
integer number AnyIntegerArray AnyIntegerDType
inexact AnyInexactArray AnyInexactDType
unsignedinteger integer AnyUnsignedIntegerArray AnyUnsignedIntegerDType
signedinteger AnySignedIntegerArray AnySignedIntegerDType
floating inexact AnyFloatingArray AnyFloatingDType
complexfloating AnyComplexFloatingArray AnyComplexFloatingDType

Integers

Unsigned:

numpy._ numpy.dtypes._ optype.numpy._
scalar scalar base dtype array-like dtype-like
uint_ unsignedinteger AnyUIntArray AnyUIntDType
uintp AnyUIntPArray AnyUIntPDType
uint8, ubyte UInt8DType AnyUInt8Array AnyUInt8DType
uint16, ushort UInt16DType AnyUInt16Array AnyUInt16DType
uint32 UInt32DType AnyUInt32Array AnyUInt32DType
uint64 UInt64DType AnyUInt64Array AnyUInt64DType
uintc UIntDType AnyUIntCArray AnyUIntCDType
ulong ULongDType AnyULongArray AnyULongDType
ulonglong ULongLongDType AnyULongLongArray AnyULongLongDType

Signed:

numpy._ numpy.dtypes._ optype.numpy._
scalar scalar base dtype array-like dtype-like
int_ signedinteger AnyIntArray AnyIntDType
intp AnyIntPArray AnyIntPDType
int8, byte Int8DType AnyInt8Array AnyInt8DType
int16, short Int16DType AnyInt16Array AnyInt16DType
int32 Int32DType AnyInt32Array AnyInt32DType
int64 Int64DType AnyInt64Array AnyInt64DType
intc IntDType AnyIntCArray AnyIntCDType
long LongDType AnyLongArray AnyLongDType
longlong LongLongDType AnyLongLongArray AnyLongLongDType

Info

Since NumPy 2, np.uint and np.int_ are aliases for np.uintp and np.intp, respectively.

Info

On unix-based platforms np.[u]intc are aliases for np.[u]int32.

Info

On NumPy 1 np.uint and np.int_ are what in NumPy 2 are now the np.ulong and np.long types, respectively.

Real floats

numpy._ numpy.dtypes._ optype.numpy._
scalar scalar base dtype array-like dtype-like
float16,
half
np.floating Float16DType AnyFloat16Array AnyFloat16DType
float32,
single
Float32DType AnyFloat32Array AnyFloat32DType
float64,
double
np.floating &
builtins.float
Float64DType AnyFloat64Array AnyFloat64DType
longdouble np.floating LongDoubleDType AnyLongDoubleArray AnyLongDoubleDType

Info

Depending on the platform, np.longdouble is (almost always) an alias for either float128, float96, or (sometimes) float64.

Complex floats

numpy._ numpy.dtypes._ optype.numpy._
scalar scalar base dtype array-like dtype-like
complex64,
csingle
complexfloating Complex64DType AnyComplex64Array AnyComplex64DType
complex128,
cdouble
complexfloating &
builtins.complex
Complex128DType AnyComplex128Array AnyComplex128DType
clongdouble complexfloating CLongDoubleDType AnyCLongDoubleArray AnyCLongDoubleDType

Info

Depending on the platform, np.clongdouble is (almost always) an alias for either complex256, complex192, or (sometimes) complex128.

"Flexible"

Scalar types with "flexible" length, whose values have a (constant) length that depends on the specific np.dtype instantiation.

numpy._ numpy.dtypes._ optype.numpy._
scalar scalar base dtype array-like dtype-like
str_ character StrDType AnyStrArray AnyStrDType
bytes_ BytesDType AnyBytesArray AnyBytesDType
dtype("c") AnyBytes8DType
void flexible VoidDType AnyVoidArray AnyVoidDType

Other types

numpy._ numpy.dtypes._ optype.numpy._
scalar scalar base dtype array-like dtype-like
bool_ generic BoolDType AnyBoolArray AnyBoolDType
object_ ObjectDType AnyObjectArray AnyObjectDType
datetime64 DateTime64DType AnyDateTime64Array AnyDateTime64DType
timedelta64 generic TimeDelta64DType AnyTimeDelta64Array AnyTimeDelta64DType
StringDType AnyStringArray AnyStringDType

Info

Since NumPy 2, np.bool is preferred over np.bool_, which only exists for backwards compatibility.

Info

At runtime np.timedelta64 is a subclass of np.signedinteger, but this is currently not reflected in the type annotations.

Info

The np.dypes.StringDType has no associated numpy scalar type, and its .type attribute returns the builtins.str type instead. But from a typing perspective, such a np.dtype[builtins.str] isn't a valid type.