Skip to content

Rename *_mut to *_inplace to match ndarray #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/cholesky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ where
A: Scalar,
S: Data<Elem = A>,
{
fn solvec_mut<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
where
Sb: DataMut<Elem = A>,
{
Expand Down Expand Up @@ -205,7 +205,7 @@ pub trait CholeskyInto {
}

/// Cholesky decomposition of Hermitian (or real symmetric) positive definite mutable reference of matrix
pub trait CholeskyMut {
pub trait CholeskyInplace {
/// Computes the Cholesky decomposition of the Hermitian (or real
/// symmetric) positive definite matrix, writing the result (`L` or `U`
/// according to the argument) to `self` and returning it.
Expand All @@ -214,7 +214,7 @@ pub trait CholeskyMut {
/// U^H * U` using the upper triangular portion of `A` and writes `U`.
/// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
/// `A = L * L^H` using the lower triangular portion of `A` and writes `L`.
fn cholesky_mut(&mut self, UPLO) -> Result<&mut Self>;
fn cholesky_inplace(&mut self, UPLO) -> Result<&mut Self>;
}

impl<A, S> Cholesky for ArrayBase<S, Ix2>
Expand All @@ -238,17 +238,17 @@ where
type Output = Self;

fn cholesky_into(mut self, uplo: UPLO) -> Result<Self> {
self.cholesky_mut(uplo)?;
self.cholesky_inplace(uplo)?;
Ok(self)
}
}

impl<A, S> CholeskyMut for ArrayBase<S, Ix2>
impl<A, S> CholeskyInplace for ArrayBase<S, Ix2>
where
A: Scalar,
S: DataMut<Elem = A>,
{
fn cholesky_mut(&mut self, uplo: UPLO) -> Result<&mut Self> {
fn cholesky_inplace(&mut self, uplo: UPLO) -> Result<&mut Self> {
unsafe { A::cholesky(self.square_layout()?, uplo, self.as_allocated_mut()?)? };
Ok(self.into_triangular(uplo))
}
Expand Down Expand Up @@ -314,33 +314,33 @@ pub trait CholeskySolve<A: Scalar> {
/// the argument, and `x` is the successful result.
fn solvec<S: Data<Elem = A>>(&self, b: &ArrayBase<S, Ix1>) -> Result<Array1<A>> {
let mut b = replicate(b);
self.solvec_mut(&mut b)?;
self.solvec_inplace(&mut b)?;
Ok(b)
}
/// Solves a system of linear equations `A * x = b` with Hermitian (or real
/// symmetric) positive definite matrix `A`, where `A` is `self`, `b` is
/// the argument, and `x` is the successful result.
fn solvec_into<S: DataMut<Elem = A>>(&self, mut b: ArrayBase<S, Ix1>) -> Result<ArrayBase<S, Ix1>> {
self.solvec_mut(&mut b)?;
self.solvec_inplace(&mut b)?;
Ok(b)
}
/// Solves a system of linear equations `A * x = b` with Hermitian (or real
/// symmetric) positive definite matrix `A`, where `A` is `self`, `b` is
/// the argument, and `x` is the successful result. The value of `x` is
/// also assigned to the argument.
fn solvec_mut<'a, S: DataMut<Elem = A>>(&self, &'a mut ArrayBase<S, Ix1>) -> Result<&'a mut ArrayBase<S, Ix1>>;
fn solvec_inplace<'a, S: DataMut<Elem = A>>(&self, &'a mut ArrayBase<S, Ix1>) -> Result<&'a mut ArrayBase<S, Ix1>>;
}

impl<A, S> CholeskySolve<A> for ArrayBase<S, Ix2>
where
A: Scalar,
S: Data<Elem = A>,
{
fn solvec_mut<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
where
Sb: DataMut<Elem = A>,
{
self.factorizec(UPLO::Upper)?.solvec_mut(b)
self.factorizec(UPLO::Upper)?.solvec_inplace(b)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/diagonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ impl<A, S: Data<Elem = A>> AsDiagonal<A> for ArrayBase<S, Ix1> {
}
}

impl<A, S, Sr> OperatorMut<Sr, Ix1> for Diagonal<S>
impl<A, S, Sr> OperatorInplace<Sr, Ix1> for Diagonal<S>
where
A: LinalgScalar,
S: Data<Elem = A>,
Sr: DataMut<Elem = A>,
{
fn op_mut<'a>(&self, mut a: &'a mut ArrayBase<Sr, Ix1>) -> &'a mut ArrayBase<Sr, Ix1> {
fn op_inplace<'a>(&self, mut a: &'a mut ArrayBase<Sr, Ix1>) -> &'a mut ArrayBase<Sr, Ix1> {
for (val, d) in a.iter_mut().zip(self.diag.iter()) {
*val = *val * *d;
}
Expand All @@ -52,7 +52,7 @@ where
{
fn op(&self, a: &ArrayBase<Sr, Ix1>) -> Array1<A> {
let mut a = replicate(a);
self.op_mut(&mut a);
self.op_inplace(&mut a);
a
}
}
Expand All @@ -69,13 +69,13 @@ where
}
}

impl<A, S, Sr> OperatorMut<Sr, Ix2> for Diagonal<S>
impl<A, S, Sr> OperatorInplace<Sr, Ix2> for Diagonal<S>
where
A: LinalgScalar,
S: Data<Elem = A>,
Sr: DataMut<Elem = A>,
{
fn op_mut<'a>(&self, mut a: &'a mut ArrayBase<Sr, Ix2>) -> &'a mut ArrayBase<Sr, Ix2> {
fn op_inplace<'a>(&self, mut a: &'a mut ArrayBase<Sr, Ix2>) -> &'a mut ArrayBase<Sr, Ix2> {
let ref d = self.diag;
for ((i, _), val) in a.indexed_iter_mut() {
*val = *val * d[i];
Expand All @@ -92,7 +92,7 @@ where
{
fn op(&self, a: &ArrayBase<Sr, Ix2>) -> Array2<A> {
let mut a = replicate(a);
self.op_mut(&mut a);
self.op_inplace(&mut a);
a
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/eigh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub trait Eigh {
}

/// Eigenvalue decomposition of mutable reference of Hermite matrix
pub trait EighMut {
pub trait EighInplace {
type EigVal;
fn eigh_mut(&mut self, UPLO) -> Result<(Self::EigVal, &mut Self)>;
fn eigh_inplace(&mut self, UPLO) -> Result<(Self::EigVal, &mut Self)>;
}

/// Eigenvalue decomposition of Hermite matrix
Expand All @@ -36,7 +36,7 @@ where
type EigVal = Array1<A::Real>;

fn eigh_into(mut self, uplo: UPLO) -> Result<(Self::EigVal, Self)> {
let (val, _) = self.eigh_mut(uplo)?;
let (val, _) = self.eigh_inplace(uplo)?;
Ok((val, self))
}
}
Expand All @@ -55,14 +55,14 @@ where
}
}

impl<A, S> EighMut for ArrayBase<S, Ix2>
impl<A, S> EighInplace for ArrayBase<S, Ix2>
where
A: Scalar,
S: DataMut<Elem = A>,
{
type EigVal = Array1<A::Real>;

fn eigh_mut(&mut self, uplo: UPLO) -> Result<(Self::EigVal, &mut Self)> {
fn eigh_inplace(&mut self, uplo: UPLO) -> Result<(Self::EigVal, &mut Self)> {
let s = unsafe { A::eigh(true, self.square_layout()?, uplo, self.as_allocated_mut()?)? };
Ok((ArrayBase::from_vec(s), self))
}
Expand All @@ -81,9 +81,9 @@ pub trait EigValshInto {
}

/// Calculate eigenvalues without eigenvectors
pub trait EigValshMut {
pub trait EigValshInplace {
type EigVal;
fn eigvalsh_mut(&mut self, UPLO) -> Result<Self::EigVal>;
fn eigvalsh_inplace(&mut self, UPLO) -> Result<Self::EigVal>;
}

impl<A, S> EigValshInto for ArrayBase<S, Ix2>
Expand All @@ -94,7 +94,7 @@ where
type EigVal = Array1<A::Real>;

fn eigvalsh_into(mut self, uplo: UPLO) -> Result<Self::EigVal> {
self.eigvalsh_mut(uplo)
self.eigvalsh_inplace(uplo)
}
}

Expand All @@ -111,14 +111,14 @@ where
}
}

impl<A, S> EigValshMut for ArrayBase<S, Ix2>
impl<A, S> EigValshInplace for ArrayBase<S, Ix2>
where
A: Scalar,
S: DataMut<Elem = A>,
{
type EigVal = Array1<A::Real>;

fn eigvalsh_mut(&mut self, uplo: UPLO) -> Result<Self::EigVal> {
fn eigvalsh_inplace(&mut self, uplo: UPLO) -> Result<Self::EigVal> {
let s = unsafe { A::eigh(true, self.square_layout()?, uplo, self.as_allocated_mut()?)? };
Ok(ArrayBase::from_vec(s))
}
Expand Down
22 changes: 11 additions & 11 deletions src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ where
fn op_into(&self, ArrayBase<S, D>) -> ArrayBase<S, D>;
}

pub trait OperatorMut<S, D>
pub trait OperatorInplace<S, D>
where
S: DataMut,
D: Dimension,
{
fn op_mut<'a>(&self, &'a mut ArrayBase<S, D>) -> &'a mut ArrayBase<S, D>;
fn op_inplace<'a>(&self, &'a mut ArrayBase<S, D>) -> &'a mut ArrayBase<S, D>;
}

impl<T, A, S, D> Operator<A, S, D> for T
Expand Down Expand Up @@ -53,7 +53,7 @@ where
A: Scalar,
S: DataMut<Elem = A>,
D: Dimension + RemoveAxis,
for<'a> T: OperatorMut<ViewRepr<&'a mut A>, D::Smaller>,
for<'a> T: OperatorInplace<ViewRepr<&'a mut A>, D::Smaller>,
{
fn op_multi(&self, a: &ArrayBase<S, D>) -> Array<A, D> {
let a = a.to_owned();
Expand All @@ -73,32 +73,32 @@ impl<T, A, S, D> OperatorMultiInto<S, D> for T
where
S: DataMut<Elem = A>,
D: Dimension + RemoveAxis,
for<'a> T: OperatorMut<ViewRepr<&'a mut A>, D::Smaller>,
for<'a> T: OperatorInplace<ViewRepr<&'a mut A>, D::Smaller>,
{
fn op_multi_into(&self, mut a: ArrayBase<S, D>) -> ArrayBase<S, D> {
self.op_multi_mut(&mut a);
self.op_multi_inplace(&mut a);
a
}
}

pub trait OperatorMultiMut<S, D>
pub trait OperatorMultiInplace<S, D>
where
S: DataMut,
D: Dimension,
{
fn op_multi_mut<'a>(&self, &'a mut ArrayBase<S, D>) -> &'a mut ArrayBase<S, D>;
fn op_multi_inplace<'a>(&self, &'a mut ArrayBase<S, D>) -> &'a mut ArrayBase<S, D>;
}

impl<T, A, S, D> OperatorMultiMut<S, D> for T
impl<T, A, S, D> OperatorMultiInplace<S, D> for T
where
S: DataMut<Elem = A>,
D: Dimension + RemoveAxis,
for<'a> T: OperatorMut<ViewRepr<&'a mut A>, D::Smaller>,
for<'a> T: OperatorInplace<ViewRepr<&'a mut A>, D::Smaller>,
{
fn op_multi_mut<'a>(&self, mut a: &'a mut ArrayBase<S, D>) -> &'a mut ArrayBase<S, D> {
fn op_multi_inplace<'a>(&self, mut a: &'a mut ArrayBase<S, D>) -> &'a mut ArrayBase<S, D> {
let n = a.ndim();
for mut col in a.axis_iter_mut(Axis(n - 1)) {
self.op_mut(&mut col);
self.op_inplace(&mut col);
}
a
}
Expand Down
10 changes: 5 additions & 5 deletions src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ pub trait QRSquareInto: Sized {
}

/// QR decomposition for mutable reference of square matrix
pub trait QRSquareMut: Sized {
pub trait QRSquareInplace: Sized {
type R;
fn qr_square_mut<'a>(&'a mut self) -> Result<(&'a mut Self, Self::R)>;
fn qr_square_inplace<'a>(&'a mut self) -> Result<(&'a mut Self, Self::R)>;
}

impl<A, S> QRSquareMut for ArrayBase<S, Ix2>
impl<A, S> QRSquareInplace for ArrayBase<S, Ix2>
where
A: Scalar,
S: DataMut<Elem = A>,
{
type R = Array2<A>;

fn qr_square_mut<'a>(&'a mut self) -> Result<(&'a mut Self, Self::R)> {
fn qr_square_inplace<'a>(&'a mut self) -> Result<(&'a mut Self, Self::R)> {
let l = self.square_layout()?;
let r = unsafe { A::qr(l, self.as_allocated_mut()?)? };
let r: Array2<_> = into_matrix(l, r)?;
Expand All @@ -75,7 +75,7 @@ where
type R = Array2<A>;

fn qr_square_into(mut self) -> Result<(Self, Self::R)> {
let (_, r) = self.qr_square_mut()?;
let (_, r) = self.qr_square_inplace()?;
Ok((self, r))
}
}
Expand Down
Loading