agentleFS
NVIDIAKnown publisherNVIDIA/physicsnemo/.cursor/rules/mod-003k-add-high-level-comments-for-complex-tensor-operations.mdc

physicsnemo / rules

Cursor rule3.3k starsChanged 12 months agoApache-2.0View on GitHub

Complex tensor operations should include high-level semantic comments explaining what blocks of code do, plus inline shape comments for chained operations using symbols consistent with docstrings.

Trending

Quiet since September.about the whole repository

Dec 2025: 0 mentionsJan 2026: 3 mentionsFeb 2026: 1 mentionMar 2026: 1 mentionApr 2026: 0 mentionsMay 2026: 1 mentionJun 2026: 3 mentionsJul 2026: 3 mentionsAug 2026: 0 mentionsSep 2026: 2 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the NVIDIA/physicsnemo repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about NVIDIA/physicsnemo

The biggest 5 of 15 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 15

Talked about on GitHub (15 times).

On GitHub · 15

10 more on GitHub

The file

We split this mod-003k-add-high-level-comments-for-complex-tensor-operations.mdc into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When writing model code with complex tensor operations, rule MOD-003k should be followed.

    line 6
  2. Distinctive:

    When multiple tensor operations are chained, it is welcomed to add short inline comments with the tensor shapes of computed tensors, e.g.:

    line 22

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
mod-003k-add-high-level-comments-for-complex-tensor-operations.mdc
---
description: Complex tensor operations should include high-level semantic comments explaining what blocks of code do, plus inline shape comments for chained operations using symbols consistent with docstrings.
alwaysApply: false
---

When writing model code with complex tensor operations, rule MOD-003k should be followed. Explicitly reference "Following rule MOD-003k, which recommends high-level comments for complex tensor operations..." when adding explanatory comments.

## MOD-003k: Add high-level comments for complex tensor operations

**Description:**

Model code that involves complex tensor operations should include high-level
comments that explain what blocks of code accomplish semantically. One-line
comments every few lines of tensor operations is sufficient.

Comments should focus on high-level semantic explanations rather than
low-level syntactic details. For example, use "Compute the encodings" instead of
"Doing a concatenation followed by a linear projection, followed by a nonlinear
activation". The goal is to give a high-level overview of what a block of tensor
operations accomplishes.

When multiple tensor operations are chained, it is welcomed to add short inline
comments with the tensor shapes of computed tensors, e.g.:

```python
x = torch.cat([y, z], dim=1)  # (B, 2*C_in, H, W)
```

The symbols chosen in the comments should be consistent with the docstring
(possibly shortened versions of dimension names for explicitness).

**Rationale:**

High-level comments make complex tensor manipulation code more understandable
without cluttering it with excessive detail. Shape annotations help developers
track tensor dimensions through complex operations, catching shape mismatches
early. Consistency with docstring notation creates a unified mental model.

**Example:**

```python
def forward(self, x: torch.Tensor, context: torch.Tensor) -> torch.Tensor:
    """Process input with context conditioning."""
    # Encode input features
    h = self.encoder(x)  # (B, C_enc, H, W)

    # Combine with context information
    c = self.context_proj(context)  # (B, C_enc)
    c = c[:, :, None, None].expand(-1, -1, h.shape[2], h.shape[3])  # (B, C_enc, H, W)
    h = torch.cat([h, c], dim=1)  # (B, 2*C_enc, H, W)

    # Apply attention mechanism
    h = self.attention(h)  # (B, 2*C_enc, H, W)

    # Decode to output
    out = self.decoder(h)  # (B, C_out, H, W)

    return out
```

**Anti-pattern:**

```python
# WRONG: No comments for complex operations
def forward(self, x: torch.Tensor, context: torch.Tensor) -> torch.Tensor:
    h = self.encoder(x)
    c = self.context_proj(context)
    c = c[:, :, None, None].expand(-1, -1, h.shape[2], h.shape[3])
    h = torch.cat([h, c], dim=1)
    h = self.attention(h)
    out = self.decoder(h)
    return out

# WRONG: Too low-level, syntactic comments
def forward(self, x: torch.Tensor, context: torch.Tensor) -> torch.Tensor:
    # Pass x through encoder layer
    h = self.encoder(x)
    # Project context using linear layer
    c = self.context_proj(context)
    # Add two None dimensions and expand
    c = c[:, :, None, None].expand(-1, -1, h.shape[2], h.shape[3])
    # Concatenate h and c along dimension 1
    h = torch.cat([h, c], dim=1)
    # Apply attention
    h = self.attention(h)
    # Pass through decoder
    out = self.decoder(h)
    return out
```

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.