Skip to content

Latest commit

 

History

History
28 lines (25 loc) · 7.82 KB

binary_operations.rst

File metadata and controls

28 lines (25 loc) · 7.82 KB

Binary Operations on Arrays

+-----------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------+--------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | | 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:

  1. 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.
  2. 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 to sum([-1])). The shorter notation sum(-1) is preferred.
  3. 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.