Skip to content

Tensor.mean (and Tensor.sum) backward fails for tuple axes #31

Description

@github-actions

File: leanpass/tensor.py

Both mean and sum use np.expand_dims(grad, axis=axis) when axis is not None. np.expand_dims only accepts an integer axis, so passing a tuple (e.g., axis=(0,2)) raises a TypeError. This deviates from NumPy’s behavior where tuple axes are allowed for reduction operations.

Fix: replace the expand_dims call with np.reshape or manually add new axes for each dimension in the tuple, then broadcast the gradient.

Impact: Users cannot compute means or sums over multiple axes while retaining gradient flow.

Filed automatically by ai-issue-scan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions