Skip to content

Commit

Permalink
add rootn tests highlighting incomplete implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkichler committed Feb 29, 2024
1 parent d802701 commit ffde18a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/cuinterval/arithmetic/basic.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

// IEEE Std 1788.1-2017, Table 4.1

// TODO: next up: pi test through looping

template<typename T>
__device__ interval<T> pos_inf()
{
Expand Down
32 changes: 32 additions & 0 deletions tests/itl/intervalarithmeticjl.itl
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,35 @@ testcase iajl_tan {
tan [1.67, 3.2] = [-10.047182299210307, 0.05847385445957865];
tan [6.638314112824137, 8.38263151220128] = [entire];
}

testcase iajl_rootn {
rootn [empty] 3 = [empty];
rootn [empty] 4 = [empty];
rootn [empty] -3 = [empty];
rootn [empty] -4 = [empty];
rootn [1, 2] 0 = [empty];
rootn [5, 8] 0 = [empty];
rootn [1, 7] 0 = [empty];
rootn [8, 27] 3 = [2, 3];
rootn [0, 27] 3 = [0, 3];
// rootn [-27, 0] 3 = [-3, 0];
// rootn [-27, 27] 3 = [-3, 3];
// rootn [-27, -8] 3 = [-3, -2];
rootn [16, 81] 4 = [2, 3];
rootn [0, 81] 4 = [0, 3];
// rootn [-81, 0] 4 = [0, 0];
// rootn [-81, 81] 4 = [0, 3];
// rootn [-81, -16] 4 = [empty];
// rootn [8, 27] -3 = [1/3, 1/2];
// rootn [0, 27] -3 = [1/3, infinity];
// rootn [-27, 0] -3 = [-infinity, -1/3];
// rootn [-27, 27] -3 = [-infinity, infinity];
// rootn [-27, -8] -3 = [-1/2, -1/3];
// rootn [16, 81] -4 = [1/3, 1/2];
// rootn [0, 81] -4 = [1/3, infinity];
// rootn [-81, 0] -4 = [empty];
// rootn [-81, 1] 1 = [-81, 1];
// rootn [-81, 81] -4 = [1/3, infinity];
// rootn [-81, -16] -4 = [empty];
// rootn [-81, -16] 1 = [-81, -16];
}
66 changes: 65 additions & 1 deletion tests/tests_intervalarithmeticjl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ void tests_intervalarithmeticjl() {
};

"iajl_tan_tan"_test = [&] {
constexpr int n = 3;
constexpr int n = 4;
std::array<I, n> h_xs {{
{0.5,0.5},
{0.5,1.67},
{1.67,3.2},
{6.638314112824137,8.38263151220128},
}};

std::array<I, n> h_res{};
Expand All @@ -144,6 +145,7 @@ void tests_intervalarithmeticjl() {
{0.54630248984379048,0.5463024898437906},
entire,
{-10.047182299210307,0.05847385445957865},
entire,
}};

CUDA_CHECK(cudaMemcpy(d_xs, h_xs.data(), n_bytes, cudaMemcpyHostToDevice));
Expand All @@ -158,6 +160,68 @@ void tests_intervalarithmeticjl() {
}
};

"iajl_rootn_rootn"_test = [&] {
constexpr int n = 11;
std::array<I, n> h_xs {{
{0,27},
{0,81},
{1,2},
{1,7},
{16,81},
{5,8},
{8,27},
empty,
empty,
empty,
empty,
}};

std::array<N, n> h_ys {{
3,
4,
0,
0,
4,
0,
3,
-3,
-4,
3,
4,
}};

std::array<I, n> h_res{};
I *d_res = (I *)d_res_;
I *d_xs = (I *)d_xs_;
N *d_ys = (N *)d_ys_;
int n_result_bytes = n * sizeof(I);
std::array<I, n> h_ref {{
{0,3},
{0,3},
empty,
empty,
{2,3},
empty,
{2,3},
empty,
empty,
empty,
empty,
}};

CUDA_CHECK(cudaMemcpy(d_xs, h_xs.data(), n_bytes, cudaMemcpyHostToDevice));
CUDA_CHECK(cudaMemcpy(d_ys, h_ys.data(), n_bytes, cudaMemcpyHostToDevice));
CUDA_CHECK(cudaMemcpy(d_res, h_res.data(), n_result_bytes, cudaMemcpyHostToDevice));
test_rootn<<<numBlocks, blockSize>>>(n, d_xs, d_ys, d_res);
CUDA_CHECK(cudaMemcpy(h_res.data(), d_res, n_result_bytes, cudaMemcpyDeviceToHost));
int max_ulp_diff = 2;
auto failed = check_all_equal<I, n>(h_res, h_ref, max_ulp_diff);
for (auto fail_id : failed) {
printf("failed at case %zu:\n", fail_id);
printf("x = [%a, %a]\ny = %d\n", h_xs[fail_id].lb, h_xs[fail_id].ub, h_ys[fail_id]);
}
};


CUDA_CHECK(cudaFree(d_xs_));
CUDA_CHECK(cudaFree(d_ys_));
Expand Down

0 comments on commit ffde18a

Please sign in to comment.