transonic.typing

Create Pythran signatures from type hints

User API

class transonic.typing.Type(*args, name_calling_module=None)[source]

Bases: transonic.typing.TemplateVar, transonic.typing.FusedType

Template variable representing the dtype of an array.

As a user, it is useful only for fused types.

>>> Type(int, float)
Type(int, float)
class transonic.typing.NDim(*args, shift=0, name_calling_module=None)[source]

Bases: transonic.typing.TemplateVar

Template variable representing the number of dimension of an array.

As a user, it is useful only for fused types.

>>> N = NDim(1, 2)
>>> N1 = N + 1
class transonic.typing.Array[source]

Bases: object

Represent a Numpy array.

>>> Array[int, "2d"]
Array[int, "2d"]
>>> Array[int, "2d", "C"]
Array[int, "2d", "C"]
>>> Array[int, "2d", "F"]
Array[int, "2d", "F"]
>>> Array[int, "2d", "strided"]
Array[int, "2d", "strided"]

Fused types:

>>> Array[Type(int, float), "1d"]
Array[Type(int, float), "1d"]
>>> Array[float, NDim(2, 3)]
Array[float, NDim(2, 3)]
>>> Array[int, "1d", "C", "positive_indices"]
Array[int, "1d", "C", "positive_indices"]
class transonic.typing.List[source]

Bases: object

Similar to typing.List

>>> List[List[int]]
List[List[int]]
class transonic.typing.Tuple[source]

Bases: object

Similar to typing.Tuple

>>> Tuple[int, Array[int, "2d"]]
Tuple[int, Array[int, "2d"]]
class transonic.typing.Dict[source]

Bases: object

Similar to typing.Dict

>>> Dict[str, int]
Dict[str, int]
class transonic.typing.Set[source]

Bases: object

Similar to typing.Set

>>> Set[str]
Set[str]
class transonic.typing.Union[source]

Bases: object

Similar to typing.Union

>>> Union[float, Array[int, "1d"]]
Union[float, Array[int, "1d"]]
transonic.typing.str2type(str_type)[source]

Compute a Transonic type from a string

>>> str2type("int[:,:]")
Array[int, "2d"]
>>> str2type("int or float[]")
Union[int, Array[float, "1d"]]
>>> str2type("(int, float[:, :])")
Tuple[int, Array[float, "2d"]]
transonic.typing.typeof(obj)[source]

Compute the Transonic type corresponding to a Python object

Supports:

  • simple Python types (int, float, complex, str)

  • homogeneous list, dict and set

  • tuple

  • numpy scalars

  • numpy arrays

transonic.typing.const(type_)[source]

Declare a type as constant (const C/Cython keyword)

Internal API

class transonic.typing.TemplateVar(*args, name_calling_module=None)[source]

Bases: object

Base class for template variables

>>> T = TemplateVar("T")
>>> T = TemplateVar("T", int, float)
>>> T = TemplateVar()
Traceback (most recent call last):
    ...
ValueError
>>> T = TemplateVar(1)
Traceback (most recent call last):
    ...
TypeError: (1,) [False]
class transonic.typing.ArrayMeta[source]

Bases: transonic.typing.Meta

Metaclass for the Array class

class transonic.typing.ListMeta[source]

Bases: transonic.typing.Meta

Metaclass for the List class

class transonic.typing.DictMeta[source]

Bases: transonic.typing.Meta

Metaclass for the Dict class

transonic.typing.format_type_as_backend_type(type_, backend_type_formatter, **kwargs)[source]

Format a Transonic type as a backend (Pythran, Cython, …) type

class transonic.typing.ConstType(type_)[source]

Bases: transonic.typing.Type

Private API class for const

Functions

const(type_)

Declare a type as constant (const C/Cython keyword)

format_type_as_backend_type(type_, …)

Format a Transonic type as a backend (Pythran, Cython, …) type

shape2str(shape)

str2shape(str_shape)

str2type(str_type)

Compute a Transonic type from a string

typeof(obj)

Compute the Transonic type corresponding to a Python object

Classes

Array

Represent a Numpy array.

ArrayMeta

Metaclass for the Array class

ConstType(type_)

Private API class for const

Dict

Similar to typing.Dict

DictMeta

Metaclass for the Dict class

FusedType

List

Similar to typing.List

ListMeta

Metaclass for the List class

MemLayout

An enumeration.

Meta

Type of the Transonic types (used to create metaclasses)

NDim(*args[, shift, name_calling_module])

Template variable representing the number of dimension of an array.

Optional

Similar to typing.Optional

OptionalMeta

Set

Similar to typing.Set

SetMeta

Metaclass for the Set class

TemplateVar(*args[, name_calling_module])

Base class for template variables

Tuple

Similar to typing.Tuple

TupleMeta

Metaclass for the Tuple class

Type(*args[, name_calling_module])

Template variable representing the dtype of an array.

Union

Similar to typing.Union

UnionMeta

Metaclass for the Union class

UnionVar(*args[, name_calling_module])

TemplateVar used for the Union type