On Wednesday, July 10, 2013 5:20:29 AM UTC-4, Simon King wrote: > > Hi, > > On 2013-07-10, broken_symlink <[email protected] <javascript:>> wrote: > > I've done some profiling of my code and it seems that my main slowdowns > are > > coming from multiplication and addition of free algebra elements. > > Is there > > anyway I can make it go faster? > > You define > > self.alg = FreeAlgebra(self.br, len(g.split(',')), g) > > This yields a very generic and very slow implementation, in particular > by the method of constructing elements later in your code (see below). > > If all your elements are homogeneous (or at least: weighted homogeneous > with respect > to positive integer weights of the algebra generators), then you might > instead use > > self.alg = FreeAlgebra(self.br, len(g.split(',')), g, > implementation='letterplace') > > I think their arithmetic is faster, and in particular you can do weighted > homogeneous Gröbner basis computations (which might be interesting in > your application, I don't know). > > My elements are not homogeneous.
> If your algebra elements are not weighted homogeneous, then you might > consider to use gap (via pexpect) or libgap (i.e., would be possible to > do on C library level) as a back-end. Gap has an implementation of free > associative unital algebras, and I think it is faster than the native > implementation in Sage. However, the (lib)gap free algebras are not > wrapped in Sage yet, hence, you would need to speak with (lib)gap on a > lower level. I'll look into this. It seems like it would require a large rewrite though. > > One remark: > > In your code, you construct an algebra element by > FreeAlgebraElement(self.alg, k) > Please don't do this! > In general, elements of an algebraic structure "A" given by data "d" > should be > created via "A(d)" or via arithmetic operations on A.gens(), but by > calling some > class constructor. > > Thanks! I fixed that by doing for g, p in k._element_list and calling self.alg.gen(g)**p also i didn't realize I wasn't taking the exponent into account. On another note, I was able to get good speedups by parallelizing some parts, I don't know how long it will take to do the computation I'm interested in though as I haven't tried yet. -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/groups/opt_out.
