Skip to content

Commit a544ee2

Browse files
authored
Merge pull request #14 from steppi/catch-test-setup
TST: Add data driven tests based on `xsref` parquet files using Catch2
2 parents 4269ce7 + c096091 commit a544ee2

File tree

191 files changed

+5041
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+5041
-164
lines changed
File renamed without changes.

.github/workflows/linux.yml

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,65 @@
11
name: Linux Tests
22

3-
on:
4-
push:
5-
branches:
6-
- main
7-
- catch-test-setup
8-
pull_request:
9-
- main
10-
- catch-test-setup
3+
on: [ push, pull_request ]
4+
5+
permissions:
6+
contents: read # to fetch code (actions/checkout)
7+
8+
env:
9+
CCACHE_DIR: "${{ github.workspace }}/.ccache"
10+
INSTALLDIR: "build-install"
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
gcc_x86_64_linux:
18+
name: GCC X86_64 Linux
19+
runs-on: ubuntu-22.04
20+
env:
21+
XSREF_TABLES_PATH: "${{ github.workspace }}/xsref/tables"
22+
23+
steps:
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
- name: Checkout xsref
26+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
27+
with:
28+
repository: 'scipy/xsref'
29+
path: 'xsref'
30+
ref: 'main'
31+
32+
- name: Checkout Catch2
33+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
34+
with:
35+
repository: 'catchorg/Catch2'
36+
path: 'Catch2'
37+
ref: 'v3.8.0'
38+
39+
- name: Install Ubuntu dependencies
40+
run: |
41+
sudo apt-get update
42+
wget https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
43+
sudo apt-get install -y -V ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
44+
sudo apt-get update
45+
sudo apt-get install -y -V libarrow-dev # For C++
46+
sudo apt-get install -y -V libarrow-glib-dev # For GLib (C)
47+
sudo apt-get install -y -V libarrow-dataset-dev # For Apache Arrow Dataset C++
48+
sudo apt-get install -y -V libparquet-dev # For Apache Parquet C++
49+
sudo apt-get install -y -V libparquet-glib-dev # For Apache Parquet GLib (C)
50+
sudo apt-get install -y libzstd-dev ccache
51+
52+
- name: Install Catch2
53+
run: |
54+
cmake -Bbuild -H. -DBUILD_TESTING=OFF
55+
sudo cmake --build build/ --target install
56+
working-directory: ./Catch2
57+
58+
- name: Configure and build
59+
run: |
60+
cmake .
61+
make
62+
63+
- name: run tests
64+
run: |
65+
ctest --output-on-failure

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,22 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
# CMake stuff
35+
CMakeLists.txt.user
36+
CMakeCache.txt
37+
CMakeFiles
38+
CMakeScripts
39+
Testing
40+
Makefile
41+
cmake_install.cmake
42+
install_manifest.txt
43+
compile_commands.json
44+
CTestTestfile.cmake
45+
_deps
46+
CMakeUserPresets.json
47+
*.cmake
48+
DartConfiguration.tcl
49+
50+
# test executable extension
51+
*.test

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(xsf)
3+
4+
# Scipy is restricted to C++17
5+
# https://docs.scipy.org/doc/scipy/dev/toolchain.html#c-language-standards
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
9+
# Tests
10+
enable_testing()
11+
add_subdirectory(tests)

include/xsf/cephes/cbrt.h

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -52,80 +52,81 @@ namespace cephes {
5252

5353
namespace detail {
5454

55-
constexpr double CBRT2 = 1.2599210498948731647672;
56-
constexpr double CBRT4 = 1.5874010519681994747517;
57-
constexpr double CBRT2I = 0.79370052598409973737585;
58-
constexpr double CBRT4I = 0.62996052494743658238361;
55+
inline constexpr double CBRT2 = 1.2599210498948731647672;
56+
inline constexpr double CBRT4 = 1.5874010519681994747517;
57+
inline constexpr double CBRT2I = 0.79370052598409973737585;
58+
inline constexpr double CBRT4I = 0.62996052494743658238361;
5959

60-
XSF_HOST_DEVICE inline double cbrt(double x) {
61-
int e, rem, sign;
62-
double z;
60+
}
6361

64-
if (!std::isfinite(x)) {
65-
return x;
66-
}
67-
if (x == 0) {
68-
return (x);
69-
}
70-
if (x > 0) {
71-
sign = 1;
72-
} else {
73-
sign = -1;
74-
x = -x;
75-
}
62+
XSF_HOST_DEVICE inline double cbrt(double x) {
63+
int e, rem, sign;
64+
double z;
7665

77-
z = x;
78-
/* extract power of 2, leaving
79-
* mantissa between 0.5 and 1
80-
*/
81-
x = std::frexp(x, &e);
66+
if (!std::isfinite(x)) {
67+
return x;
68+
}
69+
if (x == 0) {
70+
return (x);
71+
}
72+
if (x > 0) {
73+
sign = 1;
74+
} else {
75+
sign = -1;
76+
x = -x;
77+
}
78+
79+
z = x;
80+
/* extract power of 2, leaving
81+
* mantissa between 0.5 and 1
82+
*/
83+
x = std::frexp(x, &e);
84+
85+
/* Approximate cube root of number between .5 and 1,
86+
* peak relative error = 9.2e-6
87+
*/
88+
x = (((-1.3466110473359520655053e-1 * x + 5.4664601366395524503440e-1) * x - 9.5438224771509446525043e-1) *
89+
x +
90+
1.1399983354717293273738e0) *
91+
x +
92+
4.0238979564544752126924e-1;
93+
94+
/* exponent divided by 3 */
95+
if (e >= 0) {
96+
rem = e;
97+
e /= 3;
98+
rem -= 3 * e;
99+
if (rem == 1) {
100+
x *= detail::CBRT2;
101+
} else if (rem == 2) {
102+
x *= detail::CBRT4;
103+
}
104+
}
105+
/* argument less than 1 */
106+
else {
107+
e = -e;
108+
rem = e;
109+
e /= 3;
110+
rem -= 3 * e;
111+
if (rem == 1) {
112+
x *= detail::CBRT2I;
113+
} else if (rem == 2) {
114+
x *= detail::CBRT4I;
115+
}
116+
e = -e;
117+
}
82118

83-
/* Approximate cube root of number between .5 and 1,
84-
* peak relative error = 9.2e-6
85-
*/
86-
x = (((-1.3466110473359520655053e-1 * x + 5.4664601366395524503440e-1) * x - 9.5438224771509446525043e-1) *
87-
x +
88-
1.1399983354717293273738e0) *
89-
x +
90-
4.0238979564544752126924e-1;
119+
/* multiply by power of 2 */
120+
x = std::ldexp(x, e);
121+
122+
/* Newton iteration */
123+
x -= (x - (z / (x * x))) * 0.33333333333333333333;
124+
x -= (x - (z / (x * x))) * 0.33333333333333333333;
91125

92-
/* exponent divided by 3 */
93-
if (e >= 0) {
94-
rem = e;
95-
e /= 3;
96-
rem -= 3 * e;
97-
if (rem == 1) {
98-
x *= CBRT2;
99-
} else if (rem == 2) {
100-
x *= CBRT4;
101-
}
102-
}
103-
/* argument less than 1 */
104-
else {
105-
e = -e;
106-
rem = e;
107-
e /= 3;
108-
rem -= 3 * e;
109-
if (rem == 1) {
110-
x *= CBRT2I;
111-
} else if (rem == 2) {
112-
x *= CBRT4I;
113-
}
114-
e = -e;
115-
}
116-
117-
/* multiply by power of 2 */
118-
x = std::ldexp(x, e);
119-
120-
/* Newton iteration */
121-
x -= (x - (z / (x * x))) * 0.33333333333333333333;
122-
x -= (x - (z / (x * x))) * 0.33333333333333333333;
123-
124-
if (sign < 0)
125-
x = -x;
126-
return (x);
127-
}
128-
} // namespace detail
126+
if (sign < 0)
127+
x = -x;
128+
return (x);
129+
}
129130

130131
} // namespace cephes
131132
} // namespace xsf

include/xsf/cephes/exp10.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#include "../config.h"
5858
#include "../error.h"
5959

60+
#include "polevl.h"
61+
6062
namespace xsf {
6163
namespace cephes {
6264

include/xsf/cephes/gdtr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace cephes {
111111
XSF_HOST_DEVICE inline double gdtr(double a, double b, double x) {
112112

113113
if (x < 0.0) {
114-
sf_error("gdtr", SF_ERROR_DOMAIN, NULL);
114+
set_error("gdtr", SF_ERROR_DOMAIN, NULL);
115115
return (std::numeric_limits<double>::quiet_NaN());
116116
}
117117
return (igam(b, a * x));
@@ -129,7 +129,7 @@ namespace cephes {
129129
XSF_HOST_DEVICE inline double gdtri(double a, double b, double y) {
130130

131131
if ((y < 0.0) || (y > 1.0) || (a <= 0.0) || (b < 0.0)) {
132-
sf_error("gdtri", SF_ERROR_DOMAIN, NULL);
132+
set_error("gdtri", SF_ERROR_DOMAIN, NULL);
133133
return (std::numeric_limits<double>::quiet_NaN());
134134
}
135135

include/xsf/cephes/ndtr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
#pragma once
136136

137137
#include "../config.h"
138+
#include "../error.h"
138139

139140
#include "const.h"
140141
#include "polevl.h"

include/xsf/cephes/shichi.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace cephes {
151151
} // namespace detail
152152

153153
/* Sine and cosine integrals */
154-
XSF_HOST_DEVICE inline int shichi(double x, double *si, double *ci) {
154+
XSF_HOST_DEVICE inline int shichi(double x, double &si, double &ci) {
155155
double k, z, c, s, a, b;
156156
short sign;
157157

@@ -163,8 +163,8 @@ namespace cephes {
163163
}
164164

165165
if (x == 0.0) {
166-
*si = 0.0;
167-
*ci = -std::numeric_limits<double>::infinity();
166+
si = 0.0;
167+
ci = -std::numeric_limits<double>::infinity();
168168
return (0);
169169
}
170170

@@ -216,20 +216,20 @@ namespace cephes {
216216

217217
asymp:
218218
if (x > 1000) {
219-
*si = std::numeric_limits<double>::infinity();
220-
*ci = std::numeric_limits<double>::infinity();
219+
si = std::numeric_limits<double>::infinity();
220+
ci = std::numeric_limits<double>::infinity();
221221
} else {
222222
/* Asymptotic expansions
223223
* http://functions.wolfram.com/GammaBetaErf/CoshIntegral/06/02/
224224
* http://functions.wolfram.com/GammaBetaErf/SinhIntegral/06/02/0001/
225225
*/
226226
a = detail::hyp3f0(0.5, 1, 1, 4.0 / (x * x));
227227
b = detail::hyp3f0(1, 1, 1.5, 4.0 / (x * x));
228-
*si = std::cosh(x) / x * a + std::sinh(x) / (x * x) * b;
229-
*ci = std::sinh(x) / x * a + std::cosh(x) / (x * x) * b;
228+
si = std::cosh(x) / x * a + std::sinh(x) / (x * x) * b;
229+
ci = std::sinh(x) / x * a + std::cosh(x) / (x * x) * b;
230230
}
231231
if (sign) {
232-
*si = -*si;
232+
si = -si;
233233
}
234234
return 0;
235235

@@ -238,9 +238,9 @@ namespace cephes {
238238
s = -s;
239239
}
240240

241-
*si = s;
241+
si = s;
242242

243-
*ci = detail::SCIPY_EULER + std::log(x) + c;
243+
ci = detail::SCIPY_EULER + std::log(x) + c;
244244
return (0);
245245
}
246246

0 commit comments

Comments
 (0)