mindspore.ops.functional
The functional operators are initialized Primitives and can be used directly as functions. An example of the use of the functional operator is as follows:
from mindspore import Tensor, ops
from mindspore import dtype as mstype
input_x = Tensor(-1, mstype.int32)
input_dict = {'x':1, 'y':2}
result_abs = ops.absolute(input_x)
print(result_abs)
result_in_dict = ops.in_dict('x', input_dict)
print(result_in_dict)
result_not_in_dict = ops.not_in_dict('x', input_dict)
print(result_not_in_dict)
result_isconstant = ops.isconstant(input_x)
print(result_isconstant)
result_typeof = ops.typeof(input_x)
print(result_typeof)
# outputs:
# 1
# True
# False
# True
# Tensor[Int32]
Neural Network Layer Functions
Neural Network
API Name |
Description |
Supported Platforms |
2D adaptive average pooling for temporal data. |
|
|
Average pooling operation. |
|
|
Performs greedy decoding on the logits given in inputs. |
|
|
Given 4D tensor inputs x, weight and offsets, compute a 2D deformable convolution. |
|
|
During training, randomly zeroes some channels of the input tensor with probability p 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 p 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\)). |
|
|
Flattens a tensor without changing its batch size on the 0-th axis. |
|
|
Using the interpolate method specified by mode resize the input tensor x. |
|
|
Computes the Kullback-Leibler divergence between the logits and the labels. |
|
|
Local Response Normalization. |
|
|
Performs a 3D max pooling on the input Tensor. |
|
|
Pads the input tensor according to the paddings. |
|
|
Extends the last dimension of the input tensor from 1 to pad_dim_size, by filling with 0. |
|
Loss Functions
API Name |
Description |
Supported Platforms |
The cross entropy loss between input and target. |
|
|
Gets the negative log likelihood loss between inputs and target. |
|
|
Computes smooth L1 loss, a robust L1 loss. |
|
Activation Functions
API Name |
Description |
Supported Platforms |
Fast Gaussian Error Linear Units activation function. |
|
|
Returns the samples from the Gumbel-Softmax distribution and optionally discretizes. |
|
|
Hard Shrink 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. |
|
|
Activation function SeLU (Scaled exponential Linear Unit). |
|
|
Softsign activation function. |
|
|
Applies the SoftShrink function element-wise. |
|
|
Tanh activation function. |
|
Sampling Functions
API Name |
Description |
Supported Platforms |
Given an input_x and a flow-field grid, computes the output using input_x values and pixel locations from grid. |
|
Mathematical Functions
Element-by-Element Functions
API Name |
Description |
Supported Platforms |
Returns absolute value of a tensor element-wise. |
|
|
Computes arccosine of input tensors element-wise. |
|
|
Computes inverse hyperbolic cosine of the inputs element-wise. |
|
|
Adds two input tensors element-wise. |
|
|
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. |
|
|
Randomly set the elements of output to 0 or 1 with the probability of P which follows the Bernoulli distribution. |
|
|
Computes the Bessel i0 function of x element-wise. |
|
|
Computes the Bessel i0e function of x element-wise. |
|
|
Computes the Bessel i1 function of x element-wise. |
|
|
Computes the Bessel i1e function of x element-wise. |
|
|
Computes the Bessel j0 function of x element-wise. |
|
|
Computes the Bessel j1 function of x element-wise. |
|
|
Computes the Bessel k0 function of x element-wise. |
|
|
Computes the Bessel k0e function of x element-wise. |
|
|
Computes the Bessel k1 function of x element-wise. |
|
|
Computes the Bessel k1e function of x element-wise. |
|
|
Computes the Bessel y0 function of x element-wise. |
|
|
Computes the Bessel y1 function of x 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. |
|
|
Computes cosine of input element-wise. |
|
|
Computes hyperbolic cosine of input element-wise. |
|
|
Divides the first input tensor by the second input tensor in floating-point type element-wise. |
|
|
Computes the Gauss error function of x element-wise. |
|
|
Computes the complementary error function of x element-wise. |
|
|
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. |
|
|
Adds v into specified rows of x. |
|
|
Subtracts v into specified rows of x. |
|
|
Updates specified rows with values in v. |
|
|
Computes Reciprocal of input tensor element-wise. |
|
|
Flips all bits of input tensor element-wise. |
|
|
Does a linear interpolation of two tensors start and end based on a float or tensor weight. |
|
|
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. |
|
|
Multiplies two tensors element-wise. |
|
|
Returns a tensor with negative values of the input tensor element-wise. |
|
|
Calculates the y power of each element in x. |
|
|
Returns half to even of a tensor element-wise. |
|
|
Computes sine of the input element-wise. |
|
|
Computes hyperbolic sine of the input 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. |
|
|
Computes the first input tensor multiplied by the logarithm of second input tensor element-wise. |
|
functional |
Description |
---|---|
mindspore.ops.absolute |
absolute will be deprecated in the future. Please use mindspore.ops.abs instead. |
mindspore.ops.floordiv |
floordiv will be deprecated in the future. Please use mindspore.ops.floor_div instead. |
mindspore.ops.floormod |
floormod will be deprecated in the future. Please use mindspore.ops.floor_mod instead. |
mindspore.ops.neg_tensor |
neg_tensor will be deprecated in the future. Please use mindspore.ops.neg instead. |
mindspore.ops.pows |
pows will be deprecated in the future. Please use mindspore.ops.pow instead. |
mindspore.ops.sqrt |
Refer to |
mindspore.ops.square |
Refer to |
mindspore.ops.tensor_add |
tensor_add will be deprecated in the future. Please use mindspore.ops.add instead. |
mindspore.ops.tensor_div |
tensor_div will be deprecated in the future. Please use mindspore.ops.div instead. |
mindspore.ops.tensor_exp |
tensor_exp will be deprecated in the future. Please use mindspore.ops.exp instead. |
mindspore.ops.tensor_expm1 |
tensor_expm1 will be deprecated in the future. Please use mindspore.ops.expm1 instead. |
mindspore.ops.tensor_floordiv |
tensor_floordiv will be deprecated in the future. Please use mindspore.ops.floor_div instead. |
mindspore.ops.tensor_mod |
tensor_mod will be deprecated in the future. Please use mindspore.ops.floor_mod instead. |
mindspore.ops.tensor_mul |
tensor_mul will be deprecated in the future. Please use mindspore.ops.mul instead. |
mindspore.ops.tensor_pow |
tensor_pow will be deprecated in the future. Please use mindspore.ops.pow instead. |
mindspore.ops.tensor_sub |
tensor_sub will be deprecated in the future. Please use mindspore.ops.sub instead. |
Reduction Functions
API Name |
Description |
Supported Platforms |
Reduces a dimension of a tensor by the maximum value in this dimension, by default. |
|
|
Reduces a dimension of a tensor by the minimum value in the dimension, by default. |
|
|
Returns the indices of the minimum value of a tensor across the axis. |
|
|
Returns a tuple (values,indices) where 'values' is the cumulative maximum value of input Tensor x along the dimension axis, and indices is the index location of each maximum value. |
|
|
Returns a tuple (values,indices) where 'values' is the cumulative minimum value of input Tensor x along the dimension axis, and indices is the index location of each minimum value. |
|
|
Reduces a dimension of a tensor by calculating exponential for all elements in the dimension, then calculate logarithm of the sum. |
|
|
Calculates the maximum value with the corresponding index. |
|
|
Reduces a dimension of a tensor by averaging all elements in the dimension, by default. |
|
|
Calculates the minimum value with corresponding index, and returns indices and values. |
|
|
Returns the matrix norm or vector norm of a given tensor. |
|
|
Reduces a dimension of a tensor by multiplying all elements in the dimension, by default. |
|
functional |
Description |
---|---|
mindspore.ops.reduce_sum |
Refer to |
Comparison Functions
API Name |
Description |
Supported Platforms |
Returns True if abs(x-y) is smaller than tolerance element-wise, otherwise False. |
|
|
Computes the equivalence between two tensors element-wise. |
|
|
Computes the boolean value of \(x >= y\) element-wise. |
|
|
Compare the value of the input parameters \(x,y\) element-wise, and the output result is a bool value. |
|
|
Determines whether the targets are in the top k predictions. |
|
|
Returns a new Tensor with boolean elements representing if each element of x1 is “close” to the corresponding element of x2. |
|
|
Determines which elements are finite for each position. |
|
|
Determines which elements are NaN for each position. |
|
|
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. |
|
functional |
Description |
---|---|
mindspore.ops.check_bprop |
Refer to |
mindspore.ops.isinstance_ |
Refer to |
mindspore.ops.issubclass_ |
Refer to |
mindspore.ops.not_equal |
not_equal will be deprecated in the future. Please use mindspore.ops.ne instead. |
mindspore.ops.tensor_ge |
tensor_ge will be deprecated in the future. Please use mindspore.ops.ge instead. |
mindspore.ops.tensor_gt |
tensor_gt will be deprecated in the future. Please use mindspore.ops.gt instead. |
mindspore.ops.tensor_le |
tensor_le will be deprecated in the future. Please use mindspore.ops.le instead. |
mindspore.ops.tensor_lt |
tensor_lt will be deprecated in the future. Please use mindspore.ops.less instead. |
Linear Algebraic Functions
API Name |
Description |
Supported Platforms |
Computation of batch dot product between samples in two tensors containing batch dims. |
|
|
Computation a dot product between samples in two tensors. |
|
|
Returns the matrix product of two tensors. |
|
|
Solves systems of linear equations. |
|
|
Ger product of x1 and x2. |
|
|
Renormalizes the sub-tensors along dimension dim, and each sub-tensor's p-norm should not exceed the 'maxnorm'. |
|
|
Computation of Tensor contraction on arbitrary axes between tensors a and b. |
|
Tensor Operation Functions
Tensor Building
API Name |
Description |
Supported Platforms |
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. |
|
|
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. |
|
Randomly Generating Functions
API Name |
Description |
Supported Platforms |
Generates random numbers according to the Gamma random number distribution. |
|
|
Generates random numbers according to the Laplace random number distribution. |
|
|
Outputs random values from the Gamma distribution(s) described by alpha. |
|
|
Returns a tensor sampled from the multinomial probability distribution located in the corresponding row of the input tensor. |
|
|
Generates random numbers according to the Normal (or Gaussian) random number distribution. |
|
|
Generates random numbers according to the Poisson random number distribution. |
|
|
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. |
|
|
Generates random numbers according to the Uniform random number distribution. |
|
|
Uniform candidate sampler. |
|
Array Functions
API Name |
Description |
Supported Platforms |
adaptive_max_pool2d operation. |
|
|
Divides batch dimension with blocks and interleaves these blocks back into spatial dimensions. |
|
|
Adds sigmoid activation function to input logits, and uses the given logits to compute binary cross entropy between the logits and the label. |
|
|
Broadcasts input tensor to a given shape. |
|
|
Combines an array of sliding local blocks into a large containing tensor. |
|
|
Connect tensor in the specified axis. |
|
|
Constructs a diagonal tensor with a given diagonal values. |
|
|
Adds an additional dimension to input_x at the given axis. |
|
|
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 elements along an axis specified by dim. |
|
|
Gathers slices from a tensor by indices. |
|
|
Adds tensor y to specified axis and indices of Parameter x. |
|
|
Fills the elements under the dim dimension of the input Tensor x with the input value by selecting the indices in the order given in index. |
|
|
Fills elements of Tensor with value where mask is True. |
|
|
Returns a new 1-D Tensor which indexes the x tensor according to the boolean mask. |
|
|
Copy a tensor setting everything outside a central band in each innermost matrix to zero. |
|
|
Returns a Tensor with the contents in x as k[0]-th to k[1]-th diagonals of a matrix, with everything else padded with padding_value. |
|
|
Returns the diagonal part of input tensor. |
|
|
Returns a batched matrix tensor with new batched diagonal values. |
|
|
Generates coordinate matrices from given coordinate tensors. |
|
|
Returns a narrowed tensor from input tensor. |
|
|
Return a Tensor of the positions of all non-zero values. |
|
|
Computes a one-hot tensor. |
|
|
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. |
|
|
Repeat elements of a tensor along an axis, like np.repeat . |
|
|
Returns a mask tensor representing the first N positions of each cell. |
|
|
Rearranges the input Tensor based on the given shape. |
|
|
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. |
|
|
Divides a tensor's spatial dimensions into blocks and combines the block sizes with the original batch. |
|
|
Computes a Tensor such that \(output_i = \frac{\sum_j x_{indices[j]}}{N}\) where mean is over \(j\) such that \(segment\_ids[j] == i\) and \(N\) is the total number of values summed. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
Updates the value of the input tensor through the reduction operation. |
|
|
Replicates an input tensor with given multiples times. |
|
|
Finds values and indices of the k largest entries along the last dimension. |
|
|
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 the elements that are unique in each consecutive group of equivalent elements in the input tensor. |
|
|
Computes the maximum along segments of a tensor. |
|
|
Computes the minimum of a tensor along segments. |
|
|
Computes the product of a tensor along segments. |
|
|
Returns unique elements and relative indexes in 1-D tensor, filled with padding num. |
|
|
Unstacks tensor in specified axis. |
|
functional |
Description |
---|---|
mindspore.ops.cast |
Refer to |
mindspore.ops.cumprod |
Refer to |
mindspore.ops.cumsum |
Refer to |
mindspore.ops.dtype |
Refer to |
mindspore.ops.sort |
Refer to |
mindspore.ops.strided_slice |
Refer to |
mindspore.ops.tensor_scatter_update |
Refer to |
mindspore.ops.tensor_slice |
tensor_slice will be deprecated in the future. Please use mindspore.ops.slice instead. |
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. |
|
Sparse Functions
API Name |
Description |
Supported Platforms |
Convert a Tensor to COOTensor. |
|
|
Convert a Tensor to CSRTensor. |
|
|
Converts a CSRTensor to COOTensor. |
|
Gradient Clipping
API Name |
Description |
Supported Platforms |
Clips tensor values by the ratio of the sum of their norms. |
|
|
Clips tensor values to a specified min and max. |
|
Parameter Operation Functions
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. |
|
|
Using given values to update tensor value through the add operation, along with the input indices. |
|
|
Updates the value of the input tensor through the divide operation. |
|
|
Updates the value of the input tensor through the minimum operation. |
|
|
Using given values to update tensor value through the max operation, along with the input indices. |
|
|
Applies sparse addition to individual values or slices in a tensor. |
|
|
Applying sparse division to individual values or slices in a tensor. |
|
|
Applying sparse maximum to individual values or slices in a tensor. |
|
|
Applying sparse minimum to individual values or slices in a tensor. |
|
|
Applies sparse multiplication 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. |
|
Differential Functions
API Name |
Description |
Supported Platforms |
This function is designed to calculate the higher order differentiation of given composite function. |
|
|
A wrapper function to generate the gradient function for the input function. |
|
|
This function is designed to calculate the higher order differentiation of given composite function. |
|
|
Compute the jacobian-vector-product of the given network. |
|
|
A wrapper function to generate the function to calculate forward output and gradient for the input function. |
|
|
Compute the vector-jacobian-product of the given network. |
|
|
Vectorizing map (vmap) is a kind of higher-order function to map fn along the parameter axes. |
|
Debugging Functions
functional |
Description |
---|---|
mindspore.ops.print_ |
Refer to |
Other Functions
functional |
Description |
---|---|
mindspore.ops.bool_and |
Calculate the result of logical AND operation. (Usage is the same as “and” in Python) |
mindspore.ops.bool_eq |
Determine whether the Boolean values are equal. (Usage is the same as “==” in Python) |
mindspore.ops.bool_not |
Calculate the result of logical NOT operation. (Usage is the same as “not” in Python) |
mindspore.ops.bool_or |
Calculate the result of logical OR operation. (Usage is the same as “or” in Python) |
mindspore.ops.depend |
Refer to |
mindspore.ops.in_dict |
Determine if a str in dict. |
mindspore.ops.is_not |
Determine whether the input is not the same as the other one. (Usage is the same as “is not” in Python) |
mindspore.ops.is_ |
Determine whether the input is the same as the other one. (Usage is the same as “is” in Python) |
mindspore.ops.isconstant |
Determine whether the object is constant. |
mindspore.ops.not_in_dict |
Determine whether the object is not in the dict. |
mindspore.ops.partial |
Refer to |
mindspore.ops.scalar_add |
Get the sum of two numbers. (Usage is the same as “+” in Python) |
mindspore.ops.scalar_div |
Get the quotient of dividing the first input number by the second input number. (Usage is the same as “/” in Python) |
mindspore.ops.scalar_eq |
Determine whether two numbers are equal. (Usage is the same as “==” in Python) |
mindspore.ops.scalar_floordiv |
Divide the first input number by the second input number and round down to the closest integer. (Usage is the same as “//” in Python) |
mindspore.ops.scalar_ge |
Determine whether the number is greater than or equal to another number. (Usage is the same as “>=” in Python) |
mindspore.ops.scalar_gt |
Determine whether the number is greater than another number. (Usage is the same as “>” in Python) |
mindspore.ops.scalar_le |
Determine whether the number is less than or equal to another number. (Usage is the same as “<=” in Python) |
mindspore.ops.scalar_log |
Get the natural logarithm of the input number. |
mindspore.ops.scalar_lt |
Determine whether the number is less than another number. (Usage is the same as “<” in Python) |
mindspore.ops.scalar_mod |
Get the remainder of dividing the first input number by the second input number. (Usage is the same as “%” in Python) |
mindspore.ops.scalar_mul |
Get the product of the input two numbers. (Usage is the same as “*” in Python) |
mindspore.ops.scalar_ne |
Determine whether two numbers are not equal. (Usage is the same as “!=” in Python) |
mindspore.ops.scalar_pow |
Compute a number to the power of the second input number. |
mindspore.ops.scalar_sub |
Subtract the second input number from the first input number. (Usage is the same as “-” in Python) |
mindspore.ops.scalar_uadd |
Get the positive value of the input number. |
mindspore.ops.scalar_usub |
Get the negative value of the input number. |
mindspore.ops.shape_mul |
The input of shape_mul must be shape multiply elements in tuple(shape). |
mindspore.ops.stop_gradient |
Disable update during back propagation. (stop_gradient) |
mindspore.ops.string_concat |
Concatenate two strings. |
mindspore.ops.string_eq |
Determine if two strings are equal. |
mindspore.ops.typeof |
Get type of object. |
API Name |
Description |
Supported Platforms |
A decorator that adds a flag to the function. |
|
|
Count number of nonzero elements across axis of input tensor |
|