From fb6fd35f1583ad3d88c8cc0287e053546fe1ce90 Mon Sep 17 00:00:00 2001 From: adarshramiyer Date: Wed, 28 May 2025 14:00:49 -0700 Subject: [PATCH] added a tensor dimension annotation rule --- .continue/rules/tensor-annotation.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .continue/rules/tensor-annotation.md diff --git a/.continue/rules/tensor-annotation.md b/.continue/rules/tensor-annotation.md new file mode 100644 index 000000000..fd6617688 --- /dev/null +++ b/.continue/rules/tensor-annotation.md @@ -0,0 +1,16 @@ +--- +globs: /**/*.{py,ipynb} +description: Clean Tensor Dimension Annotation +--- + +# Tensor Dimension Annotation + +The goal is to help developers easily read, understand, and debug code in pytorch and JAX code where tensor computation plays a major role. + +- Import the typing and jaxtyping libraries and use them throughout according to their best practices (i.e., in a very pythonic way) +- Explicitly include the type of each function argument wherever it is possible to determine, e.g. `image: np.ndarray` +- Explicitly include the return type of each function wherever it is possible to determine, e.g. `def get_x(): -> int:` +- Include jaxtyping annotations of tensor dimensions for all tensor arguments to functions, wherever the dimensions are possible to determine. If the numeric values are unclear, use symbolic notation like "batch", "channel", "height", or "width". Create and use these symbolic dimensions in such a way that they are consistent, semantically meaningful, short, and human-readable. If einops is used, ensure that the symbolic values used there are the same as for the dimension annotations. +- Ensure that the dimension annotations are just strict enough to hold up to all edge cases. +- In the docstring of every function where tensor dimensions play a major role in the computation, incorporate a very short but detailed rationale for the input tensor dimensions. There is no need to do this for very simple functions. +- If it is possible to determine and would assist with readability, include annotations for the tensor dimensions of function outputs as well.