use crate::Value;
use ffi::FFI;
ffi_wrapper!(
LevinUWorkspace,
*mut sys::gsl_sum_levin_u_workspace,
gsl_sum_levin_u_free,
"Workspace for Levin U Transform with error estimation."
);
impl LevinUWorkspace {
#[doc(alias = "gsl_sum_levin_u_alloc")]
pub fn new(n: usize) -> Option<LevinUWorkspace> {
let tmp = unsafe { sys::gsl_sum_levin_u_alloc(n) };
if tmp.is_null() {
None
} else {
Some(LevinUWorkspace::wrap(tmp))
}
}
#[doc(alias = "gsl_sum_levin_u_accel")]
pub fn accel(&mut self, array: &[f64]) -> (Value, f64, f64) {
let mut sum_accel = 0.;
let mut abserr = 0.;
let ret = unsafe {
sys::gsl_sum_levin_u_accel(
array.as_ptr(),
array.len() as _,
self.unwrap_unique(),
&mut sum_accel,
&mut abserr,
)
};
(Value::from(ret), sum_accel, abserr)
}
pub fn sum_plain(&self) -> f64 {
unsafe { (*self.unwrap_shared()).sum_plain }
}
pub fn terms_used(&self) -> usize {
unsafe { (*self.unwrap_shared()).terms_used }
}
pub fn size(&self) -> usize {
unsafe { (*self.unwrap_shared()).size }
}
}
ffi_wrapper!(LevinUTruncWorkspace, *mut sys::gsl_sum_levin_utrunc_workspace, gsl_sum_levin_utrunc_free,
"The following functions perform the same calculation without estimating the errors. They require
`O(N)` storage instead of `O(N^2)`. This may be useful for summing many similar series where the
size of the error has already been estimated reliably and is not expected to change.");
impl LevinUTruncWorkspace {
#[doc(alias = "gsl_sum_levin_utrunc_alloc")]
pub fn new(n: usize) -> Option<LevinUTruncWorkspace> {
let tmp = unsafe { sys::gsl_sum_levin_utrunc_alloc(n) };
if tmp.is_null() {
None
} else {
Some(LevinUTruncWorkspace::wrap(tmp))
}
}
#[doc(alias = "gsl_sum_levin_utrunc_accel")]
pub fn accel(&mut self, array: &[f64]) -> (Value, f64, f64) {
let mut sum_accel = 0.;
let mut abserr_trunc = 0.;
let ret = unsafe {
sys::gsl_sum_levin_utrunc_accel(
array.as_ptr(),
array.len() as _,
self.unwrap_unique(),
&mut sum_accel,
&mut abserr_trunc,
)
};
(Value::from(ret), sum_accel, abserr_trunc)
}
pub fn sum_plain(&self) -> f64 {
unsafe { (*self.unwrap_shared()).sum_plain }
}
pub fn terms_used(&self) -> usize {
unsafe { (*self.unwrap_shared()).terms_used }
}
pub fn size(&self) -> usize {
unsafe { (*self.unwrap_shared()).size }
}
}