ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 13 Jan 2022 19:01:24 +0100Matrix constructor runs out of memoryhttps://ask.sagemath.org/question/60673/matrix-constructor-runs-out-of-memory/I am trying to construct a matrix with entries in $\mathbb{Q}(q)$, from a list of Sage vectors. I do this using
`A = matrix(QQ['q'].fraction_field(), relations)
`
where the vectors in the list `relations` are Sage vectors over `QQ['q'].fraction_field()`.
The list `relations` is generated by a subroutine involving some randomness, and in many cases the above works fine but sometimes my script uses too much memory and is killed by the operating system. Tracing the memory allocation it is clear that the problem occurs at the given line where I construct the matrix from the list of vectors.
The sorts of matrices for which the script fails are tend to have about 100 columns and 50-100 rows. They are sparse (each row has <= 4 nonzero entries) and the nonzero entries are of the form `-2/q^x + 2` where `x` is in the range `10000 - 100000`.
It seems clear that when some combination of the order of magnitude of the exponents `x` and the matrix size is reached, then the matrix constructor uses too much memory. I wondered if there is a solution anyone can suggest, or even just explain a bit more about why this constructor seems to max out on memory?
(P.S. I plan to re-implement things using sparse matrices, and maybe this will help, though I'd still like to understand better why the dense version fails.)PatrickKinnearThu, 13 Jan 2022 19:01:24 +0100https://ask.sagemath.org/question/60673/