Closed
Description
import pytensor
import pytensor.tensor as pt
x = pt.scalar("x")
y = pt.vector("y")
z = x + pt.exp(y)
pytensor.dprint(z)
Elemwise{add,no_inplace} [id A]
|InplaceDimShuffle{x} [id B]
| |x [id C]
|Elemwise{exp,no_inplace} [id D]
|y [id E]
This contains a lot of detail that is irrelevant for most users:
- Elemwise{...}. Almost all operations are
Elemwise
because users don't build graphs with scalars. I suggest we just callAdd
. The "type" of addition can be guessed from the input types which are visible withprint_type=True
. This will be even more relevant after Implementgraph.vectorize
andBlockwise
Op
#306 where everything that is not anElemwise
will likely be aBlockwise
. We can maybe add a kwarg to show the exact Op that is being used. - The inplace/no_inplace is seldom important for users. This information is still visible via either
print_destroy_map
orprint_view_map
. Maybe we can have aprint_memory_map
that is equivalent to setting both of those to True. - DimShuffles are incredibly common, but very obscure because they are a term only used in PyTensor. I suggest we specialize the name for the following 4 cases:
- ExpandDims{axis/axes=dims}
- DropDims{axis/axes=dims} (or Squeeze?)
- Transpose{axis/axes=dims}
- DimShuffle{order} (if it's a mix of the ones above)
The default dprint for the above graph would then look something like:
Add [id A]
|ExpandDims{axis=0} [id B]
| |x [id C]
|Exp [id D]
|y [id E]
And dprint(print_type=True, print_memory_map=True)
Add [id A] <TensorType(float64, (?,))>
|ExpandDims{axis=0} [id B] <TensorType(float64, (1,))> v={0: [0]}
| |x [id C] <TensorType(float64, ())>
|Exp [id D] <TensorType(float64, (?,))>
|y [id E] <TensorType(float64, (?,))>
Which I think is way more readable! We can go one step further and rename <TensorType(float64, (?,))>
to <Tensor(float64, shape=(?,))>
or even <Vector(float64, shape=(?,))>