Skip to content

Commit 36a0276

Browse files
committed
Update doctests to use random_*_using
1 parent 0470a82 commit 36a0276

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

ndarray-linalg/src/solve.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
//! Solve `A * x = b`:
66
//!
77
//! ```
8-
//! #[macro_use]
9-
//! extern crate ndarray;
10-
//! extern crate ndarray_linalg;
11-
//!
128
//! use ndarray::prelude::*;
139
//! use ndarray_linalg::Solve;
14-
//! # fn main() {
1510
//!
1611
//! let a: Array2<f64> = array![[3., 2., -1.], [2., -2., 4.], [-2., 1., -2.]];
1712
//! let b: Array1<f64> = array![1., -2., 0.];
1813
//! let x = a.solve_into(b).unwrap();
1914
//! assert!(x.abs_diff_eq(&array![1., -2., -2.], 1e-9));
20-
//!
21-
//! # }
2215
//! ```
2316
//!
2417
//! There are also special functions for solving `A^T * x = b` and
@@ -29,21 +22,18 @@
2922
//! the beginning than solving directly using `A`:
3023
//!
3124
//! ```
32-
//! # extern crate ndarray;
33-
//! # extern crate ndarray_linalg;
34-
//!
3525
//! use ndarray::prelude::*;
3626
//! use ndarray_linalg::*;
37-
//! # fn main() {
3827
//!
39-
//! let a: Array2<f64> = random((3, 3));
28+
//! /// Use fixed algorithm and seed of PRNG for reproducible test
29+
//! let mut rng = rand_pcg::Mcg128Xsl64::new(0xcafef00dd15ea5e5);
30+
//!
31+
//! let a: Array2<f64> = random_using((3, 3), &mut rng);
4032
//! let f = a.factorize_into().unwrap(); // LU factorize A (A is consumed)
4133
//! for _ in 0..10 {
42-
//! let b: Array1<f64> = random(3);
34+
//! let b: Array1<f64> = random_using(3, &mut rng);
4335
//! let x = f.solve_into(b).unwrap(); // Solve A * x = b using factorized L, U
4436
//! }
45-
//!
46-
//! # }
4737
//! ```
4838
4939
use ndarray::*;

ndarray-linalg/src/solveh.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88
//! Solve `A * x = b`, where `A` is a Hermitian (or real symmetric) matrix:
99
//!
1010
//! ```
11-
//! #[macro_use]
12-
//! extern crate ndarray;
13-
//! extern crate ndarray_linalg;
14-
//!
1511
//! use ndarray::prelude::*;
1612
//! use ndarray_linalg::SolveH;
17-
//! # fn main() {
1813
//!
1914
//! let a: Array2<f64> = array![
2015
//! [3., 2., -1.],
@@ -24,29 +19,25 @@
2419
//! let b: Array1<f64> = array![11., -12., 1.];
2520
//! let x = a.solveh_into(b).unwrap();
2621
//! assert!(x.abs_diff_eq(&array![1., 3., -2.], 1e-9));
27-
//!
28-
//! # }
2922
//! ```
3023
//!
3124
//! If you are solving multiple systems of linear equations with the same
3225
//! Hermitian or real symmetric coefficient matrix `A`, it's faster to compute
3326
//! the factorization once at the beginning than solving directly using `A`:
3427
//!
3528
//! ```
36-
//! # extern crate ndarray;
37-
//! # extern crate ndarray_linalg;
3829
//! use ndarray::prelude::*;
3930
//! use ndarray_linalg::*;
40-
//! # fn main() {
4131
//!
42-
//! let a: Array2<f64> = random((3, 3));
32+
//! /// Use fixed algorithm and seed of PRNG for reproducible test
33+
//! let mut rng = rand_pcg::Mcg128Xsl64::new(0xcafef00dd15ea5e5);
34+
//!
35+
//! let a: Array2<f64> = random_using((3, 3), &mut rng);
4336
//! let f = a.factorizeh_into().unwrap(); // Factorize A (A is consumed)
4437
//! for _ in 0..10 {
45-
//! let b: Array1<f64> = random(3);
38+
//! let b: Array1<f64> = random_using(3, &mut rng);
4639
//! let x = f.solveh_into(b).unwrap(); // Solve A * x = b using the factorization
4740
//! }
48-
//!
49-
//! # }
5041
//! ```
5142
5243
use ndarray::*;

0 commit comments

Comments
 (0)