Fast emptiness test on sparse arrays

Dear Wolframers, do you know if there is some efficient way to test that the only entries in a sparse array are set to the default element, without having recourse to the conversion of the sparse array into a list of array rules like so :

emptyQ[sparseArray_] := Length[ArrayRules[sparseArray]] == 1

Thanks for your help

I would guess this to be most efficient way to do it currently without using hidden function. If you do:

sparseArray // FullForm 

You will see the input, but you can’t access it directly using Part as a sparseArray is an atom (AtomQ). You therefore have to use functions like ArrayRules to get ‘deeper’ information from sparse arrays…

Another way would be

sparseArray["Density"] === 0.

See also What are SparseArray Properties? How and when should they be used?.

Very nice, Ilian. Perhaps this could be noted in the properties section of SparseArray documentation?

Nice hidden functionality; is this in the documentation and is this planned to change? Or is it used throughout the system already?