rgsl/types/
rstat.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5use crate::Value;
6use ffi::FFI;
7
8ffi_wrapper!(
9    RStatQuantileWorkspace,
10    *mut sys::gsl_rstat_quantile_workspace,
11    gsl_rstat_quantile_free
12);
13
14impl RStatQuantileWorkspace {
15    #[doc(alias = "gsl_rstat_quantile_alloc")]
16    pub fn new(p: f64) -> Option<Self> {
17        let s = unsafe { sys::gsl_rstat_quantile_alloc(p) };
18        if s.is_null() {
19            None
20        } else {
21            Some(Self::wrap(s))
22        }
23    }
24
25    #[cfg(feature = "v2_2")]
26    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
27    #[doc(alias = "gsl_rstat_quantile_reset")]
28    pub fn reset(&mut self) -> Result<(), Value> {
29        let ret = unsafe { sys::gsl_rstat_quantile_reset(self.unwrap_unique()) };
30        result_handler!(ret, ())
31    }
32
33    #[doc(alias = "gsl_rstat_quantile_add")]
34    pub fn add(&mut self, x: f64) -> Result<(), Value> {
35        let ret = unsafe { sys::gsl_rstat_quantile_add(x, self.unwrap_unique()) };
36        result_handler!(ret, ())
37    }
38
39    #[doc(alias = "gsl_rstat_quantile_get")]
40    pub fn get(&mut self) -> f64 {
41        unsafe { sys::gsl_rstat_quantile_get(self.unwrap_unique()) }
42    }
43}
44
45ffi_wrapper!(
46    RStatWorkspace,
47    *mut sys::gsl_rstat_workspace,
48    gsl_rstat_free
49);
50
51impl RStatWorkspace {
52    #[doc(alias = "gsl_rstat_alloc")]
53    pub fn new() -> Option<Self> {
54        let s = unsafe { sys::gsl_rstat_alloc() };
55        if s.is_null() {
56            None
57        } else {
58            Some(Self::wrap(s))
59        }
60    }
61
62    #[doc(alias = "gsl_rstat_n")]
63    pub fn n(&self) -> usize {
64        unsafe { sys::gsl_rstat_n(self.unwrap_shared()) }
65    }
66
67    #[doc(alias = "gsl_rstat_add")]
68    pub fn add(&mut self, x: f64) -> Result<(), Value> {
69        let ret = unsafe { sys::gsl_rstat_add(x, self.unwrap_unique()) };
70        result_handler!(ret, ())
71    }
72
73    #[doc(alias = "gsl_rstat_min")]
74    pub fn min(&self) -> f64 {
75        unsafe { sys::gsl_rstat_min(self.unwrap_shared()) }
76    }
77
78    #[doc(alias = "gsl_rstat_max")]
79    pub fn max(&self) -> f64 {
80        unsafe { sys::gsl_rstat_max(self.unwrap_shared()) }
81    }
82
83    #[doc(alias = "gsl_rstat_mean")]
84    pub fn mean(&self) -> f64 {
85        unsafe { sys::gsl_rstat_mean(self.unwrap_shared()) }
86    }
87
88    #[doc(alias = "gsl_rstat_variance")]
89    pub fn variance(&self) -> f64 {
90        unsafe { sys::gsl_rstat_variance(self.unwrap_shared()) }
91    }
92
93    #[doc(alias = "gsl_rstat_sd")]
94    pub fn sd(&self) -> f64 {
95        unsafe { sys::gsl_rstat_sd(self.unwrap_shared()) }
96    }
97
98    #[cfg(feature = "v2_2")]
99    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
100    #[doc(alias = "gsl_rstat_rms")]
101    pub fn rms(&self) -> f64 {
102        unsafe { sys::gsl_rstat_rms(self.unwrap_shared()) }
103    }
104
105    #[doc(alias = "gsl_rstat_sd_mean")]
106    pub fn sd_mean(&self) -> f64 {
107        unsafe { sys::gsl_rstat_sd_mean(self.unwrap_shared()) }
108    }
109
110    #[doc(alias = "gsl_rstat_median")]
111    pub fn median(&mut self) -> f64 {
112        unsafe { sys::gsl_rstat_median(self.unwrap_unique()) }
113    }
114
115    #[doc(alias = "gsl_rstat_skew")]
116    pub fn skew(&self) -> f64 {
117        unsafe { sys::gsl_rstat_skew(self.unwrap_shared()) }
118    }
119
120    #[doc(alias = "gsl_rstat_kurtosis")]
121    pub fn kurtosis(&self) -> f64 {
122        unsafe { sys::gsl_rstat_kurtosis(self.unwrap_shared()) }
123    }
124
125    #[doc(alias = "gsl_rstat_reset")]
126    pub fn reset(&mut self) -> Result<(), Value> {
127        let ret = unsafe { sys::gsl_rstat_reset(self.unwrap_unique()) };
128        result_handler!(ret, ())
129    }
130}