Warning

You are reading a version of the website built against the unstable main branch. This content is liable to change without notice and may be inappropriate for your use case. You can find the documentation for the current stable release here.

pyop3.axis_tree.visitors package

Submodules

pyop3.axis_tree.visitors.layout module

pyop3.axis_tree.visitors.layout.compute_layouts(axis_tree)[source]

Compute the layout functions for an axis tree.

Layout functions are expressions that take axis variables (symbolic indices per axis) and evaluate to an integer offset. As the simplest possible example consider the axis tree:

{“A”: 5}

This tree has only a single axis and so it only has a single layout function:

{“A”: None}: i_A

Here {"A": None} refers to the path through the tree where the layout resides and i_A is the layout function. Since the tree only has a single axis the mapping between axis indices and offsets is trivially identity.

Note that this tree will also have the zero layout:

{}: 0

meaning that if you are at the root of the tree then the offset must be zero.

Parameters:

axis_tree – The axis tree to compute the layouts of.

Returns:

Mapping from path through the axis tree to the layout function, plus the star forest.

Return type:

tuple[immutabledict.immutabledict, pyop3.StarForest]

Examples

For more examples please refer to tests/pyop3/unit/test_layout.py.

1. Linear axis tree

For the simple axis tree (equivalent to a 2D numpy array):

{"A": 5}
└──➤ {"B": 3}

the layout functions are:

{
    {}: 0,
    {"A": None}: 3*i_A,
    {"A": None, "B": None}: 3*i_A + i_B,
}

2. Multi-component axis tree

For the axis tree:

{A: [{0: 3}, {1: 4}]}}
├──➤ {B: 2}
└──➤ {C: 1}

the layout functions are:

{
    {}: 0,
    {"A": 0}: 2*i_A,
    {"A": 0, "B": None}: 2*i_A + i_B,
    {"A": 1}: i_A + 6,
    {"A": 1, "C": None}: i_A + i_C + 6,
}

3. Ragged axis tree

TODO

4. Multi-region axis tree

For the axis tree:

{A: [{a: 1}, {b: 1}]}
├──➤ {B: [{x: 2}, {y: 1}]}
└──➤ {C: [{x: 2}, {y: 1}]}

where ‘a’ and ‘b’ are axis components with size 1 and ‘x’ and ‘y’ are component regions, we expect to have the following data layout:

[ a0, a1, b0, b1 || a2, b2 ]
       "x"           "y"

In other words all entities in the ‘x’ region are partitioned to occur before those in ‘y’. This means that the layout functions are as follows:

{
    {}: 0,
    {"A": "a"}: NaN,
    {"A": "a", "B": None}: [[0, 1, 4]][i_A, i_B],
    {"A": "b"}: NaN,
    {"A": "b", "C": None}: [[2, 3, 5]][i_A, i_C],
}

The {“A”: “a”} and {“A”: “b”} entries are NaNs because they do not address contiguous data and so are meaningless.

pyop3.axis_tree.visitors.size module

pyop3.axis_tree.visitors.size.compute_axis_tree_component_size(axis_tree, path, component_label)[source]
pyop3.axis_tree.visitors.size.compute_axis_tree_size(axis_tree)[source]

Module contents

pyop3.axis_tree.visitors.get_block_shape(axis_tree)[source]

Detect any common innermost integer shape in an axis tree.