#![allow(unexpected_cfgs)]
#![allow(unused_imports)]
use crate::array::Array;
use crate::error::{NumRs2Error, Result};
use num_traits::{Float, NumCast};
use std::fmt::{Debug, Display};
pub fn noncentral_chisquare<T>(df: T, nonc: T, shape: &[usize]) -> Result<Array<T>>
where
T: Float + NumCast + Clone + Debug + Display,
{
crate::random::distributions::noncentral_chisquare(df, nonc, shape)
}
pub fn noncentral_f<T>(dfnum: T, dfden: T, nonc: T, shape: &[usize]) -> Result<Array<T>>
where
T: Float + NumCast + Clone + Debug + Display,
{
crate::random::distributions::noncentral_f(dfnum, dfden, nonc, shape)
}
pub fn truncated_normal<T>(mean: T, std: T, low: T, high: T, shape: &[usize]) -> Result<Array<T>>
where
T: Float + NumCast + Clone + Debug + Display,
{
crate::random::distributions::truncated_normal(mean, std, low, high, shape)
}
pub fn vonmises<T>(mu: T, kappa: T, shape: &[usize]) -> Result<Array<T>>
where
T: Float + NumCast + Clone + Debug + Display,
{
crate::random::distributions::vonmises(mu, kappa, shape)
}
pub fn multivariate_normal_with_rotation<T>(
mean: &[T],
cov: &Array<T>,
size: Option<&[usize]>,
rotation: Option<&Array<T>>,
) -> Result<Array<T>>
where
T: Float + NumCast + Clone + Debug + Display,
{
crate::random::distributions::multivariate_normal_with_rotation(mean, cov, size, rotation)
}
#[cfg(feature = "lapack")]
pub fn solve_linear_system<T>(a: &Array<T>, b: &Array<T>) -> Result<Array<T>>
where
T: Float
+ NumCast
+ Clone
+ Debug
+ Display
+ std::ops::AddAssign
+ std::ops::MulAssign
+ std::ops::DivAssign
+ std::ops::SubAssign,
{
crate::linalg::solve(a, b)
}
#[cfg(test)]
mod tests {
use super::*;
use approx::assert_relative_eq;
#[test]
fn test_noncentral_chisquare() {
let samples = noncentral_chisquare(2.0f64, 1.0f64, &[10])
.expect("Noncentral chi-square distribution should generate samples");
assert_eq!(samples.shape(), vec![10]);
for val in samples.to_vec() {
assert!(val > 0.0);
}
}
#[test]
fn test_noncentral_f() {
let samples = noncentral_f(2.0f64, 3.0f64, 1.0f64, &[10])
.expect("Noncentral F distribution should generate samples");
assert_eq!(samples.shape(), vec![10]);
for val in samples.to_vec() {
assert!(val > 0.0);
}
}
#[cfg(feature = "lapack")]
#[test]
fn test_solve_linear_system() {
let a_data = vec![2.0f64, 1.0f64, 1.0f64, 3.0f64];
let a = Array::from_vec(a_data).reshape(&[2, 2]);
let b_data = vec![5.0f64, 6.0f64];
let b = Array::from_vec(b_data);
let x = solve_linear_system(&a, &b).expect("Linear system should be solvable");
assert_eq!(x.shape(), vec![2]);
let ax = a
.matmul(&x.reshape(&[2, 1]))
.expect("Matrix multiplication should succeed")
.reshape(&[2]);
let ax_data = ax.to_vec();
let b_data = b.to_vec();
assert_relative_eq!(ax_data[0], b_data[0], epsilon = 1e-10);
assert_relative_eq!(ax_data[1], b_data[1], epsilon = 1e-10);
}
}