mindspore.ops.jvp

mindspore.ops.jvp(fn, inputs, v)[源代码]

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

Parameters
  • fn (Function or Cell) – The function or net that takes Tensor inputs and returns a tensor or tuple of Tensors.

  • inputs (Tensor or tuple or list) – The inputs to fn.

  • v (Tensor or tuple or list) – The shape and type of v should be the same as inputs.

Returns

Tuple, tuple of output and jvp.

  • netout (Tensors or Tuple of Tensors) - The output of “fn(inputs)”.

  • jvp (Tensors or Tuple of Tensors) - The result of the dot product.

Raises

TypeError – If the input is not a tensor or tuple or list of tensors.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore.ops import functional as F
>>> from mindspore import Tensor
>>> class Net(nn.Cell):
...     def construct(self, x, y):
...         return x**3 + y
>>> x = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32))
>>> y = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32))
>>> v = Tensor(np.array([[1, 1], [1, 1]]).astype(np.float32))
>>> output = F.jvp(Net(), (x, y), (v, v))
>>> print(output[0])
[[ 2. 10.]
 [30. 68.]]
>>> print(output[1])
[[ 4. 13.]
 [28. 49.]]