Do matrix-matrix or matrix-vector multiplication. This function returns C = alpha * A * B + beta * C Currently below cases are supported case 1 - matrix * vector: A (Tensor): 2d Tensor B (Tensor): 1d Tensor, GEMV would be invoked case 2 - matrix * matr
(A, B, C=None, alpha=1.0, beta=0.0)
| 1300 | |
| 1301 | |
| 1302 | def mult(A, B, C=None, alpha=1.0, beta=0.0): |
| 1303 | '''Do matrix-matrix or matrix-vector multiplication. |
| 1304 | This function returns C = alpha * A * B + beta * C |
| 1305 | Currently below cases are supported |
| 1306 | case 1 - matrix * vector: |
| 1307 | A (Tensor): 2d Tensor |
| 1308 | B (Tensor): 1d Tensor, GEMV would be invoked |
| 1309 | case 2 - matrix * matrix: |
| 1310 | A (Tensor): 2d Tensor |
| 1311 | B (Tensor): 2d Tensor, GEMM would be invoked |
| 1312 | case 3 - batched matrix * batched matrix: |
| 1313 | A (Tensor): 3/4d Tensor |
| 1314 | B (Tensor): 3/4d Tensor, batched GEMM would be invoked |
| 1315 | Where first/first and second dimension(s) of A, B should be exactly the same |
| 1316 | e.g. C{2,3,4,6} = A{2,3,4,5} * B{2,3,5,6} |
| 1317 | |
| 1318 | Args: |
| 1319 | A: n-d tensor |
| 1320 | B: n-d tensor |
| 1321 | C (Tensor, optional): for storing the result; If None, a new Tensor would be created. |
| 1322 | alpha (float): scaling factor |
| 1323 | beta (float): scaling factor |
| 1324 | |
| 1325 | Returns: |
| 1326 | the result Tensor |
| 1327 | ''' |
| 1328 | if C is None: |
| 1329 | return _call_singa_func(singa.Mult, A.data, B.data) |
| 1330 | else: |
| 1331 | singa.MultWithScale(alpha, A.data, B.data, beta, C.data) |
| 1332 | return C |
| 1333 | |
| 1334 | |
| 1335 | def einsum(ops, *args): |
no test coverage detected