Init a General Matrix multiplication(Gemm) operator. Compute `Y = alpha * A' * B' + beta * C`, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). `A' =
(A, B, C=None, alpha=1.0, beta=1.0, transA=0, transB=0)
| 3770 | |
| 3771 | |
| 3772 | def gemm(A, B, C=None, alpha=1.0, beta=1.0, transA=0, transB=0): |
| 3773 | """ |
| 3774 | Init a General Matrix multiplication(Gemm) operator. Compute `Y = alpha * |
| 3775 | A' * B' + beta * C`, where input tensor A has shape (M, K) or (K, M), input |
| 3776 | tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to |
| 3777 | shape (M, N), and output tensor Y has shape (M, N). |
| 3778 | `A' = transpose(A)` if transA else A |
| 3779 | `B' = transpose(B)` if transB else B |
| 3780 | Args: |
| 3781 | A (Tensor): The shape of A should be (M, K) if transA is 0, or |
| 3782 | (K, M) if transA is non-zero. |
| 3783 | B (Tensor): The shape of B should be (K, N) if transB is 0, or |
| 3784 | (N, K) if transB is non-zero. |
| 3785 | C (Tensor): (optional), Optional input tensor C. If not specified, |
| 3786 | the computation is done as if C is a scalar 0. The shape of C |
| 3787 | should be unidirectional broadcastable to (M, N). |
| 3788 | alpha (float): Scalar multiplier for the product of input tensors A * B. |
| 3789 | beta (float): Scalar multiplier for input tensor C. |
| 3790 | ransA (int): Whether A should be transposed |
| 3791 | transB (int): Whether B should be transposed |
| 3792 | Returns: |
| 3793 | Tensor, the output |
| 3794 | """ |
| 3795 | if C: |
| 3796 | return Gemm(alpha, beta, transA, transB)(A, B, C)[0] |
| 3797 | else: |
| 3798 | return Gemm(alpha, beta, transA, transB)(A, B)[0] |
| 3799 | |
| 3800 | |
| 3801 | class GlobalAveragePool(Operator): |