+-----------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | | Tensor | Einstein | Nutils | +===+================================================+================================================+================================================================================+========================================================+===============================================================================================================================+ | 1 | a ∈ ℝn | b ∈ ℝn | c = a ⋅ b ∈ ℝ | c = aibi | c = (a*b).sum(-1)
| +---+------------------------------------------------+------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | 2 | a ∈ ℝn | b ∈ ℝm | C = a ⊗ b ∈ ℝn × m | Cij = aibj | C = a[:,_]*b[_,:]
| | | | | | +-------------------------------------------------------------------------------------------------------------------------------+ | | | | | | C = function.outer(a,b)
| +---+------------------------------------------------+------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | 3 | A ∈ ℝm × n | b ∈ ℝn | c = Ab ∈ ℝm | ci = Aijbj | c = (A[:,:]*b[_,:]).sum(-1)
| +---+------------------------------------------------+------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | 4 | A ∈ ℝm × n | B ∈ ℝn × p | C = AB ∈ ℝm × p | cij = AikBkj | c = (A[:,:,_]*B[_,:,:]).sum(-2)
| +---+------------------------------------------------+------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | 5 | A ∈ ℝm × n | B ∈ ℝp × n | C = ABT ∈ ℝm × p | Cij = AikBjk | C = (A[:,_,:]*B[_,:,:]).sum(-1)
| | | | | | +-------------------------------------------------------------------------------------------------------------------------------+ | | | | | | C = function.outer(A,B).sum(-1)
| +---+------------------------------------------------+------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | 6 | A ∈ ℝm × n | B ∈ ℝm × n | c = A : B ∈ ℝ | c = AijBij | c = (A*B).sum([-2,-1])
| +---+------------------------------------------------+------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+
Notes:
- In the above table the summation axes are numbered backward. For example,
sum(-1)
is used to sum over the last axis of an array. Although forward numbering is possible in many situations, backward numbering is generally preferred in Nutils code. - When a summation over multiple axes is performed (#6), these axes are to be listed. In the case of single-axis summations listing is optional (for example
sum(-1)
is equivalent tosum([-1])
). The shorter notationsum(-1)
is preferred. - When the number of dimensions of the two arguments of a binary operation mismatch, singleton axes are automatically prepended to the "shorter" argument. This property can be used to shorten notation. For example, #3 can be written as
(A*b).sum(-1)
. To avoid ambiguities, in general, such abbreviations are discouraged.