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.
Merge pull request #4 from Cactus-proj/dev
cephes: init bessel && gamma tests
- Loading branch information
Showing
37 changed files
with
687 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Gamma Functions | ||
|
||
## Airy Functions | ||
|
||
* **fac**, [Factorial function](doubldoc.md#fac) | ||
* **gamma**, [Gamma function](doubldoc.md#gamma) | ||
* **lgam**, [Natural logarithm of gamma function](doubldoc.md#lgam) | ||
* **igam**, [Incomplete gamma integral](doubldoc.md#igam) | ||
* **igamc**, [Complemented incomplete gamma integral](doubldoc.md#igamc) | ||
* **igami**, [Inverse of complemented imcomplete gamma integral](doubldoc.md#igami) | ||
* **incbet**, [Incomplete beta integral](doubldoc.md#incbet) | ||
* **incbi**, [Inverse of imcomplete beta integral](doubldoc.md#incbi) | ||
* **psi**, [Psi (digamma) function](doubldoc.md#psi) | ||
* **rgamma**, [Reciprocal gamma function](doubldoc.md#rgamma) | ||
|
||
## Beta Functions | ||
|
||
* **beta**, [Beta function](doubldoc.md#beta) |
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
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 @@ | ||
#ifndef CEPHES_GAMMA_H | ||
/** Cephes double precision special functions suite | ||
* | ||
* cephes/bessel | ||
*/ | ||
#define CEPHES_GAMMA_H | ||
|
||
namespace cephes { | ||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
/** Gamma Functions */ | ||
/* misc/fac.c */ | ||
double fac(int i); | ||
|
||
/* cprob/gamma.c */ | ||
double gamma(double x); | ||
double lgam(double x); | ||
/* cprob/igam.c */ | ||
double igam(double a, double x); | ||
double igamc(double a, double x); | ||
/* cprob/igami.c */ | ||
double igami(double a, double y0_); | ||
/* cprob/incbet.c */ | ||
double incbet(double aa, double bb, double xx); | ||
/* cprob/incbi.c */ | ||
double incbi(double aa, double bb, double yy0); | ||
|
||
/* misc/psi.c */ | ||
double psi(double x); | ||
/* misc/rgamma.c */ | ||
double rgamma(double x); | ||
|
||
/** Beta Functions */ | ||
/* misc/beta.c */ | ||
double beta(double a, double b); | ||
|
||
#if defined(__cplusplus) | ||
} // extern "C" | ||
#endif | ||
}; // ::cephes | ||
|
||
#endif // CEPHES_GAMMA_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,3 +1,26 @@ | ||
|
||
add_gtest(airy) | ||
|
||
add_gtest(j0) | ||
add_gtest(j1) | ||
add_gtest(jn) | ||
add_gtest(jv) | ||
|
||
add_gtest(i0) | ||
add_gtest(i0e) | ||
add_gtest(i1) | ||
add_gtest(i1e) | ||
add_gtest(iv) | ||
|
||
add_gtest(y0) | ||
add_gtest(y1) | ||
add_gtest(yn) | ||
|
||
add_gtest(k0) | ||
add_gtest(k0e) | ||
add_gtest(k1) | ||
add_gtest(k1e) | ||
add_gtest(kn) | ||
|
||
add_gtest(psi) | ||
add_gtest(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
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,20 @@ | ||
#include <xtest.hpp> | ||
#include <cephes/bessel.h> | ||
|
||
|
||
TEST(BesselI0, Branches) { | ||
EXPECT_REL_NEAR_F64(cephes::i0(0.0), 1.0); | ||
|
||
// x < 0 | ||
EXPECT_REL_NEAR_F64(cephes::i0(-0.0), 1.0); | ||
EXPECT_REL_NEAR_F64(cephes::i0(-10.0), 2815.716628466253); | ||
|
||
// x <= 8.0 | ||
EXPECT_REL_NEAR_F64(cephes::i0(1.0), 1.266065877752008); | ||
EXPECT_REL_NEAR_F64(cephes::i0(8.0), 427.5641157218048); | ||
|
||
// x > 8.0 | ||
EXPECT_REL_NEAR_F64(cephes::i0(9.0), 1093.588354511374); | ||
EXPECT_REL_NEAR_F64(cephes::i0(10.0), 2815.716628466253); | ||
EXPECT_REL_NEAR_F64(cephes::i0(100.0), 1.073751707131074e42); | ||
} |
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,23 @@ | ||
#include <xtest.hpp> | ||
#include <cephes/bessel.h> | ||
|
||
/** | ||
Table[NumberForm[Exp[-Abs[x]]*BesselI[nv, x], 16], | ||
{x, {0.0, -10., 1.0, 8.0, 9.0, 10.0, 100.}}, {nv, {0}}] | ||
*/ | ||
TEST(BesselI0Exp, Branches) { | ||
EXPECT_REL_NEAR_F64(cephes::i0e(0.0), 1.0); | ||
|
||
// x < 0 | ||
EXPECT_REL_NEAR_F64(cephes::i0e(-0.0), 1.0); | ||
EXPECT_REL_NEAR_F64(cephes::i0e(-10.0), 0.1278333371634286); | ||
|
||
// x <= 8.0 | ||
EXPECT_REL_NEAR_F64(cephes::i0e(1.0), 0.4657596075936404); | ||
EXPECT_REL_NEAR_F64(cephes::i0e(8.0), 0.1434317818568503); | ||
|
||
// x > 8.0 | ||
EXPECT_REL_NEAR_F64(cephes::i0e(9.0), 0.134959524581723); | ||
EXPECT_REL_NEAR_F64(cephes::i0e(10.0), 0.1278333371634286); | ||
EXPECT_REL_NEAR_F64(cephes::i0e(100.0), 0.03994437929909669); | ||
} |
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,23 @@ | ||
#include <xtest.hpp> | ||
#include <cephes/bessel.h> | ||
|
||
/* | ||
Table[NumberForm[BesselI[1, x], 16], | ||
{x, {0.0, -10., 1.0, 8.0, 9.0, 10.0, 100.}}] | ||
*/ | ||
TEST(BesselI1, Branches) { | ||
EXPECT_REL_NEAR_F64(cephes::i1(0.0), 0.0); | ||
|
||
// x < 0 | ||
EXPECT_REL_NEAR_F64(cephes::i1(-0.0), 0.0); | ||
EXPECT_REL_NEAR_F64(cephes::i1(-10.0), -2670.988303701254); | ||
|
||
// x <= 8.0 | ||
EXPECT_REL_NEAR_F64(cephes::i1(1.0), 0.5651591039924851); | ||
EXPECT_REL_NEAR_F64(cephes::i1(8.0), 399.8731367825601); | ||
|
||
// x > 8.0 | ||
EXPECT_REL_NEAR_F64(cephes::i1(9.0), 1030.914722516956); | ||
EXPECT_REL_NEAR_F64(cephes::i1(10.0), 2670.988303701254); | ||
EXPECT_REL_NEAR_F64(cephes::i1(100.0), 1.068369390338163e+42); | ||
} |
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,23 @@ | ||
#include <xtest.hpp> | ||
#include <cephes/bessel.h> | ||
|
||
/** | ||
Table[NumberForm[Exp[-Abs[x]]*BesselI[1, x], 16], | ||
{x, {0.0, -10., 1.0, 8.0, 9.0, 10.0, 100.}}] | ||
*/ | ||
TEST(BesselI1Exp, Branches) { | ||
EXPECT_REL_NEAR_F64(cephes::i1e(0.0), 0.0); | ||
|
||
// x < 0 | ||
EXPECT_REL_NEAR_F64(cephes::i1e(-0.0), 0.0); | ||
// EXPECT_REL_NEAR_F64(cephes::i1e(-10.0), ); | ||
|
||
// // x <= 8.0 | ||
// EXPECT_REL_NEAR_F64(cephes::i1e(1.0), ); | ||
// EXPECT_REL_NEAR_F64(cephes::i1e(8.0), ); | ||
|
||
// // x > 8.0 | ||
// EXPECT_REL_NEAR_F64(cephes::i1e(9.0), ); | ||
// EXPECT_REL_NEAR_F64(cephes::i1e(10.0), ); | ||
// EXPECT_REL_NEAR_F64(cephes::i1e(100.0), ); | ||
} |
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,26 @@ | ||
#include <xtest.hpp> | ||
#include <cephes/bessel.h> | ||
|
||
/** | ||
Table[NumberForm[Exp[-Abs[x]]*BesselI[nv, x], 16], | ||
{nv, {0, 1}}, | ||
{x, {0.0, 1.0, 8.0, 9.0, 1.0, 100.}}] | ||
*/ | ||
TEST(BesselIv, Branches) { | ||
EXPECT_REL_NEAR_F64(cephes::iv(0, 0.0), 1.0); | ||
EXPECT_REL_NEAR_F64(cephes::iv(1, 0.0), 0.0); | ||
EXPECT_REL_NEAR_F64(cephes::iv(-1, 0.0), 0.0); | ||
|
||
// x < 0 | ||
EXPECT_REL_NEAR_F64(cephes::iv(0, -0.0), 1.0); | ||
// EXPECT_REL_NEAR_F64(cephes::iv(-10.0), ); | ||
|
||
// // x <= 8.0 | ||
// EXPECT_REL_NEAR_F64(cephes::iv(1.0), ); | ||
// EXPECT_REL_NEAR_F64(cephes::iv(8.0), ); | ||
|
||
// // x > 8.0 | ||
// EXPECT_REL_NEAR_F64(cephes::iv(9.0), ); | ||
// EXPECT_REL_NEAR_F64(cephes::iv(10.0), ); | ||
// EXPECT_REL_NEAR_F64(cephes::iv(100.0), ); | ||
} |
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
Oops, something went wrong.