Rate this Page

torch.chain_matmul#

torch.chain_matmul(*matrices,out=None)[source]#

Returns the matrix product of theNN 2-D tensors. This product is efficiently computedusing the matrix chain order algorithm which selects the order in which incurs the lowest cost in termsof arithmetic operations ([CLRS]). Note that since this is a function to compute the product,NNneeds to be greater than or equal to 2; if equal to 2 then a trivial matrix-matrix product is returned.IfNN is 1, then this is a no-op - the original matrix is returned as is.

Warning

torch.chain_matmul() is deprecated and will be removed in a future PyTorch release.Usetorch.linalg.multi_dot() instead, which accepts a list of two or more tensorsrather than multiple arguments.

Parameters
  • matrices (Tensors...) – a sequence of 2 or more 2-D tensors whose product is to be determined.

  • out (Tensor,optional) – the output tensor. Ignored ifout =None.

Returns

if theithi^{th} tensor was of dimensionspi×pi+1p_{i} \times p_{i + 1}, then the productwould be of dimensionsp1×pN+1p_{1} \times p_{N + 1}.

Return type

Tensor

Example:

>>>a=torch.randn(3,4)>>>b=torch.randn(4,5)>>>c=torch.randn(5,6)>>>d=torch.randn(6,7)>>># will raise a deprecation warning>>>torch.chain_matmul(a,b,c,d)tensor([[ -2.3375,  -3.9790,  -4.1119,  -6.6577,   9.5609, -11.5095,  -3.2614],        [ 21.4038,   3.3378,  -8.4982,  -5.2457, -10.2561,  -2.4684,   2.7163],        [ -0.9647,  -5.8917,  -2.3213,  -5.2284,  12.8615, -12.2816,  -2.5095]])