Skip to content

Rename issparse? #24645

@garrison

Description

@garrison

... aka Bikeshed and/or improve documentation for issparse. The docstring for issparse says

issparse(S)

Returns true if S is sparse, and false otherwise.

but this is ambiguous. What, precisely, does it mean for S (presumably an array) to be sparse? Here are two (very different) possible definitions:

  1. The array has a density of nonzero elements less than some parameter x (x could have some default value, but this would be rather arbitrary).
  2. 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:

  1. Do people agree that issparse is a poor name? If it is, can we come up with anything better?
  2. What should issparse(::Diagonal), issparse(::Tridiagonal), etc. return?
  3. 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 in sparsevector.jl. I have not grepped the package ecosystem, but I wonder how frequently it is used there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    sparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions