Skip to content

Commit

Permalink
fix: docstring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henryjac committed Feb 27, 2024
1 parent ce14d58 commit 6b02c96
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/distribution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ pub trait ContinuousMultivariateCDF<K: Float, T: Float> {
///
/// ```
/// use statrs::distribution::{ContinuousMultivariateCDF, MultivariateNormal};
/// use nalgebra::DVector;
///
/// let mvn = MultivariateNormal::new(vec![0., 0.], vec![1., 0., 0., 1.]).unwrap();
/// assert_eq!(0.25, mvn.cdf([0., 0.,]));
/// assert_eq!(0.25, mvn.cdf(DVector::from_vec(vec![0., 0.,])));
/// ```
fn cdf(&self, x: DVector<K>) -> T;

Expand All @@ -304,9 +305,10 @@ pub trait ContinuousMultivariateCDF<K: Float, T: Float> {
///
/// ```
/// use statrs::distribution::{ContinuousMultivariateCDF, MultivariateNormal};
/// use nalgebra::DVector;
///
/// let mvs = MultivariateNormal::new(vec![0., 0.], vec![1., 0., 0., 1.]).unwrap();
/// assert_eq!(f64::NEG_INFINITY, mvs.sf([f64::INFINITY, f64::INFINITY]));
/// assert_eq!(0., mvs.sf(DVector::from_vec(vec![f64::INFINITY, f64::INFINITY])));
/// ```
fn sf(&self, x: DVector<K>) -> T;
}
1 change: 1 addition & 0 deletions src/distribution/multivariate_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ impl ContinuousMultivariateCDF<f64, f64> for MultivariateNormal {
/// multivariate normal distribution, using approximation with
/// `N` points.
fn sf(&self, x: DVector<f64>) -> f64 {
// Shift integration limit wrt. mean
1. - self.cdf(x)
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/distribution/multivariate_uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use std::f64;
///
/// ```
/// use statrs::distribution::{MultivariateUniform, Continuous};
/// use statrs::statistics::Distribution;
/// use statrs::statistics::{Distribution, MeanN};
/// use nalgebra::DVector;
///
/// let n = MultivariateUniform::new(vec![-1., 0.], vec![0., 1.]).unwrap();
/// assert_eq!(n.mean().unwrap(), DVector::from_vec(vec![-0.5, 0.5]);
/// assert_eq!(n.pdf(DVector::from_vec(vec![-0.5, 0.5])), 1.);
/// assert_eq!(n.mean().unwrap(), DVector::from_vec(vec![-0.5, 0.5]));
/// assert_eq!(n.pdf(&DVector::from_vec(vec![-0.5, 0.5])), 1.);
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct MultivariateUniform {
Expand All @@ -40,11 +41,12 @@ impl MultivariateUniform {
/// use statrs::distribution::MultivariateUniform;
/// use std::f64;
///
/// let mut result = Uniform::new(vec![-1., 0.], vec![0., 1.,]);
/// let mut result = MultivariateUniform::new(vec![-1., 0.], vec![0., 1.,]);
/// assert!(result.is_ok());
///
/// result = Uniform::new(f64::NAN, f64::NAN);
/// result = Uniform::new(vec![0., f64::NAN], vec![f64::NAN, 1.]);
/// result = MultivariateUniform::new(vec![f64::NAN], vec![f64::NAN]);
/// assert!(result.is_err());
/// result = MultivariateUniform::new(vec![0., f64::NAN], vec![f64::NAN, 1.]);
/// assert!(result.is_err());
/// ```
pub fn new(min: Vec<f64>, max: Vec<f64>) -> Result<MultivariateUniform> {
Expand Down

0 comments on commit 6b02c96

Please sign in to comment.