1
$\begingroup$

I am trying to create a sparse matrix by the SparseArray command. For a set of index pairs $(i,j)$ I want to calculate the $A_{i,j}$ element and then use this table to create the rules for the sparse array. However, using the Table command to generate the elements crashes my kernel. For example, the code to randomly create 6969 elements of a 640x640 matrix:

rules = Table[{RandomInteger[{1, 640}], RandomInteger[{1, 640}]} -> 
    RandomReal[], {i, 1, 6969}];

causes my kernel to crash. If I generate 6960 such rules, it doesn't crash.

I have not yet evaluated these to create a matrix, so I must be doing something wrong in creating the list. How can I do so correctly?

Update: working on a Mac Pro (late 2013) 12-core Intel Xeon E5 with 64 GB of memory. Mac OS X 10.14.6. Running Mathematica 12.0.0.0.

Update 2: Executing the Table command above inside the SparseArray command does not cause a kernel crash. It's something wonky with how my machine and Mathematica handles Table.

$\endgroup$
6
  • $\begingroup$ I can't duplicate this... after setting rules above, I use SparseArray[rules] and it seems to work fine. $\endgroup$
    – bill s
    Jun 3 at 0:20
  • 1
    $\begingroup$ Unable to reproduce on 12.3.0 for Mac OS X x86 (64-bit) (May 10, 2021) $\endgroup$ Jun 3 at 2:40
  • $\begingroup$ could be a memory issue on your machine? according to MaxMemoryUsed[rules = Table[{RandomInteger[{1, 640}], RandomInteger[{1, 640}]} -> RandomReal[], {i, 1, 6969}];], this uses just under 1 MB for me during evaluation (0.95 MB). Maybe that's some kind of threshold for your machine? $\endgroup$
    – thorimur
    Jun 3 at 5:12
  • $\begingroup$ Also can't replicate it here on 12.3 on Linux. $\endgroup$
    – Carl Lange
    Jun 3 at 10:10
  • 1
    $\begingroup$ Try turning off the Suggestions bar. Also, I think it has been fixed in newer versions. $\endgroup$
    – ilian
    Jun 3 at 20:19
1
$\begingroup$

Error fixed in later version of Mathematica

Given that others could not reproduce the error, it made sense that the problem was either in the version of Mathematica I was using or some very odd bug in my own computer. (Thank you to all who tried to reproduce the error.)

Updating from 12.0 to 12.3 fixed the problem.

It took a while to track down because it seemed like I had done something wrong with the sparse matrix commands, but it was simply some weird bug in Table in my version of the application!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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