Le vendredi 8 janvier 2016 10:13:46 UTC+1, Johan S. R. Nielsen a écrit : > > The call to f.coefficients() run the following lines (self = f): > > tmp = {} > for j in self._bg_value.coefficients(): > for m in j.monomials(): > > tmp[self.parent(m)]=j.monomial_coefficient(self.parent()._poly_ring(m)) > > I may be missing something, but it seems that instead of the inner loop, > one could just loop over j.dict(). The values of this are already in the > right parent. Converting the keys should not be too expensive (and would > have to be done in any case, if one wants to use the output of > f.polynomial().dict() while retaining the return type of > f.coefficients()). >
Based on tests I just did, converting the keys *is expensive* and most of the time is taken by this operation. To my mind, the type of the keys for the dictionary returned by the method coefficients is weird: each key is itself a (full) multivariate power series... So the time taken by the method is due to the initialization of many distinct power series. I would be in favor of changing the method coefficients to make it either an alias of the method dict, or simply return a list of coefficients (as it is the case for multivariate polynomials). Bruno > > Johan > > > Ralf Stephan writes: > > > On Friday, January 8, 2016 at 1:51:27 AM UTC+1, Daniel Lowengrub wrote: > >> > >> 1) If we are just reading the coefficients of the power series, why > should > >> it matter if we first cast it to a polynomial? > >> > > > > We are not. There are substitutions happening, leading to expensive > > computation of powers. > > > > > >> 2) If the issue lies in the details of the PowerSeries implementation, > >> then would it make sense to simply cast powerseries to polynomials > before > >> calling methods that do not distinguish between the two? > >> > > > > In this special case yes. I don't know for the general case. > > > > Regards, > > -- > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.