Skip to content

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Aug 24, 2025

For example, after this PR,

julia> D = Diagonal(1:4)
4×4 Diagonal{Int64, UnitRange{Int64}}:
 1      
   2    
     3  
       4

julia> D .* 2
4×4 Diagonal{Int64, StepRangeLen{Int64, Int64, Int64, Int64}}:
 2      
   4    
     6  
       8

julia> using SparseArrays

julia> D = Diagonal(spzeros(2))
2×2 Diagonal{Float64, SparseVector{Float64, Int64}}:
 0.0    
     0.0

julia> D .* 2
2×2 Diagonal{Float64, SparseVector{Float64, Int64}}:
 0.0    
     0.0

julia> using FillArrays

julia> D = Diagonal(Fill(3, 2))
2×2 Diagonal{Int64, Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}}:
 3  
   3

julia> D .* 2
2×2 Diagonal{Int64, Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}}:
 6  
   6

I've not handled the other banded matrix types in this PR, but Diagonal is probably used far more commonly in packages anyway.

Copy link

codecov bot commented Aug 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.89%. Comparing base (98723df) to head (3e4e9ca).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1423      +/-   ##
==========================================
- Coverage   93.89%   93.89%   -0.01%     
==========================================
  Files          34       34              
  Lines       15920    15928       +8     
==========================================
+ Hits        14948    14955       +7     
- Misses        972      973       +1     

☔ 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.

# We may do this because the indexing within `copyto!` is restricted to the stored indices
preprocess_broadcasted(::Type{T}, A) where {T} = _preprocess_broadcasted(T, A)
function preprocess_broadcasted(::Type{T}, bc::Broadcasted) where {T}
args = map(x -> preprocess_broadcasted(T, x), bc.args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to use map instead of preprocess_broadcasted.(T, bc.args)?

(I think in old versions of Julia making "enclosures" like this was bad for performance but perhaps that's ancient history.)

Copy link
Member Author

Choose a reason for hiding this comment

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

map on small tuples unrolls the loop. I don't think the anonymous function would be an issue here (perhaps the issue has been resolved). The call seems type-stable and well-inferred.

@jishnub jishnub force-pushed the jishnub/diagonal_broadcasting branch from f1fd10f to 3e4e9ca Compare September 14, 2025 17:03
@jishnub jishnub merged commit 51923a5 into master Sep 18, 2025
4 checks passed
@jishnub jishnub deleted the jishnub/diagonal_broadcasting branch September 18, 2025 12:27
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.

2 participants