Skip to content

Fix object backend broadcasting and empty reductions - #263

Open
Robertboy18 wants to merge 5 commits into
dgasmith:mainfrom
Robertboy18:fix-object-array-broadcasting
Open

Robertboy18 wants to merge 5 commits into
dgasmith:mainfrom
Robertboy18:fix-object-array-broadcasting

Conversation

@Robertboy18

@Robertboy18 Robertboy18 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

The object backend loses singleton broadcasting: contract("i,i->i", [2], [3, 4, 5], backend="object") with object arrays returns [6], and reversing the operands raises an indexing error. Empty reductions also raise TypeError instead of returning zero.

This preserves non-singleton dimensions (including zero), indexes broadcast axes at zero, and handles empty sums without requiring arbitrary objects to support addition with an integer.

I included the docs compatibility fix from #265 as a separate commit so CI can run on this branch.

Todos

  • Add regressions for both operand orders, repeated indices, ellipses, empty axes, expressions, and object-only addition.
  • Run the object-backend tests: 34 passed.
  • Run Ruff 0.15.22 lint/formatting and the configured mypy check.

Status

  • Ready to go

Implementation and tests were AI-assisted.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.98%. Comparing base (fccdd5a) to head (674da34).

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Robertboy18

Copy link
Copy Markdown
Contributor Author

The tests and lint checks pass. The docs failure is the mkdocstrings/pymdown-extensions compatibility issue; I opened #265 with the dependency constraint and a checked reproduction. Once that is merged, I can update this branch and rerun the docs check.

@Robertboy18
Robertboy18 marked this pull request as ready for review October 17, 2026 03:20
Copilot AI balanced review requested due to automatic review settings October 17, 2026 03:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dgasmith

Copy link
Copy Markdown
Owner

Thanks for fixing this! Could you take a look at what I just pushed? I moved the broadcasting into a preparation step using np.broadcast_to, so NumPy handles the broadcasting rules and the inner loop stays a bit simpler. I also updated the docs to explain why we still have a separate object backend. Curious what you think.

@Robertboy18

Copy link
Copy Markdown
Contributor Author

Thanks @dgasmith, I kept your np.broadcast_to approach; it makes the inner loop easier to follow. I added a check for unequal dimensions on repeated labels: ii-> with shape (1, 2) should fail as it does in NumPy, rather than broadcast to (2, 2). That's in 674da34, with regression tests. The docs also make the reason for the separate backend clear: nonempty reductions work with objects that don't support adding integer zero.

This branch has not been deployed

No deployments
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.

3 participants