forked from google-deepmind/torch-cephes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #3 from Cactus-proj/dev
test: exp_int & bessel/Airy
Showing
10 changed files
with
370 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# cephes/bessel | ||
|
||
## Airy Functions | ||
|
||
* **airy**, [Airy functions](doubldoc.md#airy) | ||
|
||
## Hypergeometric Functions | ||
|
||
* **hyp2f1**, [Gauss hypergeometric function](doubldoc.md#hyp2f1) | ||
* **hyperg**, [Confluent hypergeometric function](doubldoc.md#hyperg) | ||
|
||
## Bessel functions | ||
|
||
* **j0**, [Bessel function of order zero](doubldoc.md#j0) | ||
* **j1**, [Bessel function of order one](doubldoc.md#j1) | ||
* **jn**, [Bessel function of integer order](doubldoc.md#jn) | ||
* **jv**, [Bessel function of noninteger order](doubldoc.md#jv) | ||
|
||
## Modified Bessel functions | ||
|
||
* **i0**, [Modified Bessel function of order zero](doubldoc.md#i0) | ||
* **i0e**, [Exponentially scaled modified Bessel function of order zero](doubldoc.md#i0e) | ||
* **i1**, [Modified Bessel function of order one](doubldoc.md#i1) | ||
* **i1e**, [Exponentially scaled modified Bessel function of order one](doubldoc.md#i1e) | ||
* **iv**, [Modified Bessel function of noninteger order](doubldoc.md#iv) | ||
|
||
## Modified Bessel functions - second kind | ||
|
||
* **y0**, [Bessel function of the second kind, order zero](doubldoc.md#y0) | ||
* **y1**, [Bessel function of the second kind, order one](doubldoc.md#y1) | ||
* **yn**, [Bessel function of second kind of integer order](doubldoc.md#yn) | ||
|
||
## Modified Bessel functions - third kind | ||
|
||
* **k0**, [Modified Bessel function, third kind, order zero](doubldoc.md#k0) | ||
* **k0e**, [Modified Bessel function, third kind, order zero, exponentially scaled](doubldoc.md#k0e) | ||
* **k1**, [Modified Bessel function, third kind, order one](doubldoc.md#k1) | ||
* **k1e**, [Modified Bessel function, third kind, order one, exponentially scaled](doubldoc.md#k1e) | ||
* **kn**, [Modified Bessel function, third kind, integer order](doubldoc.md#kn) | ||
|
||
## Others | ||
|
||
* **psi**, [Psi (digamma) function](doubldoc.md#psi) | ||
* **struve**, [Struve function](doubldoc.md#struve) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# cephes/Exponential integral | ||
|
||
* **expn**, [Exponential integral En](doubldoc.md#expn) | ||
|
||
## Sine and Cosine integral | ||
|
||
* **sici**, [Sine and cosine integrals](doubldoc.md#sici) | ||
* **shichi**, [Hyperbolic sine and cosine integrals](doubldoc.md#shichi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,51 @@ | ||
#ifndef CEPHES_DOUBLE_H | ||
/** Cephes double precision special functions suite */ | ||
#define CEPHES_DOUBLE_H | ||
#ifndef CEPHES_BESSEL_H | ||
/** Cephes double precision special functions suite | ||
* | ||
* cephes/bessel | ||
*/ | ||
#define CEPHES_BESSEL_H | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
/** cephes/bessel */ | ||
|
||
/** Airy Functions */ | ||
int airy(double x, double *ai, double *aip, double *bi, double *bip); | ||
|
||
/** Hypergeometric Functions */ | ||
double hyp2f1(double a, double b, double c, double x); | ||
double hyperg(double a, double b, double x); | ||
double hyp2f0(double a, double b, double x, int type, double *err); | ||
|
||
/** Bessel functions */ | ||
double j0(double x); | ||
double j1(double x); | ||
double jn(int n, double x); | ||
double jv(double n, double x); | ||
|
||
/** Modified Bessel functions */ | ||
double i0(double x); | ||
double i0e(double x); | ||
double i1(double x); | ||
double i1e(double x); | ||
double iv(double v, double x); | ||
|
||
double j0(double x); | ||
/** Modified Bessel functions - second kind */ | ||
double y0(double x); | ||
double j1(double x); | ||
double y1(double x); | ||
double jn(int n, double x); | ||
double jv(double n, double x); | ||
double yn(int n, double x); | ||
|
||
/** Modified Bessel functions - third kind */ | ||
double k0(double x); | ||
double k0e(double x); | ||
double k1(double x); | ||
double k1e(double x); | ||
double kn(int nn, double x); | ||
|
||
/** Others */ | ||
double psi(double x); | ||
|
||
double onef2(double a, double b, double c, double x, double *err); | ||
double threef0(double a, double b, double c, double x, double *err); | ||
double struve(double v, double x); | ||
double yv(double v, double x); | ||
|
||
double yn(int n, double x); | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
#endif // CEPHES_DOUBLE_H | ||
#endif // CEPHES_BESSEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef CEPHES_EXP_INT_H | ||
/** Cephes double precision special functions suite | ||
* | ||
* cephes/Exponential integral | ||
*/ | ||
#define CEPHES_EXP_INT_H | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
/** Exponential integral */ | ||
/* misc/expn.c */ | ||
double expn(int n, double x); | ||
|
||
/** Sine and Cosine integral */ | ||
/* misc/sici.c */ | ||
int sici(double x, double *si, double *ci); | ||
/** misc/shichi.c */ | ||
int shichi(double x, double *si, double *ci); | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
#endif // CEPHES_EXP_INT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,78 @@ | ||
#include <limits> | ||
#include <complex> | ||
#include <gtest/gtest.h> | ||
#include <cephes/double.h> | ||
#include <cephes/bessel.h> | ||
#include <xtest.hpp> | ||
|
||
TEST(Airy, BasicAssertions) { | ||
const double nan64 = std::numeric_limits<double>::quiet_NaN(); | ||
int ret; | ||
double x, ai, aip, bi, bip; | ||
const double nan64 = std::numeric_limits<double>::quiet_NaN(); | ||
int ret; | ||
double x, ai, aip, bi, bip; | ||
|
||
x = 26.0; | ||
ret = airy(x, &ai, &aip, &bi, &bip); | ||
EXPECT_EQ(ret, -1); | ||
EXPECT_EQ(ai, 0.0); | ||
EXPECT_EQ(aip, 0.0); | ||
EXPECT_TRUE(bi > 1e308); | ||
EXPECT_TRUE(bip > 1e308); | ||
x = 26.0; | ||
ret = airy(x, &ai, &aip, &bi, &bip); | ||
EXPECT_EQ(ret, -1); | ||
EXPECT_EQ(ai, 0.0); | ||
EXPECT_EQ(aip, 0.0); | ||
EXPECT_TRUE(bi > 1e308); | ||
EXPECT_TRUE(bip > 1e308); | ||
} | ||
|
||
TEST(Airy, Branches) { | ||
int ret; | ||
double x, ai, aip, bi, bip, ref; | ||
double ai_ref, aip_ref, bi_ref, bip_ref; | ||
|
||
// x < -2.09 | ||
x = -3.0; | ||
ret = airy(x, &ai, &aip, &bi, &bip); | ||
EXPECT_EQ(ret, 0); | ||
/* | ||
x = -3.0; | ||
{NumberForm[AiryAi[x], 16], NumberForm[AiryAiPrime[x], 16], | ||
NumberForm[AiryBi[x], 16], NumberForm[AiryBiPrime[x], 16]} | ||
*/ | ||
ai_ref = -0.378814293677658; | ||
aip_ref = 0.3145837692165989; | ||
bi_ref = -0.1982896263749266; | ||
bip_ref = -0.6756112226852585; | ||
XTEST_ISAPPROX_F64(ai); | ||
XTEST_ISAPPROX_F64(aip); | ||
XTEST_ISAPPROX_F64(bi); | ||
XTEST_ISAPPROX_F64(bip); | ||
|
||
// x >= 2.09 (cbrt(9)) | ||
x = 5.0; | ||
ret = airy(x, &ai, &aip, &bi, &bip); | ||
EXPECT_EQ(ret, 0); | ||
/* | ||
x = 5.0; | ||
{NumberForm[AiryAi[x], 16], NumberForm[AiryAiPrime[x], 16], | ||
NumberForm[AiryBi[x], 16], NumberForm[AiryBiPrime[x], 16]} | ||
*/ | ||
ai_ref = 0.0001083444281360744; | ||
aip_ref = -0.0002474138908684624; | ||
bi_ref = 657.7920441711713; | ||
bip_ref = 1435.81908021797; | ||
XTEST_ISAPPROX_F64(ai); | ||
XTEST_ISAPPROX_F64(aip); | ||
XTEST_ISAPPROX_F64(bi); | ||
XTEST_ISAPPROX_F64(bip); | ||
|
||
// x > 8.3203353 | ||
x = 8.5; | ||
ret = airy(x, &ai, &aip, &bi, &bip); | ||
EXPECT_EQ(ret, 0); | ||
/* | ||
x = 8.5; | ||
{NumberForm[AiryAi[x], 16], NumberForm[AiryAiPrime[x], 16], | ||
NumberForm[AiryBi[x], 16], NumberForm[AiryBiPrime[x], 16]} | ||
*/ | ||
ai_ref = 1.099700975519552e-8; | ||
aip_ref = -3.237725440447604e-8; | ||
bi_ref = 4.965319541471301e6; | ||
bip_ref = 1.432630103066198e7; | ||
XTEST_ISAPPROX_F64(ai); | ||
XTEST_ISAPPROX_F64(aip); | ||
XTEST_ISAPPROX_F64(bi); | ||
XTEST_ISAPPROX_F64(bip); | ||
} |
Oops, something went wrong.