You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation uses strings to identify a dimension. But maybe in the static graph framework of pytensor it would make more sense to think of them as first class objects, so that they can have their own graph-like structure? Maybe they could be a different subclass of Variable as well? I think that might lead to cleaner code for users (no typos in dimension names that lead to silent broadcasting and gigantic arrays with an out-of-memory error), and it might also make derived dimensions easier to handle and reason about?
I think we could do something like
classDimensionType(Type):
pass# I guess all dimensions have the same type?DimType=DimensionType()
classDimension(Variable):
def__init__(self, name=None, length=None):
passdeflength(self) ->TensorVariable:
...
classDimOp(Op):
passclassDimConstant(DimensionVariable):
def__init__(self, name, *, length=None):
pass# The result of stacking two dimsclassProduct(DimOp):
__props__= ("name",)
defmake_node(self, *inputs: DimensionVariable):
ifself.nameisnotNone:
name=self.nameelse:
name=f"product[{','.join(input.nameforinputininputs)}]"output=Dimension(name=name, length=prod(input.lengthforinputininputs))
returnApply(self, inputs, [output])
defdim(name, *, length=None):
returnDimConstant(name, length=length)
defstack(variable, *, dims, name=None):
dim_op=Product(name)
stacked_dim=dim_op(dims)
...
Final usage could maybe be something like this?
country=pt.dim("country")
treatment=pt.dim("treatment")
# We can talk about the stacked dim directly:interaction=pt.stacked_dim(country, treatment)
effect=xtensor(dim=interaction)
asserteffect.unstack(interaction).dims== (country, treatment)
assertpt.stack(effect, [country, treatment]).dims==interaction# Same for indices and slices...subset=pt.dim_slice(country, slice("A", "B"))
sub_effect=pt.xtensor(dims=subset)
effect=pt.xtensor(dims=country)
asserteffect.sel(country=slice("A", "B")).dims== (subset,)
effect=effect.at.sel(country=slice("A", "B")).add(sub_effect)
The text was updated successfully, but these errors were encountered:
Description
Just a couple of thoughts regarding #1411.
The current implementation uses strings to identify a dimension. But maybe in the static graph framework of pytensor it would make more sense to think of them as first class objects, so that they can have their own graph-like structure? Maybe they could be a different subclass of
Variable
as well? I think that might lead to cleaner code for users (no typos in dimension names that lead to silent broadcasting and gigantic arrays with an out-of-memory error), and it might also make derived dimensions easier to handle and reason about?I think we could do something like
Final usage could maybe be something like this?
The text was updated successfully, but these errors were encountered: