Skip to content

docs: document axis and keepdims for Tensor.sum and Tensor.mean - #83

Merged
Terminay merged 1 commit into
Terminay:mainfrom
bh-official:docs/sum-mean-axis
Oct 26, 2026
Merged

Terminay merged 1 commit into
Terminay:mainfrom
bh-official:docs/sum-mean-axis

Conversation

@bh-official

Copy link
Copy Markdown
Contributor

Closes #5

What was wrong: docs/api-reference/tensor.md described Tensor.sum() and Tensor.mean() as "full reduction, not per-axis", but both accept axis and keepdims and reduce per-axis.

What changed: Replaced that sentence for both methods with a parameter table (axis: int, tuple of int or None, negative axes allowed; keepdims: bool) and the resulting shapes for a (2, 3) input. Only the sum/mean sections were touched; line endings (CRLF) preserved.

Checked by running (fresh venv, pip install -e .), on Tensor(np.arange(6.).reshape(2,3), requires_grad=True):

  • .sum() -> shape (), 15.0; .mean() -> 2.5
  • .sum(axis=0) -> shape (3,); .sum(axis=1, keepdims=True) -> shape (2, 1)
  • .mean(axis=-1) -> shape (2,); .sum(axis=(0,1), keepdims=True) -> shape (1, 1)
  • backward gives gradients of the input's shape for all of these (1 for sum, 1/n for mean)
  • pytest: 22 passed

The API reference described both methods as a full reduction, not
per-axis, but they accept axis (int, tuple or None, negatives allowed)
and keepdims. Add a parameter table and shape examples for each.

Closes Terminay#5

@Terminay Terminay left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats you're the first documentation contributor to leanpass! The changes are well addressed and very elegantly implemented.

Your name will appear in the readme as a contributor soon, thanks for joining leanpass.

@Terminay
Terminay merged commit c7316c8 into Terminay:main Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs say sum() and mean() are full-reduction only

2 participants