Description
The implementation of broadcast
over SparseMatrixCSC
s separates unary functions into three classes (with disjoint logic): (1) unary functions that map zeros to zeros and may map nonzeros to zeros; (2) unary functions that map zeros to zeros and nonzeros to nonzeros; and (3) unary functions that map both zeros and nonzeros to nonzeros.
In the first class, when a nonzero in the original sparse matrix maps to exact zero under, e.g., sin
or round
, the implementation expunges that entry.
On the one hand, this behavior seems like a holdover from the aggressive-stored-zero-expunging era, now inconsistent with behavior elsewhere. Additionally, this behavior comes at the cost of a branch and additional communication on every iteration of an inner loop, the inability to apply an @simd
decoration on that inner loop, and some additional code.
On the other hand, in some cases, for example broadcast
ing round
over a sparse matrix with unity-balanced or standard normally distributed entries, a substantial fraction of the nonzeros might map to zero, and expunging those zeros may be advantageous for some applications (though perhaps not for others).
Should this first class still exist? Thoughts? Best!
Ref. #17265.