pyxu.operator.blocks#

stack(ops)[source]#

Map operators over the same input.

A stacked operator \(S: \mathbb{R}^{M_{1} \times\cdots\times M_{D}} \to \mathbb{R}^{Q \times N_{1} \times\cdots\times N_{K}} is an operator containing (vertically) :math:`Q\) blocks of smaller operators \(\{ O_{q}: \mathbb{R}^{M_{1} \times\cdots\times M_{D}} \to \mathbb{R}^{N_{1} \times\cdots\times N_{K}} \}_{q=1}^{Q}\):

\[\begin{split}S = \left[ \begin{array}{c} O_{1} \\ \vdots \\ O_{Q} \\ \end{array} \right]\end{split}\]

Each sub-operator \(O_{q}\) acts on the same input and returns parallel outputs which get stacked along the zero-th axis.

Parameters:

ops (Sequence ( OpT )) – (Q,) identically-shaped operators to map over inputs.

Returns:

op – Stacked (M1,…,MD) -> (Q, N1,…,NK) operator.

Return type:

OpT

Examples

import pyxu.operator as pxo
import numpy as np

op = pxo.Sum((3, 4), axis=-1)  # (3,4) -> (3,1)
A = pxo.stack([op, 2*op])  # (3,4) -> (2,3,1)

x = np.arange(A.dim_size).reshape(A.dim_shape)  # [[ 0  1  2  3]
                                                #  [ 4  5  6  7]
                                                #  [ 8  9 10 11]]
y = A.apply(x)  # [[[ 6.]
                #   [22.]
                #   [38.]]
                #
                #  [[12.]
                #   [44.]
                #   [76.]]]

See also

block_diag()

block_diag(ops)[source]#

Zip operators over parallel inputs.

A block-diagonal operator \(B: \mathbb{R}^{Q \times M_{1} \times\cdots\times M_{D}} \to \mathbb{R}^{Q \times N_{1} \times\cdots\times N_{K}}\) is an operator containing (diagonally) \(Q\) blocks of smaller operators \(\{ O_{q}: \mathbb{R}^{M_{1} \times\cdots\times M_{D}} \to \mathbb{R}^{N_{1} \times\cdots\times N_{K}} \}_{q=1}^{Q}\):

\[\begin{split}B = \left[ \begin{array}{ccc} O_{1} & & \\ & \ddots & \\ & & O_{Q} \\ \end{array} \right]\end{split}\]

Each sub-operator \(O_{q}\) acts on the \(q\)-th slice of the inputs along the zero-th axis.

Parameters:

ops (Sequence ( OpT )) – (Q,) identically-shaped operators to zip over inputs.

Returns:

op – Block-diagonal (Q, M1,…,MD) -> (Q, N1,…,NK) operator.

Return type:

OpT

Examples

import pyxu.operator as pxo
import numpy as np

op = pxo.Sum((3, 4), axis=-1)  # (3,4) -> (3,1)
A = pxo.block_diag([op, 2*op])  # (2,3,4) -> (2,3,1)

x = np.arange(A.dim_size).reshape(A.dim_shape)  # [[[ 0  1  2  3]
                                                #   [ 4  5  6  7]
                                                #   [ 8  9 10 11]]
                                                #
                                                #  [[12 13 14 15]
                                                #   [16 17 18 19]
                                                #   [20 21 22 23]]]
y = A.apply(x)  # [[[  6.]
                #   [ 22.]
                #   [ 38.]]
                #
                #  [[108.]
                #   [140.]
                #   [172.]]]

See also

stack()