pyccel.ast.numpyext module#
Module containing objects from the numpy module understood by pyccel
- class pyccel.ast.numpyext.NumpyAbs(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent 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(a, axis=None, keepdims=Literal(False), initial=None, where=None)[source]View on GitHub#
Bases:
NumpyReductionRepresents a call to numpy.max for code generation.
Represents a custom class for handling maximum operations.
- Parameters:
a (array_like) – The input array for which the maximum argument is calculated.
axis (None | LiteralInteger | iterable[LiteralInteger], optional) – Axis or axes along which a sum is performed. If axis is None then a sum is performed over all elements of arg.
keepdims (LiteralTrue | LiteralFalse, default=LiteralFalse) – Indicates if output arrays should have the same number of dimensions as arg.
initial (TypedAstNode, default=None) – The start value for the sum.
where (TypedAstNode, default=None) – Boolean indicating elements to include in the sum.
- property argView on GitHub#
Get the argument to the max function.
This method retrieves the argument used in the max function.
- property initialView on GitHub#
The start value for the sum.
The start value for the sum.
- property is_elementalView on GitHub#
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(a, axis=None, keepdims=Literal(False), initial=None, where=None)[source]View on GitHub#
Bases:
NumpyReductionRepresents a call to numpy.min for code generation.
Represents a custom class for handling minimum operations.
- Parameters:
a (array_like) – The input array for which the minimum argument is calculated.
axis (None | LiteralInteger | iterable[LiteralInteger], optional) – Axis or axes along which a sum is performed. If axis is None then a sum is performed over all elements of arg.
keepdims (LiteralTrue | LiteralFalse, default=LiteralFalse) – Indicates if output arrays should have the same number of dimensions as arg.
initial (TypedAstNode, default=None) – The start value for the sum.
where (TypedAstNode, default=None) – Boolean indicating elements to include in the sum.
- property argView on GitHub#
Get the argument to the min function.
This method retrieves the argument used in the min function.
- property initialView on GitHub#
The start value for the sum.
The start value for the sum.
- name = 'amin'#
- class pyccel.ast.numpyext.NumpyArange(start, stop=None, step=None, dtype=None)[source]View on GitHub#
Bases:
NumpyNewArrayRepresents 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 argView on GitHub#
- property is_indexableView on GitHub#
Indicate whether the expression can be indexed.
Indicate whether the expression can be indexed to get an element without calculating the entire result. E.g cos(x)[i] is equivalent to cos(x[i]) but func_call(x)[i] is not equivalent to func_call(x[i]).
- name = 'arange'#
- property startView on GitHub#
- property stepView on GitHub#
- property stopView on GitHub#
- class pyccel.ast.numpyext.NumpyArccos(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the arccos function in the Numpy library
- name = 'arccos'#
- class pyccel.ast.numpyext.NumpyArccosh(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the arccosh function in the Numpy library
- name = 'arccosh'#
- class pyccel.ast.numpyext.NumpyArcsin(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the arcsin function in the Numpy library
- name = 'arcsin'#
- class pyccel.ast.numpyext.NumpyArcsinh(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the arcsinh function in the Numpy library
- name = 'arcsinh'#
- class pyccel.ast.numpyext.NumpyArctan(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the arctan function in the Numpy library
- name = 'arctan'#
- class pyccel.ast.numpyext.NumpyArctan2(x1, x2)[source]View on GitHub#
Bases:
NumpyUfuncBinaryRepresent a call to the arctan2 function in the Numpy library
- name = 'arctan2'#
- class pyccel.ast.numpyext.NumpyArctanh(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent 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]View on GitHub#
Bases:
NumpyNewArrayRepresents 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 argView on GitHub#
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]View on GitHub#
Bases:
NumpyFullAbstract class for all classes which inherit from NumpyFull but the fill_value is implicitly specified
- class pyccel.ast.numpyext.NumpyBool(arg)[source]View on GitHub#
Bases:
PythonBoolRepresents 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_elementalView on GitHub#
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]View on GitHub#
Bases:
PythonComplexRepresents 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_elementalView on GitHub#
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]View on GitHub#
Bases:
NumpyComplexRepresents 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]View on GitHub#
Bases:
NumpyComplexRepresents 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]View on GitHub#
Bases:
PythonConjugateRepresents 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_elementalView on GitHub#
Indicates whether the function should be called elementwise for an array argument
- name = 'conj'#
- class pyccel.ast.numpyext.NumpyCos(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the cos function in the Numpy library
- name = 'cos'#
- class pyccel.ast.numpyext.NumpyCosh(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the cosh function in the Numpy library
- name = 'cosh'#
- class pyccel.ast.numpyext.NumpyCountNonZero(a, axis=None, *, keepdims=Literal(False))[source]View on GitHub#
Bases:
PyccelFunctionClass 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 arrayView on GitHub#
The argument which was passed to numpy.nonzero
- property axisView on GitHub#
The dimension which the results describe
- property keep_dimsView on GitHub#
Indicates if output arrays should have the same number of dimensions as arg
- name = 'count_nonzero'#
- class pyccel.ast.numpyext.NumpyCross(a, b, axisa=-Literal(1), axisb=-Literal(1), axisc=-Literal(1), axis=Literal(None), *, c)[source]View on GitHub#
Bases:
PyccelFunctionClass representing a call to numpy.cross or numpy.linalg.cross in the user code.
Class representing a call to numpy.cross or numpy.linalg.cross in the user code.
- Parameters:
a (TypedAstNode) – The first vector.
b (TypedAstNode) – The second vector.
axisa (LiteralInteger, default: -1) – Axis of a that defines the vector(s).
axisb (LiteralInteger, default: -1) – Axis of b that defines the vector(s).
axisc (LiteralInteger, default: -1) – Axis of c that defines the vector(s).
axis (LiteralInteger, optional) – If defined, the axis of a, b and c that defines the vector(s) and cross product(s). Overrides axisa, axisb and axisc.
c (Variable) – Argument provided by the semantic parser describing the variable where the result will be saved.
- property aView on GitHub#
The first vector in the cross product.
The first vector in the cross product.
- property axis_aView on GitHub#
Axis of a that defines the vector where the operator acts.
Axis of a that defines the vector where the operator acts.
- property axis_bView on GitHub#
Axis of b that defines the vector where the operator acts.
Axis of b that defines the vector where the operator acts.
- property axis_cView on GitHub#
Axis of c that defines the vector where the operator acts.
Axis of c that defines the vector where the operator acts.
- property bView on GitHub#
The second vector in the cross product.
The second vector in the cross product.
- property cView on GitHub#
The vector in which the cross product is saved.
The vector in which the cross product is saved.
- insert_indices(*idxs)[source]View on GitHub#
Insert the indices into the arrays.
Insert the indices into the arrays to get a 1D cross product expression. This function is used by the loop unrolling.
- Parameters:
*idxs (Variable) – The indices to be inserted.
- Returns:
The new 1D cross product expression.
- Return type:
- property n_indicesView on GitHub#
The number of indices required to get a 1D cross product expression.
The number of indices required to get a 1D cross product expression.
- name = 'cross'#
- class pyccel.ast.numpyext.NumpyDivide(x1, x2)[source]View on GitHub#
Bases:
PyccelDivClass representing a class to numpy.divide or numpy.true_divide in the user code.
Class representing a class to numpy.divide or numpy.true_divide in the user code.
- Parameters:
x1 (TypedAstNode) – The dividend.
x2 (TypedAstNode) – The divisor.
- name = 'divide'#
- class pyccel.ast.numpyext.NumpyEmpty(shape, dtype='float', order='C')[source]View on GitHub#
Bases:
NumpyAutoFillRepresents 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_valueView on GitHub#
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]View on GitHub#
Bases:
PyccelFunctionRepresents 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_likeSee 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]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the exp function in the Numpy library
- name = 'exp'#
- class pyccel.ast.numpyext.NumpyExpm1(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the np.expm1 function in the Numpy library.
Represent a call to the np.expm1 function in the Numpy library.
- Parameters:
x (PyccelAstType) – The argument of the unary function.
- name = 'expm1'#
- class pyccel.ast.numpyext.NumpyFabs(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the fabs function in the Numpy library
- name = 'fabs'#
- class pyccel.ast.numpyext.NumpyFloat(arg)[source]View on GitHub#
Bases:
PythonFloatRepresents 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_elementalView on GitHub#
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]View on GitHub#
Bases:
NumpyFloatRepresents 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]View on GitHub#
Bases:
NumpyFloatRepresents 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]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent 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]View on GitHub#
Bases:
NumpyNewArrayRepresents 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_valueView on GitHub#
- name = 'full'#
- class pyccel.ast.numpyext.NumpyFullLike(a, fill_value, dtype=None, order='K', subok=True, shape=None)[source]View on GitHub#
Bases:
PyccelFunctionRepresents 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_likeSee 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]View on GitHub#
Bases:
NumpyUfuncBinaryRepresent a call to the hypot function in the Numpy library
- name = 'hypot'#
- class pyccel.ast.numpyext.NumpyImag(arg)[source]View on GitHub#
Bases:
PythonImagRepresents 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_elementalView on GitHub#
Indicates whether the function should be called elementwise for an array argument
- name = 'imag'#
- class pyccel.ast.numpyext.NumpyInt(arg)[source]View on GitHub#
Bases:
PythonIntRepresents 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_elementalView on GitHub#
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]View on GitHub#
Bases:
NumpyIntRepresents 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]View on GitHub#
Bases:
NumpyIntRepresents 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]View on GitHub#
Bases:
NumpyIntRepresents 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]View on GitHub#
Bases:
NumpyIntRepresents 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]View on GitHub#
Bases:
NumpyUfuncUnaryRepresents 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.isfiniteSee NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .
- name = 'isfinite'#
- class pyccel.ast.numpyext.NumpyIsInf(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresents 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.isinfSee NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .
- name = 'isinf'#
- class pyccel.ast.numpyext.NumpyIsNan(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresents 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.isnanSee NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .
- name = 'isnan'#
- class pyccel.ast.numpyext.NumpyLinalgCross(x1, x2, axis=Literal(None), *, c)[source]View on GitHub#
Bases:
NumpyCrossClass representing a call to numpy.linalg.cross in the user code.
Class representing a call to numpy.linalg.cross in the user code.
- Parameters:
x1 (TypedAstNode) – The first vector.
x2 (TypedAstNode) – The second vector.
axis (LiteralInteger, optional) – If defined, the axis of a, b and c that defines the vector(s) and cross product(s). Overrides axisa, axisb and axisc.
c (Variable) – Argument provided by the semantic parser describing the variable where the result will be saved.
- class pyccel.ast.numpyext.NumpyLinspace(start, stop, num=None, endpoint=True, dtype=None)[source]View on GitHub#
Bases:
NumpyNewArrayRepresents 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 endpointView on GitHub#
Indicates if the stop must be included or not.
- property indView on GitHub#
Used to store the index generated by the created for loop and needed by linspace function.
- property indexView on GitHub#
Used in the fortran codegen when there is no for loop created.
- property is_elementalView on GitHub#
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 numView on GitHub#
Represent the number of generated elements by the linspace function.
- property startView on GitHub#
Represent the starting value of the sequence.
- property stepView on GitHub#
Represent size of spacing between generated elements.
- property stopView on GitHub#
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]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the log function in the Numpy library
- name = 'log'#
- class pyccel.ast.numpyext.NumpyMatmul(a, b, *, dtype=None, order='K')[source]View on GitHub#
Bases:
PyccelFunctionRepresents 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.
dtype (PythonType, PyccelFunctionDef, LiteralString, optional) – The data type of the result.
order (str, default='K') – Ordering used for the indices of a multi-dimensional array.
- property aView on GitHub#
- property bView on GitHub#
- property is_indexableView on GitHub#
Indicate whether the expression can be indexed.
Indicate whether the expression can be indexed to get an element without calculating the entire result. E.g cos(x)[i] is equivalent to cos(x[i]) but func_call(x)[i] is not equivalent to func_call(x[i]). Matmul can be indexed if multiple ranks are available but the 2D matmul itself cannot be indexed.
- name = 'matmul'#
- class pyccel.ast.numpyext.NumpyMod(x1, x2)[source]View on GitHub#
Bases:
NumpyUfuncBinaryRepresent 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]View on GitHub#
Bases:
PyccelFunctionA 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]View on GitHub#
Bases:
PyccelFunctionSuperclass 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_dtypeView on GitHub#
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]View on GitHub#
Bases:
PyccelFunctionClass 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 arrayView on GitHub#
The array argument
- property elementsView on GitHub#
The elements of the tuple
- name = 'nonzero'#
- class pyccel.ast.numpyext.NumpyNonZeroElement(a, dim)[source]View on GitHub#
Bases:
NumpyNewArrayRepresents 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 arrayView on GitHub#
The argument which was passed to numpy.nonzero
- property dimView on GitHub#
The dimension which the results describe
- name = 'nonzero'#
- class pyccel.ast.numpyext.NumpyNorm(x, ord=Literal(None), axis=None, keepdims=Literal(False))[source]View on GitHub#
Bases:
NumpyReductionRepresents call to numpy.norm.
Represents a call to the NumPy function norm.
- Parameters:
x (TypedAstNode) – The first argument passed to the function.
ord (Literal) – Order of the norm.
axis (TypedAstNode, optional) – The second argument passed to the function, indicating the axis along which the norm should be calculated.
keepdims (LiteralTrue | LiteralFalse, default=LiteralFalse) – Indicates if output arrays should have the same number of dimensions as x.
- name = 'norm'#
- property orderView on GitHub#
The order of the norm.
The order of the norm.
- class pyccel.ast.numpyext.NumpyOnes(shape, dtype='float', order='C')[source]View on GitHub#
Bases:
NumpyAutoFillRepresents 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_valueView on GitHub#
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]View on GitHub#
Bases:
PyccelFunctionRepresents 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_likeSee 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]View on GitHub#
Bases:
PyccelFunctionRepresents 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 argView on GitHub#
- name = 'product'#
- class pyccel.ast.numpyext.NumpyRand(*args)[source]View on GitHub#
Bases:
PyccelFunctionRepresents 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]View on GitHub#
Bases:
PyccelFunctionClass 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 highView on GitHub#
return high property of NumpyRandint
- property lowView on GitHub#
return low property of NumpyRandint
- name = 'randint'#
- property rand_exprView on GitHub#
- class pyccel.ast.numpyext.NumpyReal(arg)[source]View on GitHub#
Bases:
PythonRealRepresents 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_elementalView on GitHub#
Indicates whether the function should be called elementwise for an array argument
- name = 'real'#
- class pyccel.ast.numpyext.NumpyReduction(arg, *args, axis=None, keepdims=Literal(False), where=None)[source]View on GitHub#
Bases:
PyccelFunctionRepresents a call to a NumPy reduction function.
Represents a call to a NumPy reduction function, e.g. sum.
- Parameters:
arg (list | tuple | PythonTuple | PythonList | Variable) – The array being reduced.
*args (PyccelAstNode) – Other arguments to be passed to the PyccelFunction superclass.
axis (None | LiteralInteger | iterable[LiteralInteger], optional) – Axis or axes along which the reduction is performed. If axis is None then the reduction is performed over all elements of arr.
keepdims (LiteralTrue | LiteralFalse, default=LiteralFalse) – Indicates if output arrays should have the same number of dimensions The start value for the sum.
where (TypedAstNode, default=None) – Boolean indicating elements to include in the sum.
- property argView on GitHub#
The array to be reduced.
The array to be reduced.
- property axisView on GitHub#
Axis or axes along which the reduction is performed.
Axis or axes along which the reduction is performed.
- property is_indexableView on GitHub#
Indicate whether the expression can be indexed.
Indicate whether the expression can be indexed to get an element without calculating the entire result. E.g cos(x)[i] is equivalent to cos(x[i]) but func_call(x)[i] is not equivalent to func_call(x[i]).
- class pyccel.ast.numpyext.NumpyResultType(*arrays_and_dtypes)[source]View on GitHub#
Bases:
PyccelFunctionClass 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]View on GitHub#
Bases:
PyccelFunctionRepresents 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]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent 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]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the sin function in the Numpy library
- name = 'sin'#
- class pyccel.ast.numpyext.NumpySinh(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the sinh function in the Numpy library
- name = 'sinh'#
- class pyccel.ast.numpyext.NumpySize(a, axis=None)[source]View on GitHub#
Bases:
PyccelFunctionRepresent 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.sizeSee NumPy docs : https://numpy.org/doc/stable/reference/generated/numpy.ma.size.html .
- name = 'size'#
- class pyccel.ast.numpyext.NumpySqrt(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the sqrt function in the Numpy library
- name = 'sqrt'#
- class pyccel.ast.numpyext.NumpySum(a, axis=None, dtype=None, keepdims=Literal(False), initial=None, where=None)[source]View on GitHub#
Bases:
NumpyReductionRepresents a call to numpy.sum for code generation.
Represents a call to numpy.sum for code generation.
- Parameters:
a (list | tuple | PythonTuple | PythonList | Variable) – The array being summed over.
axis (None | LiteralInteger | iterable[LiteralInteger], optional) – Axis or axes along which a sum is performed. If axis is None then a sum is performed over all elements of arg.
dtype (PythonType, PyccelFunctionDef, LiteralString, optional) – The data type of the result.
keepdims (LiteralTrue | LiteralFalse, default=LiteralFalse) – Indicates if output arrays should have the same number of dimensions as arg.
initial (TypedAstNode, default=None) – The start value for the sum.
where (TypedAstNode, default=None) – Boolean indicating elements to include in the sum.
- property initialView on GitHub#
The start value for the sum.
The start value for the sum.
- name = 'sum'#
- class pyccel.ast.numpyext.NumpyTan(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the tan function in the Numpy library
- name = 'tan'#
- class pyccel.ast.numpyext.NumpyTanh(x)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresent a call to the tanh function in the Numpy library
- name = 'tanh'#
- class pyccel.ast.numpyext.NumpyTranspose(x, *axes)[source]View on GitHub#
Bases:
NumpyUfuncUnaryRepresents 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_varView on GitHub#
Return the variable being transposed
- property is_elementalView on GitHub#
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.
- property is_indexableView on GitHub#
Indicate whether the expression can be indexed.
Indicate whether the expression can be indexed to get an element without calculating the entire result. E.g cos(x)[i] is equivalent to cos(x[i]) but func_call(x)[i] is not equivalent to func_call(x[i]).
- name = 'transpose'#
- class pyccel.ast.numpyext.NumpyUfuncBase(*args)[source]View on GitHub#
Bases:
PyccelFunctionBase 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_elementalView on GitHub#
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]View on GitHub#
Bases:
NumpyUfuncBaseClass 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]View on GitHub#
Bases:
NumpyUfuncBaseClass 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 argView on GitHub#
The argument passed to the NumPy unary function.
The argument passed to the NumPy unary function.
- class pyccel.ast.numpyext.NumpyVecdot(x1, x2, axis=-Literal(1), keepdims=Literal(False), where=None, order='K', dtype=None)[source]View on GitHub#
Bases:
NumpyReductionClass representing a call to numpy.vecdot in the user code.
Class representing a call to numpy.vecdot in the user code.
- Parameters:
x1 (TypedAstNode) – The first vector.
x2 (TypedAstNode) – The second vector.
axis (None | LiteralInteger | iterable[LiteralInteger], default=-1) – Axis or axes along which a sum is performed. If axis is None then a sum is performed over all elements of arg.
keepdims (LiteralTrue | LiteralFalse, default=LiteralFalse) – Indicates if output arrays should have the same number of dimensions as arg.
where (TypedAstNode, default=None) – Boolean indicating elements to include in the sum.
order (str) – The ordering of the array (C/Fortran).
dtype (PythonType, PyccelFunctionDef, LiteralString, str) – The data type passed to the NumPy function.
- property is_indexableView on GitHub#
Indicate whether the expression can be indexed.
Indicate whether the expression can be indexed to get an element without calculating the entire result. E.g cos(x)[i] is equivalent to cos(x[i]) but func_call(x)[i] is not equivalent to func_call(x[i]).
- name = 'vecdot'#
- property x1View on GitHub#
The first vector.
The first vector.
- property x2View on GitHub#
The second vector.
The second vector.
- class pyccel.ast.numpyext.NumpyWhere(condition, x=None, y=None)[source]View on GitHub#
Bases:
PyccelFunctionRepresents 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 conditionView on GitHub#
Boolean argument determining which value is returned
- property is_elementalView on GitHub#
Indicates whether the function should be called elementwise for an array argument
- name = 'where'#
- property value_falseView on GitHub#
Value returned when the condition is evaluated to False.
- property value_trueView on GitHub#
Value returned when the condition is evaluated to True.
- class pyccel.ast.numpyext.NumpyZeros(shape, dtype='float', order='C')[source]View on GitHub#
Bases:
NumpyAutoFillRepresents 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_valueView on GitHub#
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]View on GitHub#
Bases:
PyccelFunctionRepresents 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_likeSee documentation of numpy.zeros_like: https://numpy.org/doc/stable/reference/generated/numpy.zeros_like.html .
- name = 'zeros_like'#
- pyccel.ast.numpyext.process_dtype(dtype)[source]View on GitHub#
Analyse a dtype passed to a NumPy array creation function.
This function takes a dtype passed to a NumPy array creation function, processes it in different ways depending on its type, and finally extracts the corresponding type and precision from the dtype_registry dictionary.
This function could be useful when working with numpy creation function having a dtype argument, like numpy.array, numpy.arrange, numpy.linspace…
- Parameters:
dtype (PythonType, PyccelFunctionDef, LiteralString, str, VariableTypeAnnotation) – The actual dtype passed to the NumPy function.
- Returns:
Datatype – The Datatype corresponding to the passed dtype.
int – The precision corresponding to the passed dtype.
- Raises:
TypeError – In the case of unrecognized argument type.:
TypeError – In the case of passed string argument not recognized as valid dtype.:
- pyccel.ast.numpyext.process_index_for_reduction(indices, axis, keepdims)[source]View on GitHub#
Process the insertion of an index into a reduction function.
Get the elements necessary to describe the indexed result of the reduction function. This is used in the loop unrolling.
E.g. for sum(arr, axis=0), the indexed expression is >>> sum(arr[:,*indices], axis=0)
This function returns the new axis and the indices used to index arr.
- Parameters:
indices (iterable[TypedAstNode] | TypedAstNode) – The indices that will index the result of the reduction function.
axis (iterable[TypedAstNode]) – The axis or axes along which the reduction is performed.
keepdims (LiteralTrue | LiteralFalse) – Indicates if the output array should have the same number of dimensions as arr.
- Returns:
new_indices (list[TypedAstNode]) – The indices which will index the argument of the reduction function.
new_axis (list[LiteralInteger]) – Axis or axes along which the resulting reduction is performed.
- pyccel.ast.numpyext.process_shape(is_scalar, shape)[source]View on GitHub#
Modify the input shape to the expected type.
Modify the input shape to the expected type.
- Parameters:
is_scalar (bool) – True if the result is a scalar, False if it is an array.
shape (TypedAstNode | iterable | int) – Input shape.
- Returns:
The shape of the array in a compatible format.
- Return type:
tuple[int | TypedAstNode]