Skip to content

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

@mtfishman

Description

@mtfishman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions