Skip to content

Commit

Permalink
added pown
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkichler committed Feb 28, 2024
1 parent a06f740 commit 13d47ab
Show file tree
Hide file tree
Showing 22 changed files with 586 additions and 19 deletions.
40 changes: 23 additions & 17 deletions include/cuinterval/arithmetic/basic.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -671,31 +671,34 @@ __device__ interval<T> pown(interval<T> x, std::integral auto n)
return empty<T>();
}

using intrinsic::next_floating;
using intrinsic::prev_floating;

if (n % 2) { // odd power
if (entire(x)) {
return x;
}

if (n > 0) {
if (inf(x) == 0) {
return { 0, pow(sup(x), n) }; // TODO: rounding
return { 0, next_floating(pow(sup(x), n)) };
} else if (sup(x) == 0) {
return { pow(inf(x), n), 0 }; // TODO: rounding
return { prev_floating(pow(inf(x), n)), 0 };
} else {
return { pow(inf(x), n), pow(sup(x), n) }; // TODO: rounding
return { prev_floating(pow(inf(x), n)), next_floating(pow(sup(x), n)) };
}
} else {
if (inf(x) >= 0) {
if (inf(x) == 0) {
return { pow(sup(x), n), intrinsic::pos_inf<T>() }; // TODO: rounding
return { prev_floating(pow(sup(x), n)), next_floating(intrinsic::pos_inf<T>()) };
} else {
return { pow(sup(x), n), pow(inf(x), n) }; // TODO: rounding
return { prev_floating(pow(sup(x), n)), next_floating(pow(inf(x), n)) };
}
} else if (sup(x) <= 0) {
if (sup(x) == 0) {
return { intrinsic::neg_inf<T>(), pow(inf(x), n) }; // TODO: rounding
return { prev_floating(intrinsic::neg_inf<T>()), next_floating(pow(inf(x), n)) };
} else {
return { pow(sup(x), n), pow(inf(x), n) }; // TODO: rounding
return { prev_floating(pow(sup(x), n)), next_floating(pow(inf(x), n)) };
}
} else {
return entire<T>();
Expand All @@ -704,19 +707,19 @@ __device__ interval<T> pown(interval<T> x, std::integral auto n)
} else { // even power
if (n > 0) {
if (inf(x) >= 0) {
return { pow(inf(x), n), pow(sup(x), n) }; // TODO: rounding
return { prev_floating(pow(inf(x), n)), next_floating(pow(sup(x), n)) };
} else if (sup(x) <= 0) {
return { pow(sup(x), n), pow(inf(x), n) }; // TODO: rounding
return { prev_floating(pow(sup(x), n)), next_floating(pow(inf(x), n)) };
} else {
return { pow(mig(x), n), pow(mag(x), n) }; // TODO: rounding
return { prev_floating(pow(mig(x), n)), next_floating(pow(mag(x), n)) };
}
} else {
if (inf(x) >= 0) {
return { pow(sup(x), n), pow(inf(x), n) }; // TODO: rounding
return { prev_floating(pow(sup(x), n)), next_floating(pow(inf(x), n)) };
} else if (sup(x) <= 0) {
return { pow(inf(x), n), pow(sup(x), n) }; // TODO: rounding
return { prev_floating(pow(inf(x), n)), next_floating(pow(sup(x), n)) };
} else {
return { pow(mag(x), n), pow(mig(x), n) }; // TODO: rounding
return { prev_floating(pow(mag(x), n)), next_floating(pow(mig(x), n)) };
}
}
}
Expand Down Expand Up @@ -968,10 +971,6 @@ __device__ interval<T> tan(interval<T> x)
}

constexpr interval<T> pi{ 0x1.921fb54442d18p+1, 0x1.921fb54442d19p+1 };
constexpr interval<T> tau{ 0x1.921fb54442d18p+2, 0x1.921fb54442d19p+2 };

T cos_min = static_cast<T>(-1);
T cos_max = static_cast<T>(1);

T w = width(x);

Expand Down Expand Up @@ -1210,4 +1209,11 @@ __device__ interval<T> atanh(interval<T> x)
intrinsic::next_after(intrinsic::next_after(atanh(sup(xx)), range.ub), range.ub) };
}

template<typename T>
__device__ interval<T> cot(interval<T> x)
{
// return cos(x) / sin(x);
return {};
}

#endif // CUINTERVAL_ARITHMETIC_BASIC_CUH
10 changes: 8 additions & 2 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import defaultdict
from enum import Enum

ParamType = Enum('ParamType', ['I','B', 'T'])
ParamType = Enum('ParamType', ['I','B','T','N']) # interval | boolean | type | number

indent_one = ' ' * 4
indent_two = ' ' * 8
Expand Down Expand Up @@ -37,6 +37,7 @@ def convert_to_test(file_path):
using I = interval<T>;
using B = bool;
using N = int;
I empty = ::empty<T>();
I entire = ::entire<T>();
Expand All @@ -55,6 +56,7 @@ def convert_to_test(file_path):
I = ParamType.I
B = ParamType.B
T = ParamType.T
N = ParamType.N
supported = {
"pos": {"args": [I], "ret": I, "ulp_error": 0},
"neg": {"args": [I], "ret": I, "ulp_error": 0},
Expand Down Expand Up @@ -123,6 +125,8 @@ def convert_to_test(file_path):
"atanh": {"args": [I], "ret": I, "ulp_error": 3},
"sinpi": {"args": [I], "ret": I, "ulp_error": 3},
"cospi": {"args": [I], "ret": I, "ulp_error": 3},
"pown": {"args": [I, N], "ret": I, "ulp_error": 1},
# "cot": {"args": [I], "ret": I, "ulp_error": 4},
}

empty = '{empty}'
Expand All @@ -133,12 +137,14 @@ def convert_to_test(file_path):
failed_code = {
'params': {
T: 'h_{}[fail_id]',
N: 'h_{}[fail_id]',
I: 'h_{}[fail_id].lb, h_{}[fail_id].ub'
},
'cuda': {
T: '{} = %a\\n',
B: '{} = %d\\n',
I: '{} = [%a, %a]\\n'
I: '{} = [%a, %a]\\n',
N: '{} = %d\\n'
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/test_ops.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,22 @@ __global__ void test_cospi(int n, interval<T> *x, interval<T> *res)
}
}

template<typename T>
__global__ void test_cot(int n, interval<T> *x, interval<T> *res)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < n) {
res[i] = cot(x[i]);
}
}

template<typename T>
__global__ void test_pown(int n, interval<T> *x, int *n_pow, interval<T> *res)
{
int i = threadIdx.x + blockIdx.x * blockDim.x;
if (i < n) {
res[i] = pown(x[i], n_pow[i]);
}
}

#endif // TEST_OPS_CUH
1 change: 1 addition & 0 deletions tests/tests_abs_rev.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_abs_rev() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_atan2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_atan2() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_c_xsc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_c_xsc() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_filib.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_filib() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_ieee1788_constructors.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_ieee1788_constructors() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_ieee1788_exceptions.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_ieee1788_exceptions() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_libieeep1788_bool.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_libieeep1788_bool() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_libieeep1788_cancel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_libieeep1788_cancel() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
1 change: 1 addition & 0 deletions tests/tests_libieeep1788_class.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void tests_libieeep1788_class() {

using I = interval<T>;
using B = bool;
using N = int;

I empty = ::empty<T>();
I entire = ::entire<T>();
Expand Down
Loading

0 comments on commit 13d47ab

Please sign in to comment.