Binary Operations
Dot product (single contraction)
The dot product (or single contraction) between a tensor of order n
and a tensor of order m
is a tensor of order m + n - 2
. For example, single contraction between two vectors $\mathbf{b}$ and $\mathbf{c}$ can be written as:
and single contraction between a second order tensor $\mathbf{B}$ and a vector $\mathbf{c}$:
Base.LinAlg.dot
— Function.dot(::Vec, ::Vec)
dot(::Vec, ::SecondOrderTensor)
dot(::SecondOrderTensor, ::Vec)
dot(::SecondOrderTensor, ::SecondOrderTensor)
Computes the dot product (single contraction) between two tensors. The symbol ⋅
, written \cdot
, is overloaded for single contraction.
Example:
julia> A = rand(Tensor{2, 2})
2×2 Tensors.Tensor{2,2,Float64,4}:
0.590845 0.566237
0.766797 0.460085
julia> B = rand(Tensor{1, 2})
2-element Tensors.Tensor{1,2,Float64,2}:
0.794026
0.854147
julia> dot(A, B)
2-element Tensors.Tensor{1,2,Float64,2}:
0.952796
1.00184
julia> A ⋅ B
2-element Tensors.Tensor{1,2,Float64,2}:
0.952796
1.00184
Double contraction
A double contraction between two tensors contracts the two most inner indices. The result of a double contraction between a tensor of order n
and a tensor of order m
is a tensor of order m + n - 4
. For example, double contraction between two second order tensors $\mathbf{B}$ and $\mathbf{C}$ can be written as:
and double contraction between a fourth order tensor $\mathsf{B}$ and a second order tensor $\mathbf{C}$:
Tensors.dcontract
— Function.dcontract(::SecondOrderTensor, ::SecondOrderTensor)
dcontract(::SecondOrderTensor, ::FourthOrderTensor)
dcontract(::FourthOrderTensor, ::SecondOrderTensor)
dcontract(::FourthOrderTensor, ::FourthOrderTensor)
Computes the double contraction between two tensors. The symbol ⊡
, written \boxdot
, is overloaded for double contraction. The reason :
is not used is because it does not have the same precedence as multiplication.
Example:
julia> A = rand(SymmetricTensor{2, 2});
julia> B = rand(SymmetricTensor{2, 2});
julia> dcontract(A,B)
1.9732018397544984
julia> A ⊡ B
1.9732018397544984
Tensor product (open product)
The tensor product (or open product) between a tensor of order n
and a tensor of order m
is a tensor of order m + n
. For example, open product between two vectors $\mathbf{b}$ and $\mathbf{c}$ can be written as:
and open product between two second order tensors $\mathbf{B}$ and $\mathbf{C}$:
Tensors.otimes
— Function.otimes(::Vec, ::Vec)
otimes(::SecondOrderTensor, ::SecondOrderTensor)
Computes the open product between two tensors. The symbol ⊗
, written \otimes
, is overloaded for tensor products.
Example:
julia> A = rand(SymmetricTensor{2, 2});
julia> B = rand(SymmetricTensor{2, 2});
julia> A ⊗ B
2×2×2×2 Tensors.SymmetricTensor{4,2,Float64,9}:
[:, :, 1, 1] =
0.271839 0.352792
0.352792 0.260518
[:, :, 2, 1] =
0.469146 0.608857
0.608857 0.449607
[:, :, 1, 2] =
0.469146 0.608857
0.608857 0.449607
[:, :, 2, 2] =
0.504668 0.654957
0.654957 0.48365