How do findall ,findmax ,findmin, argmax, argmin work on SparseArrays/SparseMatrixCSC

In particular, if you look at the source code (https://github.com/JuliaLang/julia/blob/0224c42bce6daec1b5580b8a8a6b43f9437d2cee/stdlib/SparseArrays/src/sparsematrix.jl#L1544-L1563), the findall function first calls predicate(0) with the user-specified predicate function. If this returns false, then it subsequently calls the predicate only on the sparse nonzero elements.

For example, this means that findall(x -> abs(x) > 0.1, A) is efficient for a sparse matrix, with complexity proportional to the number of nonzero entries of A.

4 Likes