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.
12.3.0 for Mac OS X x86 (64-bit) (May 10, 2021)
$\endgroup$MaxMemoryUsed[rules = Table[{RandomInteger[{1, 640}], RandomInteger[{1, 640}]} -> RandomReal[], {i, 1, 6969}];]
, this uses just under1 MB
for me during evaluation (0.95 MB
). Maybe that's some kind of threshold for your machine? $\endgroup$