mindspore.ops.functional

functional算子是经过初始化后的Primitive,可以直接作为函数使用。functional算子的使用示例如下:

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]

神经网络层算子

激活函数

functional

Description

mindspore.ops.tanh

Refer to mindspore.ops.Tanh.

数学运算算子

逐元素运算

functional

Description

mindspore.ops.absolute

Refer to mindspore.ops.Abs.

mindspore.ops.acos

Refer to mindspore.ops.ACos.

mindspore.ops.acosh

Refer to mindspore.ops.Acosh.

mindspore.ops.add

Refer to mindspore.ops.Add.

mindspore.ops.addn

Refer to mindspore.ops.AddN.

mindspore.ops.asin

Refer to mindspore.ops.Asin.

mindspore.ops.asinh

Refer to mindspore.ops.Asinh.

mindspore.ops.atan

Refer to mindspore.ops.Atan.

mindspore.ops.atan2

Refer to mindspore.ops.Atan2.

mindspore.ops.atanh

Refer to mindspore.ops.Atanh.

mindspore.ops.bitwise_and

Refer to mindspore.ops.BitwiseAnd.

mindspore.ops.bitwise_or

Refer to mindspore.ops.BitwiseOr.

mindspore.ops.bitwise_xor

Refer to mindspore.ops.BitwiseXor.

mindspore.ops.cos

Refer to mindspore.ops.Cos.

mindspore.ops.cosh

Refer to mindspore.ops.Cosh.

mindspore.ops.div

Refer to mindspore.ops.RealDiv.

mindspore.ops.erf

Refer to mindspore.ops.Erf.

mindspore.ops.erfc

Refer to mindspore.ops.Erfc.

mindspore.ops.exp

Refer to mindspore.ops.Exp.

mindspore.ops.floor

Refer to mindspore.ops.Floor.

mindspore.ops.floordiv

Refer to mindspore.ops.FloorDiv.

mindspore.ops.floormod

Refer to mindspore.ops.FloorMod.

mindspore.ops.log

Refer to mindspore.ops.Log.

mindspore.ops.logical_and

Refer to mindspore.ops.LogicalAnd.

mindspore.ops.logical_not

Refer to mindspore.ops.LogicalNot.

mindspore.ops.logical_or

Refer to mindspore.ops.LogicalOr.

mindspore.ops.invert

Refer to mindspore.ops.Invert.

mindspore.ops.mul

Refer to mindspore.ops.Mul.

mindspore.ops.neg_tensor

Refer to mindspore.ops.Neg.

mindspore.ops.pows

Refer to mindspore.ops.Pow.

mindspore.ops.sin

Refer to mindspore.ops.Sin.

mindspore.ops.sinh

Refer to mindspore.ops.Sinh.

mindspore.ops.sqrt

Refer to mindspore.ops.Sqrt.

mindspore.ops.square

Refer to mindspore.ops.Square.

mindspore.ops.sub

Refer to mindspore.ops.Sub.

mindspore.ops.tan

Refer to mindspore.ops.Tan.

mindspore.ops.tensor_add

Refer to mindspore.ops.Add.

mindspore.ops.tensor_div

Refer to mindspore.ops.RealDiv.

mindspore.ops.tensor_exp

Refer to mindspore.ops.Exp.

mindspore.ops.tensor_expm1

Refer to mindspore.ops.Expm1.

mindspore.ops.tensor_floordiv

Refer to mindspore.ops.FloorDiv.

mindspore.ops.tensor_mod

Refer to mindspore.ops.FloorMod.

mindspore.ops.tensor_mul

Refer to mindspore.ops.Mul.

mindspore.ops.tensor_pow

Refer to mindspore.ops.Pow.

mindspore.ops.tensor_sub

Refer to mindspore.ops.Sub.

Reduction算子

functional

Description

mindspore.ops.reduce_max

Refer to mindspore.ops.ReduceMax.

mindspore.ops.reduce_mean

Refer to mindspore.ops.ReduceMean.

mindspore.ops.reduce_min

Refer to mindspore.ops.ReduceMin.

mindspore.ops.reduce_prod

Refer to mindspore.ops.ReduceProd.

mindspore.ops.reduce_sum

Refer to mindspore.ops.ReduceSum.

比较算子

functional

Description

mindspore.ops.check_bprop

Refer to mindspore.ops.CheckBprop.

mindspore.ops.equal

Refer to mindspore.ops.Equal.

mindspore.ops.ge

Refer to mindspore.ops.GreaterEqual.

mindspore.ops.gt

Refer to mindspore.ops.Greater.

mindspore.ops.le

Refer to mindspore.ops.LessEqual.

mindspore.ops.less

Refer to mindspore.ops.Less.

mindspore.ops.isfinite

Refer to mindspore.ops.IsFinite.

mindspore.ops.isinstance_

Refer to mindspore.ops.IsInstance.

mindspore.ops.isnan

Refer to mindspore.ops.IsNan.

mindspore.ops.issubclass_

Refer to mindspore.ops.IsSubClass.

mindspore.ops.maximum

Refer to mindspore.ops.Maximum.

mindspore.ops.minimum

Refer to mindspore.ops.Minimum.

mindspore.ops.not_equal

Refer to mindspore.ops.NotEqual.

mindspore.ops.same_type_shape

Refer to mindspore.ops.SameTypeShape.

mindspore.ops.tensor_ge

Refer to mindspore.ops.GreaterEqual.

mindspore.ops.tensor_gt

Refer to mindspore.ops.Greater.

mindspore.ops.tensor_le

Refer to mindspore.ops.LessEqual.

mindspore.ops.tensor_lt

Refer to mindspore.ops.Less.

线性代数算子

接口名

概述

支持平台

mindspore.ops.matmul

计算两个数组的乘积。

Ascend GPU CPU

Tensor操作算子

Tensor创建

functional

Description

mindspore.ops.eye

Refer to mindspore.ops.Eye.

mindspore.ops.fill

Refer to mindspore.ops.Fill.

mindspore.ops.ones_like

Refer to mindspore.ops.OnesLike.

mindspore.ops.zeros_like

Refer to mindspore.ops.ZerosLike.

随机生成算子

接口名

概述

支持平台

mindspore.ops.gamma

Generates random numbers according to the Gamma random number distribution.

Ascend

mindspore.ops.multinomial

Returns a tensor sampled from the multinomial probability distribution located in the corresponding row of the input tensor.

GPU

mindspore.ops.poisson

Generates random numbers according to the Poisson random number distribution.

Ascend

Array操作

functional

Description

mindspore.ops.cast

Refer to mindspore.ops.Cast.

mindspore.ops.cumprod

Refer to mindspore.ops.CumProd.

mindspore.ops.cumsum

Refer to mindspore.ops.CumSum.

mindspore.ops.dtype

Refer to mindspore.ops.DType.

mindspore.ops.expand_dims

Refer to mindspore.ops.ExpandDims.

mindspore.ops.gather

Refer to mindspore.ops.Gather.

mindspore.ops.gather_d

Refer to mindspore.ops.GatherD.

mindspore.ops.gather_nd

Refer to mindspore.ops.GatherNd.

mindspore.ops.rank

Refer to mindspore.ops.Rank.

mindspore.ops.reshape

Refer to mindspore.ops.Reshape.

mindspore.ops.scatter_nd

Refer to mindspore.ops.ScatterNd.

mindspore.ops.shape

Refer to mindspore.ops.Shape.

mindspore.ops.size

Refer to mindspore.ops.Size.

mindspore.ops.sort

Refer to mindspore.ops.Sort.

mindspore.ops.squeeze

Refer to mindspore.ops.Squeeze.

mindspore.ops.stack

Refer to mindspore.ops.Stack.

mindspore.ops.strided_slice

Refer to mindspore.ops.StridedSlice.

mindspore.ops.tensor_scatter_add

Refer to mindspore.ops.TensorScatterAdd.

mindspore.ops.tensor_scatter_update

Refer to mindspore.ops.TensorScatterUpdate.

mindspore.ops.tensor_slice

Refer to mindspore.ops.Slice.

mindspore.ops.tile

Refer to mindspore.ops.Tile.

mindspore.ops.transpose

Refer to mindspore.ops.Transpose.

接口名

概述

支持平台

mindspore.ops.select

Returns the selected elements, either from input \(x\) or input \(y\), depending on the condition cond.

Ascend GPU CPU

mindspore.ops.unique

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.

Ascend GPU CPU

类型转换

functional

Description

mindspore.ops.scalar_cast

Refer to mindspore.ops.ScalarCast.

mindspore.ops.scalar_to_array

Refer to mindspore.ops.ScalarToArray.

mindspore.ops.scalar_to_tensor

Refer to mindspore.ops.ScalarToTensor.

mindspore.ops.tuple_to_array

Refer to mindspore.ops.TupleToArray.

Parameter操作算子

functional

Description

mindspore.ops.assign

Refer to mindspore.ops.Assign.

mindspore.ops.assign_add

Refer to mindspore.ops.AssignAdd.

mindspore.ops.assign_sub

Refer to mindspore.ops.AssignSub.

mindspore.ops.scatter_nd_update

Refer to mindspore.ops.ScatterNdUpdate.

mindspore.ops.scatter_update

Refer to mindspore.ops.ScatterUpdate.

调试算子

functional

Description

mindspore.ops.print_

Refer to mindspore.ops.Print.

其他算子

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.Depend.

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.Partial.

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.

接口名

概述

支持平台

mindspore.ops.arange

根据给定的范围返回指定均匀间隔的数据。

Ascend GPU CPU

mindspore.ops.batch_dot

当输入的两个Tensor是批量数据时,对其进行批量点积操作。

Ascend GPU CPU

mindspore.ops.clip_by_global_norm

通过权重梯度总和的比率来裁剪多个Tensor的值。

Ascend GPU CPU

mindspore.ops.clip_by_value

将输入Tensor值裁剪到指定的最小值和最大值之间。

Ascend GPU CPU

mindspore.ops.core

A decorator that adds a flag to the function.

Ascend GPU CPU

mindspore.ops.count_nonzero

Count number of nonzero elements across axis of input tensor

Ascend GPU CPU

mindspore.ops.cummin

Computation of the cumulative minimum of elements of 'x' in the dimension axis, and the index location of each maximum value found in the dimension 'axis'.

Ascend

mindspore.ops.dot

两个Tensor之间的点积。

Ascend GPU CPU

mindspore.ops.grad

A wrapper function to generate the gradient function for the input function.

Ascend GPU CPU

mindspore.ops.jvp

Compute the jacobian-vector-product of the given network.

Ascend GPU CPU

mindspore.ops.laplace

Generates random numbers according to the Laplace random number distribution.

Ascend

mindspore.ops.narrow

Returns a narrowed tensor from input tensor.

Ascend GPU CPU

mindspore.ops.normal

Generates random numbers according to the Normal (or Gaussian) random number distribution.

Ascend GPU CPU

mindspore.ops.repeat_elements

在指定轴上复制输入Tensor的元素,类似 np.repeat 的功能。

Ascend GPU CPU

mindspore.ops.sequence_mask

返回一个表示每个单元的前N个位置的掩码Tensor。

GPU

mindspore.ops.tensor_dot

在指定轴上对Tensor ab 进行点乘操作。

Ascend GPU CPU

mindspore.ops.uniform

生成服从均匀分布的随机数。

Ascend GPU

mindspore.ops.vjp

Compute the vector-jacobian-product of the given network.

Ascend GPU CPU