Nearest and NearestTo cause a kernel crash on Mathematica 12.0.0 for Mac OS X. (running on OS X 10.11.6) when operating on a list of SparseArray vectors.

Here's my minimal breaking example:

examples = {{0, 0, 1}, {0, 1, 1}, {1, 0, 1}}
sparseExamples = SparseArray /@ examples

NearestTo[First@examples]@examples (*works OK*)

NearestTo[First@sparseExamples]@sparseExamples (*causes a kernel crash*)

This appears to be confined to Nearest and NearestTo; other functions such as DistanceMatrix work fine on SparseArrays.

DistanceMatrix[sparseExamples] (*works OK*)

This appears to be a "new" problem; there are a couple posts from ~18 months ago that imply that Nearest plays well with SparseArrays:

It's also a bit surprising, given how many different data types Nearest and NearestTo operate on.

  • 1
    $\begingroup$ Interesting bug report! Unfortunately, it is not appropriate for stackexchange which is a Q&A site, so you get -1 from me. I recommend editing your post to turn it into a question (like asking for a workaround or something like that). Also, I recommend submitting the bug report directly to Wolfram Research. $\endgroup$ – QuantumDot Dec 27 '19 at 18:34
  • 3
    $\begingroup$ Confirmed. I'll report it as a bug. $\endgroup$ – Daniel Lichtblau Dec 27 '19 at 19:14
  • 1
    $\begingroup$ I'm voting to close this question as off-topic because this is not a question. $\endgroup$ – QuantumDot Dec 27 '19 at 21:44
  • 2
    $\begingroup$ Confirmed crash for 12.0 on Win 10 Ent. $\endgroup$ – Edmund Dec 27 '19 at 21:53

From the comment thread, is a confirmed bug Mathematica 12.0 on both Mac OS X and Windows.

Interestingly, for NearestTo[x][elems] this is only a problem if both x and elems are SparseArrays.

Converting at least one of these to Normal form avoids crashing. So for the previous example data:

examples = {{0, 0, 1}, {0, 1, 1}, {1, 0, 1}}
sparseExamples = SparseArray /@ examples





will yield the desired answer without crashing the kernel. The former is probably closest to the desired behavior, as it keeps the list of elements in SparseArray format (saving memory), and returns a SparseArray result.


Not the answer you're looking for? Browse other questions tagged or ask your own question.