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.
einsum
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(); Copy
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(); Copy
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(); Copy
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(); Copy
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(); Copy
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(); Copy
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:
...
a string describing the contraction, in the same format as numpy.einsum.
Rest
the input(s) to contract (each one a Tensor), whose shapes should be consistent with equation.
The output tensor.
Generated using TypeDoc
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:
Dot product:
Batch dot product:
Outer prouduct:
Matrix transpose:
Batch matrix transpose:
Limitations:
This implementation of einsum has the following limitations:
...
notation is not supported.