I'm not sure I agree with this. I would expect the global sum() to try to use a sum method first, and only do the default if that did not exist, since some classes might have better ways of summing themselves than the default. But then the only reason for having sum methods would be if there was such a more efficient way of summing. The present situation is still bad, though, as it is inconsistent.
I am (of course) open to persuasion! John On Sat, Nov 13, 2010 at 5:18 AM, Dima Pasechnik <dimp...@gmail.com> wrote: > I don't think sum() method is needed. It's certainly a code bloat. > Could you check that sum() in vector_double_dense can be removed? > (remove it there, do sage -b, run testsuite, see if there were any > errors caused by it) > > On Nov 13, 12:59 pm, Maxim <maxim.courno...@gmail.com> wrote: >> If I try to find the sum of a vector of floats that way, it works as >> expected: >> sage: vector([1,float(2),3]).sum() >> -> 6.0 >> >> However, applying the same logic on a vector made of integers: >> sage: vector([1,2,3]).sum() >> -> Traceback (click to the left of this block for traceback) >> ... >> AttributeError: >> 'sage.modules.vector_integer_dense.Vector_integer_dense' >> object has no attribute 'sum' >> >> Workaround (thanks to Dr. Drake) is to call the sum function directly >> like this: >> sage: sum(vector([1,2,3])) >> -> 6 >> >> Browsing through the code, one can find the .sum() method being >> defined for floats at the end of the file vector_double_dense.pyx, >> while this method is absent in the vector_integer_dense.pyx. >> >> Did I luckily stumbled on a rarity, or should this self.sum() method >> be part of every types' definition? (where applicable). in any case, >> uniformity would help (method present in every type definition / >> completely removed) to prevent confusion. > > -- > To post to this group, send an email to sage-devel@googlegroups.com > To unsubscribe from this group, send an email to > sage-devel+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org