Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: many extended interval arithmetic unit tests #31

Merged
merged 23 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
af95ec1
fix: change cargo test profile to get correct times in benchmark
ramonfmir Apr 11, 2024
17c6ca8
test: all add and mul tests on critical intervals
ramonfmir Apr 12, 2024
bb7ceb6
wip: planning more domain tests
ramonfmir Apr 12, 2024
fdfece8
fix: `is_zero` and `is_one` check for empty intervals
ramonfmir Apr 16, 2024
cfb7f95
test: checker tests for EIF
ramonfmir Apr 16, 2024
f95cdbc
fix: `abs` interval calculation
ramonfmir Apr 18, 2024
c453992
test: interval `neg`, `abs`, and some concrete intervals for `exp` an…
ramonfmir Apr 18, 2024
2c47908
fix: negative cases for interval `sqrt`
ramonfmir Apr 18, 2024
1e81804
test: interval `sqrt` tests
ramonfmir Apr 18, 2024
d08f847
fix: `log` on negative intervals
ramonfmir Apr 18, 2024
45637f4
fix: let `log` work for non-negative input
ramonfmir Apr 18, 2024
2ad6f4f
test: tests up to interval `sub`
ramonfmir Apr 18, 2024
0607637
test: interval `mul` tests
ramonfmir Apr 19, 2024
a6eecc9
refactor: neater `is_zero` and `is_one`
ramonfmir Apr 19, 2024
72f99b5
style: no prints in tests
ramonfmir Apr 19, 2024
fbc8dc8
test: interval `min` and `max`
ramonfmir Apr 23, 2024
f535173
feat: interval macros
ramonfmir Apr 23, 2024
09c0e98
test: more `div` interval tests
ramonfmir Apr 23, 2024
3285d4e
feat: macros for all intervals
ramonfmir Apr 23, 2024
d234a2d
style: do not name all intervals
ramonfmir Apr 23, 2024
ab664fc
fix: be careful with `0 ^ 0`
ramonfmir Apr 23, 2024
90e294a
fix: `I ^ [0, 0] = [1, 1]`
ramonfmir Apr 23, 2024
03153b5
test: many tests for interval `pow`
ramonfmir Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion egg-pre-dcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ intervals-good = "0.1.1"

[profile.test]
debug = true
opt-level = 1
lto = "fat"
codegen-units = 1
opt-level = 3
debug-assertions = false
overflow-checks = false
incremental = false

[profile.release]
debug = true
Expand Down
94 changes: 72 additions & 22 deletions egg-pre-dcp/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,45 @@ impl Domain {
}
}

#[macro_export]
macro_rules! CC {
($a:expr, $b:expr) => { Domain::make_cc(domain::make_float($a), domain::make_float($b)) };
}

#[macro_export]
macro_rules! CO {
($a:expr, $b:expr) => { Domain::make_co(domain::make_float($a), domain::make_float($b)) };
}

#[macro_export]
macro_rules! CI {
($a:expr) => { Domain::make_ci(domain::make_float($a)) };
}

#[macro_export]
macro_rules! OC {
($a:expr, $b:expr) => { Domain::make_oc(domain::make_float($a), domain::make_float($b)) };
}

#[macro_export]
macro_rules! OO {
($a:expr, $b:expr) => { Domain::make_oo(domain::make_float($a), domain::make_float($b)) };
}

#[macro_export]
macro_rules! OI {
($b:expr) => { Domain::make_oi(domain::make_float($b)) };
}

#[macro_export]
macro_rules! IC {
($b:expr) => { Domain::make_ic(domain::make_float($b)) };
}

#[macro_export]
macro_rules! IO {
($b:expr) => { Domain::make_io(domain::make_float($b)) };
}

impl PartialOrd for Domain {
fn partial_cmp(&self, other: &Domain) -> Option<Ordering> {
Expand Down Expand Up @@ -339,7 +378,7 @@ pub fn zero_dom() -> Domain {
}

pub fn is_zero(d: &Domain) -> bool {
d.subseteq(&zero_dom())
d.eq(&zero_dom())
}

pub fn option_is_zero(d: Option<&Domain>) -> bool {
Expand All @@ -351,7 +390,7 @@ pub fn one_dom() -> Domain {
}

pub fn is_one(d: &Domain) -> bool {
d.subseteq(&one_dom())
d.eq(&one_dom())
}

pub fn option_is_one(d: Option<&Domain>) -> bool {
Expand All @@ -362,6 +401,22 @@ pub fn free_dom() -> Domain {
Domain::make_ii()
}

pub fn empty_dom() -> Domain {
Domain::make_oo(zero(), zero())
}

pub fn pos_dom() -> Domain {
Domain::make_oi(zero())
}

pub fn is_pos(d: &Domain) -> bool {
d.subseteq(&pos_dom())
}

pub fn option_is_pos(d: Option<&Domain>) -> bool {
d.map_or(false, is_pos)
}

pub fn nonneg_dom() -> Domain {
Domain::make_ci(zero())
}
Expand All @@ -386,18 +441,6 @@ pub fn option_is_nonpos(d: Option<&Domain>) -> bool {
d.map_or(false, is_nonpos)
}

pub fn pos_dom() -> Domain {
Domain::make_oi(zero())
}

pub fn is_pos(d: &Domain) -> bool {
d.subseteq(&pos_dom())
}

pub fn option_is_pos(d: Option<&Domain>) -> bool {
d.map_or(false, is_pos)
}

pub fn neg_dom() -> Domain {
Domain::make_io(neg_zero())
}
Expand Down Expand Up @@ -475,11 +518,11 @@ pub fn abs(d: &Domain) -> Domain {
Domain::make_from_endpoints(-b, -a, r, l)
} else {
if a_abs < b_abs {
Domain::make_from_endpoints(zero(), b, false, r)
Domain::make_from_endpoints(zero(), b_abs, false, r)
} else if b_abs < a_abs {
Domain::make_from_endpoints(zero(), a, false, l)
Domain::make_from_endpoints(zero(), a_abs, false, l)
} else {
Domain::make_from_endpoints(zero(), a, false, l && r)
Domain::make_from_endpoints(zero(), a_abs, false, l && r)
}
}
} else {
Expand All @@ -492,15 +535,23 @@ pub fn option_abs(d_o: Option<Domain>) -> Option<Domain> {
}

pub fn sqrt(d: &Domain) -> Domain {
Domain::make(d.interval.sqrt(), d.lo_open, d.hi_open)
if is_nonneg(d) {
Domain::make(d.interval.sqrt(), d.lo_open, d.hi_open)
} else {
free_dom()
}
}

pub fn option_sqrt(d_o: Option<Domain>) -> Option<Domain> {
execute_unary(d_o, sqrt)
}

pub fn log(d: &Domain) -> Domain {
Domain::make(d.interval.ln(), d.lo_open, d.hi_open)
if is_nonneg(d) {
Domain::make(d.interval.ln(), d.lo_open, d.hi_open)
} else {
free_dom()
}
}

pub fn option_log(d_o: Option<Domain>) -> Option<Domain> {
Expand Down Expand Up @@ -638,7 +689,6 @@ fn perform_mult(
}

// For multiplication, opennes of endpoints depends on the values.
// NOTE(RFM): For the case splitting part, c.f. with `classify`.
pub fn mul(d1: &Domain, d2: &Domain) -> Domain {
let d1_pos = is_pos(d1);
let d1_neg = is_neg(d1);
Expand Down Expand Up @@ -845,11 +895,11 @@ pub fn pow(d1: &Domain, d2: &Domain) -> Domain {
Some(f) => {
if ((f as u32) as f64) == f {
let n = f as u32;
if n == 0 && does_not_contain_zero(d1) {
if n == 0 {
return Domain::make_singleton(1.0);
} else if n == 1 {
return d1.clone();
} else if n % 2 == 0 {
} else if n > 0 && n % 2 == 0 {
let d = abs(d1);
let lo = d.lo_float();
let hi = d.hi_float();
Expand Down
Loading
Loading