335 Star 1.5K Fork 862

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tensor_dot.md 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-07-21 15:16 . replace target=blank

Differences with torch.dot

View Source On Gitee

torch.dot

torch.dot(input, other, *, out=None)

For more information, see torch.dot.

mindspore.ops.tensor_dot

mindspore.ops.tensor_dot(x1, x2, axes)

For more information, see mindspore.ops.tensor_dot.

Differences

API function of MindSpore is not consistent with that of PyTorch.

PyTorch: Calculates the dot product (inner product) of two tensors of the same shape, only 1D is supported. The supported input data types include uint8, int8/16/32/64, float32/64.

MindSpore: Calculates the dot product of two tensors on any axis. Support tensor of any dimension, but the shape corresponding to the specified axis should be equal. The function of the PyTorch is the same when the input is 1D and the axis is set to 0. The supported input data types are float16 or float32.

Categories Subcategories PyTorch MindSpore Differences
Parameters Parameter 1 input x1 Different parameter names
Parameter 2 other x2 Different parameter names
Parameter 3 out - For details, see General Difference Parameter Table
Parameter 4 - axes The function of the PyTorch is the same when the input is 1D and the axis is set to 0.

Code Example 1

The data type of the input is int, and the data type of the output is also int.

import torch
import numpy as np
input_x1 = torch.tensor([2, 3, 4], dtype=torch.int32)
input_x2 = torch.tensor([2, 1, 3], dtype=torch.int32)
output = torch.dot(input_x1, input_x2)
print(output)
print(output.dtype)
# tensor(19)
# torch.int32
# MindSpore doesn't support this feature currently.

Code Example 2

The data type of the input is float, and the data type of the output is also float.

import torch
import numpy as np
input_x1 = torch.tensor([2, 3, 4], dtype=torch.float32)
input_x2 = torch.tensor([2, 1, 3], dtype=torch.float32)
output = torch.dot(input_x1, input_x2)
print(output)
print(output.dtype)
# tensor(19)
# torch.float32

import mindspore as ms
import mindspore.ops as ops
import numpy as np
input_x1 = ms.Tensor(np.array([2, 3, 4]), ms.float32)
input_x2 = ms.Tensor(np.array([2, 1, 3]), ms.float32)
output = ops.tensor_dot(input_x1, input_x2, 1)
print(output)
print(output.dtype)
# 19.0
# Float32
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0

搜索帮助

53164aa7 5694891 3bd8fe86 5694891