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.

class pytato.transform.WalkMapper[source]

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

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


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



Callback after expr has been traversed.

Return type


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

Copy the elements of a DictOfNamedArrays into a DictOfNamedArrays.

Return type



A new DictOfNamedArrays containing copies of the items in source_dict


Returns the dependencies of each named array in expr.

Return type

Dict[str, FrozenSet[Array]]

Visualizing Array Expression Graphs


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


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

Return type



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


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

Return type


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


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



Returns the shape after broadcasting exprs in an operation.

Return type

Tuple[Union[int, Array], …]

pytato.utils.dim_to_index_lambda_components(expr, vng)[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.