dot multiply Args: a (CTensor): 2d input tensor. b (CTensor): 2d input tensor. Returns: CTensor: the output CTensor.
(cls, a, b)
| 4939 | |
| 4940 | @classmethod |
| 4941 | def dot(cls, a, b): |
| 4942 | """ |
| 4943 | dot multiply |
| 4944 | Args: |
| 4945 | a (CTensor): 2d input tensor. |
| 4946 | b (CTensor): 2d input tensor. |
| 4947 | Returns: |
| 4948 | CTensor: the output CTensor. |
| 4949 | """ |
| 4950 | batch_size = a.shape()[0] |
| 4951 | ret = [] |
| 4952 | for indice in range(batch_size): |
| 4953 | tmp_a = singa.SliceOn(a, indice, indice + 1, 0) # 1 * d |
| 4954 | tmp_b = singa.SliceOn(b, indice, indice + 1, 0) # 1 * d |
| 4955 | tmp_b = singa.DefaultTranspose(tmp_b) |
| 4956 | tmp_tensor = singa.Mult(tmp_a, tmp_b) # 1 * d * d * 1 |
| 4957 | ret.append(tmp_tensor) |
| 4958 | ret = singa.VecTensor(ret) |
| 4959 | ret = singa.ConcatOn(ret, 0) # b * 1 |
| 4960 | return singa.Reshape(ret, [ret.shape()[0]]) # b |
| 4961 | |
| 4962 | def forward(self, a, b): |
| 4963 | """ |