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
I will get a "ValueError: Cannot use variadic specifiers (*name or ...) more than once.". That seems a bit overly restrictive: it's certainly possible to infer *C from the shape of mask. Can the requirement be relaxed to something like "only 1 non-determinable variadic specifier can be used in each shape", i.e. the following algorithm?
# Each shape is the list of dimension names and whether its variadic.# Returns the non-determinable variadic names.defeliminate_determinable_variadic_shapes(*shapes: Sequence[tuple[str, bool]]):
remaining=set(range(len(shapes)))
# Variadic dimension names that can be determined.deteriminable=set()
whileTrue:
new_remaining=set()
foriinremaining:
variadics= [
nameforname, variadicinshapes[i]
ifvariadicandnamenotindeteriminable
]
iflen(variadics) >1:
new_remaining.add(i)
eliflen(variadics) ==1:
deteriminable.add(variadics[0])
print(variadics[0], 'becomes determinable because of', shapes[i])
iflen(remaining) ==len(new_remaining):
returnset([
nameforshapeinshapesforname, variadicinshapeifvariadicandnamenotindeteriminable
])
remaining=new_remaining
The text was updated successfully, but these errors were encountered:
IIUC, you're basically trying to resolve the variadic shapes one-at-a-time?
Indeed that'd be possible in-principle but might be fairly tricky to implement -- right now we leave checking this to the runtime type checker, which is what gets to determine the order in which arguments are checked.
We don't have to do that. We could use the runtime type checker just to traverse all the annotations (i.e. to handle nested annotations like tuple[dict[str, Float[Array, ...), record all the annotations it comes across as the ones we want to check against, and then do shape-checks ourselves using an algorithm like the one you describe.
In practice I'm afraid that'd be a fair amount of work, that might end up being fairly fragile (it'd involve using a dynamic context I think), for quite a niche feature, I'm afraid.
Currently if I write a function like the following:
I will get a "ValueError: Cannot use variadic specifiers (
*name
or...
) more than once.". That seems a bit overly restrictive: it's certainly possible to infer *C from the shape ofmask
. Can the requirement be relaxed to something like "only 1 non-determinable variadic specifier can be used in each shape", i.e. the following algorithm?The text was updated successfully, but these errors were encountered: