Transforming Array Expression Graphs

class pytato.transform.CopyMapper[source]

Performs a deep copy of a pytato.array.Array. The typical use of this mapper is to override individual map_ methods in subclasses to permit term rewriting on an expression graph.

class pytato.transform.DependencyMapper[source]

Maps a pytato.array.Array to a frozenset of pytato.array.Array’s it depends on. .. warning:

This returns every node in the graph! Consider a custom
:class:`CombineMapper` or a :class:`SubsetDependencyMapper` instead.
class pytato.transform.InputGatherer[source]

Mapper to combine all instances of pytato.array.InputArgumentBase that an array expression depends on.

class pytato.transform.SizeParamGatherer[source]

Mapper to combine all instances of pytato.array.SizeParam that an array expression depends on.

class pytato.transform.SubsetDependencyMapper(universe)[source]

Mapper to combine the dependencies of an expression that are a subset of universe.

class pytato.transform.WalkMapper[source]

A mapper that walks over all the arrays in a pytato.Array.

Users may override the specific mapper methods in a derived class or override WalkMapper.visit() and WalkMapper.post_visit().

visit(expr)[source]

If this method returns True, expr is traversed during the walk. If this method returns False, expr is not traversed as a part of the walk.

Return type

bool

post_visit(expr)[source]

Callback after expr has been traversed.

Return type

None

class pytato.transform.CachedWalkMapper[source]

WalkMapper that visits each node in the DAG exactly once. This loses some information compared to WalkMapper as a node is visited only from one of its predecessors.

class pytato.transform.TopoSortMapper[source]

A mapper that creates a list of nodes in topological order.

pytato.transform.copy_dict_of_named_arrays(source_dict, copy_mapper)[source]

Copy the elements of a DictOfNamedArrays into a DictOfNamedArrays.

Parameters
Return type

DictOfNamedArrays

Returns

A new DictOfNamedArrays containing copies of the items in source_dict

pytato.transform.get_dependencies(expr)[source]

Returns the dependencies of each named array in expr.

Return type

Dict[str, FrozenSet[Array]]

Visualizing Array Expression Graphs

pytato.get_dot_graph(result)[source]

Return a string in the dot language depicting the graph of the computation of result.

Parameters

result (Union[Array, DictOfNamedArrays]) – Outputs of the computation (cf. pytato.generate_loopy()).

Return type

str

pytato.show_dot_graph(result)[source]

Show a graph representing the computation of result in a browser.

Parameters

result (Union[Array, DictOfNamedArrays]) – Outputs of the computation (cf. pytato.generate_loopy()).

Return type

None

Utilities and Diagnostics

Helper routines

pytato.utils.are_shape_components_equal(dim1, dim2)[source]

Returns True iff dim1 and dim2 are have equal SizeParam coefficients in their expressions.

Return type

bool

pytato.utils.are_shapes_equal(shape1, shape2)[source]

Returns True iff shape1 and shape2 have the same dimensionality and the correpsonding components are equal as defined by are_shape_components_equal().

Return type

bool

pytato.utils.get_shape_after_broadcasting(exprs)[source]

Returns the shape after broadcasting exprs in an operation.

Return type

Tuple[Union[int, Array], …]

pytato.utils.dim_to_index_lambda_components(expr, vng=None)[source]

Returns the scalar expressions and bindings to use the shape component within an index lambda.

>>> n = pt.make_size_param("n")
>>> expr, bnds = dim_to_index_lambda_components(3*n+8, UniqueNameGenerator())
>>> print(expr)
3*_in + 8
>>> bnds  
{'_in': <pytato.array.SizeParam ...>}
Return type

Tuple[Union[Number, bool_, bool, Expression], Dict[str, SizeParam]]

Pytato-specific exceptions

class pytato.diagnostic.NameClashError[source]

Raised when 2 non-identical InputArgumentBase’s are reachable in an Array’s DAG and share the same name. Here, we refer to 2 objects a and b as being identical iff a is b.

class pytato.diagnostic.CannotBroadcastError[source]