mindspore/docs/api/api_python/mint/mindspore.mint.func_einsum.rst

25 lines
2.1 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.mint.einsum
=====================
.. py:function:: mindspore.mint.einsum(equation, *operands)
基于爱因斯坦求和约定Einsum符号沿着指定维度对输入Tensor元素的乘积求和。可以使用这个运算符来执行对角线、减法、转置、矩阵乘法、乘法、内积运算等等。
.. note::
现在支持子列表模式。例如mint.einsum(op1, sublist1, op2, sublist2, ..., sublist_out)。在子列表模式中, `equation` 由子列表推导得到Python的省略号和介于[0, 52)的整数list组成子列表。每个操作数后面都有一个子列表并且最后有一个表示输出的子列表。
动态shape、动态rank的输入不支持在 `图模式(mode=mindspore.GRAPH_MODE) <https://www.mindspore.cn/tutorials/zh-CN/master/compile/static_graph.html>`_ 下执行。
.. warning::
这是一个实验性API后续可能修改或删除。
参数:
- **equation** (str) - 基于爱因斯坦求和约定的符号,表示想要执行的操作。符号只能包含字母(必须在 [a-zA-Z] 中、逗号、省略号和箭头。字母表示输入Tensor维数逗号表示单独的Tensor省略号表示忽略的Tensor维数箭头的左边表示输入Tensor右边表示期望输出的维度。如果方程中没有箭头则方程中仅出现一次的字母将代表一部分的输出的维度并按字母顺序升序排序。此时输出是先将输入操作数维度根据字母对齐后按元素相乘然后将不属于输出字母对应的维度进行相加。如果方程中有一个箭头则代表输出的字母必须在输入字母中出现至少一次而在输出字母中只能最多出现一次。
- **operands** (Tensor) - 用于计算的输入Tensor。Tensor的数据类型必须相同。
返回:
Tensorshape可以根据 `equation` 得到。数据类型和输入Tensor相同。
异常:
- **TypeError** - `equation` 无效或者不匹配输入Tensor。
- **ValueError** - 子列表模式下子列表的数字不介于[0, 52)之间。