- This function provides summation of array elements according to
- the Einstein summation convention. For example:
-
trace(a) -> einsum("ii", a)
-
transpose(a) -> einsum("ji", a)
-
multiply(a,b) -> einsum(",", a, b)
-
inner(a,b) -> einsum("i,i", a, b)
-
outer(a,b) -> einsum("i,j", a, b)
-
matvec(a,b) -> einsum("ij,j", a, b)
-
matmat(a,b) -> einsum("ij,jk", a, b)
subscripts: The string of subscripts for einstein summation. nop: The number of operands op_in: The array of operands dtype: Either NULL, or the data type to force the calculation as. order: The order for the calculation/the output axes. casting: What kind of casts should be permitted. out: Either NULL, or an array into which the output should be placed.
By default, the labels get placed in alphabetical order at the end of the output. So, if c = einsum("i,j", a, b) then c[i,j] == a[i]*b[j], but if c = einsum("j,i", a, b) then c[i,j] = a[j]*b[i].
Alternatively, you can control the output order or prevent an axis from being summed/force an axis to be summed by providing indices for the output. This allows us to turn 'trace' into 'diag', for example.
System Message: ERROR/3 (<string>
, line 28) Unexpected indentation.
<blockquote>
-
diag(a) -> einsum("ii->i", a)
-
sum(a, axis=0) -> einsum("i...->", a)
</blockquote>
Subscripts at the beginning and end may be specified by putting an ellipsis "..." in the middle. For example, the function einsum("i...i", a) takes the diagonal of the first and last dimensions of the operand, and einsum("ij...,jk...->ik...") takes the matrix product using the first two indices of each operand instead of the last two.
When there is only one operand, no axes being summed, and no output parameter, this function returns a view into the operand instead of making a copy.
nop+1 (+1 is for the output) must fit in NPY_MAXARGS
Parse the subscripts string into label_counts and op_labels
Move subscripts to the start of the labels for the next op
Find the number of broadcast dimensions, which is the maximum number of labels == 0 in an op_labels array.
If there is no output signature, create one using each label that appeared once, in alphabetical order
If no output was specified, always broadcast left (like normal)
Parse the output subscript string
Parse the output subscript string
Set all the op references to NULL
Process all the input ops, combining dimensions into their diagonal where specified.
If there's just one operand and no output parameter, first try remapping the axes to the output to return a view instead of a copy.
Check whether any dimensions need to be combined
The char type may be either signed or unsigned, we need it to be signed here.
If any dimensions are combined, create a view which combines them
No combining needed
Set the output op
Set up the labels for the iterator (output + combined labels). Can just share the output_labels memory, because iter_labels is output_labels with some more labels appended.
Set up the op_axes for the iterator
Set up the op_dtypes if dtype was provided
Set the op_axes for the output
Set the iterator per-op flags
Allocate the iterator
Initialize the output to all zeros and reset the iterator
System Message: ERROR/3 (<string>
, line 1) Document or section may not begin with a transition.
System Message: ERROR/3 (<string>
, line 1) Document may not end with a transition.
Acceleration for some specific loop structures. Note that with axis coalescing, inputs with more dimensions can be reduced to fit into these patterns.
System Message: ERROR/3 (<string>
, line 1) Document or section may not begin with a transition.
System Message: ERROR/3 (<string>
, line 1) Document may not end with a transition.
Get an inner loop function, specializing it based on the strides that are fixed for the whole loop.
Finally, the main loop
If the API was needed, it may have thrown an error