Skip to content

Commit 048d588

Browse files
authored
Merge pull request #62 from termoshtt/new_doc
Document update
2 parents 2fd5f12 + 776ed20 commit 048d588

File tree

7 files changed

+72
-46
lines changed

7 files changed

+72
-46
lines changed

src/cholesky.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Cholesky decomposition
2+
//!
3+
//! https://en.wikipedia.org/wiki/Cholesky_decomposition
24
35
use ndarray::*;
46

@@ -10,15 +12,18 @@ use super::types::*;
1012

1113
pub use lapack_traits::UPLO;
1214

15+
/// Cholesky decomposition of matrix reference
1316
pub trait Cholesky {
1417
type Output;
1518
fn cholesky(&self, UPLO) -> Result<Self::Output>;
1619
}
1720

21+
/// Cholesky decomposition
1822
pub trait CholeskyInto: Sized {
1923
fn cholesky_into(self, UPLO) -> Result<Self>;
2024
}
2125

26+
/// Cholesky decomposition of mutable reference of matrix
2227
pub trait CholeskyMut {
2328
fn cholesky_mut(&mut self, UPLO) -> Result<&mut Self>;
2429
}

src/eigh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use super::layout::*;
99
use super::operator::*;
1010
use super::types::*;
1111

12-
/// Eigenvalue decomposition of Hermite matrix
12+
/// Eigenvalue decomposition of Hermite matrix reference
1313
pub trait Eigh {
1414
type EigVal;
1515
type EigVec;
1616
fn eigh(&self, UPLO) -> Result<(Self::EigVal, Self::EigVec)>;
1717
}
1818

19-
/// Eigenvalue decomposition of Hermite matrix
19+
/// Eigenvalue decomposition of mutable reference of Hermite matrix
2020
pub trait EighMut {
2121
type EigVal;
2222
fn eigh_mut(&mut self, UPLO) -> Result<(Self::EigVal, &mut Self)>;

src/lib.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,6 @@
1616
//! - [assertions for array](index.html#macros)
1717
//! - [generator functions](generate/index.html)
1818
//! - [Scalar trait](types/trait.Scalar.html)
19-
//!
20-
//! Usage
21-
//! ------
22-
//! Most functions in this crate is defined as [self-consuming trait technique][sct] like [serde]
23-
//! does.
24-
//!
25-
//! For example, we can execute [eigh][eigh] using three types of interfaces:
26-
//!
27-
//! ```rust,ignore
28-
//! let a = random((3, 3));
29-
//! let (eval, evec) = a.eigh(UPLO::Upper)?;
30-
//! let (eval, evec) = (&a).eigh(UPLO::Upper)?;
31-
//! let (eval, evec) = (&mut a).eigh(UPLO::Upper)?;
32-
//! ```
33-
//!
34-
//! The first type `a.eigh()` consumes `a`, and the memory of `a` is used for `evec`.
35-
//! The second type `(&a).eigh()` consumes the reference (not `a` itself),
36-
//! and the memory for `evec` is newly allocated.
37-
//! The last one `(&mut a).eigh()` is similar to the first one;
38-
//! It borrows `a` mutably, and rewrite it to contains `evec`.
39-
//! In all cases, the array `eval` is newly allocated.
40-
//!
41-
//! [sct]:https://github.com/serde-rs/serde/releases/tag/v0.9.0
42-
//! [serde]:https://github.com/serde-rs/serde
4319
4420
extern crate blas;
4521
extern crate lapack;

src/opnorm.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,41 @@ use super::error::*;
66
use super::layout::*;
77
use super::types::*;
88

9-
use lapack_traits::LapackScalar;
109
pub use lapack_traits::NormType;
1110

11+
/// Operator norm using `*lange` LAPACK routines
12+
///
13+
/// https://en.wikipedia.org/wiki/Operator_norm
1214
pub trait OperationNorm {
13-
type Output;
14-
fn opnorm(&self, t: NormType) -> Self::Output;
15-
fn opnorm_one(&self) -> Self::Output {
15+
/// the value of norm
16+
type Output: RealScalar;
17+
18+
fn opnorm(&self, t: NormType) -> Result<Self::Output>;
19+
20+
/// the one norm of a matrix (maximum column sum)
21+
fn opnorm_one(&self) -> Result<Self::Output> {
1622
self.opnorm(NormType::One)
1723
}
18-
fn opnorm_inf(&self) -> Self::Output {
24+
25+
/// the infinity norm of a matrix (maximum row sum)
26+
fn opnorm_inf(&self) -> Result<Self::Output> {
1927
self.opnorm(NormType::Infinity)
2028
}
21-
fn opnorm_fro(&self) -> Self::Output {
29+
30+
/// the Frobenius norm of a matrix (square root of sum of squares)
31+
fn opnorm_fro(&self) -> Result<Self::Output> {
2232
self.opnorm(NormType::Frobenius)
2333
}
2434
}
2535

2636
impl<A, S> OperationNorm for ArrayBase<S, Ix2>
2737
where
28-
A: LapackScalar + AssociatedReal,
38+
A: Scalar,
2939
S: Data<Elem = A>,
3040
{
31-
type Output = Result<A::Real>;
41+
type Output = A::Real;
3242

33-
fn opnorm(&self, t: NormType) -> Self::Output {
43+
fn opnorm(&self, t: NormType) -> Result<Self::Output> {
3444
let l = self.layout()?;
3545
let a = self.as_allocated()?;
3646
Ok(A::opnorm(t, l, a))

src/qr.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! QR decomposition
2+
//!
3+
//! https://en.wikipedia.org/wiki/QR_decomposition
24
35
use ndarray::*;
46
use num_traits::Zero;
@@ -7,50 +9,80 @@ use super::convert::*;
79
use super::error::*;
810
use super::layout::*;
911
use super::triangular::*;
12+
use super::types::*;
1013

11-
use lapack_traits::{LapackScalar, UPLO};
14+
pub use lapack_traits::UPLO;
1215

16+
/// QR decomposition for matrix reference
17+
///
18+
/// This creates copy due for reshaping array.
19+
/// To avoid copy and the matrix is square, please use `QRSquare*` traits.
1320
pub trait QR {
1421
type Q;
1522
type R;
1623
fn qr(&self) -> Result<(Self::Q, Self::R)>;
1724
}
1825

26+
/// QR decomposition
27+
///
28+
/// This creates copy due for reshaping array.
29+
/// To avoid copy and the matrix is square, please use `QRSquare*` traits.
1930
pub trait QRInto: Sized {
2031
type Q;
2132
type R;
2233
fn qr_into(self) -> Result<(Self::Q, Self::R)>;
2334
}
2435

36+
/// QR decomposition for square matrix reference
2537
pub trait QRSquare: Sized {
2638
type Q;
2739
type R;
2840
fn qr_square(&self) -> Result<(Self::Q, Self::R)>;
2941
}
3042

43+
/// QR decomposition for square matrix
3144
pub trait QRSquareInto: Sized {
3245
type R;
3346
fn qr_square_into(self) -> Result<(Self, Self::R)>;
3447
}
3548

36-
impl<A, S> QRSquareInto for ArrayBase<S, Ix2>
49+
/// QR decomposition for mutable reference of square matrix
50+
pub trait QRSquareMut: Sized {
51+
type R;
52+
fn qr_square_mut<'a>(&'a mut self) -> Result<(&'a mut Self, Self::R)>;
53+
}
54+
55+
impl<A, S> QRSquareMut for ArrayBase<S, Ix2>
3756
where
38-
A: LapackScalar + Copy + Zero,
57+
A: Scalar,
3958
S: DataMut<Elem = A>,
4059
{
4160
type R = Array2<A>;
4261

43-
fn qr_square_into(mut self) -> Result<(Self, Self::R)> {
62+
fn qr_square_mut<'a>(&'a mut self) -> Result<(&'a mut Self, Self::R)> {
4463
let l = self.square_layout()?;
4564
let r = A::qr(l, self.as_allocated_mut()?)?;
4665
let r: Array2<_> = into_matrix(l, r)?;
4766
Ok((self, r.into_triangular(UPLO::Upper)))
4867
}
4968
}
5069

70+
impl<A, S> QRSquareInto for ArrayBase<S, Ix2>
71+
where
72+
A: Scalar,
73+
S: DataMut<Elem = A>,
74+
{
75+
type R = Array2<A>;
76+
77+
fn qr_square_into(mut self) -> Result<(Self, Self::R)> {
78+
let (_, r) = self.qr_square_mut()?;
79+
Ok((self, r))
80+
}
81+
}
82+
5183
impl<A, S> QRSquare for ArrayBase<S, Ix2>
5284
where
53-
A: LapackScalar + Copy + Zero,
85+
A: Scalar,
5486
S: Data<Elem = A>,
5587
{
5688
type Q = Array2<A>;
@@ -65,7 +97,7 @@ where
6597

6698
impl<A, S> QRInto for ArrayBase<S, Ix2>
6799
where
68-
A: LapackScalar + Copy + Zero,
100+
A: Scalar,
69101
S: DataMut<Elem = A>,
70102
{
71103
type Q = Array2<A>;
@@ -85,7 +117,7 @@ where
85117

86118
impl<A, S> QR for ArrayBase<S, Ix2>
87119
where
88-
A: LapackScalar + Copy + Zero,
120+
A: Scalar,
89121
S: Data<Elem = A>,
90122
{
91123
type Q = Array2<A>;

src/solve.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//! Solve linear problems
22
3-
43
use ndarray::*;
54

65
use super::convert::*;
76
use super::error::*;
8-
use super::lapack_traits::*;
97
use super::layout::*;
108
use super::types::*;
119

@@ -18,7 +16,7 @@ pub struct Factorized<S: Data> {
1816

1917
impl<A, S> Factorized<S>
2018
where
21-
A: LapackScalar,
19+
A: Scalar,
2220
S: Data<Elem = A>,
2321
{
2422
pub fn solve<Sb>(&self, t: Transpose, mut rhs: ArrayBase<Sb, Ix1>) -> Result<ArrayBase<Sb, Ix1>>
@@ -38,7 +36,7 @@ where
3836

3937
impl<A, S> Factorized<S>
4038
where
41-
A: LapackScalar,
39+
A: Scalar,
4240
S: DataMut<Elem = A>,
4341
{
4442
pub fn into_inverse(mut self) -> Result<ArrayBase<S, Ix2>> {

src/svd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! singular-value decomposition
2+
//!
3+
//! https://en.wikipedia.org/wiki/Singular_value_decomposition
24
35
use ndarray::*;
46

@@ -7,20 +9,23 @@ use super::error::*;
79
use super::layout::*;
810
use super::types::*;
911

12+
/// singular-value decomposition of matrix reference
1013
pub trait SVD {
1114
type U;
1215
type VT;
1316
type Sigma;
1417
fn svd(&self, calc_u: bool, calc_vt: bool) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)>;
1518
}
1619

20+
/// singular-value decomposition
1721
pub trait SVDInto {
1822
type U;
1923
type VT;
2024
type Sigma;
2125
fn svd_into(self, calc_u: bool, calc_vt: bool) -> Result<(Option<Self::U>, Self::Sigma, Option<Self::VT>)>;
2226
}
2327

28+
/// singular-value decomposition for mutable reference of matrix
2429
pub trait SVDMut {
2530
type U;
2631
type VT;

0 commit comments

Comments
 (0)