Skip to content

← tensor_math package

TensorDot

Apply a tensor product / contraction between two arrays.

The output will generally have the concatenation of the axes of the two input arrays minus the respective contracted axes. A tensor product is a generalization of various kind of products, depending on the list of axes to contract, including inner product, outer product, matrix multiplication and kronecker product. The most common usage is as a generalized matrix multiplication, where a single axis in both arrays is specified for contraction, which then drops out from both arrays. Conventionally this would be the last axis of the first array and the first axis of the second array, but for packets, the most common use case is to use the same named axis in both arrays, e.g., space for multiplying a spatial filter. An example would be an ICA weights packet that has a space axis (channels) and a feature axis (components) as one operand and a multi-channel time series of space x time as the other operand. The resulting array will then have axes feature x time. This can be accomplished by setting axis1 to space and leaving axis2 set to (same) or, equivalently, setting axis2 also to space. This node avoids potential mistakes in lining up the correct axes with each other when performing plain-array matrix multiplication and automatically ensures that the correct output axis is present. The node also seamlessly supports additional axes in either operand, for example having a time series with an additional instance axis (segmented data) would work as expected in the previous example and yield segmented ICA components. Some other usages are a) leaving the axes empty (contracting no axes) to perform an outer product, which is analogous to the Kronecker product on matrices; the resulting array will have all the axes of both input arrays, and b) specifing (all) as the axis to contract in both arrays, which will perform an inner tensor product, resulting in a scalar output, i.e., a single number. When this node is used with two packets, the output will have all chunks of the first operand, but only the chunks that are also in the second operand will be contracted with the first operand, while the remaining ones are retained as is. When used with one packet and a plain array, the output will have the same chunks as the packet, and every chunk will be contracted with the plain array. More Info... Version 0.9.0

Ports/Properties

data1

Data 1 to process.

  • verbose name: Data1
  • default value: None
  • port type: DataPort
  • value type: AnyNumeric (can be None)
  • data direction: IN

data2

Data 2 to process.

  • verbose name: Data2
  • default value: None
  • port type: DataPort
  • value type: AnyNumeric (can be None)
  • data direction: IN

result

Resulting data.

  • verbose name: Result
  • default value: None
  • port type: DataPort
  • value type: AnyNumeric (can be None)
  • data direction: OUT

axis1

Axis to contract (sum out) in the first array. This axis will drop out from the first operand. This can be a named axis (e.g., 'space') or an integer index (0 for the first axis, 1 for second, -1 for the last, etc.). Specifying a single axis amounts to a generalized matrix multiplication where either side may have additional axes that are preserved. It is also possible to list multiple axes as a comma-separated list, for example: time,space (a tensor double contraction). The field can also be left empty to contract no axis (yielding an outer product). Listing all axes, or equivalently, using the special keyword (all) contracts all axes (yielding an inner product / scalar output). Note that, when one (or both) of your operands are plain arrays, it is mandatory to use an integer index for that operand to be explicit.

  • verbose name: Axis In Data1
  • default value: space
  • port type: ComboPort
  • value type: str (can be None)

axis2

Axis to contract (sum out) in the second array. The same conventions apply as for axis1. The special value (same) is a shorthand for entering the same text as in the above field. The axis listed here must have the same length in data2 as the corresponding axis in data1, since the contraction (inner product) is performed along these two axes. If a comma-separated list is given, the axes are "contracted" with each other in the order given.

  • verbose name: Axis In Data2
  • default value: (same)
  • port type: ComboPort
  • value type: str (can be None)

stream

Name of stream to process. Wildcards are supported, so mystream* will process all streams whose name starts with mystream.

  • verbose name: Stream
  • default value: None
  • port type: StringPort
  • value type: str (can be None)

allow_markers

Allow processing chunks marked as containing markers. This is mainly to prevent accidental manipulation of marker streams in packets.

  • verbose name: Allow Markers
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

  • verbose name: Set Breakpoint (Debug Only)
  • default value: False
  • port type: BoolPort
  • value type: bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

  • verbose name: Metadata
  • default value: {}
  • port type: DictPort
  • value type: dict (can be None)