pytaco.inner

pytaco.inner(t1, t2, out_format=mode_format(compressed), dtype=None)

The inner product of two arrays.

In general, this is a sum product over the last dimensions of the two inputs. If a or b is a scalar, element-wise multiplication is performed.

Parameters
t1, t2: tensors, array_like

The tensors to take the inner product of. If non-scalar, the size of their last dimensions must match.

out_format: format, mode_format, optional
  • If a format is specified, the result tensor is stored in the format out_format.

  • If a mode_format is specified, the result the result tensor has a with all of the dimensions stored in the mode_format passed in.

dtype: Datatype

The datatype of the output tensor.

Returns
res: tensor

The inner product of the tensors passed in.

Notes

For 3-D tensors, this is equivalent to writing A[i, j] = B[i, j, k] * C[i, j, k]. We can also explicitly write A[i, j] = sum(B[i, j, k] * C[i, j, k], k) assuming the tensors and index variables have been defined.

Examples

>>> import pytaco as pt
>>> import numpy as np
>>> a = np.arange(24).reshape((2,3,4))
>>> b = np.arange(4)
>>> pt.inner(a, b).to_array()
array([[ 14,  38,  62],
       [ 86, 110, 134]], dtype=int64)

We could perform the same computations with sparse tensors of any format.