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

Do findall findmax ,findmin, argmax, argmin work on SparseArrays by
convert sparse to Matrix type before doing operations on these functions? If yes, is the computational cost too much of converting?

No, there is no conversion, and findall operates only on the nonzero elements if the predicate is false for zero.

2 Likes

findall operates only on the nonzero elements if the predicate is false for zero.

Does this mean something like findall(!iszero, some_matrix) ? where some_matrix is SparseMatrixCSC

In particular, if you look at the source code (julia/sparsematrix.jl at 0224c42bce6daec1b5580b8a8a6b43f9437d2cee · JuliaLang/julia · GitHub), 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