PyTaco Index Variables

class pytaco.index_var(name)

Creates an index variable that can be used to access a pytaco.tensor.

Makes an index variable with the name, name to access a dimension of a given tensor.

name: str, optional

The name PyTaco assigns to the index_var created. If no name is specified, PyTaco generated its own name for the index_var.


Index variables with the same name cannot be used to access different dimensions of the same tensor. This is a feature that taco currently does not support.


Index variables must be declared before use. So for example, if we need to make an index expression that adds two matrices we would write:

>>> import pytaco as pt
>>> i, j = pt.index_var(), pt.index_var()
>>> t1 = pt.tensor([2, 2])
>>> t2 = pt.tensor([2, 2])
>>> t1.insert([1, 1], 100)
>>> add_expr = t1[i, j] + t2[i, j]

This can get cumbersome if we need a large number of pytaco.index_var s so PyTaco provides a convenience function to return a list of pytaco.index_var s called pytaco.get_index_vars().

This means line 2 above could be replaced by:

>>> i, j = pt.get_index_vars(2)

Returns the name of the pytaco.index_var