Skip to content

Conversation

@DanielVandH
Copy link
Collaborator

Finishes off #383 (no perms to commit directly)

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.97%. Comparing base (3519be9) to head (c7b9554).
⚠️ Report is 1 commits behind head on CachedStyle.

Files with missing lines Patch % Lines
src/cache.jl 92.85% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           CachedStyle     #385       +/-   ##
================================================
+ Coverage         0.00%   95.97%   +95.97%     
================================================
  Files               17       17               
  Lines             3273     3333       +60     
================================================
+ Hits                 0     3199     +3199     
+ Misses            3273      134     -3139     

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

@eval layout_broadcasted(::ZerosLayout, ::CachedLayout, ::typeof($op), a::AbstractVector, b::AbstractVector) = broadcast(DefaultArrayStyle{1}(), $op, a, b)
end

function resize_bcargs(bc::Broadcasted{<:CachedArrayStyle}, dest)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function resize_bcargs(bc::Broadcasted{<:CachedArrayStyle}, dest)
function resize_bcargs!(bc::Broadcasted{<:CachedArrayStyle}, dest)

rsz_args = let len = length(dest)
map(bc.args) do arg
resizedata!(arg, len)
iscached = arg isa AbstractCachedArray || (arg isa SubArray && parent(arg) isa AbstractCachedArray)
Copy link
Member

Choose a reason for hiding this comment

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

This should be all based on memory layouts not types.

map(bc.args) do arg
resizedata!(arg, len)
iscached = arg isa AbstractCachedArray || (arg isa SubArray && parent(arg) isa AbstractCachedArray)
iscached ? cacheddata(arg) : arg
Copy link
Member

Choose a reason for hiding this comment

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

This seems very unlikely to be type stable. I think we want to rewrite this whole map in a functional programming style, something like:

_bc_resizecacheddata!(n) = ()
_bc_resizecacheddata!(n, a, b...) = __bc_resizecacheddata!(n, MemoryLayout(a), a, b...)
__bc_resizecacheddata!(n, _, a, b...) = (a, _bc_resizecacheddata!(b...))
function __bc_resizecacheddata!(n, ::AbstractCachedLayout, a::AbstractVector, b...)
    resizedata!(a, n)
    (view(cacheddata(a), 1:n), _bc_resizecacheddata!(b...))
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that since bc.args is a Tuple these should be functionally equivalent? But I'll change it anyway to not rely on that

κ[1:2]
leads to a stack overflow.
=#
rsz_bc = resize_bcargs(Base.Broadcast.flatten(bc), dest)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced flatten is preferable to a recursive call. I.e. something like

_bc_resizedata!(n, a::Broadcasted, b...) = (broadcasted(a.f, _bc_resizedata!(n, a.args...)...), _bc_resizedata!(n, b...))

But I think it is fine to flatten for now and come back later if there's an issue.

@DanielVandH DanielVandH merged commit c7b9554 into JuliaArrays:CachedStyle Oct 27, 2025
16 of 17 checks passed
@DanielVandH
Copy link
Collaborator Author

Didn't mean to merge it but whatever, I'll address the comments directly on the other PR

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