Skip to content

Class-level scoping question #383

@avikchaudhuri

Description

@avikchaudhuri

Hi, jaxtyping n00b here. Are there any plans to ever support class-level scoping for named dims?

Today, if I define a class with methods that refer to the same named dim, then it appears that the names act as if they were quantified by the individual methods, while allowing them to bind to different things for the same class instance (and indeed, for different calls to the same method).

What are my options if I want to specify only some of these to be method-level, but others to be class-level? In old-style generics, one would specify class-level type params with Generic. Is there a corresponding construct for names, or something similar defined somewhere else or planned?

class Foo(GenericName["dim"]):
  x: Float[Tensor, "dim"]

  def __init__(self, x: Float[Tensor, "dim"]):
    self.x = x

  def m(x: Float[Tensor, "dim other"]) -> Float[Tensor, "other dim"]: ...
  def n(x: Float[Tensor, "dim another"]) -> Float[Tensor, "another dim"]: ...

(I'm not sure how runtime type checking would work here, probably will need an attribute on self. So there might be legit reasons for not having something like this, but thought it is still worth asking.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions