WIP: experiment with first class dim objects #1517
Open
+485
−83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Very much still an experiment! I'm still working on this, but thought it might be helpful to already share what I have so far...
In this version of named-dims, we use objects to represent dimensions instead of plain strings. This allows us to ensure that array axes with shared dimensions are always compatible.
A dimension variable stores the length of the dimension at runtime.
The type of the dimension provides the identity that is used to ensure tensors don't use duplicate dimensions.
We can then create tensors with given dimensions:
(Obvious todo: improve pretty printing!)
(Currently those are the
dim.type.dim
objects, I think we could just usedim.type
directly to make it cleaner)foo.clone_dim()
prodvides a new dimension, that has the same shape asfoo
, but a different identity, so that we can build a tensor out offoo
andfoo.clone_dim()
. Different instances offoo.clone_dim()
are treated as different dimensions.We can recover a dimension variable from an xtensor that has this dimension (because it implicitly stores the size of the dimension, and also stores the dimension type):
@OriolAbril @ricardoV94
📚 Documentation preview 📚: https://pytensor--1517.org.readthedocs.build/en/1517/