Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Improve logic for checking if map/broadcast calls preserve zeros #22

Open
mtfishman opened this issue Jan 15, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@mtfishman
Copy link
Member

An important part of the logic for map/broadcast is first determining if the function preserves zero values (or more generally, stored values, though for now we are focusing on the case where unstored values are zero). If it doesn't, all elements of the destination need to be instantiated, while if it does, we only need to loop over the values that are stored in the arrays being mapped/broadcasted.

The logic as of #21 is based on a function:

function preserves_unstored(f, a_dest::AbstractArray, as::AbstractArray...)
  I = first(eachindex(as...))
  return iszero(f(map(a -> getunstoredindex(a, I), as)...))
end

which has the disadvantage that calling getunstoredindex could be expensive, say if the sparse array is an array of large arrays it could allocate a large array, and additionally checking if it is zero could be expensive as well. It would be good to try to come up with a better system for that.

@mtfishman mtfishman added the enhancement New feature or request label Jan 15, 2025
@mtfishman mtfishman changed the title [ENHANCEMENT] Improve logic for checking of map/broadcast calls preserve zeros [ENHANCEMENT] Improve logic for checking if map/broadcast calls preserve zeros Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant