dpctl.tensor.matmul

dpctl.tensor.matmul(x1, x2, out=None, order='K')[source]

Computes the matrix product. Implements the same semantics as the built-in operator @.

Parameters:
  • x1 (usm_ndarray) – first input array. Expected to have numeric data type, and at least one dimension. If x1 is one-dimensional having shape (M,), and x2 has more than one dimension, x1 is effectively treated as a two-dimensional array with shape (1, M), although the prepended dimension is removed from the output array. If x1 has shape (…, M, K), the innermost two dimensions form matrices on which to perform matrix multiplication.

  • x2 (usm_ndarray) – second input array. Expected to have numeric data type, and at least one dimension. If x2 is one-dimensional having shape (N,), and x1 has more than one dimension, x2 is effectively treated as a two-dimensional array with shape (N, 1), although the appended dimension is removed from the output array. If x2 has shape (…, K, N), the innermost two dimensions form matrices on which to perform matrix multiplication.

  • out (Optional[usm_ndarray]) – the array into which the result of the matrix product is written. The data type of out must match the expected data type of the result or (if provided) dtype. If None then a new array is returned. Default: None.

  • dtype (Optional[dtype]) – data type of the returned array. If None, the data type of the returned array is determined by the Type Promotion Rules. Default: None.

  • order (["K", "C", "F", "A"]) – memory layout of the output array, if out is None, otherwise the order parameter value is not used. Default: K.

Returns:

  • if both x1 and x2 are one-dimensional arrays with shape (N,), returned array is a zero-dimensional array containing inner product as its only element.

  • if x1 is two-dimensional array with shape (M, K) and x2 is a two-dimensional array with shape (K, N), returned array is a two-dimensional array with shape (M, N) and contains the conventional matrix product.

  • if x1 is a one-dimensional array with shape (K,) and x2 is an array with shape (…, K, N), returned array contains the conventional matrix product and has shape (…, N).

  • if x1 is an array with shape (…, M, K) and x2 is a one-dimensional array with shape (K,), returned array has shape (…, M) and contains the conventional matrix product.

  • if x1 is a two-dimensional array with shape (M, K) and x2 is an array with shape (…, K, N), returned array contains conventional matrix product for each stacked matrix and has shape (…, M, N).

  • if x1 has shape (…, M, K) and x2 is a two-dimensional array with shape (K, N), returned array contains conventional matrix product for each stacked matrix and has shape (…, M, N).

  • if both x1 and x2 have more than two dimensions, returned array contains conventional matrix product for each stacked matrix and has shape determined by broadcasting rules for x1.shape[:-2] and x2.shape[:-2].

The data type of the returned array is determined by the Type Promotion Rules. If either x1 or x2 has a complex floating point type, neither argument is complex conjugated or transposed.

Return type:

usm_ndarray