[sage-devel] Re: sage-python puzzle

2017-09-15 Thread 'Martin R' via sage-devel
Thanks for the hint. I am currently happy with %prun followed by %lprun. The only thing I dislike about this is that I have to guess who calls the most offending method or function, but it's not much of a hassle, since %prun also includes the cumulative timings. Martin Am Freitag, 15. Septem

[sage-devel] Re: sage-python puzzle

2017-09-15 Thread Maarten Derickx
By the way, if you are doing a lot of optimisation you should consider using gprof2dot https://github.com/jrfonseca/gprof2dot . It can turn your python profiling data into a really useful grafical visualisation of the call graph, instantly showing you which parts of the code to optimize. And I i

[sage-devel] Re: sage-python puzzle

2017-09-14 Thread Samuel Lelievre
Thu 2017-09-14 18:06:48 UTC, Martin R: > almost by accident, I just noticed the following: > > [...] > > Is there any drawback to the faster method? No! Good that you tested and found what works faster. Sorry if anything I said was misleading. Are you working on speeding up the 'to_matrix' and

[sage-devel] Re: sage-python puzzle

2017-09-14 Thread 'Martin R' via sage-devel
Dear Samuel, almost by accident, I just noticed the following: def to_matrix_1(self): entries = { (v-1, i): 1 for i, v in enumerate(self) } return MatrixSpace(ZZ, len(self), sparse = True)(entries) def to_matrix_2(self): entries = { (v-1, i): 1 for i, v in enumerate(self) } retur

[sage-devel] Re: sage-python puzzle

2017-09-11 Thread Samuel Lelievre
Mon 2017-09-11 10:07:01 UTC-5, Martin R: > Is there a recommended (fast) way to turn input > into a (square) matrix (with entries in ZZ)? > Currently I do "corner = matrix(corner)" Suppose you defined m_list = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] and you want to turn m_list into a 3 by 3 matri

[sage-devel] Re: sage-python puzzle

2017-09-11 Thread 'Martin R' via sage-devel
Thank you! Is there a recommended (fast) way to turn input into a (square) matrix (with entries in ZZ)? currently I do "corner = matrix(corner)" Thanks again, Martin Am Montag, 11. September 2017 17:00:20 UTC+2 schrieb Samuel Lelievre: > > Mon 2017-09-11, 9:38:45 (UTC-5), Martin R: > > Appa

[sage-devel] Re: sage-python puzzle

2017-09-11 Thread Samuel Lelievre
Mon 2017-09-11, 9:38:45 (UTC-5), Martin R: > Apparently, corner[i,j] is a lot faster than corner[i][j]. Yes: if m is a matrix, m[i, j] accesses the element (i, j) of m, while m[i][j] first extracts line i of m, stores it as a vector, then extracts element j of that vector. This explains the speed

[sage-devel] Re: sage-python puzzle

2017-09-11 Thread 'Martin R' via sage-devel
Apparently, corner[i,j] is a lot faster than corner[i][j]. With this modification, the two versions are roughly equally fast. I don't get it, though, because the second version should be doing a lot more work. Martin Am Montag, 11. September 2017 16:23:07 UTC+2 schrieb Martin R: > > I don't u