hfloat polynomials

March 21 2010 by roman_pearce 1191
false

2


I want to evaluate a polynomial and turn its coefficients into hfloats. Shouldn't evalhf do this? For example:
f := randpoly([x,y,z]);  # integer coefficients
g := evalf(f);    # software float coefficients
h := evalhf(f);   # error
I think the last one should give me a polynomial with hardware floating point coefficients. Instead I get an error. You can make a polynomial with hfloat coefficients in several ways, e.g.:
h := inner(map(HFloat,[coeffs(f,indets(f),'m')]),[m]);
And polynomial arithmetic basically works:
subs({x=HFloat(2),y=HFloat(3),z=HFloat(4)}, h);
I don't expect this to be as fast as compiled code, but it should be faster than software floats. Do kernel function evaluate everything in hardware floating point? I did a test:
f := randpoly([x,y,z,t,u,v],degree=20,dense):
g := evalf(f):
h := inner(map(HFloat,[coeffs(f,indets(f),'m')]),[m]):
gc(): time(eval(eval(f,1), {x=2,y=-2,z=3,t=-3,u=4,v=-4}));
gc(): time(eval(eval(g,1), {x=2.0,y=-2.0,z=3.0,t=-3.0,u=4.0,v=-4.0}));
gc(): time(eval(eval(h,1), {x=HFloat(2.0),y=HFloat(-2.0),z=HFloat(3.0),t=HFloat(-3.0),u=HFloat(4.0),v=HFloat(-4.0)}));
This is pretty crude, but I got 0.38 seconds for immediate integers, 1.9 seconds for software floats, and 0.62 seconds for hfloats. Is this because hfloats are a dag that has to allocate memory? It still might be good enough for sparse linear algebra. Software floats are definitely too slow. Also, can anything here be done much more efficiently than what I have done? Particularly evaluation and construction of hfloat polynomials. All input is appreciated.
 
Loading Comments & Answers

You must be logged into your MaplePrimes account in order to post a comment. If you don't have an account, you can create an account here.

     

Forgot Your Password? Create an Account