[Numpy-discussion] polynomial ring dtype
Tue Sep 22 14:57:15 CDT 2009
sorry if this a duplicate, it seems that my last mail got lost...
is there something to take care about when sending a mail to the numpy
On Tue, Sep 22, 2009 at 9:42 AM, Sebastian Walter
> This is somewhat similar to the question about fixed-point arithmetic
> earlier on this mailing list.
> I need to do computations on arrays whose elements are truncated polynomials.
> At the momement, I have implemented the univariate truncated
> polynomials as objects of a class UTPS.
> The class basically looks like this:
> class UTPS:
> def __init__(self, taylor_coeffs):
> """ polynomial x(t) = tc + tc t + tc t^2 + tc
> t^3 + ... """
> self.tc = numpy.asarray(taylor_coeffs)
> def __add__(self, rhs):
> return UTPS(self.tc + rhs.tc)
> def sin(self):
> # numpy.sin(self) apparently automatically calls self.sin()
> which is very cool
> One can create arrays of UTPS instances like this:
> x = numpy.array( [[UTPS([1,2]), UTPS([3,4])], [UTPS([0,1]), UTPS([4,3])]])
> and perform funcs and ufuncs on it
> y = numpy.sum(x)
> y = numy.sin(x)
> y = numpy.dot(numpy.eye(2), x)
> This works out of the box, which is very nice.
> my question:
> Is it possible to speed up the computation by defining a special dtype
> for truncated polynomials? Especially when the arrays get large,
> computing on arrays of objects is quite slow. I had a look at the
> numpy svn trunk but couldn't find any clues.
> If you are interested, you can have a look at the full pre alpha
> version code (BSD licence) at http://github.com/b45ch1/algopy .
More information about the NumPy-Discussion