• Tensor contraction over specified indices and outer product.

    einsum allows defining Tensors by defining their element-wise computation. This computation is based on Einstein summation.

    Some special cases include:

    Matrix multiplication:

    const x = tf.tensor2d([[1, 2, 3], [4, 5, 6]]);
    const y = tf.tensor2d([[0, 1], [2, 3], [4, 5]]);
    x.print();
    y.print();
    tf.einsum('ij,jk->ik', x, y).print();

    Dot product:

    const x = tf.tensor1d([1, 2, 3]);
    const y = tf.tensor1d([0, 1, 2]);
    x.print();
    y.print();
    tf.einsum('i,i->', x, y).print();

    Batch dot product:

    const x = tf.tensor2d([[1, 2, 3], [4, 5, 6]]);
    const y = tf.tensor2d([[0, 1, 2], [3, 4, 5]]);
    x.print();
    y.print();
    tf.einsum('bi,bi->b', x, y).print();

    Outer prouduct:

    const x = tf.tensor1d([1, 3, 5]);
    const y = tf.tensor1d([2, 4, 6]);
    x.print();
    y.print();
    tf.einsum('i,j->ij', x, y).print();

    Matrix transpose:

    const x = tf.tensor2d([[1, 2], [3, 4]]);
    x.print();
    tf.einsum('ij->ji', x).print();

    Batch matrix transpose:

    const x = tf.tensor3d([[[1, 2], [3, 4]], [[-1, -2], [-3, -4]]]);
    x.print();
    tf.einsum('bij->bji', x).print();

    Limitations:

    This implementation of einsum has the following limitations:

    • Does not support >2 input tensors.
    • Does not support duplicate axes for any given input tensor. E.g., equation 'ii->' is not supported.
    • The ... notation is not supported.

    Parameters

    • equation: string

      a string describing the contraction, in the same format as numpy.einsum.

    • Rest ...tensors: Tensor<Rank>[]

      the input(s) to contract (each one a Tensor), whose shapes should be consistent with equation.

    Returns Tensor

    The output tensor.

    Doc

Generated using TypeDoc