Open bd4edba6-a6b9-4042-be56-832c680989e3 opened 13 years ago
Description changed:
---
+++
@@ -1,5 +1,6 @@
The matrix constructor taking a list of rows as input is way too slow (apparently quadratic in the number of rows) compared to simply constructing a zero matrix then assigning the lines (quasi linear).
+```
lines=[vector(QQ,[QQ.random_element() for j in xrange(500)]) for i in xrange(1000)]
import resource
@@ -24,8 +25,10 @@
time2 = end-start
print time2
sys.stdout.flush()
+```
+Timings:
-Timings:
+```
50 0.128008 0.028002
100 0.104007 0.056003
150 0.32402 0.088006
@@ -46,13 +49,15 @@
900 12.292769 0.532033
950 13.752859 0.560035
1000 15.972999 0.620038
+```
+Same problem with sparse matrices:
-Same problem with sparse matrices:
+```
50 1.584099 1.188075
100 3.116194 2.264142
150 4.748297 3.404213
200 6.904432 4.580286
250 8.928558 5.756359
300 11.564722 6.976436
-
+```
Same problem with block_matrix (block_matrix is slower than assigning the blocks directly).
I think that this is only a problem with sparse matrices now.
indeed with Sage 5.9 I get on a AMD Phenom(tm) II X2 B55 with the code in the description:
50 0.028002 0.012001
100 0.120007 0.036002
150 0.15601 0.052003
200 0.188012 0.076005
250 0.220014 0.092005
300 0.31202 0.116007
350 0.360023 0.128008
400 0.400025 0.15601
450 0.424026 0.16001
500 0.532033 0.200013
550 0.584036 0.200013
600 0.608038 0.236015
650 0.620038 0.240015
700 0.752047 0.276018
750 0.820051 0.260016
800 0.752047 0.31202
850 0.988061 0.30802
900 0.928058 0.348021
950 0.964061 0.336021
1000 1.092068 0.388024
It is still slower than assigning the lines one per one, but quasi linear now.
David, please could you provide code for the sparse and block matrices?
Paul
The matrix constructor taking a list of rows as input is way too slow (apparently quadratic in the number of rows) compared to simply constructing a zero matrix then assigning the lines (quasi linear).
Timings:
Same problem with sparse matrices:
Same problem with block_matrix (block_matrix is slower than assigning the blocks directly).
CC: @zimmermann6 @ClementPernet
Component: linear algebra
Keywords: matrix constructor
Issue created by migration from https://trac.sagemath.org/ticket/10312