Skip to content

Conversation

mtfishman
Copy link
Collaborator

@mtfishman mtfishman commented Aug 17, 2025

Fixes #295. That issue seemed to be caused by code in the generic block broadcasting logic such as

subblocks(::Any, bs::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, dim::Integer) =
(nothing for _ in blockaxes(bs[dim], 1))
function subblocks(arr::AbstractArray, bs::Tuple{Vararg{AbstractUnitRange{<:Integer}}}, dim::Integer)
return SubBlockIterator(arr, bs, dim)
end
@inline _bview(arg, ::Vararg) = arg
@inline _bview(A::AbstractArray, I...) = view(A, I...)
assuming the broadcasting expression is already flat. This PR adds a call to Broadcast.flatten to explicitly flatten the broadcast expression in the generic block broadcast code.

It appears that at some point BlockedStyle broadcasting expressions were being flattened in this Broadcast.instantiate definition:

@inline function Broadcast.instantiate(bc::Broadcasted{Style}) where {Style <:BlockStyle}
bcf = Broadcast.instantiate(Broadcast.flatten(Broadcasted{Nothing}(bc.f, bc.args, bc.axes)))
return Broadcasted{Style}(bcf.f, bcf.args, bcf.axes)
end
but that was changed in #193. Reverting that change broke the tests introduced in #193 so I guess it is not safe to do that.

I have to admit I'm not sure if this is the best place to call Broadcast.flatten, a lot of this broadcasting code is hard to follow. The place I put it in this PR fixes #295, doesn't break other tests, and is hopefully least likely to interfere with custom implementations of block broadcasting in downstream packages.

Copy link

codecov bot commented Aug 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.04%. Comparing base (a4a0b93) to head (25ae39b).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
+ Coverage   93.81%   94.04%   +0.23%     
==========================================
  Files          19       19              
  Lines        1761     1764       +3     
==========================================
+ Hits         1652     1659       +7     
+ Misses        109      105       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@dlfivefifty dlfivefifty merged commit 9c5639d into JuliaArrays:master Sep 4, 2025
17 checks passed
@mtfishman mtfishman deleted the mf/nested_blockedarray_broadcast branch September 5, 2025 00:06
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.

DimensionMismatch in broadcast

2 participants