N-D broadcasting for `Tensor`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- machine-learning
Research direction
Start by locating the Tensor binary-operation implementations and the existing Matrix row-vector and column-vector fast paths. Compare their behavior with NumPy broadcasting, including incompatible axes and zero-size shapes, and resolve the setitem scope question. Done means all Tensor binary ops produce contiguous broadcast-shaped results, report both shapes and the failing axis on errors, and preserve the existing rank-2 fast paths.
Written by the indexing model from the issue text.
Description
Problem
Once Tensor exists, almost every realistic workload runs into shape pairs that are obviously compatible without being identical: subtract a per-feature mean from every row, add a per-channel bias to a stack of images, scale a batch by a per-sample weight. Without broadcasting, the user has to allocate an expanded intermediate by hand — verbose, and exactly the kind of allocation that wipes out the benefit of running the op in C in the first place.
Matrix already has rank-2-only shortcuts for the row-vector and column-vector cases. The Tensor surface needs a general answer that subsumes them without regressing them.
Desired functionality
NumPy-style N-D broadcasting on every Tensor binary op. Shape pairs NumPy accepts are accepted; shape pairs NumPy rejects are rejected with an error message that names both operands' shapes and the axis where compatibility fails. The result of a broadcast op is a freshly-allocated contiguous tensor with the broadcast shape.
Constraints
- NumPy semantics, exactly. No bocpy-specific broadcasting rules.
- No views and no strides on the public Tensor surface — broadcasting is a compute-time concern, not a storage-time one.
- No measurable regression on rank-2
Matrixworkloads. Row-vector and column-vector broadcast shapes that hit a fast path today must still hit a fast path.
Out of scope
Reductions, batched matmul, stride-based views, broadcast_to / broadcast_arrays-style helpers, F-order layout, new ops.
Open questions
- Behaviour on zero-size shapes (any axis equal to zero).
- Whether broadcasting also applies to
Tensor.__setitem__right-hand sides, or whether scalar-broadcast remains the only accepted case there. Interacts with M4.
- Dominant language
- Python
- Stars
- 184
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/bocpy
-
Difficulty 3/5 1-2 days Newbie friendliness 63/100
-
design
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
design
Difficulty 5/5 Over a week Newbie friendliness 28/100
-
maths
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
maths
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100