use ffi;
use enums;
use std::io::Write;
pub struct Histogram {
h: *mut ffi::gsl_histogram
}
impl Histogram {
pub fn new(n: u64) -> Option<Histogram> {
let tmp = unsafe { ffi::gsl_histogram_alloc(n) };
if tmp.is_null() {
None
} else {
Some(Histogram {
h: tmp
})
}
}
pub fn set_ranges(&self, range: &[f64]) -> enums::value::Value {
unsafe { ffi::gsl_histogram_set_ranges(self.h, range.as_ptr(), range.len() as u64) }
}
pub fn set_ranges_uniform(&self, xmin: f64, xmax: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_set_ranges_uniform(self.h, xmin, xmax) }
}
pub fn copy(&self, dest: &Histogram) -> enums::value::Value {
unsafe { ffi::gsl_histogram_memcpy(dest.h, self.h) }
}
pub fn clone(&self) -> Option<Histogram> {
let tmp = unsafe { ffi::gsl_histogram_clone(self.h) };
if tmp.is_null() {
None
} else {
Some(Histogram {
h: tmp
})
}
}
pub fn increment(&self, x: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_increment(self.h, x) }
}
pub fn accumulate(&self, x: f64, weight: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_accumulate(self.h, x, weight) }
}
pub fn get(&self, i: u64) -> f64 {
unsafe { ffi::gsl_histogram_get(self.h, i) }
}
pub fn get_range(&self, i: u64, lower: &mut f64, upper: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_get_range(self.h, i, lower, upper) }
}
pub fn max(&self) -> f64 {
unsafe { ffi::gsl_histogram_max(self.h) }
}
pub fn min(&self) -> f64 {
unsafe { ffi::gsl_histogram_min(self.h) }
}
pub fn bins(&self) -> u64 {
unsafe { ffi::gsl_histogram_bins(self.h) }
}
pub fn reset(&self) {
unsafe { ffi::gsl_histogram_reset(self.h) }
}
pub fn find(&self, x: f64, i: &mut u64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_find(self.h, x, i) }
}
pub fn max_val(&self) -> f64 {
unsafe { ffi::gsl_histogram_max_val(self.h) }
}
pub fn max_bin(&self) -> u64 {
unsafe { ffi::gsl_histogram_max_bin(self.h) }
}
pub fn min_val(&self) -> f64 {
unsafe { ffi::gsl_histogram_min_val(self.h) }
}
pub fn min_bin(&self) -> u64 {
unsafe { ffi::gsl_histogram_min_bin(self.h) }
}
pub fn mean(&self) -> f64 {
unsafe { ffi::gsl_histogram_mean(self.h) }
}
pub fn sigma(&self) -> f64 {
unsafe { ffi::gsl_histogram_sigma(self.h) }
}
pub fn sum(&self) -> f64 {
unsafe { ffi::gsl_histogram_sum(self.h) }
}
pub fn equal_bins_p(&self, other: &Histogram) -> bool {
match unsafe { ffi::gsl_histogram_equal_bins_p(self.h, other.h) } {
0i32 => false,
_ => true
}
}
pub fn add(&self, other: &Histogram) -> enums::value::Value {
unsafe { ffi::gsl_histogram_add(self.h, other.h) }
}
pub fn sub(&self, other: &Histogram) -> enums::value::Value {
unsafe { ffi::gsl_histogram_sub(self.h, other.h) }
}
pub fn mul(&self, other: &Histogram) -> enums::value::Value {
unsafe { ffi::gsl_histogram_mul(self.h, other.h) }
}
pub fn div(&self, other: &Histogram) -> enums::value::Value {
unsafe { ffi::gsl_histogram_div(self.h, other.h) }
}
pub fn scale(&self, scale: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_scale(self.h, scale) }
}
pub fn shift(&self, offset: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram_shift(self.h, offset) }
}
#[allow(unused_must_use)]
pub fn print(&self, stream: &mut Write) -> enums::value::Value {
unsafe {
let n = (*self.h).n as isize;
for i in 0isize..n {
write!(stream, "{}", *(*self.h).range.offset(i));
write!(stream, " ");
write!(stream, "{}", *(*self.h).range.offset(i + 1));
write!(stream, " ");
write!(stream, "{}", *(*self.h).range.offset(i));
write!(stream, "\n");
}
::Value::Success
}
}
}
impl Drop for Histogram {
fn drop(&mut self) {
unsafe { ffi::gsl_histogram_free(self.h) };
self.h = ::std::ptr::null_mut();
}
}
impl ffi::FFI<ffi::gsl_histogram> for Histogram {
fn wrap(h: *mut ffi::gsl_histogram) -> Histogram {
Histogram {
h: h
}
}
fn unwrap(h: &Histogram) -> *mut ffi::gsl_histogram {
h.h
}
}
pub struct HistogramPdf {
h: *mut ffi::gsl_histogram_pdf
}
impl HistogramPdf {
pub fn new(n: u64) -> Option<HistogramPdf> {
let tmp = unsafe { ffi::gsl_histogram_pdf_alloc(n) };
if tmp.is_null() {
None
} else {
Some(HistogramPdf {
h: tmp
})
}
}
pub fn init(&self, h: &Histogram) -> enums::value::Value {
unsafe { ffi::gsl_histogram_pdf_init(self.h, h.h) }
}
pub fn sample(&self, r: f64) -> f64 {
unsafe { ffi::gsl_histogram_pdf_sample(self.h, r) }
}
}
impl Drop for HistogramPdf {
fn drop(&mut self) {
unsafe { ffi::gsl_histogram_pdf_free(self.h) };
self.h = ::std::ptr::null_mut();
}
}
impl ffi::FFI<ffi::gsl_histogram_pdf> for HistogramPdf {
fn wrap(h: *mut ffi::gsl_histogram_pdf) -> HistogramPdf {
HistogramPdf {
h: h
}
}
fn unwrap(h: &HistogramPdf) -> *mut ffi::gsl_histogram_pdf {
h.h
}
}
pub struct Histogram2D {
h: *mut ffi::gsl_histogram2d
}
impl Histogram2D {
pub fn new(nx: u64, ny: u64) -> Option<Histogram2D> {
let tmp = unsafe { ffi::gsl_histogram2d_alloc(nx, ny) };
if tmp.is_null() {
None
} else {
Some(Histogram2D {
h: tmp
})
}
}
pub fn set_ranges(&self, xrange: &[f64], yrange: &[f64]) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_set_ranges(self.h, xrange.as_ptr(), xrange.len() as u64, yrange.as_ptr(), yrange.len() as u64) }
}
pub fn set_ranges_uniform(&self, xmin: f64, xmax: f64, ymin: f64, ymax: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_set_ranges_uniform(self.h, xmin, xmax, ymin, ymax) }
}
pub fn copy(&self, dest: &Histogram2D) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_memcpy(dest.h, self.h) }
}
pub fn clone(&self) -> Option<Histogram2D> {
let tmp = unsafe { ffi::gsl_histogram2d_clone(self.h) };
if tmp.is_null() {
None
} else {
Some(Histogram2D {
h: tmp
})
}
}
pub fn increment(&self, x: f64, y: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_increment(self.h, x, y) }
}
pub fn accumulate(&self, x: f64, y: f64, weight: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_accumulate(self.h, x, y, weight) }
}
pub fn get(&self, i: u64, j: u64) -> f64 {
unsafe { ffi::gsl_histogram2d_get(self.h, i, j) }
}
pub fn get_xrange(&self, i: u64, xlower: &mut f64, xupper: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_get_xrange(self.h, i, xlower, xupper) }
}
pub fn get_yrange(&self, j: u64, ylower: &mut f64, yupper: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_get_yrange(self.h, j, ylower, yupper) }
}
pub fn xmax(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_xmax(self.h) }
}
pub fn xmin(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_xmin(self.h) }
}
pub fn nx(&self) -> u64 {
unsafe { ffi::gsl_histogram2d_nx(self.h) }
}
pub fn ymax(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_ymax(self.h) }
}
pub fn ymin(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_ymin(self.h) }
}
pub fn ny(&self) -> u64 {
unsafe { ffi::gsl_histogram2d_ny(self.h) }
}
pub fn reset(&self) {
unsafe { ffi::gsl_histogram2d_reset(self.h) }
}
pub fn find(&self, x: f64, y: f64, i: &mut u64, j: &mut u64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_find(self.h, x, y, i, j) }
}
pub fn max_val(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_max_val(self.h) }
}
pub fn max_bin(&self, i: &mut u64, j: &mut u64) {
unsafe { ffi::gsl_histogram2d_max_bin(self.h, i, j) }
}
pub fn min_val(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_min_val(self.h) }
}
pub fn min_bin(&self, i: &mut u64, j: &mut u64) {
unsafe { ffi::gsl_histogram2d_min_bin(self.h, i, j) }
}
pub fn xmean(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_xmean(self.h) }
}
pub fn ymean(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_ymean(self.h) }
}
pub fn xsigma(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_xsigma(self.h) }
}
pub fn ysigma(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_ysigma(self.h) }
}
pub fn cov(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_cov(self.h) }
}
pub fn sum(&self) -> f64 {
unsafe { ffi::gsl_histogram2d_sum(self.h) }
}
pub fn equal_bins_p(&self, other: &Histogram2D) -> bool {
match unsafe { ffi::gsl_histogram2d_equal_bins_p(self.h, other.h) } {
0 => false,
_ => true
}
}
pub fn add(&self, other: &Histogram2D) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_add(self.h, other.h) }
}
pub fn sub(&self, other: &Histogram2D) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_sub(self.h, other.h) }
}
pub fn mul(&self, other: &Histogram2D) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_mul(self.h, other.h) }
}
pub fn div(&self, other: &Histogram2D) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_div(self.h, other.h) }
}
pub fn scale(&self, scale: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_scale(self.h, scale) }
}
pub fn shift(&self, offset: f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_shift(self.h, offset) }
}
}
impl Drop for Histogram2D {
fn drop(&mut self) {
unsafe { ffi::gsl_histogram2d_free(self.h) };
self.h = ::std::ptr::null_mut();
}
}
impl ffi::FFI<ffi::gsl_histogram2d> for Histogram2D {
fn wrap(h: *mut ffi::gsl_histogram2d) -> Histogram2D {
Histogram2D {
h: h
}
}
fn unwrap(h: &Histogram2D) -> *mut ffi::gsl_histogram2d {
h.h
}
}
pub struct Histogram2DPdf {
h: *mut ffi::gsl_histogram2d_pdf
}
impl Histogram2DPdf {
pub fn new(nx: u64, ny: u64) -> Option<Histogram2DPdf> {
let tmp = unsafe { ffi::gsl_histogram2d_pdf_alloc(nx, ny) };
if tmp.is_null() {
None
} else {
Some(Histogram2DPdf {
h: tmp
})
}
}
pub fn init(&self, h: &Histogram2D) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_pdf_init(self.h, h.h) }
}
pub fn sample(&self, r1: f64, r2: f64, x: &mut f64, y: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_histogram2d_pdf_sample(self.h, r1, r2, x, y) }
}
}
impl Drop for Histogram2DPdf {
fn drop(&mut self) {
unsafe { ffi::gsl_histogram2d_pdf_free(self.h) };
self.h = ::std::ptr::null_mut();
}
}
impl ffi::FFI<ffi::gsl_histogram2d_pdf> for Histogram2DPdf {
fn wrap(h: *mut ffi::gsl_histogram2d_pdf) -> Histogram2DPdf {
Histogram2DPdf {
h: h
}
}
fn unwrap(h: &Histogram2DPdf) -> *mut ffi::gsl_histogram2d_pdf {
h.h
}
}