mindspore.ops
operators that can be used for constructor function of Cell
import mindspore.ops as ops
Compared with the previous version, the added, deleted and supported platforms change information of mindspore.ops operators in MindSpore, please refer to the link API Updates .
Operator Primitives
Primitive is the base class of operator primitives in python. |
|
PrimitiveWithCheck is the base class of primitives in python, which defines functions to check the input arguments of operators, but uses the infer method registered in c++ source codes. |
|
PrimitiveWithInfer is the base class of primitives in python and defines functions for tracking inference in python. |
Decorators
Creates a PrimitiveWithInfer operator that can infer the value at compile time. |
|
A decorator which is used to bind the registration information to the func parameter of |
|
The decorator of the Hybrid DSL function for the Custom Op. |
|
A decorator which is used to register an operator. |
|
Primitive attributes register. |
Neural Network Layer Operators
Neural Network
API Name |
Description |
Supported Platforms |
Average pooling operation. |
|
|
3D Average pooling operation. |
|
|
Batch Normalization for input data and updated parameters. |
|
|
2D convolution layer. |
|
|
Compute a 2D transposed convolution, which is also known as a deconvolution (although it is not an actual deconvolution). |
|
|
3D convolution layer. |
|
|
Computes a 3D transposed convolution, which is also known as a deconvolution (although it is not an actual deconvolution). |
|
|
Performs greedy decoding on the logits given in inputs. |
|
|
During training, randomly zeroes some of the elements of the input tensor with probability 1-keep_prob from a Bernoulli distribution. |
|
|
During training, randomly zeroes some channels of the input tensor with probability 1-keep_prob from a Bernoulli distribution(For a 4-dimensional tensor with a shape of NCHW, the channel feature map refers to a 2-dimensional feature map with the shape of HW). |
|
|
During training, randomly zeroes some channels of the input tensor with probability 1-keep_prob from a Bernoulli distribution(For a 5-dimensional tensor with a shape of NCDHW, the channel feature map refers to a 3-dimensional feature map with a shape of DHW). |
|
|
Applies a single-layer gated recurrent unit (GRU) to an input sequence. |
|
|
Applies a recurrent neural network to the input. |
|
|
Flattens a tensor without changing its batch size on the 0-th axis. |
|
|
Applies the Layer Normalization to the input tensor. |
|
|
Local Response Normalization. |
|
|
Performs the Long Short-Term Memory (LSTM) on the input. |
|
|
Max pooling operation. |
|
|
3D max pooling operation. |
|
|
Performs max pooling on the input Tensor and returns both max values and indices. |
|
|
Pads the input tensor according to the paddings and mode. |
|
|
Pads the input tensor according to the paddings. |
|
|
Returns a slice of input tensor based on the specified indices. |
|
|
Extends the last dimension of the input tensor from 1 to pad_dim_size, by filling with 0. |
|
|
Resizes the input tensor by using the nearest neighbor algorithm. |
|
|
Resizes an image to a certain size using the bilinear interpolation. |
|
Loss Function
API Name |
Description |
Supported Platforms |
Adds sigmoid activation function to input logits, and uses the given logits to compute binary cross entropy between the logits and the label. |
|
|
Computes the binary cross entropy between the logits and the labels. |
|
|
Calculates the CTC (Connectionist Temporal Classification) loss and the gradient. |
|
|
Computes the Kullback-Leibler divergence between the logits and the labels. |
|
|
Calculates half of the L2 norm, but do not square the result. |
|
|
Gets the negative log likelihood loss between logits and labels. |
|
|
Computes the RNNTLoss and its gradient with respect to the softmax outputs. |
|
|
Uses the given logits to compute sigmoid cross entropy between the logits and the label. |
|
|
Refer to |
|
|
SoftMarginLoss operation. |
|
|
Gets the softmax cross-entropy value between logits and labels with one-hot encoding. |
|
|
Computes the softmax cross-entropy value between logits and sparse encoding labels. |
|
Activation Function
API Name |
Description |
Supported Platforms |
Exponential Linear Uint activation function. |
|
|
Fast Gaussian Error Linear Units activation function. |
|
|
Gaussian Error Linear Units activation function. |
|
|
Hard Shrink activation function. |
|
|
Hard sigmoid activation function. |
|
|
Hard swish activation function. |
|
|
Log Softmax activation function. |
|
|
Computes MISH(A Self Regularized Non-Monotonic Neural Activation Function) of input tensors element-wise. |
|
|
Parametric Rectified Linear Unit activation function. |
|
|
Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise. |
|
|
Computes ReLU (Rectified Linear Unit) upper bounded by 6 of input tensors element-wise. |
|
|
Activation function SeLU (Scaled exponential Linear Unit). |
|
|
Sigmoid activation function. |
|
|
Applies the Softmax operation to the input tensor on the specified axis. |
|
|
Softplus activation function. |
|
|
Applies the SoftShrink function element-wise. |
|
|
Softsign activation function. |
|
|
Tanh activation function. |
|
Optimizer
API Name |
Description |
Supported Platforms |
Updates gradients by the Adaptive Moment Estimation (Adam) algorithm. |
|
|
Updates gradients by the Adaptive Moment Estimation algorithm with weight decay (AdamWeightDecay). |
|
|
2D adaptive average pooling for temporal data. |
|
|
Updates relevant entries according to the adadelta scheme. |
|
|
Updates relevant entries according to the adagrad scheme. |
|
|
Update var according to the proximal adagrad scheme. |
|
|
Updates relevant entries according to the adagradv2 scheme. |
|
|
Updates relevant entries according to the adamax scheme. |
|
|
Updates relevant entries according to the AddSign algorithm. |
|
|
Optimizer that implements the centered RMSProp algorithm. |
|
|
Updates relevant entries according to the FTRL scheme. |
|
|
Updates var by subtracting alpha * delta from it. |
|
|
Optimizer that implements the Momentum algorithm. |
|
|
Updates relevant entries according to the AddSign algorithm. |
|
|
Updates relevant entries according to the proximal adagrad algorithm. |
|
|
Updates relevant entries according to the FOBOS(Forward Backward Splitting) algorithm. |
|
|
Optimizer that implements the Root Mean Square prop(RMSProp) algorithm. |
|
|
Conducts LARS (layer-wise adaptive rate scaling) update on the sum of squares of gradient. |
|
|
Deprecated |
|
|
Updates relevant entries according to the adagrad scheme, one more epsilon attribute than SparseApplyAdagrad. |
|
|
Updates relevant entries according to the proximal adagrad algorithm. |
|
|
Computes the stochastic gradient descent. |
|
|
Updates relevant entries according to the FTRL-proximal scheme For more details, please refer to |
|
|
Updates relevant entries according to the FTRL-proximal scheme. |
|
Distance Function
API Name |
Description |
Supported Platforms |
Computes batched the p-norm distance between each pair of the two collections of row vectors. |
|
|
Computes the Levenshtein Edit Distance. |
|
|
Returns the matrix norm or vector norm of a given tensor. |
|
Sampling Operator
API Name |
Description |
Supported Platforms |
Compute accidental hits of sampled classes which match target classes. |
|
|
Generates random labels with a log-uniform distribution for sampled_candidates. |
|
|
Uniform candidate sampler. |
|
Image Processing
API Name |
Description |
Supported Platforms |
Decodes bounding boxes locations. |
|
|
Encodes bounding boxes locations. |
|
|
Checks bounding box. |
|
|
Extracts crops from the input image tensor and resizes them. |
|
|
Extract patches from input and put them in the "depth" output dimension. |
|
|
Calculates intersection over union for boxes. |
|
|
L2 Normalization Operator. |
|
|
When object detection problem is performed in the computer vision field, object detection algorithm generates a plurality of bounding boxes. |
|
|
Computes the Region of Interest (RoI) Align operator. |
|
Text Processing
API Name |
Description |
Supported Platforms |
Updates log_probs with repeat n-grams. |
|
Mathematical Operators
Element-wise Operator
API Name |
Description |
Supported Platforms |
Returns absolute value of a tensor element-wise. |
|
|
Computes accumulation of all input tensors element-wise. |
|
|
Computes arccosine of input tensors element-wise. |
|
|
Computes inverse hyperbolic cosine of the inputs element-wise. |
|
|
Adds two input tensors element-wise. |
|
|
Performs the element-wise division of tensor x1 by tensor x2, multiply the result by the scalar value and add it to input_data. |
|
|
Performs the element-wise product of tensor x1 and tensor x2, multiply the result by the scalar value and add it to input_data. |
|
|
Computes addition of all input tensors element-wise. |
|
|
Computes arcsine of input tensors element-wise. |
|
|
Computes inverse hyperbolic sine of the input element-wise. |
|
|
Computes the trigonometric inverse tangent of the input element-wise. |
|
|
Returns arctangent of x/y element-wise. |
|
|
Computes inverse hyperbolic tangent of the input element-wise. |
|
|
Computes BesselI0e of input element-wise. |
|
|
Computes BesselI1e of input element-wise. |
|
|
Returns bitwise and of two tensors element-wise. |
|
|
Returns bitwise or of two tensors element-wise. |
|
|
Returns bitwise xor of two tensors element-wise. |
|
|
Rounds a tensor up to the closest integer element-wise. |
|
|
Returns a tensor of complex numbers that are the complex conjugate of each element in input. |
|
|
Computes cosine of input element-wise. |
|
|
Computes hyperbolic cosine of input element-wise. |
|
|
Computes the quotient of dividing the first input tensor by the second input tensor element-wise. |
|
|
Computes a safe divide and returns 0 if the x2 is zero. |
|
|
This operator uses equation to represent a tuple of tensors operations, you can use this operator to perform diagonal/reducesum/transpose/matmul/mul/inner product operations, etc. |
|
|
Computes the Gauss error function of x element-wise. |
|
|
Computes the complementary error function of x element-wise. |
|
|
Computes the inverse error function of input. |
|
|
Returns exponential of a tensor element-wise. |
|
|
Returns exponential then minus 1 of a tensor element-wise. |
|
|
Rounds a tensor down to the closest integer element-wise. |
|
|
Divides the first input tensor by the second input tensor element-wise and round down to the closest integer. |
|
|
Computes the remainder of division element-wise. |
|
|
Returns a new tensor containing imaginary value of the input. |
|
|
Computes Reciprocal of input tensor element-wise. |
|
|
Flips all bits of input tensor element-wise. |
|
|
Computes the minimum of input tensors element-wise. |
|
|
Returns the natural logarithm of a tensor element-wise. |
|
|
Returns the natural logarithm of one plus the input tensor element-wise. |
|
|
Computes the "logical AND" of two tensors element-wise. |
|
|
Computes the "logical NOT" of a tensor element-wise. |
|
|
Computes the "logical OR" of two tensors element-wise. |
|
|
Computes the remainder of dividing the first input tensor by the second input tensor element-wise. |
|
|
Multiplies two tensors element-wise. |
|
|
Computes x * y element-wise. |
|
|
Returns a tensor with negative values of the input tensor element-wise. |
|
|
Calculates the y power of each element in x. |
|
|
Returns a Tensor that is the real part of the input. |
|
|
Divides the first input tensor by the second input tensor in floating-point type element-wise. |
|
|
Returns reciprocal of a tensor element-wise. |
|
|
Returns an integer that is closest to x element-wise. |
|
|
Returns half to even of a tensor element-wise. |
|
|
Computes reciprocal of square root of input tensor element-wise. |
|
|
Performs sign on the tensor element-wise. |
|
|
Computes sine of the input element-wise. |
|
|
Computes hyperbolic sine of the input element-wise. |
|
|
Returns square root of a tensor element-wise. |
|
|
Returns square of a tensor element-wise. |
|
|
Subtracts the second input tensor from the first input tensor element-wise and returns square of it. |
|
|
Returns the square sum of a tensor element-wise |
|
|
Subtracts the second input tensor from the first input tensor element-wise. |
|
|
Computes tangent of x element-wise. |
|
|
Returns a new tensor with the truncated integer values of the elements of input. |
|
|
Divides the first input tensor by the second input tensor element-wise for integer types, negative numbers will round fractional quantities towards zero. |
|
|
Returns the remainder of division element-wise. |
|
|
Divides the first input tensor by the second input tensor element-wise. |
|
|
Computes the first input tensor multiplied by the logarithm of second input tensor element-wise. |
|
Reduction Operator
API Name |
Description |
Supported Platforms |
Returns the indices of the maximum value of a tensor across the axis. |
|
|
Calculates the maximum value with the corresponding index. |
|
|
Returns the indices of the minimum value of a tensor across the axis. |
|
|
Calculates the minimum value with corresponding index, and returns indices and values. |
|
|
Reduces a dimension of a tensor by the "logicalAND" of all elements in the dimension, by default. |
|
|
Reduces a dimension of a tensor by the "logical OR" of all elements in the dimension, by default. |
|
|
Reduces a dimension of a tensor by the maximum value in this dimension, by default. |
|
|
Reduces a dimension of a tensor by averaging all elements in the dimension, by default. |
|
|
Reduces a dimension of a tensor by the minimum value in the dimension, by default. |
|
|
Reduces a dimension of a tensor by multiplying all elements in the dimension, by default. |
|
|
Reduces a dimension of a tensor by summing all elements in the dimension, by default. |
|
Comparison Operator
API Name |
Description |
Supported Platforms |
Returns True if abs(x-y) is smaller than tolerance element-wise, otherwise False. |
|
|
Checks whether the data type and the shape of corresponding elements from tuples x and y are the same. |
|
|
Computes the equivalence between two tensors element-wise. |
|
|
Computes the number of the same elements of two tensors. |
|
|
Compare the value of the input parameters \(x,y\) element-wise, and the output result is a bool value. |
|
|
Computes the boolean value of \(x >= y\) element-wise. |
|
|
Determines whether the targets are in the top k predictions. |
|
|
Determines which elements are finite for each position. |
|
|
Determines which elements are inf or -inf for each position |
|
|
Checks whether an object is an instance of a target type. |
|
|
Determines which elements are NaN for each position. |
|
|
Checks whether this type is a sub-class of another type. |
|
|
Computes the boolean value of \(x < y\) element-wise. |
|
|
Computes the boolean value of \(x <= y\) element-wise. |
|
|
Computes the maximum of input tensors element-wise. |
|
|
Computes the minimum of input tensors element-wise. |
|
|
Computes the non-equivalence of two tensors element-wise. |
|
|
Checks whether the data type and shape of two tensors are the same. |
|
|
Finds values and indices of the k largest entries along the last dimension. |
|
Linear Algebraic Operator
API Name |
Description |
Supported Platforms |
Computes matrix multiplication between two tensors by batch. |
|
|
Returns the sum of the input Tensor and the bias Tensor. |
|
|
Ger product of x1 and x2. |
|
|
Multiplies matrix a and matrix b. |
|
|
Returns the inverse of the input matrix. |
|
Tensor Operation Operator
Tensor Construction
API Name |
Description |
Supported Platforms |
Create a Tensor with the same data type and shape as input, and the element value is the minimum value that the corresponding data type can be expressed. |
|
|
Creates a tensor with ones on the diagonal and zeros in the rest. |
|
|
Create a Tensor of the specified shape and fill it with the specified value. |
|
|
Returns a Tensor whose value is num evenly spaced in the interval start and stop (including start and stop), and the length of the output Tensor is num. |
|
|
Computes a one-hot tensor. |
|
|
Creates a tensor filled with value ones. |
|
|
Returns a Tensor with a value of 1 and its shape and data type is the same as the input. |
|
|
Creates a tensor filled with value zeros. |
|
|
Returns a Tensor with a value of 0 and its shape and data type is the same as the input. |
|
Random Generation Operator
API Name |
Description |
Supported Platforms |
Produces random positive floating-point values x, distributed according to probability density function: |
|
|
Returns a tensor sampled from the multinomial probability distribution located in the corresponding row of tensor input. |
|
|
Generates random samples from a given categorical distribution tensor. |
|
|
Generates a random sample as index tensor with a mask tensor from a given tensor. |
|
|
Generates n random samples from 0 to n-1 without repeating. |
|
|
Generates random numbers according to the Laplace random number distribution (mean=0, lambda=1). |
|
|
Generates random numbers according to the standard Normal (or Gaussian) random number distribution. |
|
|
Produces random integer values i, uniformly distributed on the closed interval [minval, maxval), that is, distributed according to the discrete probability function: |
|
|
Produces random floating-point values, uniformly distributed to the interval [0, 1). |
|
Array Operation
API Name |
Description |
Supported Platforms |
Divides batch dimension with blocks and interleaves these blocks back into spatial dimensions. |
|
|
Divides batch dimension with blocks and interleaves these blocks back into spatial dimensions. |
|
|
Broadcasts input tensor to a given shape. |
|
|
Returns a tensor with the new specified data type. |
|
|
Connect tensor in the specified axis. |
|
|
Computes the cumulative product of the tensor x along axis. |
|
|
Computes the cumulative sum of input tensor along axis. |
|
|
Returns the dimension index in the destination data format given in the source data format. |
|
|
Rearrange blocks of depth data into spatial dimensions. |
|
|
Returns the data type of the input tensor as mindspore.dtype. |
|
|
Adds an additional dimension to input_x at the given axis. |
|
|
Determines if the elements contain Not a Number(NaN), infinite or negative infinite. |
|
|
Returns the slice of the input tensor corresponding to the elements of input_indices on the specified axis. |
|
|
Gathers elements along an axis specified by dim. |
|
|
Gathers slices from a tensor by indices. |
|
|
Returns a rank 1 histogram counting the number of entries in values that fall into every bin. |
|
|
Returns a Tensor with the same shape and contents as input. |
|
|
Adds tensor y to specified axis and indices of tensor x. |
|
|
Adds v into specified rows of x. |
|
|
Subtracts v into specified rows of x. |
|
|
Updates specified rows with values in v. |
|
|
Computes the inverse of an index permutation. |
|
|
Fills elements with value where mask is True. |
|
|
Returns a new 1-D Tensor which indexes the x tensor according to the boolean mask. |
|
|
Generates coordinate matrices from given coordinate tensors. |
|
|
Concats tensor in the first dimension. |
|
|
Computes element-wise population count(a.k.a bitsum, bitcount). |
|
|
Creates a sequence of numbers that begins at start and extends by increments of delta up to but not including limit. |
|
|
Returns the rank of a tensor. |
|
|
Rearranges the input Tensor based on the given shape. |
|
|
Reverses variable length slices. |
|
|
Reverses specific dimensions of a tensor. |
|
|
Scatters a tensor into a new tensor depending on the specified indices. |
|
|
The conditional tensor determines whether the corresponding element in the output must be selected from \(x\) (if True) or \(y\) (if False) based on the value of each element. |
|
|
Returns the shape of the input tensor. |
|
|
Returns a Scalar of type int that represents the size of the input Tensor and the total number of elements in the Tensor. |
|
|
Slices a tensor in the specified shape. |
|
|
Sorts the elements of the input tensor along a given dimension in ascending order by value. |
|
|
Divides spatial dimensions into blocks and combines the block size with the original batch. |
|
|
Rearrange blocks of spatial data into depth. |
|
|
Returns a slice of input tensor based on the specified indices and axis. |
|
|
Splits the input tensor into output_num of tensors along the given axis and output numbers. |
|
|
Return the Tensor after deleting the dimension of size 1 in the specified axis. |
|
|
Stacks a list of tensors in specified axis. |
|
|
Extracts a strided slice of a Tensor based on begin/end index and strides. |
|
|
Creates a new tensor by adding the values from the positions in input_x indicated by indices, with values from updates. |
|
|
Creates a new tensor by dividing the values from the positions in input_x indicated by indices, with values from updates. |
|
|
By comparing the value at the position indicated by indices in x with the value in the updates, the value at the index will eventually be equal to the largest one to create a new tensor. |
|
|
By comparing the value at the position indicated by indices in input_x with the value in the updates, the value at the index will eventually be equal to the smallest one to create a new tensor. |
|
|
Creates a new tensor by multiplying the values from the positions in input_x indicated by indices, with values from updates. |
|
|
Creates a new tensor by subtracting the values from the positions in input_x indicated by indices, with values from updates. |
|
|
Creates a new tensor by updating the positions in input_x indicated by indices, with values from update. |
|
|
Returns the shape of the input tensor. |
|
|
Replicates an input tensor with given multiples times. |
|
|
Permutes the dimensions of the input tensor according to input permutation. |
|
|
Returns the unique elements of input tensor and also return a tensor containing the index of each value of input tensor corresponding to the output unique tensor. |
|
|
Returns unique elements and relative indexes in 1-D tensor, filled with padding num. |
|
|
Computes the maximum along segments of a tensor. |
|
|
Computes the minimum of a tensor along segments. |
|
|
Computes the product of a tensor along segments. |
|
|
Computes the sum of a tensor along segments. |
|
|
Unstacks tensor in specified axis. |
|
Type Conversion
API Name |
Description |
Supported Platforms |
Casts the input scalar to another type. |
|
|
Converts a scalar to a Tensor. |
|
|
Converts a scalar to a Tensor, and converts the data type to the specified type. |
|
|
Converts a tuple to a tensor. |
|
Parameter Operation Operator
API Name |
Description |
Supported Platforms |
Assigns Parameter with a value. |
|
|
Updates a Parameter by adding a value to it. |
|
|
Updates a Parameter by subtracting a value from it. |
|
|
Updates the value of the input tensor through the addition operation. |
|
|
Updates the value of the input tensor through the divide operation. |
|
|
Updates the value of the input tensor through the maximum operation. |
|
|
Updates the value of the input tensor through the minimum operation. |
|
|
Updates the value of the input tensor through the multiply operation. |
|
|
Applies sparse addition to individual values or slices in a tensor. |
|
|
Applies sparse subtraction to individual values or slices in a tensor. |
|
|
Updates tensor values by using input indices and value. |
|
|
Applies sparse addition to the input using individual values or slices. |
|
|
Updates the value of the input tensor through the subtraction operation. |
|
|
Updates tensor values by using input indices and value. |
|
Data Operation Operator
API Name |
Description |
Supported Platforms |
Returns the next element in the dataset queue. |
|
Communication Operator
Note that the APIs in the following list need to preset communication environment variables. For the Ascend devices, users need to prepare the rank table, set rank_id and device_id. Please see the Ascend tutorial for more details. For the GPU device, users need to prepare the host file and mpi, please see the GPU tutorial .
API Name |
Description |
Supported Platforms |
Gathers tensors from the specified communication group. |
|
|
Reduces the tensor data across all devices in such a way that all devices will get the same final result. |
|
|
AlltoAll is a collective operation. |
|
|
Broadcasts the tensor to the whole group. |
|
|
NeighborExchange is a collective operation. |
|
|
NeighborExchangeV2 is a collective operation. |
|
|
Operation options for reducing tensors. |
|
|
Reduces and scatters tensors from the specified communication group. |
|
Debugging Operator
API Name |
Description |
Supported Platforms |
Outputs the tensor to protocol buffer through histogram summary operator. |
|
|
Outputs the image tensor to protocol buffer through image summary operator. |
|
|
Outputs a scalar to a protocol buffer through a scalar summary operator. |
|
|
Outputs a tensor to a protocol buffer through a tensor summary operator. |
|
|
Outputs the inputs to stdout. |
|
|
Allocates a flag to store the overflow status. |
|
|
Clears the flag which stores the overflow status. |
|
|
Updates the flag which is the output tensor of NPUAllocFloatStatus with the latest overflow status. |
|
Sparse Operator
API Name |
Description |
Supported Platforms |
Multiplies sparse matrix A by dense matrix B. |
|
|
Converts a sparse representation into a dense tensor. |
|
Frame Operators
API Name |
Description |
Supported Platforms |
Depend is used for processing dependency operations. |
|
|
A higher-order function which is used to generate the gradient function for the input function. |
|
|
This operation is used as a tag to hook gradient in intermediate variables. |
|
|
Hypermap will apply the set operation to input sequences. |
|
|
Attaches callback to the graph node that will be invoked on the node's gradient. |
|
|
Map will apply the set operation on input sequences. |
|
|
Generates overloaded functions. |
|
|
Makes a partial function instance. |
|
Operator Information Registration
Class for AiCPU operator information register. |
|
Class used for generating the registration information for the func parameter of |
|
Various combinations of dtype and format of Ascend ops. |
|
Class for TBE operator information register. |
|
Gets the virtual implementation function by a primitive object or primitive name. |
Customizing Operator
Custom primitive is used for user defined operators and is to enhance the expressive ability of built-in primitives. |