Skip to content

Commit

Permalink
add new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
imrn99 committed Oct 7, 2024
1 parent 54dae2a commit f6b6243
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
8 changes: 6 additions & 2 deletions integraal/src/structure/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ use crate::{ComputeMethod, DomainDescriptor, FunctionDescriptor, Scalar};
/// Integral error
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum IntegraalError {
/// One or more parameters are missing.
MissingParameters(&'static str),
/// Some parameters do not fit the requirements of the computation method.
BadParameters(&'static str),
/// Specified parameters are conflicting or ambiguous.
InconsistentParameters(&'static str),
/// One or more parameters are missing.
MissingParameters(&'static str),
/// A given method isn't implemented for the specified parameters (e.g. due to requirements).
Unimplemented(&'static str),
}

/// Main integral computation structure
Expand Down
48 changes: 28 additions & 20 deletions integraal/src/structure/implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ fn values_explicit_arm<X: Scalar>(
})
.sum()
}
#[cfg(feature = "boole")] // FIXME: replace by an error
#[cfg(feature = "boole")]
ComputeMethod::Boole => {
unimplemented!("E: Boole's method isn't implemented for non-uniform domains");
return Err(IntegraalError::Unimplemented(
"Boole's method isn't implemented for non-uniform domains",
));
}
#[cfg(feature = "romberg")] // FIXME: replace by an error
#[cfg(feature = "romberg")]
ComputeMethod::Romberg { .. } => {
unimplemented!("E: Romberg's method isn't implemented for non-uniform domains");
return Err(IntegraalError::Unimplemented(
"Romberg's method isn't implemented for non-uniform domains",
));
}
#[cfg(feature = "montecarlo")]
ComputeMethod::MonteCarlo { n_sample: _ } => {
Expand Down Expand Up @@ -214,12 +218,12 @@ fn values_uniform_arm<X: Scalar>(
.sum()
}
ComputeMethod::Boole => {
// FIXME: replace with an error
assert_eq!(
*n_step % 4,
0,
"E: domain should be divided into a multiple of 4 segments for Boole's method"
);
if *n_step % 4 != 0 {
return Err(IntegraalError::BadParameters(
"domain should be divided into a multiple of 4 segments for Boole's method",
));
}

let c = X::from(2.0 / 45.0).unwrap() * *step;

let m1 = X::from(7.0).unwrap() * (vals[0] + vals[*n_step - 1]);
Expand Down Expand Up @@ -326,13 +330,17 @@ fn closure_explicit_arm<X: Scalar>(
})
.sum()
}
#[cfg(feature = "boole")] // FIXME: replace by an error
#[cfg(feature = "boole")]
ComputeMethod::Boole => {
unimplemented!("E: Boole's method isn't implemented for non-uniform domains");
return Err(IntegraalError::Unimplemented(
"Boole's method isn't implemented for non-uniform domains",
));
}
#[cfg(feature = "romberg")] // FIXME: replace by an error
#[cfg(feature = "romberg")]
ComputeMethod::Romberg { .. } => {
unimplemented!("E: Romberg's method isn't implemented for non-uniform domains");
return Err(IntegraalError::Unimplemented(
"Romberg's method isn't implemented for non-uniform domains",
));
}
#[cfg(feature = "montecarlo")]
ComputeMethod::MonteCarlo { n_sample: _ } => {
Expand Down Expand Up @@ -401,12 +409,12 @@ fn closure_uniform_arm<X: Scalar>(
.sum()
}
ComputeMethod::Boole => {
// FIXME: replace with an error
assert_eq!(
*n_step % 4,
0,
"E: domain should be divided into a multiple of 4 segments for Boole's method"
);
if *n_step % 4 != 0 {
return Err(IntegraalError::BadParameters(
"domain should be divided into a multiple of 4 segments for Boole's method",
));
}

let c = X::from(2.0 / 45.0).unwrap() * *step;

let m1 = X::from(7.0).unwrap()
Expand Down

0 comments on commit f6b6243

Please sign in to comment.