pyccel.ast.numpyext module#
Module containing objects from the numpy module understood by pyccel
- class pyccel.ast.numpyext.NumpyAbs(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the abs function in the Numpy library.
Represent a call to the abs function in the Numpy library.
- Parameters:
x (TypedAstNode) – The argument passed to the function.
- name = 'abs'#
- class pyccel.ast.numpyext.NumpyAmax(arg)[source]#
Bases:
PyccelFunction
Represents a call to numpy.max for code generation.
Represents a custom class for handling maximum operations.
- Parameters:
arg (array_like) – The input array for which the maximum argument is calculated.
- property arg#
Get the argument to the max function.
This method retrieves the argument used in the max function.
- property is_elemental#
Whether the function acts elementwise on an array argument.
Boolean indicating whether the (scalar) function should be called elementwise on an array argument. Here we set the default to False.
- name = 'amax'#
- class pyccel.ast.numpyext.NumpyAmin(arg)[source]#
Bases:
PyccelFunction
Represents a call to numpy.min for code generation.
Represents a custom class for handling minimum operations.
- Parameters:
arg (array_like) – The input array for which the minimum argument is calculated.
- property arg#
Get the argument to the min function.
This method retrieves the argument used in the min function.
- name = 'amin'#
- class pyccel.ast.numpyext.NumpyArange(start, stop=None, step=None, dtype=None)[source]#
Bases:
NumpyNewArray
Represents a call to numpy.arange for code generation.
A class representing a call to the NumPy arange function.
- Parameters:
start (Numeric) – Start of interval, default value 0.
stop (Numeric) – End of interval.
step (Numeric) – Spacing between values, default value 1.
dtype (Datatype) – The type of the output array, if dtype is not given, infer the data type from the other input arguments.
- property arg#
- name = 'arange'#
- property start#
- property step#
- property stop#
- class pyccel.ast.numpyext.NumpyArccos(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the arccos function in the Numpy library
- name = 'arccos'#
- class pyccel.ast.numpyext.NumpyArccosh(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the arccosh function in the Numpy library
- name = 'arccosh'#
- class pyccel.ast.numpyext.NumpyArcsin(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the arcsin function in the Numpy library
- name = 'arcsin'#
- class pyccel.ast.numpyext.NumpyArcsinh(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the arcsinh function in the Numpy library
- name = 'arcsinh'#
- class pyccel.ast.numpyext.NumpyArctan(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the arctan function in the Numpy library
- name = 'arctan'#
- class pyccel.ast.numpyext.NumpyArctan2(x1, x2)[source]#
Bases:
NumpyUfuncBinary
Represent a call to the arctan2 function in the Numpy library
- name = 'arctan2'#
- class pyccel.ast.numpyext.NumpyArctanh(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the arctanh function in the Numpy library
- name = 'arctanh'#
- class pyccel.ast.numpyext.NumpyArray(arg, dtype=None, order='K', ndmin=None)[source]#
Bases:
NumpyNewArray
Represents a call to numpy.array for code generation.
A class representing a call to the NumPy array function.
- Parameters:
arg (list, tuple, PythonList) – The data from which the array is initialised.
dtype (PythonType, PyccelFunctionDef, LiteralString, str) – The data type passed to the NumPy function.
order (str) – The ordering of the array (C/Fortran).
ndmin (LiteralInteger, int, optional) – The minimum number of dimensions that the resulting array should have.
- property arg#
The data from which the array is initialised.
A PyccelAstNode describing the data from which the array is initialised.
- name = 'array'#
- class pyccel.ast.numpyext.NumpyAutoFill(shape, dtype='float', order='C')[source]#
Bases:
NumpyFull
Abstract class for all classes which inherit from NumpyFull but the fill_value is implicitly specified
- class pyccel.ast.numpyext.NumpyBool(arg)[source]#
Bases:
PythonBool
Represents a call to numpy.bool() function.
Represents a call to the NumPy cast function bool.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- property is_elemental#
Indicates whether the function can be applied elementwise.
Indicates whether the function should be called elementwise for an array argument
- name = 'bool'#
- class pyccel.ast.numpyext.NumpyComplex(arg0, arg1=Literal(0.0))[source]#
Bases:
PythonComplex
Represents a call to numpy.complex() function.
Represents a call to the NumPy cast function complex.
- Parameters:
arg0 (TypedAstNode) – The first argument passed to the function. Either the array/scalar being cast or the real part of the complex.
arg1 (TypedAstNode, optional) – The second argument passed to the function. The imaginary part of the complex.
- property is_elemental#
Indicates whether the function can be applied elementwise.
Indicates whether the function should be called elementwise for an array argument
- name = 'complex'#
- class pyccel.ast.numpyext.NumpyComplex128(arg0, arg1=Literal(0.0))[source]#
Bases:
NumpyComplex
Represents a call to numpy.complex128() function.
Represents a call to numpy.complex128() function.
- Parameters:
arg0 (TypedAstNode) – The argument passed to the function.
arg1 (TypedAstNode) – Unused inherited argument.
- name = 'complex128'#
- class pyccel.ast.numpyext.NumpyComplex64(arg0, arg1=Literal(0.0))[source]#
Bases:
NumpyComplex
Represents a call to numpy.complex64() function.
Represents a call to numpy.complex64() function.
- Parameters:
arg0 (TypedAstNode) – The argument passed to the function.
arg1 (TypedAstNode) – Unused inherited argument.
- name = 'complex64'#
- class pyccel.ast.numpyext.NumpyConjugate(arg)[source]#
Bases:
PythonConjugate
Represents a call to numpy.conj for code generation.
Represents a call to the NumPy function conj or conjugate. > a = 1+2j > np.conj(a) 1-2j
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- property is_elemental#
Indicates whether the function should be called elementwise for an array argument
- name = 'conj'#
- class pyccel.ast.numpyext.NumpyCos(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the cos function in the Numpy library
- name = 'cos'#
- class pyccel.ast.numpyext.NumpyCosh(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the cosh function in the Numpy library
- name = 'cosh'#
- class pyccel.ast.numpyext.NumpyCountNonZero(a, axis=None, *, keepdims=Literal(False))[source]#
Bases:
PyccelFunction
Class representing a call to the NumPy function count_nonzero.
Class representing a call to the NumPy function count_nonzero which counts the number of non-zero elements in an array.
- Parameters:
a (TypedAstNode) – An array for which the non-zero elements should be counted.
axis (int, optional) – The dimension along which the non-zero elements are counted.
keepdims (LiteralTrue | LiteralFalse) – Indicates if output arrays should have the same number of dimensions as arg.
- property array#
The argument which was passed to numpy.nonzero
- property axis#
The dimension which the results describe
- property keep_dims#
Indicates if output arrays should have the same number of dimensions as arg
- name = 'count_nonzero'#
- class pyccel.ast.numpyext.NumpyEmpty(shape, dtype='float', order='C')[source]#
Bases:
NumpyAutoFill
Represents a call to numpy.empty for code generation.
Represents a call to numpy.empty for code generation.
- Parameters:
shape (TypedAstNode) – The shape of the array to be created.
dtype (PythonType, PyccelFunctionDef, LiteralString, str) – The actual dtype passed to the NumPy function.
order (str, LiteralString) – The order passed to the function.
- property fill_value#
The value with which the array will be filled on initialisation.
The value with which the array will be filled on initialisation.
- name = 'empty'#
- class pyccel.ast.numpyext.NumpyEmptyLike(a, dtype=None, order='K', subok=True, shape=None)[source]#
Bases:
PyccelFunction
Represents a call to numpy.empty_like for code generation.
This wrapper class represents calls to the function numpy.empty_like. Objects of this class are never present in the Pyccel AST, because the class constructor always returns an object of type NumpyEmpty.
- Parameters:
a (Variable) – Numpy array which is used as a template.
dtype (PythonType, PyccelFunctionDef, LiteralString, str, optional) – Type of the data contained in the new array. If None, a.dtype is used.
order (str, default='K') – Ordering used for the indices of a multi-dimensional array.
subok (bool, default=True) – This parameter is currently ignored.
shape (PythonTuple of TypedAstNode) – Overrides the shape of the array. For a 1D array this is either a LiteralInteger or an expression. For a ND array this is a TypedAstNode with the class type HomogeneousTupleType.
See also
numpy.empty_like
See documentation of numpy.empty_like: https://numpy.org/doc/stable/reference/generated/numpy.empty_like.html .
- name = 'empty_like'#
- class pyccel.ast.numpyext.NumpyExp(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the exp function in the Numpy library
- name = 'exp'#
- class pyccel.ast.numpyext.NumpyFabs(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the fabs function in the Numpy library
- name = 'fabs'#
- class pyccel.ast.numpyext.NumpyFloat(arg)[source]#
Bases:
PythonFloat
Represents a call to numpy.float() function.
Represents a call to the NumPy cast function float.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- property is_elemental#
Indicates whether the function can be applied elementwise.
Indicates whether the function should be called elementwise for an array argument
- name = 'float'#
- class pyccel.ast.numpyext.NumpyFloat32(arg)[source]#
Bases:
NumpyFloat
Represents a call to numpy.float32() function.
Represents a call to numpy.float32() function.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- name = 'float32'#
- class pyccel.ast.numpyext.NumpyFloat64(arg)[source]#
Bases:
NumpyFloat
Represents a call to numpy.float64() function.
Represents a call to numpy.float64() function.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- name = 'float64'#
- class pyccel.ast.numpyext.NumpyFloor(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the floor function in the Numpy library.
Represent a call to the floor function in the Numpy library.
- Parameters:
x (TypedAstNode) – The argument passed to the function.
- name = 'floor'#
- class pyccel.ast.numpyext.NumpyFull(shape, fill_value, dtype=None, order='C')[source]#
Bases:
NumpyNewArray
Represents a call to numpy.full for code generation.
Represents a call to the NumPy function full which creates an array of a specified size and shape filled with a specified value.
- Parameters:
shape (TypedAstNode) – Shape of the new array, e.g.,
(2, 3)
or2
. For a 1D array this is either a LiteralInteger or an expression. For a ND array this is a TypedAstNode with the class type HomogeneousTupleType.fill_value (TypedAstNode) – Fill value.
dtype (PythonType, PyccelFunctionDef, LiteralString, str, optional) – Datatype for the constructed array. If None the dtype of the fill value is used.
order ({'C', 'F'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory.
- property fill_value#
- name = 'full'#
- class pyccel.ast.numpyext.NumpyFullLike(a, fill_value, dtype=None, order='K', subok=True, shape=None)[source]#
Bases:
PyccelFunction
Represents a call to numpy.full_like for code generation.
This wrapper class represents calls to the function numpy.full_like. Objects of this class are never present in the Pyccel AST, because the class constructor always returns an object of type NumpyFull.
- Parameters:
a (Variable) – Numpy array which is used as a template.
fill_value (TypedAstNode) – Scalar value which will be assigned to each entry of the new array.
dtype (PythonType, PyccelFunctionDef, LiteralString, str, optional) – Type of the data contained in the new array. If None, a.dtype is used.
order (str, default='K') – Ordering used for the indices of a multi-dimensional array.
subok (bool, default=True) – This parameter is currently ignored.
shape (PythonTuple of TypedAstNode) – Overrides the shape of the array. For a 1D array this is either a LiteralInteger or an expression. For a ND array this is a TypedAstNode with the class type HomogeneousTupleType.
See also
numpy.full_like
See documentation of numpy.full_like: https://numpy.org/doc/stable/reference/generated/numpy.full_like.html .
- name = 'full_like'#
- class pyccel.ast.numpyext.NumpyHypot(x1, x2)[source]#
Bases:
NumpyUfuncBinary
Represent a call to the hypot function in the Numpy library
- name = 'hypot'#
- class pyccel.ast.numpyext.NumpyImag(arg)[source]#
Bases:
PythonImag
Represents a call to numpy.imag for code generation.
Represents a call to the NumPy function imag. > a = 1+2j > np.imag(a) 2.0
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- property is_elemental#
Indicates whether the function should be called elementwise for an array argument
- name = 'imag'#
- class pyccel.ast.numpyext.NumpyInt(arg)[source]#
Bases:
PythonInt
Represents a call to numpy.int() function.
Represents a call to the NumPy cast function int.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
base (TypedAstNode) – The argument passed to the function to indicate the base in which the integer is expressed.
- property is_elemental#
Indicates whether the function can be applied elementwise.
Indicates whether the function should be called elementwise for an array argument
- name = 'int'#
- class pyccel.ast.numpyext.NumpyInt16(arg)[source]#
Bases:
NumpyInt
Represents a call to numpy.int16() function.
Represents a call to numpy.int16() function.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- name = 'int16'#
- class pyccel.ast.numpyext.NumpyInt32(arg)[source]#
Bases:
NumpyInt
Represents a call to numpy.int32() function.
Represents a call to numpy.int32() function.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- name = 'int32'#
- class pyccel.ast.numpyext.NumpyInt64(arg)[source]#
Bases:
NumpyInt
Represents a call to numpy.int64() function.
Represents a call to numpy.int64() function.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- name = 'int64'#
- class pyccel.ast.numpyext.NumpyInt8(arg)[source]#
Bases:
NumpyInt
Represents a call to numpy.int8() function.
Represents a call to numpy.int8() function.
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- name = 'int8'#
- class pyccel.ast.numpyext.NumpyIsFinite(x)[source]#
Bases:
NumpyUfuncUnary
Represents a call to numpy.isfinite() function.
This class corresponds to a call to the Numpy ‘isfinite’ function, which is used to determine whether elements in a given array or expression are finite (neither NaN nor infinity).
- Parameters:
x (TypedAstNode) – A Pyccel expression or array to be checked for finiteness.
See also
numpy.isfinite
See NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .
- name = 'isfinite'#
- class pyccel.ast.numpyext.NumpyIsInf(x)[source]#
Bases:
NumpyUfuncUnary
Represents a call to numpy.isinf() function.
This class represents a call to the Numpy ‘isinf’ function, which is used to determine whether elements in a given array or expression are positive or negative infinity.
- Parameters:
x (TypedAstNode) – A Pyccel expression or array to be checked for infinity values.
See also
numpy.isinf
See NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .
- name = 'isinf'#
- class pyccel.ast.numpyext.NumpyIsNan(x)[source]#
Bases:
NumpyUfuncUnary
Represents a call to numpy.isnan() function.
This class encapsulates a call to the Numpy ‘isnan’ function. It is used to check whether the elements of a given array or expression are NaN (Not-a-Number).
- Parameters:
x (TypedAstNode) – A Pyccel expression or array to be checked for NaN values.
See also
numpy.isnan
See NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .
- name = 'isnan'#
- class pyccel.ast.numpyext.NumpyLinspace(start, stop, num=None, endpoint=True, dtype=None)[source]#
Bases:
NumpyNewArray
Represents a call to the function numpy.linspace.
A class representing a call to the NumPy linspace function which returns num evenly spaced samples, calculated over the interval [start, stop].
- Parameters:
start (list , tuple , PythonTuple, PythonList, Variable, Literals) – Represents the starting value of the sequence.
stop (list , tuple , PythonTuple, PythonList, Variable, Literals) – Represents the ending value of the sequence (if endpoint is set to False).
num (int, optional) – Number of samples to generate. Default is 50. Must be non-negative.
endpoint (bool, optional) – If True, stop is the last sample. Otherwise, it is not included. Default is True.
dtype (str, PyccelType) – The type of the output array. If dtype is not given, the data type is calculated from start and stop, the calculated dtype will never be an integer.
- property endpoint#
Indicates if the stop must be included or not.
- property ind#
Used to store the index generated by the created for loop and needed by linspace function.
- property index#
Used in the fortran codegen when there is no for loop created.
- property is_elemental#
Whether the function acts elementwise on an array argument.
Boolean indicating whether the (scalar) function should be called elementwise on an array argument. Here we set the default to False.
- name = 'linspace'#
- property num#
Represent the number of generated elements by the linspace function.
- property start#
Represent the starting value of the sequence.
- property step#
Represent size of spacing between generated elements.
- property stop#
Represent the end value of the sequence, if the endpoint is False the stop will not be included.
- class pyccel.ast.numpyext.NumpyLog(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the log function in the Numpy library
- name = 'log'#
- class pyccel.ast.numpyext.NumpyMatmul(a, b)[source]#
Bases:
PyccelFunction
Represents a call to numpy.matmul for code generation.
Represents a call to NumPy’s matmul function for code generation.
- Parameters:
a (TypedAstNode) – The first argument of the matrix multiplication.
b (TypedAstNode) – The second argument of the matrix multiplication.
- property a#
- property b#
- name = 'matmul'#
- class pyccel.ast.numpyext.NumpyMod(x1, x2)[source]#
Bases:
NumpyUfuncBinary
Represent a call to the numpy.mod function.
Represent a call to the mod function in the Numpy library.
- Parameters:
x1 (TypedAstNode) – Dividend of the operator.
x2 (TypedAstNode) – Divisor of the operator.
- name = 'mod'#
- class pyccel.ast.numpyext.NumpyNDArray(*args, **kwargs)[source]#
Bases:
PyccelFunction
A class representing np.ndarray.
A class representing np.ndarray. np.ndarray is useful for type checks. NumpyNDArray is not designed to be instantiated as np.ndarray raises a warning when used in code, but as its implementation is identical to np.array the __new__ method maps to that class so the method is supported.
- Parameters:
*args (tuple) – Positional arguments. See NumpyArray.
**kwargs (dict) – Keyword arguments. See NumpyArray.
- name = 'ndarray'#
- class pyccel.ast.numpyext.NumpyNewArray(*args, class_type, init_dtype=None)[source]#
Bases:
PyccelFunction
Superclass for nodes representing NumPy array allocation functions.
Class from which all nodes representing a NumPy function which implies a call to Allocate should inherit.
- Parameters:
*args (tuple of TypedAstNode) – The arguments of the superclass PyccelFunction.
class_type (NumpyNDArrayType) – The type of the new array.
init_dtype (PythonType, PyccelFunctionDef, LiteralString, str) – The actual dtype passed to the NumPy function.
- property init_dtype#
The dtype provided to the function when it was initialised in Python.
The dtype provided to the function when it was initialised in Python. If no dtype was provided then this should equal None.
- class pyccel.ast.numpyext.NumpyNonZero(a)[source]#
Bases:
PyccelFunction
Class representing a call to the function numpy.nonzero.
Class representing a call to the NumPy function nonzero which indicates which elements of an array are non-zero.
- Parameters:
a (TypedAstNode) – The array argument that was passed to the function.
Examples
>>> x = np.array([[3, 0, 0], [0, 4, 0], [5, 6, 0]]) >>> np.nonzero(x) (array([0, 1, 2, 2]), array([0, 1, 0, 1]))
- property array#
The array argument
- property elements#
The elements of the tuple
- name = 'nonzero'#
- class pyccel.ast.numpyext.NumpyNonZeroElement(a, dim)[source]#
Bases:
NumpyNewArray
Represents an element of the tuple returned by NumpyNonZero.
Represents an element of the tuple returned by NumpyNonZero which represents a call to numpy.nonzero.
- Parameters:
a (TypedAstNode) – The argument which was passed to numpy.nonzero.
dim (int) – The index of the element in the tuple.
- property array#
The argument which was passed to numpy.nonzero
- property dim#
The dimension which the results describe
- name = 'nonzero'#
- class pyccel.ast.numpyext.NumpyNorm(arg, axis=None)[source]#
Bases:
PyccelFunction
Represents call to numpy.norm.
Represents a call to the NumPy function norm.
- Parameters:
arg (TypedAstNode) – The first argument passed to the function.
axis (TypedAstNode, optional) – The second argument passed to the function, indicating the axis along which the norm should be calculated.
- property arg#
- property axis#
Mimic the behavior of axis argument of numpy.norm in python, and dim argument of Norm2 in Fortran.
- name = 'norm'#
- property python_arg#
numpy.norm argument without casting. the actual arg property contains casting methods for C/Fortran, which is not necessary for a Python code, and the casting makes Python language tests fail.
- class pyccel.ast.numpyext.NumpyOnes(shape, dtype='float', order='C')[source]#
Bases:
NumpyAutoFill
Represents a call to numpy.ones for code generation.
Represents a call to numpy.ones for code generation.
- Parameters:
shape (TypedAstNode) – The shape passed as argument to the function call.
dtype (PyccelAstNode | PyccelType | str, default = 'float') – The datatype specified in the argument of the function call.
order (str, default='C') – The order specified in the argument of the function call.
- property fill_value#
The value with which the array will be filled on initialisation.
The value with which the array will be filled on initialisation.
- name = 'ones'#
- class pyccel.ast.numpyext.NumpyOnesLike(a, dtype=None, order='K', subok=True, shape=None)[source]#
Bases:
PyccelFunction
Represents a call to numpy.ones_like for code generation.
This wrapper class represents calls to the function numpy.ones_like. Objects of this class are never present in the Pyccel AST, because the class constructor always returns an object of type NumpyOnes.
- Parameters:
a (Variable) – Numpy array which is used as a template.
dtype (PythonType, PyccelFunctionDef, LiteralString, str, optional) – Type of the data contained in the new array. If None, a.dtype is used.
order (str, default='K') – Ordering used for the indices of a multi-dimensional array.
subok (bool, default=True) – This parameter is currently ignored.
shape (PythonTuple of TypedAstNode) – Overrides the shape of the array. For a 1D array this is either a LiteralInteger or an expression. For a ND array this is a TypedAstNode with the class type HomogeneousTupleType.
See also
numpy.ones_like
See documentation of numpy.ones_like: https://numpy.org/doc/stable/reference/generated/numpy.ones_like.html .
- name = 'ones_like'#
- class pyccel.ast.numpyext.NumpyProduct(arg)[source]#
Bases:
PyccelFunction
Represents a call to numpy.prod for code generation.
Represents a call to numpy.prod for code generation.
- Parameters:
arg (list , tuple , PythonTuple, PythonList, Variable) – The argument passed to the prod function.
- property arg#
- name = 'product'#
- class pyccel.ast.numpyext.NumpyRand(*args)[source]#
Bases:
PyccelFunction
Represents a call to numpy.random.random or numpy.random.rand for code generation.
Represents a call to numpy.random.random or numpy.random.rand for code generation.
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the function.
- name = 'rand'#
- class pyccel.ast.numpyext.NumpyRandint(low, high=None, size=None)[source]#
Bases:
PyccelFunction
Class representing a call to NumPy’s randint function.
Class representing a call to NumPy’s randint function.
- Parameters:
low (TypedAstNode) – The first argument passed to the function. The smallest possible value for the generated number.
high (TypedAstNode, optional) – The second argument passed to the function. The largest possible value for the generated number.
size (TypedAstNode, optional) – The size of the array that will be generated.
- property high#
return high property of NumpyRandint
- property low#
return low property of NumpyRandint
- name = 'randint'#
- property rand_expr#
- class pyccel.ast.numpyext.NumpyReal(arg)[source]#
Bases:
PythonReal
Represents a call to numpy.real for code generation.
Represents a call to the NumPy function real. > a = 1+2j > np.real(a) 1.0
- Parameters:
arg (TypedAstNode) – The argument passed to the function.
- property is_elemental#
Indicates whether the function should be called elementwise for an array argument
- name = 'real'#
- class pyccel.ast.numpyext.NumpyResultType(*arrays_and_dtypes)[source]#
Bases:
PyccelFunction
Class representing a call to the numpy.result_type function.
A class representing a call to the NumPy function result_type which returns the datatype of an expression. This function can be used to access the dtype property of a NumPy array.
- Parameters:
*arrays_and_dtypes (TypedAstNode) – Any arrays and dtypes passed to the function (currently only accepts one array and no dtypes).
- name = 'result_type'#
- class pyccel.ast.numpyext.NumpyShape(arg)[source]#
Bases:
PyccelFunction
Represents a call to numpy.shape for code generation.
This wrapper class represents calls to the function numpy.shape in the user code, or equivalently to the shape property of a numpy.ndarray.
Objects of this class are never present in the Pyccel AST, because the class constructor always returns a PythonTuple with the required shape.
- Parameters:
arg (TypedAstNode) – The Numpy array whose shape is being investigated.
- Returns:
The shape of the Numpy array, i.e. its size along each dimension.
- Return type:
- name = 'shape'#
- class pyccel.ast.numpyext.NumpySign(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the sign function in the Numpy library.
Represent a call to the sign function in the Numpy library.
- Parameters:
x (TypedAstNode) – The argument passed to the function.
- name = 'sign'#
- class pyccel.ast.numpyext.NumpySin(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the sin function in the Numpy library
- name = 'sin'#
- class pyccel.ast.numpyext.NumpySinh(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the sinh function in the Numpy library
- name = 'sinh'#
- class pyccel.ast.numpyext.NumpySize(a, axis=None)[source]#
Bases:
PyccelFunction
Represent a call to numpy.size in the user code.
This wrapper class represents a call to the NumPy size function, which returns the total number of elements in a multidimensional array, or the number of elements along a given dimension.
Objects of this class are never present in the Pyccel AST, because the class constructor returns objects of type PyccelArraySize, LiteralInteger, or PyccelArrayShapeElement.
- Parameters:
a (TypedAstNode) – An array of unknown size.
axis (TypedAstNode, optional) – The integer dimension along which the size is requested.
See also
numpy.size
See NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.ma.size.html .
- name = 'size'#
- class pyccel.ast.numpyext.NumpySqrt(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the sqrt function in the Numpy library
- name = 'sqrt'#
- class pyccel.ast.numpyext.NumpySum(arg)[source]#
Bases:
PyccelFunction
Represents a call to numpy.sum for code generation.
Represents a call to numpy.sum for code generation.
- Parameters:
arg (list , tuple , PythonTuple, PythonList, Variable) – The argument passed to the sum function.
- property arg#
- name = 'sum'#
- class pyccel.ast.numpyext.NumpyTan(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the tan function in the Numpy library
- name = 'tan'#
- class pyccel.ast.numpyext.NumpyTanh(x)[source]#
Bases:
NumpyUfuncUnary
Represent a call to the tanh function in the Numpy library
- name = 'tanh'#
- class pyccel.ast.numpyext.NumpyTranspose(x, *axes)[source]#
Bases:
NumpyUfuncUnary
Represents a call to the transpose function from the Numpy library.
Represents a call to the transpose function from the Numpy library.
- Parameters:
x (TypedAstNode) – The array to be transposed.
*axes (tuple[TypedAstNode]) – The axes along which the user wishes to transpose their array.
- property internal_var#
Return the variable being transposed
- property is_elemental#
Whether the function acts elementwise on an array argument.
Boolean indicating whether the (scalar) function should be called elementwise on an array argument. Here we set the default to False.
- name = 'transpose'#
- class pyccel.ast.numpyext.NumpyUfuncBase(*args)[source]#
Bases:
PyccelFunction
Base class for Numpy’s universal functions.
The class from which NumPy’s universal functions inherit. All classes which inherit from this class operate on their arguments elementally.
- Parameters:
*args (tuple of TypedAstNode) – The arguments passed to the function.
- property is_elemental#
Whether the function acts elementwise on an array argument.
Boolean indicating whether the (scalar) function should be called elementwise on an array argument. Here we set the default to False.
- class pyccel.ast.numpyext.NumpyUfuncBinary(x1, x2)[source]#
Bases:
NumpyUfuncBase
Class representing Numpy’s universal function with two arguments.
Class representing Numpy’s universal function. All classes which inherit from this class have two arguments and operate on them in lockstep. In other words it should be equivalent to write: >>> for i,_ in enumerate(iterable1): NumpyUfuncUnary(iterable1(i), iterable2(i))
or >>> NumpyUfuncUnary(iterable1, iterable2)
- Parameters:
x1 (TypedAstNode) – The first argument passed to the function.
x2 (TypedAstNode) – The second argument passed to the function.
- class pyccel.ast.numpyext.NumpyUfuncUnary(x)[source]#
Bases:
NumpyUfuncBase
Class representing Numpy’s universal function with one argument.
Class representing Numpy’s universal function. All classes which inherit from this class have one argument and operate on it elementally. In other words it should be equivalent to write: >>> for i in iterable: NumpyUfuncUnary(i)
or >>> NumpyUfuncUnary(iterable)
- Parameters:
x (TypedAstNode) – The argument passed to the function.
- property arg#
The argument passed to the NumPy unary function.
The argument passed to the NumPy unary function.
- class pyccel.ast.numpyext.NumpyWhere(condition, x=None, y=None)[source]#
Bases:
PyccelFunction
Represents a call to numpy.where.
Represents a call to NumPy’s where function.
- Parameters:
condition (TypedAstNode) – The condition which determines which value is returned.
x (TypedAstNode, optional) – The value if True. If x is provided, y should also be provided.
y (TypedAstNode, optional) – The value if False. If y is provided, x should also be provided.
- property condition#
Boolean argument determining which value is returned
- property is_elemental#
Indicates whether the function should be called elementwise for an array argument
- name = 'where'#
- property value_false#
Value returned when the condition is evaluated to False.
- property value_true#
Value returned when the condition is evaluated to True.
- class pyccel.ast.numpyext.NumpyZeros(shape, dtype='float', order='C')[source]#
Bases:
NumpyAutoFill
Represents a call to numpy.zeros for code generation.
Represents a call to numpy.zeros for code generation.
- Parameters:
shape (TypedAstNode) – The shape passed as argument to the function call.
dtype (PyccelAstNode | PyccelType | str, default = 'float') – The datatype specified in the argument of the function call.
order (str, default='C') – The order specified in the argument of the function call.
- property fill_value#
The value with which the array will be filled on initialisation.
The value with which the array will be filled on initialisation.
- name = 'zeros'#
- class pyccel.ast.numpyext.NumpyZerosLike(a, dtype=None, order='K', subok=True, shape=None)[source]#
Bases:
PyccelFunction
Represents a call to numpy.zeros_like for code generation.
This wrapper class represents calls to the function numpy.zeros_like. Objects of this class are never present in the Pyccel AST, because the class constructor always returns an object of type NumpyZeros.
- Parameters:
a (Variable) – Numpy array which is used as a template.
dtype (PythonType, PyccelFunctionDef, LiteralString, str, optional) – Type of the data contained in the new array. If None, a.dtype is used.
order (str, default='K') – Ordering used for the indices of a multi-dimensional array.
subok (bool, default=True) – This parameter is currently ignored.
shape (PythonTuple of TypedAstNode) – Overrides the shape of the array. For a 1D array this is either a LiteralInteger or an expression. For a ND array this is a TypedAstNode with the class type HomogeneousTupleType.
See also
numpy.zeros_like
See documentation of numpy.zeros_like: https://numpy.org/doc/stable/reference/generated/numpy.zeros_like.html .
- name = 'zeros_like'#