JuliaArrays / JuliaArrays/BlockArrays.jl

Drop support for mixed blocks in broadcast?

Open
#194 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
254
Forks
39
PR merge metrics
No merged PRs in 30d

Description

At the moment we combine the block structure in broadcasting. E.g.:

julia> mortar([[1,2],[3,4,5]]) + mortar([[1],[2,3,4],[5]])
4-blocked 5-element BlockVector{Int64}:
  2
 ──
  4
 ──
  6
  8
 ──
 10

But this was an arbitrary decision with a major drawback: it makes it hard to preserve specialised block structure in a type-stable way. E.g. here we allocate since its impossible at compile time to determine Fill(2,2) is the same:

julia> x = BlockArray(1:4, Fill(2,2))
2-blocked 4-element BlockVector{Int64, Vector{UnitRange{Int64}}, Tuple{BlockedUnitRange{StepRange{Int64, Int64}}}}:
 1
 2
 ─
 3
 4

julia> x + x
2-blocked 4-element BlockVector{Int64}:
 2
 4
 ─
 6
 8

I suspect it would be more useful to error out if the block structure doesn't match. With the exception of the length-1 special case to still support:


julia> x .+ x'
2×2-blocked 4×4 BlockMatrix{Int64, Matrix{Matrix{Int64}}, Tuple{BlockedUnitRange{StepRange{Int64, Int64}}, BlockedUnitRange{StepRange{Int64, Int64}}}}:
 2  3  │  4  5
 3  4  │  5  6
 ──────┼──────
 4  5  │  6  7
 5  6  │  7  8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; start by locating the broadcasting implementation and its existing tests for block structure compatibility. Review the examples to define matching structures, the length-1 exception, and the expected error for mismatches; done means behavior is covered by tests without losing specialized block structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.