mindspore.ops.derivative
- mindspore.ops.derivative(fn, primals, order)[source]
This function is designed to calculate the higher order differentiation of given composite function. To figure out order-th order differentiations, original inputs and order must be provided together. In particular, the value of input first order derivative is set to 1, while the other to 0.
Note
If primals is tensor of int type, it will be converted to tensor of float type.
- Parameters
- Returns
Tuple(out_primals, out_series)
out_primals (Union[Tensor, list[Tensor]]) - The output of fn(primals).
out_series (Union[Tensor, list[Tensor]]) - The order-th order of derivative of output with respect to the inputs.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import nn >>> mindspore.set_context(mode=mindspore.GRAPH_MODE) >>> class Net(nn.Cell): ... def __init__(self): ... super().__init__() ... self.sin = mindspore.ops.Sin() ... self.exp = mindspore.ops.Exp() ... def construct(self, x): ... out1 = self.sin(x) ... out2 = self.exp(out1) ... return out2 >>> >>> primals = mindspore.tensor([[1, 2], [3, 4]], mindspore.float32) >>> order = 3 >>> net = Net() >>> out_primals, out_series = mindspore.ops.derivative(net, primals, order) >>> print(out_primals, out_series) [[2.319777 2.4825778] [1.1515628 0.4691642]] [[-4.0515366 3.6724353 ] [ 0.5053504 -0.52061415]]