mod-003k-add-high-level-comments-for-complex-tensor-operations

mod-003k-add-high-level-comments-for-complex-tensor-operations is a cursor rule for Cursor from NVIDIA/physicsnemo. It costs 30 tokens per session (817 once invoked), scanned A, original, Apache-2.0.

A coding rule for adding brief comments that explain the meaning of complex tensor operations. Tensor operations manipulate multi-dimensional numerical data used in machine learning.

In plain words
What is it for?
Use it when writing model code with chained tensor operations, including short comments that show resulting shapes.
Why use it?
It helps readers understand what a block of model code accomplishes without forcing them to decode every operation.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

About the project

PhysicsNeMo is an open-source PyTorch framework for creating, training, and fine-tuning machine-learning models for physics, scientific computing, and engineering. Researchers and engineers use its reusable components and training recipes for applications such as aerodynamics, weather forecasting, structural mechanics, geophysics, and thermal design. The catalogue entries provide rules and skills for working with PhysicsNeMo projects.

NVIDIA/physicsnemo · 3,222 stars · on GitHub · developer.nvidia.com

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nvidia/physicsnemo/mod-003k-add-high-level-comments-for-complex-tensor-operations
Clone the repo
git clone --depth 1 https://github.com/NVIDIA/physicsnemo

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for mod-003k-add-high-level-comments-for-complex-tensor-operations

README.md
[![agentmods](https://agentmods.dev/badge/rules/nvidia/physicsnemo/mod-003k-add-high-level-comments-for-complex-tensor-operations.svg)](https://agentmods.dev/rules/nvidia/physicsnemo/mod-003k-add-high-level-comments-for-complex-tensor-operations)
Your own site
<a href="https://agentmods.dev/rules/nvidia/physicsnemo/mod-003k-add-high-level-comments-for-complex-tensor-operations"><img src="https://agentmods.dev/badge/rules/nvidia/physicsnemo/mod-003k-add-high-level-comments-for-complex-tensor-operations.svg" alt="Measured on agentmods" height="20"></a>
Per session 30 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 817 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00030 $0.00817
Opus 5 $0.00015 $0.00409
Sonnet 5 $0.00006 $0.00163
Haiku 4.5 $0.00003 $0.00082

Measured 6d ago against content hash 4f6c4d819303, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

mod-003k-add-high-level-comments-for-complex-tensor-operations scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/mod-003k-add-high-level-comments-for-complex-tensor-operations.mdc · 90 lines

What it actually says

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.:

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:

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:

# 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
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 90 lines · 30 tokens per session scan A 4f6c4d819303

Subscribe to this mod's changes

mod-003k-add-high-level-comments-for-complex-tensor-operations is a cursor rule published in the GitHub repository NVIDIA/physicsnemo (3,222 stars, last pushed yesterday), licensed Apache-2.0. It adds 30 tokens to every session and 817 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.