On Thursday, 4 December 2014 07:27:21 UTC+1, Nathann Cohen wrote: > > Also, I do not understand why you have so many expressions like: > > (val*bm.transpose())[0,0] > val*bm.transpose() is actually a number but the way Sage handles it is awkward:
sage: M = Matrix(RR,[[1],[1]]) sage: Matrix(RR,[[-1,0]])*M [-1.00000000000000] sage: abs(Matrix(RR,[[-1,0]])*M) -1.00000000000000 # some norm of the matrix?? soo I either have to do abs(abs(...)) or access the (only) element of the matrix. > > If you have performance problems, do not compute a whole matrix if you > are only interested by its [0,0] coordinate O_o > > You call j.transpose() repeatedly. Store jt=j.transpose() and use it. > > Store and use bm.transpose() instead of bm. You tanspose bm when you > use it in the first loop, and you transpose bm() again in > vec2int[j].transpose(). > > Also, given that the profiling does not say much of where 99% of the > computations is going, try to run your code without the .write() calls > (and their internal str() calls). Make it run without storing anything > and see how it goes. Perhaps you should store the results directly as > Sage objects using "save" and not as strings... No idea, you need to > test things ^^; > Thanks for the suggestions I'll check them out. > > Nathann > > On 4 December 2014 at 03:44, Nils Bruin <nbr...@sfu.ca <javascript:>> > wrote: > > On Wednesday, December 3, 2014 1:33:46 PM UTC-8, Jernej wrote: > >> > >> > >> for i in xrange(1, cur): > >> for j in xrange(i+1, cur): > >> iv = (cache[i]*vec2int[j].transpose())[0,0] > > > > > > It looks like you should rewrite this loop so that j is the out > variable, so > > that you can pull > > vec2int[j].transpose() > > to the out loop. No need to cache it. > > > > In any case, your profiling data indicates: > > > > 1 85.572 85.572 113.024 113.024 > > <string>:9(constructGraph_fast) > > 3733128 10.413 0.000 10.413 0.000 > > matrix_space.py:145(__classcall__) > > 1604418 9.434 0.000 19.921 0.000 {method 'transpose' of > > 'sage.matrix.matrix_dense.Matrix_dense' objects} > > 1604418 3.186 0.000 4.174 0.000 {method '__copy__' of > > 'sage.matrix.matrix_generic_dense.Matrix_generic_dense' objects} > > > > so most time is spent in "constructGraph_fast", which I guess is your > > program itself. The transpose is a bit noticeable but hardly constitutes > the > > majority of the time. The construction for the matrix spaces is incurred > > twice: both for the transpose and for computing the product. By pulling > the > > transpose to the outside loop that should roughly be cut in half (and > you'd > > only have the sqrt of the number of transposes). > > > > It looks like most time is getting lost in basic python interpretation > and > > shuffling around elements. If you make a big matrix out of cache[i] > vectors, > > you can eliminate the loop over i. The only thing left would be > inspecting > > the elements, for which you can then write a simple cython routine > (which > > should be lightning fast). > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.