use std::env; use num_bigint::BigInt; use num_traits::One; use num_traits::Zero; use rmath::HMatrix; use rmath::Rational; use rmath::NumericalMatrix; use rand::rngs::StdRng; use rand::SeedableRng; use rand::RngCore; fn main( ) { let size = env::args().skip(1).map(|it| { it.parse::().unwrap() }).take(1).collect::>()[0]; let mut rand = { let seed = [ 1,0,1,3, 2,5,0,0, 200,1,0,0, 210,30,0,0, 78,134,31,0, 253,11,7,0, 120,169,89,48, 200,0,202,0 ]; StdRng::from_seed(seed) }; let mtx = HMatrix::>::new( usize::try_from(size).unwrap(),usize::try_from(size).unwrap(), |_| { Rational::new(BigInt::from(rand.next_u32() % (size * 20)) - size * 10, BigInt::one()) }); let b = HMatrix::>::new( usize::try_from(size).unwrap(),usize::try_from(size).unwrap(), |_| { Rational::new(BigInt::from(rand.next_u32() % (size * 10)) - (size * 5), BigInt::one()) }); let lu = mtx.clone().lu().unwrap(); let x = lu.solve(&b).unwrap(); assert!((mtx * x - b).is_zero()); }