pyccel.ast.datatypes module#
Classes and methods that handle supported datatypes in C/Fortran.
- class pyccel.ast.datatypes.CharType(self)[source]#
Bases:
FixedSizeType
Class representing a char type in C/Fortran.
Class representing a char type in C/Fortran. This datatype is useful for describing strings.
- class pyccel.ast.datatypes.ContainerType[source]#
Bases:
PyccelType
Base class representing a type which contains objects of other types.
Base class representing a type which contains objects of other types. E.g. classes, arrays, etc.
- shape_is_compatible(shape)[source]#
Check if the provided shape is compatible with the datatype.
Check if the provided shape is compatible with the format expected for this datatype.
- Parameters:
shape (Any) – The proposed shape.
- Returns:
True if the shape is acceptable, False otherwise.
- Return type:
bool
- class pyccel.ast.datatypes.CustomDataType(self)[source]#
Bases:
PyccelType
Class from which user-defined types inherit.
A general class for custom data types which is used as a base class when a user defines their own type using classes.
- property datatype#
The datatype of the object.
The datatype of the object.
- property order#
The data layout ordering in memory.
Indicates whether the data is stored in row-major (‘C’) or column-major (‘F’) format. This is only relevant if rank > 1. When it is not relevant this function returns None.
- property rank#
Number of dimensions of the object.
Number of dimensions of the object. If the object is a scalar then this is equal to 0.
- pyccel.ast.datatypes.DataTypeFactory(name, argnames=(), *, BaseClass=<class 'pyccel.ast.datatypes.CustomDataType'>)[source]#
Create a new data class.
Create a new data class which sub-classes a DataType. This provides a new data type which can be used, for example, for class types.
- Parameters:
name (str) – The name of the new class.
argnames (iterable[str]) – A list of all the arguments for the new class. This can be used to create classes which are parametrised by a type.
BaseClass (type inheriting from DataType) – The class from which the new type will be sub-classed.
- Returns:
A new DataType class.
- Return type:
type
- class pyccel.ast.datatypes.DictType(self, key_type, value_type)[source]#
Bases:
ContainerType
Class representing the homogeneous dictionary type.
Class representing the type of a homogeneous dict. This is a container type and should be used as the class_type.
- Parameters:
key_type (PyccelType) – The type of the keys of the homogeneous dictionary.
value_type (PyccelType) – The type of the values of the homogeneous dictionary.
- property container_rank#
Number of dimensions of the container.
Number of dimensions of the object described by the container. This is equal to the number of values required to index an element of this container.
- property datatype#
The datatype of the object.
The datatype of the object.
- property key_type#
The type of the keys of the object.
The type of the keys of the object.
- property order#
The data layout ordering in memory.
Indicates whether the data is stored in row-major (‘C’) or column-major (‘F’) format. This is only relevant if rank > 1. When it is not relevant this function returns None.
- property rank#
Number of dimensions of the object.
Number of dimensions of the object. If the object is a scalar then this is equal to 0.
- property value_type#
The type of the values of the object.
The type of the values of the object.
- class pyccel.ast.datatypes.FixedSizeNumericType(self)[source]#
Bases:
FixedSizeType
Base class representing a scalar numeric datatype.
The base class representing a scalar numeric datatype which can be represented in memory. E.g. int32, int64.
- property precision#
Precision of the datatype of the object.
The precision of the datatype of the object. This number is related to the number of bytes that the datatype takes up in memory. For basic types the number is equivalent to the number of bytes in memory (e.g. float64 has precision = 8 as it takes up 8 bytes), however for less simple types the connection is less trivial. For example complex128 has precision = 8 as it is comprised of two float64 objects (which have precision=8). It should be noted that this is not the convention chosen by NumPy (in NumPy a complex128 is so named because 16*8=precision*bits_in_a_byte=128).
The precision in Pyccel is equivalent to the kind parameter in Fortran.
- class pyccel.ast.datatypes.FixedSizeType(self)[source]#
Bases:
PyccelType
Base class representing a built-in scalar datatype.
The base class representing a built-in scalar datatype which can be represented in memory. E.g. int32, int64.
- property datatype#
The datatype of the object.
The datatype of the object.
- property order#
The data layout ordering in memory.
Indicates whether the data is stored in row-major (‘C’) or column-major (‘F’) format. This is only relevant if rank > 1. When it is not relevant this function returns None.
- property primitive_type#
The datatype category of the object.
The datatype category of the object (e.g. integer, floating point).
- property rank#
Number of dimensions of the object.
Number of dimensions of the object. If the object is a scalar then this is equal to 0.
- switch_basic_type(new_type)[source]#
Change the basic type to the new type.
Change the basic type to the new type. In the case of a FixedSizeType the switch will replace the type completely, directly returning the new type.
- Parameters:
new_type (PyccelType) – The new basic type.
- Returns:
The new type.
- Return type:
- class pyccel.ast.datatypes.GenericType(self)[source]#
Bases:
FixedSizeType
Class representing a generic datatype.
Class representing a generic datatype. This datatype is useful for describing the type of an empty container (list/tuple/etc) or an argument which can accept any type (e.g. MPI arguments).
- class pyccel.ast.datatypes.HomogeneousContainerType[source]#
Bases:
ContainerType
Base class representing a datatype which contains multiple elements of a given type.
Base class representing a datatype which contains multiple elements of a given type. This is the case for objects such as arrays, lists, etc.
- property container_rank#
Number of dimensions of the container.
Number of dimensions of the object described by the container. This is equal to the number of values required to index an element of this container.
- property datatype#
The datatype of the object.
The datatype of the object.
- property element_type#
The type of elements of the object.
The PyccelType describing an element of the container.
- property order#
The data layout ordering in memory.
Indicates whether the data is stored in row-major (‘C’) or column-major (‘F’) format. This is only relevant if rank > 1. When it is not relevant this function returns None.
- property precision#
Precision of the datatype of the object.
The precision of the datatype of the object. This number is related to the number of bytes that the datatype takes up in memory. For basic types the number is equivalent to the number of bytes in memory (e.g. float64 has precision = 8 as it takes up 8 bytes), however for less simple types the connection is less trivial. For example complex128 has precision = 8 as it is comprised of two float64 objects (which have precision=8). It should be noted that this is not the convention chosen by NumPy (in NumPy a complex128 is so named because 16*8=precision*bits_in_a_byte=128).
The precision in Pyccel is equivalent to the kind parameter in Fortran.
- property primitive_type#
The datatype category of elements of the object.
The datatype category of elements of the object (e.g. integer, floating point).
- property rank#
Number of dimensions of the object.
Number of dimensions of the object. If the object is a scalar then this is equal to 0.
- switch_basic_type(new_type)[source]#
Change the basic type to the new type.
Change the basic type to the new type. In the case of a FixedSizeType the switch will replace the type completely, directly returning the new type. In the case of a homogeneous container type, a new container type will be returned whose underlying elements are of the new type. This method is not implemented for inhomogeneous containers.
- Parameters:
new_type (PyccelType) – The new basic type.
- Returns:
The new type.
- Return type:
- switch_rank(new_rank, new_order=None)[source]#
Get a type which is identical to this type in all aspects except the rank.
Get a type which is identical to this type in all aspects except the rank. The order must be provided if the rank is increased from 1. This is never the case for 1D containers.
- Parameters:
new_rank (int) – The rank of the new type.
new_order (str, optional) – The order of the new type. For 1D containers this should not be provided.
- Returns:
The new type.
- Return type:
- class pyccel.ast.datatypes.HomogeneousListType(self, element_type)[source]#
Bases:
HomogeneousContainerType
Class representing the homogeneous list type.
Class representing the type of a homogeneous list. This is a container type and should be used as the class_type.
- Parameters:
element_type (PyccelType) – The type which is stored in the homogeneous list.
- class pyccel.ast.datatypes.HomogeneousSetType(self, element_type)[source]#
Bases:
HomogeneousContainerType
Class representing the homogeneous set type.
Class representing the type of a homogeneous set. This is a container type and should be used as the class_type.
- Parameters:
element_type (PyccelType) – The type which is stored in the homogeneous set.
- class pyccel.ast.datatypes.HomogeneousTupleType(self, element_type)[source]#
Bases:
HomogeneousContainerType
,TupleType
Class representing the homogeneous tuple type.
Class representing the type of a homogeneous tuple. This is a container type and should be used as the class_type.
- Parameters:
element_type (PyccelType) – The type of the elements of the homogeneous tuple.
- shape_is_compatible(shape)[source]#
Check if the provided shape is compatible with the datatype.
Check if the provided shape is compatible with the format expected for this datatype.
- Parameters:
shape (Any) – The proposed shape.
- Returns:
True if the shape is acceptable, False otherwise.
- Return type:
bool
- class pyccel.ast.datatypes.InhomogeneousTupleType(self, *args)[source]#
Bases:
ContainerType
,TupleType
Class representing the inhomogeneous tuple type.
Class representing the type of an inhomogeneous tuple. This is a basic datatype as it cannot be arbitrarily indexed. It is therefore parametrised by the datatypes that it contains.
- Parameters:
*args (tuple of DataTypes) – The datatypes stored in the inhomogeneous tuple.
- property container_rank#
Number of dimensions of the container.
Number of dimensions of the object described by the container. This is equal to the number of values required to index an element of this container.
- property datatype#
The datatype of the object.
The datatype of the object. For an inhomogeneous tuple the datatype is the type of the tuple unless the tuple is comprised of containers which are all based on compatible data types. In this case one of the underlying types is returned.
- property order#
The data layout ordering in memory.
Indicates whether the data is stored in row-major (‘C’) or column-major (‘F’) format. This is only relevant if rank > 1. When it is not relevant this function returns None.
- property rank#
Number of dimensions of the object.
Number of dimensions of the object. If the object is a scalar then this is equal to 0.
- shape_is_compatible(shape)[source]#
Check if the provided shape is compatible with the datatype.
Check if the provided shape is compatible with the format expected for this datatype.
- Parameters:
shape (Any) – The proposed shape.
- Returns:
True if the shape is acceptable, False otherwise.
- Return type:
bool
- class pyccel.ast.datatypes.PrimitiveBooleanType(self)[source]#
Bases:
PrimitiveType
Class representing a boolean datatype.
Class representing a boolean datatype.
- class pyccel.ast.datatypes.PrimitiveCharacterType(self)[source]#
Bases:
PrimitiveType
Class representing a character datatype.
Class representing a character datatype.
- class pyccel.ast.datatypes.PrimitiveComplexType(self)[source]#
Bases:
PrimitiveType
Class representing a complex datatype.
Class representing a complex datatype.
- class pyccel.ast.datatypes.PrimitiveFloatingPointType(self)[source]#
Bases:
PrimitiveType
Class representing a floating point datatype.
Class representing a floating point datatype.
- class pyccel.ast.datatypes.PrimitiveIntegerType(self)[source]#
Bases:
PrimitiveType
Class representing an integer datatype.
Class representing an integer datatype.
- class pyccel.ast.datatypes.PrimitiveType(self)[source]#
Bases:
object
Base class representing types of datatypes.
The base class representing the category of datatype to which a FixedSizeType may belong (e.g. integer, floating point).
- class pyccel.ast.datatypes.PyccelType[source]#
Bases:
object
Base class representing the type of an object.
Base class representing the type of an object from which all types must inherit. A type must contain enough information to describe the declaration type in a low-level language.
Types contain an addition operator. The operator indicates the type that is expected when calling an arithmetic operator on objects of these types.
Where applicable, types also contain an and operator. The operator indicates the type that is expected when calling a bitwise comparison operator on objects of these types.
A type also contains an attribute _name which can be useful to examine the type.
- property name#
Get the name of the pyccel type.
Get the name of the pyccel type.
- shape_is_compatible(shape)[source]#
Check if the provided shape is compatible with the datatype.
Check if the provided shape is compatible with the format expected for this datatype.
- Parameters:
shape (Any) – The proposed shape.
- Returns:
True if the shape is acceptable, False otherwise.
- Return type:
bool
- switch_basic_type(new_type)[source]#
Change the basic type to the new type.
Change the basic type to the new type. In the case of a FixedSizeType the switch will replace the type completely, directly returning the new type. In the case of a homogeneous container type, a new container type will be returned whose underlying elements are of the new type. This method is not implemented for inhomogeneous containers.
- Parameters:
new_type (PyccelType) – The new basic type.
- Returns:
The new type.
- Return type:
- class pyccel.ast.datatypes.PythonNativeBool(self)[source]#
Bases:
PythonNativeNumericType
Class representing Python’s native boolean type.
Class representing Python’s native boolean type.
- class pyccel.ast.datatypes.PythonNativeComplex(self)[source]#
Bases:
PythonNativeNumericType
Class representing Python’s native complex type.
Class representing Python’s native complex type.
- property element_type#
The type of an element of the complex.
The type of an element of the complex. In other words, the type of the floats which comprise the complex type.
- class pyccel.ast.datatypes.PythonNativeFloat(self)[source]#
Bases:
PythonNativeNumericType
Class representing Python’s native floating point type.
Class representing Python’s native floating point type.
- class pyccel.ast.datatypes.PythonNativeInt(self)[source]#
Bases:
PythonNativeNumericType
Class representing Python’s native integer type.
Class representing Python’s native integer type.
- class pyccel.ast.datatypes.PythonNativeNumericType(self)[source]#
Bases:
FixedSizeNumericType
Base class representing a built-in scalar numeric datatype.
Base class representing a built-in scalar numeric datatype.
- class pyccel.ast.datatypes.StringType(self)[source]#
Bases:
ContainerType
Class representing Python’s native string type.
Class representing Python’s native string type.
- property container_rank#
Number of dimensions of the container.
Number of dimensions of the object described by the container. This is equal to the number of values required to index an element of this container.
- property datatype#
The datatype of the object.
The datatype of the object.
- property element_type#
The type of elements of the object.
The PyccelType describing an element of the container.
- property order#
The data layout ordering in memory.
Indicates whether the data is stored in row-major (‘C’) or column-major (‘F’) format. This is only relevant if rank > 1. When it is not relevant this function returns None.
- property primitive_type#
The datatype category of elements of the object.
The datatype category of elements of the object (e.g. integer, floating point).
- property rank#
Number of dimensions of the object.
Number of dimensions of the object. If the object is a scalar then this is equal to 0.
- class pyccel.ast.datatypes.SymbolicType(self)[source]#
Bases:
FixedSizeType
Class representing the datatype of a placeholder symbol.
Class representing the datatype of a placeholder symbol. This type should be used for objects which will not appear in the generated code but are used to identify objects (e.g. Type aliases).
- class pyccel.ast.datatypes.TupleType[source]#
Bases:
object
Base class representing tuple datatypes.
The class from which tuple datatypes must inherit.
- class pyccel.ast.datatypes.TypeAlias(self)[source]#
Bases:
SymbolicType
Class representing the type of a symbolic object describing a type descriptor.
Class representing the type of a symbolic object describing a type descriptor. This type is equivalent to Python’s built-in typing.TypeAlias.
See also
typing.TypeAlias
See documentation of typing.TypeAlias: https://docs.python.org/3/library/typing.html#typing.TypeAlias .
- class pyccel.ast.datatypes.VoidType(self)[source]#
Bases:
FixedSizeType
Class representing a void datatype.
Class representing a void datatype. This class is especially useful in the C-Python wrapper when a void* type is needed to collect pointers from Fortran.