cephes | Mirror of the Cephes C source for reference
kandi X-RAY | cephes Summary
kandi X-RAY | cephes Summary
Mirror of the Cephes C source for reference
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cephes
cephes Key Features
cephes Examples and Code Snippets
Community Discussions
Trending Discussions on cephes
QUESTION
The map format OpenDrive, provides (among others) the geometry of a road. Each segment of the road can have a different geometry (e.g. line, arc, spiral, polynomial). The provided information for a road geometry "spiral", is the following:
...ANSWER
Answered 2018-Mar-06 at 13:43I am not sure if your current code is correct. I wrote a short script to interpolate Euler spirals using similar parameters and it gives different results:
QUESTION
I'm planning on writing a typescript library for distributions on that will depend on cephes
.
In order for the web assembly to be used in the browser we have to compile it like this:
...ANSWER
Answered 2019-May-23 at 21:25I think you should be as straightforward as possible. Since your consumers can't really get around having to await
, I would suggest that you leave it to your consumers to await cephes.compiled
.
If you're bundling cephes
, you might want to re-export cephes.compiled
from your library so that your consumers can just use your library:
QUESTION
As I understand it, vectorized numpy functions are faster than Python loops because loops are done in C or Fortran. I would like to know where in the source code this happens.
For example, the scipy.special.bdtr
binomial CDF function accepts array-like arguments k,n,p
and will return an ndarray provided the arguments are broadcastable. The documentation says that scipy.special.bdtr
is a wrapper for a routine in the Cephes Mathematical Functions Library. Digging through the source code on Github, I found a scipy/special/cephes/bdtr.c
file containing the C code for the routine; here are what I believe to be the first three lines of the relevant C function:
double bdtr(k, n, p)
int k, n;
double p;
It appears that the underlying C function does not operate on arrays, and I can't find the source code where this function is converted to a Python function that operates on arrays.
...ANSWER
Answered 2019-Jan-17 at 14:23In the case of scipy.special
functions, the C code only contains the "kernels" of the functions, that is, how to apply the function to scalars. Each of these is then wrapped into a ufunc
with automatically generated Cython code. To do this, it uses C header files, like scipy/special/cephes.h
, Cython declaration files, like scipy/special/_cephes.pxd
, the file scipy/special/functions.json
, where all the functions to be generated for scipy.special
are listed, and finally scipy/special/_generate_pyx.py
, which is where the Cython code is actually produced.
QUESTION
I am new to scientific computing and trying to contribute to scipy
but I can't get it to build.
I git clone
'd the source then ran python setup.py build
. I get a break saying:
scipy/special/cephes/bdtr.c: In function ‘cephes_bdtrc’: scipy/special/cephes/bdtr.c:157:5: error: non-floating-point argument in call to function ‘__builtin_isnan’ if (npy_isnan(k) || npy_isnan(n) || npy_isnan(p)) {
Ubuntu 16.04, Intel i7. For other work I have Anaconda 1.6.3 installed. Python 2.7.13 and gfortran.
I followed the setup here and here.
Any ideas? Maybe a gcc switch?
...ANSWER
Answered 2017-Oct-26 at 08:29This appears to be a bug in this particular scipy/numpy combination. n
and k
are integer variables, so they cannot be NaNs, introduced in commit ede5590b12dbeecd244fdafa4443b6c3a9d9ef40 (BUG: special: fix ufunc results for nan
arguments).
You could change the reported line locally to
QUESTION
I've seen in many impletation of sine/cosine a so called extended modular precision arithmetic. But what it is for? For instance in the cephes implemetation, after reduction to the range [0,pi/4], they are doing this modular precision arithmetic to improve the precision.
Hereunder the code:
...ANSWER
Answered 2017-Mar-01 at 20:31In the context of argument reduction for trigonometric functions, what you are looking at is Cody-Waite argument reduction, a technique introduced in the book: William J. Cody and William Waite, Software Manual for the Elementary Functions, Prentice-Hall, 1980. The goal is to achieve, for arguments up to a certain magnitude, an accurate reduced argument, despite subtractive cancellation in intermediate computation. For this purpose, the relevant constant is represented with more than native precision, by using a sum of multiple numbers of decreasing magnitude (here: DP1
, DP2
, DP3
), such that all of the intermediate products except the least significant one can be computed without rounding error.
Consider as an example the computation of sin (113) in IEEE-754 binary32
(single precision). The typical argument reduction would conceptually compute i=rintf(x/(π/2)); reduced_x = x-i*(π/2)
. The binary32
number closest to π/2 is 0x1.921fb6p+0
. We compute i=72
, the product rounds to 0x1.c463acp+6
, which is close to the argument x=0x1.c40000p+6
. During subtraction, some leading bits cancel, and we wind up with reduced_x = -0x1.8eb000p-4
. Note the trailing zeros introduced by renormalization. These zero bits carry no useful information. Applying an accurate approximation to the reduced argument, sin(x) = -0x1.8e0eeap-4
, whereas the true result is -0x1.8e0e9d39...p-4
. We wind up with large relative error and large ulp error.
We can remedy this by using a two-step Cody-Waite argument reduction. For example, we could use pio2_hi = 0x1.921f00p+0
, and pio2_lo = 0x1.6a8886p-17
. Note the eight trailing zero bits in single-precision representation ofpio2_hi
, which allow us to multiply with any 8-bit integer i
and still have the product i * pio2_hi
representable exactly as a single-precision number. When we compute ((x - i * pio2_hi) - i * pio2_lo)
, we get reduced_x = -0x1.8eafb4p-4
, and therefore sin(x) = -0x1.8e0e9ep-4
, a quite accurate result.
The best way to split the constant into a sum will depend on the magnitude of i
we need to handle, on the maximum number of bits subject to subtractive cancellation for a given argument range (based on how close integer multiples of π/2 can get to integers), and performance considerations. Typical real-life use cases involve two- to four-stage Cody-Waite reduction schemes. The availability of fused multiple-add (FMA) allows the use of constituent constants with fewer trailing zero bits. See this paper: Sylvie Boldo, Marc Daumas, and Ren-Cang Li, "Formally verified argument reduction with a fused multiply-add." IEEE Transactions on Computers, 58 :1139–1145, 2009. For a worked example using fmaf()
you might want to look at the code in one of my previous answers.
QUESTION
Are there any pure-python implementations of the inverse error function?
I know that SciPy has scipy.special.erfinv(), but that relies on some C extensions. I'd like a pure python implementation.
I've tried writing my own using the Wikipedia and Wolfram references, but it always seems to diverge from the true value when the arg is > 0.9.
I've also attempted to port the underlying C code that Scipy uses (ndtri.c
and the cephes polevl.c
functions) but that's also not passing my unit tests.
Edit: As requested, I've added the ported code.
Docstrings (and doctests) have been removed because they're longer than the functions. I haven't yet put much effort into making the port more pythonic - I'll worry about that once I get something that passes unit tests.
Supporting functions from cephespolevl.c
...ANSWER
Answered 2017-Feb-22 at 02:12sympy? some digging may be needed to see how its implemented internally http://docs.sympy.org/latest/modules/functions/special.html#sympy.functions.special.error_functions.erfinv
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cephes
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page