patrick-kidger / patrick-kidger/jaxtyping

Support for type checking dataclass properties

Open
#342 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
1.9k
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Suppose you have a dataclass:

@jaxtyped(typechecker=typechecker)
@dataclass
class MyDataclass:
    x: Float[Array, "n"]

  @property
  def plus1(self) -> Float[Array, "n"]:
     return self.x + 1.0

There is no way AFAIK how to enforce that "n" is derived from the class definition. Is there a way to enforce this? And is this a feature that would make sense? Note also symbolic shapes cannot be expressed with checking, eg. Float[Array, "n+1"] would fail as n is undefined in the function input.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing @jaxtyped(typechecker=typechecker) around dataclass fields and @property return annotations, then inspect how symbolic shape names are resolved. A complete result should establish whether class-derived dimensions and expressions such as "n+1" can be enforced, with tests covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.