Skip to content

Separation of Scalar trait into another crate #139

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 11 commits into from
Apr 27, 2019
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ serde-1 = ["ndarray/serde-1", "num-complex/serde"]
[dependencies]
lapacke = "0.2"
num-traits = "0.2"
rand = "0.6"
rand = "0.5"
cauchy = "0.2"

[dependencies.num-complex]
version = "0.2"
version = "0.2.1"
default-features = false
features = ["rand"]

[dependencies.ndarray]
version = "0.12"
Expand Down
6 changes: 3 additions & 3 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn close_max<A, S1, S2, D>(
atol: A::Real,
) -> Result<A::Real, A::Real>
where
A: Scalar,
A: Scalar + Lapack,
S1: Data<Elem = A>,
S2: Data<Elem = A>,
D: Dimension,
Expand All @@ -52,7 +52,7 @@ pub fn close_l1<A, S1, S2, D>(
rtol: A::Real,
) -> Result<A::Real, A::Real>
where
A: Scalar,
A: Scalar + Lapack,
S1: Data<Elem = A>,
S2: Data<Elem = A>,
D: Dimension,
Expand All @@ -72,7 +72,7 @@ pub fn close_l2<A, S1, S2, D>(
rtol: A::Real,
) -> Result<A::Real, A::Real>
where
A: Scalar,
A: Scalar + Lapack,
S1: Data<Elem = A>,
S2: Data<Elem = A>,
D: Dimension,
Expand Down
44 changes: 22 additions & 22 deletions src/cholesky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::layout::*;
use crate::triangular::IntoTriangular;
use crate::types::*;

pub use crate::lapack_traits::UPLO;
pub use crate::lapack::UPLO;

/// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix
pub struct CholeskyFactorized<S: Data> {
Expand All @@ -66,7 +66,7 @@ pub struct CholeskyFactorized<S: Data> {

impl<A, S> CholeskyFactorized<S>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
/// Returns `L` from the Cholesky decomposition `A = L * L^H`.
Expand Down Expand Up @@ -96,10 +96,10 @@ where

impl<A, S> DeterminantC for CholeskyFactorized<S>
where
A: Absolute,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = <A as AssociatedReal>::Real;
type Output = <A as Scalar>::Real;

fn detc(&self) -> Self::Output {
self.ln_detc().exp()
Expand All @@ -109,17 +109,17 @@ where
self.factor
.diag()
.iter()
.map(|elem| elem.abs_sqr().ln())
.map(|elem| elem.square().ln())
.sum::<Self::Output>()
}
}

impl<A, S> DeterminantCInto for CholeskyFactorized<S>
where
A: Absolute,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = <A as AssociatedReal>::Real;
type Output = <A as Scalar>::Real;

fn detc_into(self) -> Self::Output {
self.detc()
Expand All @@ -132,7 +132,7 @@ where

impl<A, S> InverseC for CholeskyFactorized<S>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = Array2<A>;
Expand All @@ -148,7 +148,7 @@ where

impl<A, S> InverseCInto for CholeskyFactorized<S>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type Output = ArrayBase<S, Ix2>;
Expand All @@ -163,7 +163,7 @@ where

impl<A, S> SolveC<A> for CholeskyFactorized<S>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
Expand Down Expand Up @@ -226,7 +226,7 @@ pub trait CholeskyInplace {

impl<A, S> Cholesky for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = Array2<A>;
Expand All @@ -239,7 +239,7 @@ where

impl<A, S> CholeskyInto for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type Output = Self;
Expand All @@ -252,7 +252,7 @@ where

impl<A, S> CholeskyInplace for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
fn cholesky_inplace(&mut self, uplo: UPLO) -> Result<&mut Self> {
Expand Down Expand Up @@ -289,7 +289,7 @@ pub trait FactorizeCInto<S: Data> {

impl<A, S> FactorizeCInto<S> for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
fn factorizec_into(self, uplo: UPLO) -> Result<CholeskyFactorized<S>> {
Expand All @@ -302,7 +302,7 @@ where

impl<A, Si> FactorizeC<OwnedRepr<A>> for ArrayBase<Si, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
Si: Data<Elem = A>,
{
fn factorizec(&self, uplo: UPLO) -> Result<CholeskyFactorized<OwnedRepr<A>>> {
Expand Down Expand Up @@ -343,7 +343,7 @@ pub trait SolveC<A: Scalar> {

impl<A, S> SolveC<A> for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
fn solvec_inplace<'a, Sb>(&self, b: &'a mut ArrayBase<Sb, Ix1>) -> Result<&'a mut ArrayBase<Sb, Ix1>>
Expand Down Expand Up @@ -372,7 +372,7 @@ pub trait InverseCInto {

impl<A, S> InverseC for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = Array2<A>;
Expand All @@ -384,7 +384,7 @@ where

impl<A, S> InverseCInto for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type Output = Self;
Expand Down Expand Up @@ -430,10 +430,10 @@ pub trait DeterminantCInto {

impl<A, S> DeterminantC for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = Result<<A as AssociatedReal>::Real>;
type Output = Result<<A as Scalar>::Real>;

fn detc(&self) -> Self::Output {
Ok(self.ln_detc()?.exp())
Expand All @@ -446,10 +446,10 @@ where

impl<A, S> DeterminantCInto for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type Output = Result<<A as AssociatedReal>::Real>;
type Output = Result<<A as Scalar>::Real>;

fn detc_into(self) -> Self::Output {
Ok(self.ln_detc_into()?.exp())
Expand Down
6 changes: 3 additions & 3 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use ndarray::*;

use super::error::*;
use super::lapack_traits::UPLO;
use super::lapack::UPLO;
use super::layout::*;
use super::types::Conjugate;
use super::types::*;

pub fn into_col<S>(a: ArrayBase<S, Ix1>) -> ArrayBase<S, Ix2>
where
Expand Down Expand Up @@ -107,7 +107,7 @@ where
/// ***Panics*** if `a` is not square.
pub(crate) fn triangular_fill_hermitian<A, S>(a: &mut ArrayBase<S, Ix2>, uplo: UPLO)
where
A: Conjugate,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
assert!(a.is_square());
Expand Down
18 changes: 9 additions & 9 deletions src/eigh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait EighInto: Sized {

impl<A, S> EighInto for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type EigVal = Array1<A::Real>;
Expand All @@ -43,7 +43,7 @@ where

impl<A, S> Eigh for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type EigVal = Array1<A::Real>;
Expand All @@ -57,7 +57,7 @@ where

impl<A, S> EighInplace for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type EigVal = Array1<A::Real>;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub trait EigValshInplace {

impl<A, S> EigValshInto for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type EigVal = Array1<A::Real>;
Expand All @@ -100,7 +100,7 @@ where

impl<A, S> EigValsh for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type EigVal = Array1<A::Real>;
Expand All @@ -113,7 +113,7 @@ where

impl<A, S> EigValshInplace for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A>,
{
type EigVal = Array1<A::Real>;
Expand All @@ -132,7 +132,7 @@ pub trait SymmetricSqrt {

impl<A, S> SymmetricSqrt for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = Array2<A>;
Expand All @@ -151,14 +151,14 @@ pub trait SymmetricSqrtInto {

impl<A, S> SymmetricSqrtInto for ArrayBase<S, Ix2>
where
A: Scalar,
A: Scalar + Lapack,
S: DataMut<Elem = A> + DataOwned,
{
type Output = Array2<A>;

fn ssqrt_into(self, uplo: UPLO) -> Result<Self::Output> {
let (e, v) = self.eigh_into(uplo)?;
let e_sqrt = Array1::from_iter(e.iter().map(|r| AssociatedReal::inject(r.sqrt())));
let e_sqrt = Array1::from_iter(e.iter().map(|r| Scalar::from_real(r.sqrt())));
let ev = e_sqrt.into_diagonal().op(&v.t());
Ok(v.op(&ev))
}
Expand Down
Loading