Skip to content

Commit 7137414

Browse files
authored
Merge pull request #135 from termoshtt/rust2018
Rust2018 edition
2 parents 59d0f82 + 8e4704e commit 7137414

38 files changed

+146
-208
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "ndarray-linalg"
33
version = "0.10.1-alpha.0"
44
authors = ["Toshiki Teramura <[email protected]>"]
5+
edition = "2018"
56

67
description = "Linear algebra package for rust-ndarray using LAPACK"
78
documentation = "https://docs.rs/ndarray-linalg/"

src/cholesky.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
use ndarray::*;
4747
use num_traits::Float;
4848

49-
use super::convert::*;
50-
use super::error::*;
51-
use super::layout::*;
52-
use super::triangular::IntoTriangular;
53-
use super::types::*;
49+
use crate::convert::*;
50+
use crate::error::*;
51+
use crate::layout::*;
52+
use crate::triangular::IntoTriangular;
53+
use crate::types::*;
5454

55-
pub use lapack_traits::UPLO;
55+
pub use crate::lapack_traits::UPLO;
5656

5757
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix
5858
pub struct CholeskyFactorized<S: Data> {
@@ -194,7 +194,7 @@ pub trait Cholesky {
194194
/// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
195195
/// `A = L * L^H` using the lower triangular portion of `A` and returns
196196
/// `L`.
197-
fn cholesky(&self, UPLO) -> Result<Self::Output>;
197+
fn cholesky(&self, uplo: UPLO) -> Result<Self::Output>;
198198
}
199199

200200
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix
@@ -208,7 +208,7 @@ pub trait CholeskyInto {
208208
/// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
209209
/// `A = L * L^H` using the lower triangular portion of `A` and returns
210210
/// `L`.
211-
fn cholesky_into(self, UPLO) -> Result<Self::Output>;
211+
fn cholesky_into(self, uplo: UPLO) -> Result<Self::Output>;
212212
}
213213

214214
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite mutable reference of matrix
@@ -221,7 +221,7 @@ pub trait CholeskyInplace {
221221
/// U^H * U` using the upper triangular portion of `A` and writes `U`.
222222
/// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
223223
/// `A = L * L^H` using the lower triangular portion of `A` and writes `L`.
224-
fn cholesky_inplace(&mut self, UPLO) -> Result<&mut Self>;
224+
fn cholesky_inplace(&mut self, uplo: UPLO) -> Result<&mut Self>;
225225
}
226226

227227
impl<A, S> Cholesky for ArrayBase<S, Ix2>
@@ -271,7 +271,7 @@ pub trait FactorizeC<S: Data> {
271271
/// factorization containing `U`. Otherwise, if the argument is
272272
/// `UPLO::Lower`, computes the decomposition `A = L * L^H` using the lower
273273
/// triangular portion of `A` and returns the factorization containing `L`.
274-
fn factorizec(&self, UPLO) -> Result<CholeskyFactorized<S>>;
274+
fn factorizec(&self, uplo: UPLO) -> Result<CholeskyFactorized<S>>;
275275
}
276276

277277
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix
@@ -284,7 +284,7 @@ pub trait FactorizeCInto<S: Data> {
284284
/// factorization containing `U`. Otherwise, if the argument is
285285
/// `UPLO::Lower`, computes the decomposition `A = L * L^H` using the lower
286286
/// triangular portion of `A` and returns the factorization containing `L`.
287-
fn factorizec_into(self, UPLO) -> Result<CholeskyFactorized<S>>;
287+
fn factorizec_into(self, uplo: UPLO) -> Result<CholeskyFactorized<S>>;
288288
}
289289

290290
impl<A, S> FactorizeCInto<S> for ArrayBase<S, Ix2>
@@ -335,7 +335,10 @@ pub trait SolveC<A: Scalar> {
335335
/// symmetric) positive definite matrix `A`, where `A` is `self`, `b` is
336336
/// the argument, and `x` is the successful result. The value of `x` is
337337
/// also assigned to the argument.
338-
fn solvec_inplace<'a, S: DataMut<Elem = A>>(&self, &'a mut ArrayBase<S, Ix1>) -> Result<&'a mut ArrayBase<S, Ix1>>;
338+
fn solvec_inplace<'a, S: DataMut<Elem = A>>(
339+
&self,
340+
b: &'a mut ArrayBase<S, Ix1>,
341+
) -> Result<&'a mut ArrayBase<S, Ix1>>;
339342
}
340343

341344
impl<A, S> SolveC<A> for ArrayBase<S, Ix2>

src/eigh.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
33
use ndarray::*;
44

5-
use super::diagonal::*;
6-
use super::error::*;
7-
use super::layout::*;
8-
use super::operator::*;
9-
use super::types::*;
10-
use super::UPLO;
5+
use crate::diagonal::*;
6+
use crate::error::*;
7+
use crate::layout::*;
8+
use crate::operator::Operator;
9+
use crate::types::*;
10+
use crate::UPLO;
1111

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

1919
/// Eigenvalue decomposition of mutable reference of Hermite matrix
2020
pub trait EighInplace {
2121
type EigVal;
22-
fn eigh_inplace(&mut self, UPLO) -> Result<(Self::EigVal, &mut Self)>;
22+
fn eigh_inplace(&mut self, uplo: UPLO) -> Result<(Self::EigVal, &mut Self)>;
2323
}
2424

2525
/// Eigenvalue decomposition of Hermite matrix
2626
pub trait EighInto: Sized {
2727
type EigVal;
28-
fn eigh_into(self, UPLO) -> Result<(Self::EigVal, Self)>;
28+
fn eigh_into(self, uplo: UPLO) -> Result<(Self::EigVal, Self)>;
2929
}
3030

3131
impl<A, S> EighInto for ArrayBase<S, Ix2>
@@ -71,19 +71,19 @@ where
7171
/// Calculate eigenvalues without eigenvectors
7272
pub trait EigValsh {
7373
type EigVal;
74-
fn eigvalsh(&self, UPLO) -> Result<Self::EigVal>;
74+
fn eigvalsh(&self, uplo: UPLO) -> Result<Self::EigVal>;
7575
}
7676

7777
/// Calculate eigenvalues without eigenvectors
7878
pub trait EigValshInto {
7979
type EigVal;
80-
fn eigvalsh_into(self, UPLO) -> Result<Self::EigVal>;
80+
fn eigvalsh_into(self, uplo: UPLO) -> Result<Self::EigVal>;
8181
}
8282

8383
/// Calculate eigenvalues without eigenvectors
8484
pub trait EigValshInplace {
8585
type EigVal;
86-
fn eigvalsh_inplace(&mut self, UPLO) -> Result<Self::EigVal>;
86+
fn eigvalsh_inplace(&mut self, uplo: UPLO) -> Result<Self::EigVal>;
8787
}
8888

8989
impl<A, S> EigValshInto for ArrayBase<S, Ix2>
@@ -127,7 +127,7 @@ where
127127
/// Calculate symmetric square-root matrix using `eigh`
128128
pub trait SymmetricSqrt {
129129
type Output;
130-
fn ssqrt(&self, UPLO) -> Result<Self::Output>;
130+
fn ssqrt(&self, uplo: UPLO) -> Result<Self::Output>;
131131
}
132132

133133
impl<A, S> SymmetricSqrt for ArrayBase<S, Ix2>
@@ -146,7 +146,7 @@ where
146146
/// Calculate symmetric square-root matrix using `eigh`
147147
pub trait SymmetricSqrtInto {
148148
type Output;
149-
fn ssqrt_into(self, UPLO) -> Result<Self::Output>;
149+
fn ssqrt_into(self, uplo: UPLO) -> Result<Self::Output>;
150150
}
151151

152152
impl<A, S> SymmetricSqrtInto for ArrayBase<S, Ix2>

src/lapack_traits/cholesky.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
33
use lapacke;
44

5-
use error::*;
6-
use layout::MatrixLayout;
7-
use types::*;
5+
use crate::error::*;
6+
use crate::layout::MatrixLayout;
7+
use crate::types::*;
88

99
use super::{into_result, UPLO};
1010

1111
pub trait Cholesky_: Sized {
1212
/// Cholesky: wrapper of `*potrf`
1313
///
1414
/// **Warning: Only the portion of `a` corresponding to `UPLO` is written.**
15-
unsafe fn cholesky(MatrixLayout, UPLO, a: &mut [Self]) -> Result<()>;
15+
unsafe fn cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;
1616
/// Wrapper of `*potri`
1717
///
1818
/// **Warning: Only the portion of `a` corresponding to `UPLO` is written.**
19-
unsafe fn inv_cholesky(MatrixLayout, UPLO, a: &mut [Self]) -> Result<()>;
19+
unsafe fn inv_cholesky(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<()>;
2020
/// Wrapper of `*potrs`
21-
unsafe fn solve_cholesky(MatrixLayout, UPLO, a: &[Self], b: &mut [Self]) -> Result<()>;
21+
unsafe fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()>;
2222
}
2323

2424
macro_rules! impl_cholesky {

src/lapack_traits/eigh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
use lapacke;
44
use num_traits::Zero;
55

6-
use error::*;
7-
use layout::MatrixLayout;
8-
use types::*;
6+
use crate::error::*;
7+
use crate::layout::MatrixLayout;
8+
use crate::types::*;
99

1010
use super::{into_result, UPLO};
1111

1212
/// Wraps `*syev` for real and `*heev` for complex
1313
pub trait Eigh_: AssociatedReal {
14-
unsafe fn eigh(calc_eigenvec: bool, MatrixLayout, UPLO, a: &mut [Self]) -> Result<Vec<Self::Real>>;
14+
unsafe fn eigh(calc_eigenvec: bool, l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<Vec<Self::Real>>;
1515
}
1616

1717
macro_rules! impl_eigh {

src/lapack_traits/opnorm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
use lapacke;
44
use lapacke::Layout::ColumnMajor as cm;
55

6-
use layout::MatrixLayout;
7-
use types::*;
6+
use crate::layout::MatrixLayout;
7+
use crate::types::*;
88

99
pub use super::NormType;
1010

1111
pub trait OperatorNorm_: AssociatedReal {
12-
unsafe fn opnorm(NormType, MatrixLayout, &[Self]) -> Self::Real;
12+
unsafe fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
1313
}
1414

1515
macro_rules! impl_opnorm {

src/lapack_traits/qr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ use lapacke;
44
use num_traits::Zero;
55
use std::cmp::min;
66

7-
use error::*;
8-
use layout::MatrixLayout;
9-
use types::*;
7+
use crate::error::*;
8+
use crate::layout::MatrixLayout;
9+
use crate::types::*;
1010

1111
use super::into_result;
1212

1313
/// Wraps `*geqrf` and `*orgqr` (`*ungqr` for complex numbers)
1414
pub trait QR_: Sized {
15-
unsafe fn householder(MatrixLayout, a: &mut [Self]) -> Result<Vec<Self>>;
16-
unsafe fn q(MatrixLayout, a: &mut [Self], tau: &[Self]) -> Result<()>;
17-
unsafe fn qr(MatrixLayout, a: &mut [Self]) -> Result<Vec<Self>>;
15+
unsafe fn householder(l: MatrixLayout, a: &mut [Self]) -> Result<Vec<Self>>;
16+
unsafe fn q(l: MatrixLayout, a: &mut [Self], tau: &[Self]) -> Result<()>;
17+
unsafe fn qr(l: MatrixLayout, a: &mut [Self]) -> Result<Vec<Self>>;
1818
}
1919

2020
macro_rules! impl_qr {

src/lapack_traits/solve.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Solve linear problem using LU decomposition
22
33
use lapacke;
4-
5-
use error::*;
6-
use layout::MatrixLayout;
74
use num_traits::Zero;
8-
use types::*;
5+
6+
use crate::error::*;
7+
use crate::layout::MatrixLayout;
8+
use crate::types::*;
99

1010
use super::NormType;
1111
use super::{into_result, Pivot, Transpose};
@@ -20,13 +20,13 @@ pub trait Solve_: AssociatedReal + Sized {
2020
/// return_code-1)]` is exactly zero. The factorization has been completed,
2121
/// but the factor `U` is exactly singular, and division by zero will occur
2222
/// if it is used to solve a system of equations.
23-
unsafe fn lu(MatrixLayout, a: &mut [Self]) -> Result<Pivot>;
24-
unsafe fn inv(MatrixLayout, a: &mut [Self], &Pivot) -> Result<()>;
23+
unsafe fn lu(l: MatrixLayout, a: &mut [Self]) -> Result<Pivot>;
24+
unsafe fn inv(l: MatrixLayout, a: &mut [Self], p: &Pivot) -> Result<()>;
2525
/// Estimates the the reciprocal of the condition number of the matrix in 1-norm.
2626
///
2727
/// `anorm` should be the 1-norm of the matrix `a`.
28-
unsafe fn rcond(MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;
29-
unsafe fn solve(MatrixLayout, Transpose, a: &[Self], &Pivot, b: &mut [Self]) -> Result<()>;
28+
unsafe fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;
29+
unsafe fn solve(l: MatrixLayout, t: Transpose, a: &[Self], p: &Pivot, b: &mut [Self]) -> Result<()>;
3030
}
3131

3232
macro_rules! impl_solve {

src/lapack_traits/solveh.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
55
use lapacke;
66

7-
use error::*;
8-
use layout::MatrixLayout;
9-
use types::*;
7+
use crate::error::*;
8+
use crate::layout::MatrixLayout;
9+
use crate::types::*;
1010

1111
use super::{into_result, Pivot, UPLO};
1212

1313
pub trait Solveh_: Sized {
1414
/// Bunch-Kaufman: wrapper of `*sytrf` and `*hetrf`
15-
unsafe fn bk(MatrixLayout, UPLO, a: &mut [Self]) -> Result<Pivot>;
15+
unsafe fn bk(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<Pivot>;
1616
/// Wrapper of `*sytri` and `*hetri`
17-
unsafe fn invh(MatrixLayout, UPLO, a: &mut [Self], &Pivot) -> Result<()>;
17+
unsafe fn invh(l: MatrixLayout, uplo: UPLO, a: &mut [Self], ipiv: &Pivot) -> Result<()>;
1818
/// Wrapper of `*sytrs` and `*hetrs`
19-
unsafe fn solveh(MatrixLayout, UPLO, a: &[Self], &Pivot, b: &mut [Self]) -> Result<()>;
19+
unsafe fn solveh(l: MatrixLayout, uplo: UPLO, a: &[Self], ipiv: &Pivot, b: &mut [Self]) -> Result<()>;
2020
}
2121

2222
macro_rules! impl_solveh {

src/lapack_traits/svd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use lapacke;
44
use num_traits::Zero;
55

6-
use error::*;
7-
use layout::MatrixLayout;
8-
use types::*;
6+
use crate::error::*;
7+
use crate::layout::MatrixLayout;
8+
use crate::types::*;
99

1010
use super::into_result;
1111

@@ -29,7 +29,7 @@ pub struct SVDOutput<A: AssociatedReal> {
2929

3030
/// Wraps `*gesvd`
3131
pub trait SVD_: AssociatedReal {
32-
unsafe fn svd(MatrixLayout, calc_u: bool, calc_vt: bool, a: &mut [Self]) -> Result<SVDOutput<Self>>;
32+
unsafe fn svd(l: MatrixLayout, calc_u: bool, calc_vt: bool, a: &mut [Self]) -> Result<SVDOutput<Self>>;
3333
}
3434

3535
macro_rules! impl_svd {

src/lapack_traits/triangular.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
use lapacke;
44

55
use super::{into_result, Transpose, UPLO};
6-
use error::*;
7-
use layout::MatrixLayout;
8-
use types::*;
6+
7+
use crate::error::*;
8+
use crate::layout::MatrixLayout;
9+
use crate::types::*;
910

1011
#[derive(Debug, Clone, Copy)]
1112
#[repr(u8)]
@@ -16,12 +17,12 @@ pub enum Diag {
1617

1718
/// Wraps `*trtri` and `*trtrs`
1819
pub trait Triangular_: Sized {
19-
unsafe fn inv_triangular(l: MatrixLayout, UPLO, Diag, a: &mut [Self]) -> Result<()>;
20+
unsafe fn inv_triangular(l: MatrixLayout, uplo: UPLO, d: Diag, a: &mut [Self]) -> Result<()>;
2021
unsafe fn solve_triangular(
2122
al: MatrixLayout,
2223
bl: MatrixLayout,
23-
UPLO,
24-
Diag,
24+
uplo: UPLO,
25+
d: Diag,
2526
a: &[Self],
2627
b: &mut [Self],
2728
) -> Result<()>;

src/layout.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ where
129129
}
130130

131131
fn as_allocated(&self) -> Result<&[A]> {
132-
Ok(self
133-
.as_slice_memory_order()
134-
.ok_or_else(|| LinalgError::MemoryNotCont)?)
132+
Ok(self.as_slice_memory_order().ok_or_else(|| LinalgError::MemoryNotCont)?)
135133
}
136134
}
137135

src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
//! - [generator functions](generate/index.html)
1818
//! - [Scalar trait](types/trait.Scalar.html)
1919
20-
extern crate lapacke;
21-
extern crate num_complex;
22-
extern crate num_traits;
23-
extern crate rand;
24-
#[macro_use(s)]
25-
extern crate ndarray;
26-
2720
pub mod assert;
2821
pub mod cholesky;
2922
pub mod convert;

0 commit comments

Comments
 (0)