Tensorex.Operator.contract
You're seeing just the function
contract
, go back to Tensorex.Operator module for more information.
Specs
contract(Tensorex.t(), [non_neg_integer()]) :: Tensorex.t() | number()
Performs a self contraction on the given tensor.
It is known as the trace for 2nd rank tensors.
iex> Tensorex.Operator.contract(
...> Tensorex.from_list([[1, 2, 3],
...> [4, 5, 6],
...> [7, 8, 9]]), [0, 1])
15
iex> Tensorex.Operator.contract(
...> Tensorex.from_list([[[1, 2, 3],
...> [4, 5, 6],
...> [7, 8, 9]],
...> [[2, 3, 4],
...> [5, 6, 7],
...> [8, 9, 1]],
...> [[3, 4, 5],
...> [6, 7, 8],
...> [9, 1, 2]]]), [0, 2])
%Tensorex{data: %{[0] => 9, [1] => 18, [2] => 18}, shape: [3]}