Constants and functions

from ndtypes import ndt

Constants

The ndt namespace includes the following dtype constants. Currently they are an alternative for using the ndt.type constructor.
>>> ndt.bool
ndt.type('bool')

# It follows that the constants do not define separate classes.
>>> type(ndt.bool)
<class 'ndtypes.ndt.type.type'>
Constants
void
bool
int8
int32
int64
int128
uint8
uint32
uint64
uint128
float16
float64
float128
complex64
complex128
complex_float32
complex_float64

Functions

Some dtypes and arrays can also be constructed using functions instead of the string notation.

Create dtypes

ndt.make_string()

Create a variable length string dtype with encoding UTF8.

>>> ndt.make_string()
ndt.type('string')
ndt.make_fixed_string(length, encoding='utf8')

Create a fixed string dtype.

>>> ndt.make_fixed_string(100, encoding='utf32')
ndt.type("fixed_string[100, 'utf32']")
ndt.make_fixed_bytes(length, align)

Create a fixed bytes dtype.

>>> ndt.make_fixed_bytes(100, 2)
ndt.type('fixed_bytes[100, align=2]')
ndt.make_tuple(field_types)

Create a tuple dtype.

>>> ndt.make_tuple([ndt.int64, ndt.complex128])
ndt.type('(int64, complex[float64])')
ndt.make_struct(field_types, field_names)

Create a struct dtype.

>>> ndt.make_struct([ndt.int64], ["x"])
ndt.type('{x: int64}')

Create arrays

ndt.make_fixed_dim(size, dtype)

Create an array with a fixed dimension.

>>> ndt.make_fixed_dim(10, ndt.int32)
ndt.type('10 * int32')
>>> ndt.make_fixed_dim(20, ndt.make_fixed_dim(10, ndt.int32))
ndt.type('20 * 10 * int32')
ndt.make_var_dim(dtype)

Create an array with a variable dimension.

>>> ndt.make_var_dim(ndt.int32)
ndt.type('var * int32')
>>> ndt.make_var_dim(ndt.make_var_dim(ndt.int32))
ndt.type('var * var * int32')
ndt.make_fixed_dim_kind(dtype)

Create an array with a fixed dimension kind.

>>> ndt.make_fixed_dim_kind(ndt.int32)
ndt.type('Fixed * int32')