arpfloat icon indicating copy to clipboard operation
arpfloat copied to clipboard

Any plan for trigonometric functions?

Open fxpineau opened this issue 3 years ago • 5 comments

In a short/medium/long term? They are supported in rug or astro-float. See also, e.g., this paper.

fxpineau avatar Jan 03 '23 14:01 fxpineau

Hey @fxpineau. Yes, I think that I'll work on implementing them. I already implemented e and pi, and started reading on log and exp. The paper that you attached looks excellent. Btw, if you are interested in implementing something then that would be great. You can start with something small. I would love to review the pull request.

nadavrot avatar Jan 04 '23 07:01 nadavrot

I landed a quick implementation of sine(). It's incomplete, and we are still missing support for Inf,NaN, etc. And the Taylor series is unbounded, but the implementation can already compute a bunch of normal values in double precision and get bit accurate results.

nadavrot avatar Jan 06 '23 07:01 nadavrot

For a lib I am working on, I am computing rotation matrices obtained from Euler angles and compare them to (high precision) matrices provided by the literature. I am doing one shot computations (hard coding the result in the lib) and I finally chose to write bc scripts. If cosine() is also implemented, I will compare bc and arpfloat results. I may also extend the lib with high precision computations and arpfloat seems a very good candidate to me.

fxpineau avatar Jan 06 '23 08:01 fxpineau

I implemented Sin, Cos, Tan, Exp, Log, Pow, and a few constants (pi, e, ln2). Can you think of other functions or constants?

nadavrot avatar Jan 16 '23 23:01 nadavrot

Doing a quick cprofile of nanoGPT model training on M1 CPU for the perf7 proposal:

ncalls tottime percall cumtime percall filename:lineno(function)
440 6.682 0.015 6.682 0.015 {method 'run_backward' of 'torch._C._EngineBase' objects}
1920 1.183 0.001 1.183 0.001 {built-in method torch.tanh}

It looks like torch.tanh() is really expensive and could use some love.

BSD tanh() seems really branchy. GNU tahh()

chadbrewbaker avatar Feb 20 '23 15:02 chadbrewbaker