-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
... aka Bikeshed and/or improve documentation for issparse. The docstring for issparse says
issparse(S)Returns
trueifSis sparse, andfalseotherwise.
but this is ambiguous. What, precisely, does it mean for S (presumably an array) to be sparse? Here are two (very different) possible definitions:
- The array has a density of nonzero elements less than some parameter
x(xcould have some default value, but this would be rather arbitrary). - The array is represented by a some "sparse" data type.
It is the second option that is implemented by issparse. In a way this makes sense, as the function does not take such a parameter x (representing the threshold density of nonzero elements). But at a minimum this should be more clearly explained in the documentation. (I'm also unable to explain why issparse(::Diagonal) and related types return false -- perhaps it's a bug, or perhaps I do not understand fully what this function is meant to do.)
On the other hand, the current behavior makes issparse different from many other functions I can think of, such as istril, istriu, issymmetric, ishermitian, and isreal. Each of these considers the value itself rather than the datatype; for instance, isreal(0im) == true.
Perhaps a better name for this function, then, would be issparsetype? I can think of downsides to this name (you do not pass a type to it). Another idea would be issparsestorage, but I don't know if I like this either.
So I ask:
- Do people agree that
issparseis a poor name? If it is, can we come up with anything better? - What should
issparse(::Diagonal),issparse(::Tridiagonal), etc. return? - Is this function even useful? I just searched discourse, and it's never been mentioned there. In Base,
it is used only in the concatenation functions insparsevector.jl. I have not grepped the package ecosystem, but I wonder how frequently it is used there.