forked from M-Labs/nalgebra
Run rustmt.
This commit is contained in:
parent
a3d363f397
commit
0d24cf4dc0
@ -1,6 +1,6 @@
|
|||||||
use base::Matrix;
|
|
||||||
use base::dimension::{Dynamic, U1, U2, U3, U4, U5, U6};
|
use base::dimension::{Dynamic, U1, U2, U3, U4, U5, U6};
|
||||||
use base::matrix_slice::{SliceStorage, SliceStorageMut};
|
use base::matrix_slice::{SliceStorage, SliceStorageMut};
|
||||||
|
use base::Matrix;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use base::{DefaultAllocator, Scalar};
|
|
||||||
use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
||||||
use base::dimension::{Dim, U1};
|
use base::dimension::{Dim, U1};
|
||||||
use base::storage::ContiguousStorageMut;
|
use base::storage::ContiguousStorageMut;
|
||||||
|
use base::{DefaultAllocator, Scalar};
|
||||||
|
|
||||||
/// A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()`
|
/// A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()`
|
||||||
/// elements of type `N`.
|
/// elements of type `N`.
|
||||||
@ -33,8 +33,9 @@ pub trait Allocator<N: Scalar, R: Dim, C: Dim = U1>: Any + Sized {
|
|||||||
|
|
||||||
/// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom ×
|
/// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom ×
|
||||||
/// CFrom) elements to a smaller or larger size (RTo, CTo).
|
/// CFrom) elements to a smaller or larger size (RTo, CTo).
|
||||||
pub trait Reallocator<N: Scalar, RFrom: Dim, CFrom: Dim, RTo: Dim, CTo: Dim>
|
pub trait Reallocator<N: Scalar, RFrom: Dim, CFrom: Dim, RTo: Dim, CTo: Dim>:
|
||||||
: Allocator<N, RFrom, CFrom> + Allocator<N, RTo, CTo> {
|
Allocator<N, RFrom, CFrom> + Allocator<N, RTo, CTo>
|
||||||
|
{
|
||||||
/// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer
|
/// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer
|
||||||
/// `buf`. Data stored by `buf` are linearly copied to the output:
|
/// `buf`. Data stored by `buf` are linearly copied to the output:
|
||||||
///
|
///
|
||||||
@ -57,8 +58,8 @@ pub type SameShapeC<C1, C2> = <ShapeConstraint as SameNumberOfColumns<C1, C2>>::
|
|||||||
|
|
||||||
// FIXME: Bad name.
|
// FIXME: Bad name.
|
||||||
/// Restricts the given number of rows and columns to be respectively the same.
|
/// Restricts the given number of rows and columns to be respectively the same.
|
||||||
pub trait SameShapeAllocator<N, R1, C1, R2, C2>
|
pub trait SameShapeAllocator<N, R1, C1, R2, C2>:
|
||||||
: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>
|
Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>
|
||||||
where
|
where
|
||||||
R1: Dim,
|
R1: Dim,
|
||||||
R2: Dim,
|
R2: Dim,
|
||||||
@ -78,13 +79,12 @@ where
|
|||||||
N: Scalar,
|
N: Scalar,
|
||||||
DefaultAllocator: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>,
|
DefaultAllocator: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>,
|
||||||
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
|
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: Bad name.
|
// XXX: Bad name.
|
||||||
/// Restricts the given number of rows to be equal.
|
/// Restricts the given number of rows to be equal.
|
||||||
pub trait SameShapeVectorAllocator<N, R1, R2>
|
pub trait SameShapeVectorAllocator<N, R1, R2>:
|
||||||
: Allocator<N, R1> + Allocator<N, SameShapeR<R1, R2>> + SameShapeAllocator<N, R1, U1, R2, U1>
|
Allocator<N, R1> + Allocator<N, SameShapeR<R1, R2>> + SameShapeAllocator<N, R1, U1, R2, U1>
|
||||||
where
|
where
|
||||||
R1: Dim,
|
R1: Dim,
|
||||||
R2: Dim,
|
R2: Dim,
|
||||||
@ -100,5 +100,4 @@ where
|
|||||||
N: Scalar,
|
N: Scalar,
|
||||||
DefaultAllocator: Allocator<N, R1, U1> + Allocator<N, SameShapeR<R1, R2>>,
|
DefaultAllocator: Allocator<N, R1, U1> + Allocator<N, SameShapeR<R1, R2>>,
|
||||||
ShapeConstraint: SameNumberOfRows<R1, R2>,
|
ShapeConstraint: SameNumberOfRows<R1, R2>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
@ -14,7 +14,6 @@ use base::storage::{Storage, StorageMut};
|
|||||||
use base::{DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector};
|
use base::{DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector};
|
||||||
|
|
||||||
impl<N: Scalar + PartialOrd + Signed, D: Dim, S: Storage<N, D>> Vector<N, D, S> {
|
impl<N: Scalar + PartialOrd + Signed, D: Dim, S: Storage<N, D>> Vector<N, D, S> {
|
||||||
|
|
||||||
/// Computes the index of the vector component with the largest value.
|
/// Computes the index of the vector component with the largest value.
|
||||||
///
|
///
|
||||||
/// # Examples:
|
/// # Examples:
|
||||||
@ -685,13 +684,19 @@ where
|
|||||||
// We could use matrixmultiply for large statically-sized matrices but the performance
|
// We could use matrixmultiply for large statically-sized matrices but the performance
|
||||||
// threshold to activate it would be different from SMALL_DIM because our code optimizes
|
// threshold to activate it would be different from SMALL_DIM because our code optimizes
|
||||||
// better for statically-sized matrices.
|
// better for statically-sized matrices.
|
||||||
let is_dynamic = R1::is::<Dynamic>() || C1::is::<Dynamic>() || R2::is::<Dynamic>()
|
let is_dynamic = R1::is::<Dynamic>()
|
||||||
|| C2::is::<Dynamic>() || R3::is::<Dynamic>()
|
|| C1::is::<Dynamic>()
|
||||||
|
|| R2::is::<Dynamic>()
|
||||||
|
|| C2::is::<Dynamic>()
|
||||||
|
|| R3::is::<Dynamic>()
|
||||||
|| C3::is::<Dynamic>();
|
|| C3::is::<Dynamic>();
|
||||||
// Threshold determined empirically.
|
// Threshold determined empirically.
|
||||||
const SMALL_DIM: usize = 5;
|
const SMALL_DIM: usize = 5;
|
||||||
|
|
||||||
if is_dynamic && nrows1 > SMALL_DIM && ncols1 > SMALL_DIM && nrows2 > SMALL_DIM
|
if is_dynamic
|
||||||
|
&& nrows1 > SMALL_DIM
|
||||||
|
&& ncols1 > SMALL_DIM
|
||||||
|
&& nrows2 > SMALL_DIM
|
||||||
&& ncols2 > SMALL_DIM
|
&& ncols2 > SMALL_DIM
|
||||||
{
|
{
|
||||||
if N::is::<f32>() {
|
if N::is::<f32>() {
|
||||||
|
@ -7,15 +7,18 @@
|
|||||||
|
|
||||||
use num::One;
|
use num::One;
|
||||||
|
|
||||||
use base::{DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector,
|
use base::allocator::Allocator;
|
||||||
Vector3, VectorN};
|
|
||||||
use base::dimension::{DimName, DimNameDiff, DimNameSub, U1};
|
use base::dimension::{DimName, DimNameDiff, DimNameSub, U1};
|
||||||
use base::storage::{Storage, StorageMut};
|
use base::storage::{Storage, StorageMut};
|
||||||
use base::allocator::Allocator;
|
use base::{
|
||||||
use geometry::{Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point3, Rotation2,
|
DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, Vector3,
|
||||||
Rotation3};
|
VectorN,
|
||||||
|
};
|
||||||
|
use geometry::{
|
||||||
|
Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point3, Rotation2, Rotation3,
|
||||||
|
};
|
||||||
|
|
||||||
use alga::general::{Ring, Real};
|
use alga::general::{Real, Ring};
|
||||||
use alga::linear::Transformation;
|
use alga::linear::Transformation;
|
||||||
|
|
||||||
impl<N, D: DimName> MatrixN<N, D>
|
impl<N, D: DimName> MatrixN<N, D>
|
||||||
@ -302,7 +305,8 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
|||||||
SB: Storage<N, DimNameDiff<D, U1>>,
|
SB: Storage<N, DimNameDiff<D, U1>>,
|
||||||
DefaultAllocator: Allocator<N, DimNameDiff<D, U1>>,
|
DefaultAllocator: Allocator<N, DimNameDiff<D, U1>>,
|
||||||
{
|
{
|
||||||
let scale = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0)
|
let scale = self
|
||||||
|
.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0)
|
||||||
.tr_dot(&shift);
|
.tr_dot(&shift);
|
||||||
let post_translation =
|
let post_translation =
|
||||||
self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0) * shift;
|
self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0) * shift;
|
||||||
@ -341,9 +345,8 @@ where
|
|||||||
let transform = self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0);
|
let transform = self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0);
|
||||||
let translation = self.fixed_slice::<DimNameDiff<D, U1>, U1>(0, D::dim() - 1);
|
let translation = self.fixed_slice::<DimNameDiff<D, U1>, U1>(0, D::dim() - 1);
|
||||||
let normalizer = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0);
|
let normalizer = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0);
|
||||||
let n = normalizer.tr_dot(&pt.coords) + unsafe {
|
let n = normalizer.tr_dot(&pt.coords)
|
||||||
*self.get_unchecked(D::dim() - 1, D::dim() - 1)
|
+ unsafe { *self.get_unchecked(D::dim() - 1, D::dim() - 1) };
|
||||||
};
|
|
||||||
|
|
||||||
if !n.is_zero() {
|
if !n.is_zero() {
|
||||||
return transform * (pt / n) + translation;
|
return transform * (pt / n) + translation;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Non-conventional componentwise operators.
|
// Non-conventional component-wise operators.
|
||||||
|
|
||||||
use num::{Signed, Zero};
|
use num::{Signed, Zero};
|
||||||
use std::ops::{Add, Mul};
|
use std::ops::{Add, Mul};
|
||||||
|
@ -8,11 +8,9 @@ pub struct ShapeConstraint;
|
|||||||
/// Constraints `C1` and `R2` to be equivalent.
|
/// Constraints `C1` and `R2` to be equivalent.
|
||||||
pub trait AreMultipliable<R1: Dim, C1: Dim, R2: Dim, C2: Dim>: DimEq<C1, R2> {}
|
pub trait AreMultipliable<R1: Dim, C1: Dim, R2: Dim, C2: Dim>: DimEq<C1, R2> {}
|
||||||
|
|
||||||
impl<R1: Dim, C1: Dim, R2: Dim, C2: Dim> AreMultipliable<R1, C1, R2, C2> for ShapeConstraint
|
impl<R1: Dim, C1: Dim, R2: Dim, C2: Dim> AreMultipliable<R1, C1, R2, C2> for ShapeConstraint where
|
||||||
where
|
ShapeConstraint: DimEq<C1, R2>
|
||||||
ShapeConstraint: DimEq<C1, R2>,
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Constraints `D1` and `D2` to be equivalent.
|
/// Constraints `D1` and `D2` to be equivalent.
|
||||||
pub trait DimEq<D1: Dim, D2: Dim> {
|
pub trait DimEq<D1: Dim, D2: Dim> {
|
||||||
@ -70,8 +68,9 @@ equality_trait_decl!(
|
|||||||
|
|
||||||
/// Constraints D1 and D2 to be equivalent, where they both designate dimensions of algebraic
|
/// Constraints D1 and D2 to be equivalent, where they both designate dimensions of algebraic
|
||||||
/// entities (e.g. square matrices).
|
/// entities (e.g. square matrices).
|
||||||
pub trait SameDimension<D1: Dim, D2: Dim>
|
pub trait SameDimension<D1: Dim, D2: Dim>:
|
||||||
: SameNumberOfRows<D1, D2> + SameNumberOfColumns<D1, D2> {
|
SameNumberOfRows<D1, D2> + SameNumberOfColumns<D1, D2>
|
||||||
|
{
|
||||||
/// This is either equal to `D1` or `D2`, always choosing the one (if any) which is a type-level
|
/// This is either equal to `D1` or `D2`, always choosing the one (if any) which is a type-level
|
||||||
/// constant.
|
/// constant.
|
||||||
type Representative: Dim;
|
type Representative: Dim;
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
use base::{Matrix, Scalar};
|
|
||||||
use base::dimension::{U1, U2, U3, U4, U5, U6};
|
use base::dimension::{U1, U2, U3, U4, U5, U6};
|
||||||
use base::storage::{ContiguousStorage, ContiguousStorageMut};
|
use base::storage::{ContiguousStorage, ContiguousStorageMut};
|
||||||
|
use base::{Matrix, Scalar};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -7,7 +7,7 @@ use std::cmp;
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
use typenum::{
|
use typenum::{
|
||||||
self, B1, Bit, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, UInt, UTerm, Unsigned,
|
self, Bit, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, UInt, UTerm, Unsigned, B1,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
|
@ -285,7 +285,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
let copied_value_start = i + nremove.value();
|
let copied_value_start = i + nremove.value();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr_in = m.data
|
let ptr_in = m
|
||||||
|
.data
|
||||||
.ptr()
|
.ptr()
|
||||||
.offset((copied_value_start * nrows.value()) as isize);
|
.offset((copied_value_start * nrows.value()) as isize);
|
||||||
let ptr_out = m.data.ptr_mut().offset((i * nrows.value()) as isize);
|
let ptr_out = m.data.ptr_mut().offset((i * nrows.value()) as isize);
|
||||||
@ -448,7 +449,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
|
|
||||||
if ninsert.value() != 0 && i != ncols.value() {
|
if ninsert.value() != 0 && i != ncols.value() {
|
||||||
let ptr_in = res.data.ptr().offset((i * nrows.value()) as isize);
|
let ptr_in = res.data.ptr().offset((i * nrows.value()) as isize);
|
||||||
let ptr_out = res.data
|
let ptr_out = res
|
||||||
|
.data
|
||||||
.ptr_mut()
|
.ptr_mut()
|
||||||
.offset(((i + ninsert.value()) * nrows.value()) as isize);
|
.offset(((i + ninsert.value()) * nrows.value()) as isize);
|
||||||
|
|
||||||
|
@ -3,21 +3,20 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use base::Scalar;
|
|
||||||
use base::dimension::Dim;
|
use base::dimension::Dim;
|
||||||
use base::storage::{Storage, StorageMut};
|
use base::storage::{Storage, StorageMut};
|
||||||
|
use base::Scalar;
|
||||||
|
|
||||||
macro_rules! iterator {
|
macro_rules! iterator {
|
||||||
(struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => {
|
(struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => {
|
||||||
|
|
||||||
/// An iterator through a dense matrix with arbitrary strides matrix.
|
/// An iterator through a dense matrix with arbitrary strides matrix.
|
||||||
pub struct $Name<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> {
|
pub struct $Name<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> {
|
||||||
ptr: $Ptr,
|
ptr: $Ptr,
|
||||||
inner_ptr: $Ptr,
|
inner_ptr: $Ptr,
|
||||||
inner_end: $Ptr,
|
inner_end: $Ptr,
|
||||||
size: usize, // We can't use an end pointer here because a stride might be zero.
|
size: usize, // We can't use an end pointer here because a stride might be zero.
|
||||||
strides: (S::RStride, S::CStride),
|
strides: (S::RStride, S::CStride),
|
||||||
_phantoms: PhantomData<($Ref, R, C, S)>
|
_phantoms: PhantomData<($Ref, R, C, S)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: we need to specialize for the case where the matrix storage is owned (in which
|
// FIXME: we need to specialize for the case where the matrix storage is owned (in which
|
||||||
@ -25,23 +24,25 @@ macro_rules! iterator {
|
|||||||
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> $Name<'a, N, R, C, S> {
|
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> $Name<'a, N, R, C, S> {
|
||||||
/// Creates a new iterator for the given matrix storage.
|
/// Creates a new iterator for the given matrix storage.
|
||||||
pub fn new(storage: $SRef) -> $Name<'a, N, R, C, S> {
|
pub fn new(storage: $SRef) -> $Name<'a, N, R, C, S> {
|
||||||
let shape = storage.shape();
|
let shape = storage.shape();
|
||||||
let strides = storage.strides();
|
let strides = storage.strides();
|
||||||
let inner_offset = shape.0.value() * strides.0.value();
|
let inner_offset = shape.0.value() * strides.0.value();
|
||||||
let ptr = storage.$ptr();
|
let ptr = storage.$ptr();
|
||||||
|
|
||||||
$Name {
|
$Name {
|
||||||
ptr: ptr,
|
ptr: ptr,
|
||||||
inner_ptr: ptr,
|
inner_ptr: ptr,
|
||||||
inner_end: unsafe { ptr.offset(inner_offset as isize) },
|
inner_end: unsafe { ptr.offset(inner_offset as isize) },
|
||||||
size: shape.0.value() * shape.1.value(),
|
size: shape.0.value() * shape.1.value(),
|
||||||
strides: strides,
|
strides: strides,
|
||||||
_phantoms: PhantomData
|
_phantoms: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> Iterator for $Name<'a, N, R, C, S> {
|
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> Iterator
|
||||||
|
for $Name<'a, N, R, C, S>
|
||||||
|
{
|
||||||
type Item = $Ref;
|
type Item = $Ref;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -82,13 +83,15 @@ macro_rules! iterator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> ExactSizeIterator for $Name<'a, N, R, C, S> {
|
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> ExactSizeIterator
|
||||||
|
for $Name<'a, N, R, C, S>
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator!(struct MatrixIter for Storage.ptr -> *const N, &'a N, &'a S);
|
iterator!(struct MatrixIter for Storage.ptr -> *const N, &'a N, &'a S);
|
||||||
|
@ -107,8 +107,7 @@ where
|
|||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
GenericArray<N, Prod<R::Value, C::Value>>: Copy,
|
GenericArray<N, Prod<R::Value, C::Value>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N, R, C> Clone for MatrixArray<N, R, C>
|
impl<N, R, C> Clone for MatrixArray<N, R, C>
|
||||||
where
|
where
|
||||||
@ -133,8 +132,7 @@ where
|
|||||||
C: DimName,
|
C: DimName,
|
||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N, R, C> PartialEq for MatrixArray<N, R, C>
|
impl<N, R, C> PartialEq for MatrixArray<N, R, C>
|
||||||
where
|
where
|
||||||
@ -234,8 +232,7 @@ where
|
|||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<N, R, C> ContiguousStorageMut<N, R, C> for MatrixArray<N, R, C>
|
unsafe impl<N, R, C> ContiguousStorageMut<N, R, C> for MatrixArray<N, R, C>
|
||||||
where
|
where
|
||||||
@ -245,8 +242,7 @@ where
|
|||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -211,17 +211,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorage<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
unsafe impl<N: Scalar, C: Dim> ContiguousStorage<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where
|
||||||
where
|
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
unsafe impl<N: Scalar, C: Dim> ContiguousStorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where
|
||||||
where
|
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> StorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
unsafe impl<N: Scalar, R: DimName> StorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||||
where
|
where
|
||||||
@ -253,14 +249,10 @@ impl<N: Abomonation, R: Dim, C: Dim> Abomonation for MatrixVec<N, R, C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorage<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
unsafe impl<N: Scalar, R: DimName> ContiguousStorage<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where
|
||||||
where
|
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
unsafe impl<N: Scalar, R: DimName> ContiguousStorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where
|
||||||
where
|
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
@ -12,7 +12,6 @@ pub mod storage;
|
|||||||
|
|
||||||
mod alias;
|
mod alias;
|
||||||
mod alias_slice;
|
mod alias_slice;
|
||||||
mod swizzle;
|
|
||||||
mod cg;
|
mod cg;
|
||||||
mod componentwise;
|
mod componentwise;
|
||||||
mod construction;
|
mod construction;
|
||||||
@ -27,6 +26,7 @@ mod matrix_slice;
|
|||||||
mod matrix_vec;
|
mod matrix_vec;
|
||||||
mod properties;
|
mod properties;
|
||||||
mod scalar;
|
mod scalar;
|
||||||
|
mod swizzle;
|
||||||
mod unit;
|
mod unit;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
use std::iter;
|
|
||||||
use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub,
|
|
||||||
SubAssign};
|
|
||||||
use std::cmp::PartialOrd;
|
|
||||||
use num::{One, Signed, Zero};
|
use num::{One, Signed, Zero};
|
||||||
|
use std::cmp::PartialOrd;
|
||||||
|
use std::iter;
|
||||||
|
use std::ops::{
|
||||||
|
Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign,
|
||||||
|
};
|
||||||
|
|
||||||
use alga::general::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub};
|
use alga::general::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub};
|
||||||
|
|
||||||
use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, MatrixSum, Scalar};
|
|
||||||
use base::dimension::{Dim, DimMul, DimName, DimProd};
|
|
||||||
use base::constraint::{AreMultipliable, DimEq, SameNumberOfColumns, SameNumberOfRows,
|
|
||||||
ShapeConstraint};
|
|
||||||
use base::storage::{ContiguousStorageMut, Storage, StorageMut};
|
|
||||||
use base::allocator::{Allocator, SameShapeAllocator, SameShapeC, SameShapeR};
|
use base::allocator::{Allocator, SameShapeAllocator, SameShapeC, SameShapeR};
|
||||||
|
use base::constraint::{
|
||||||
|
AreMultipliable, DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint,
|
||||||
|
};
|
||||||
|
use base::dimension::{Dim, DimMul, DimName, DimProd};
|
||||||
|
use base::storage::{ContiguousStorageMut, Storage, StorageMut};
|
||||||
|
use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, MatrixSum, Scalar};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@ -783,7 +785,8 @@ impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matri
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn amin(&self) -> N {
|
pub fn amin(&self) -> N {
|
||||||
let mut it = self.iter();
|
let mut it = self.iter();
|
||||||
let mut min = it.next()
|
let mut min = it
|
||||||
|
.next()
|
||||||
.expect("amin: empty matrices not supported.")
|
.expect("amin: empty matrices not supported.")
|
||||||
.abs();
|
.abs();
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
use std::any::Any;
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
/// The basic scalar type for all structures of `nalgebra`.
|
/// The basic scalar type for all structures of `nalgebra`.
|
||||||
///
|
///
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use base::Scalar;
|
use base::allocator::{Allocator, SameShapeC, SameShapeR};
|
||||||
use base::default_allocator::DefaultAllocator;
|
use base::default_allocator::DefaultAllocator;
|
||||||
use base::dimension::{Dim, U1};
|
use base::dimension::{Dim, U1};
|
||||||
use base::allocator::{Allocator, SameShapeC, SameShapeR};
|
use base::Scalar;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Aliases for allocation results.
|
* Aliases for allocation results.
|
||||||
@ -177,8 +177,9 @@ pub unsafe trait StorageMut<N: Scalar, R: Dim, C: Dim = U1>: Storage<N, R, C> {
|
|||||||
/// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value
|
/// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value
|
||||||
/// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because
|
/// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because
|
||||||
/// failing to comply to this may cause Undefined Behaviors.
|
/// failing to comply to this may cause Undefined Behaviors.
|
||||||
pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>
|
pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>:
|
||||||
: Storage<N, R, C> {
|
Storage<N, R, C>
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A mutable matrix storage that is stored contiguously in memory.
|
/// A mutable matrix storage that is stored contiguously in memory.
|
||||||
@ -186,6 +187,7 @@ pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>
|
|||||||
/// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value
|
/// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value
|
||||||
/// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because
|
/// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because
|
||||||
/// failing to comply to this may cause Undefined Behaviors.
|
/// failing to comply to this may cause Undefined Behaviors.
|
||||||
pub unsafe trait ContiguousStorageMut<N: Scalar, R: Dim, C: Dim = U1>
|
pub unsafe trait ContiguousStorageMut<N: Scalar, R: Dim, C: Dim = U1>:
|
||||||
: ContiguousStorage<N, R, C> + StorageMut<N, R, C> {
|
ContiguousStorage<N, R, C> + StorageMut<N, R, C>
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use base::{Scalar, Vector, DimName, Vector2, Vector3};
|
use base::{DimName, Scalar, Vector, Vector2, Vector3};
|
||||||
use storage::Storage;
|
use storage::Storage;
|
||||||
use typenum::{self, Cmp, Greater};
|
use typenum::{self, Cmp, Greater};
|
||||||
|
|
||||||
|
|
||||||
macro_rules! impl_swizzle {
|
macro_rules! impl_swizzle {
|
||||||
($(where $BaseDim: ident: $name: ident() -> $Result: ident[$($i: expr),*]);*) => {
|
($(where $BaseDim: ident: $name: ident() -> $Result: ident[$($i: expr),*]);*) => {
|
||||||
$(
|
$(
|
||||||
@ -64,4 +63,4 @@ impl_swizzle!(
|
|||||||
where U2: zzx() -> Vector3[2, 2, 0];
|
where U2: zzx() -> Vector3[2, 2, 0];
|
||||||
where U2: zzy() -> Vector3[2, 2, 1];
|
where U2: zzy() -> Vector3[2, 2, 1];
|
||||||
where U2: zzz() -> Vector3[2, 2, 2]
|
where U2: zzz() -> Vector3[2, 2, 2]
|
||||||
);
|
);
|
||||||
|
@ -6,7 +6,7 @@ use std::io::{Result as IOResult, Write};
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
@ -26,23 +26,19 @@ use geometry::{Point, Translation};
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "R: Serialize,
|
||||||
serialize = "R: Serialize,
|
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Serialize"
|
Owned<N, D>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "R: Deserialize<'de>,
|
||||||
deserialize = "R: Deserialize<'de>,
|
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Deserialize<'de>"
|
Owned<N, D>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
pub struct Isometry<N: Real, D: DimName, R>
|
pub struct Isometry<N: Real, D: DimName, R>
|
||||||
where
|
where
|
||||||
@ -54,7 +50,10 @@ where
|
|||||||
pub translation: Translation<N, D>,
|
pub translation: Translation<N, D>,
|
||||||
|
|
||||||
// One dummy private field just to prevent explicit construction.
|
// One dummy private field just to prevent explicit construction.
|
||||||
#[cfg_attr(feature = "serde-serialize", serde(skip_serializing, skip_deserializing))]
|
#[cfg_attr(
|
||||||
|
feature = "serde-serialize",
|
||||||
|
serde(skip_serializing, skip_deserializing)
|
||||||
|
)]
|
||||||
_noconstruct: PhantomData<N>,
|
_noconstruct: PhantomData<N>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +97,7 @@ impl<N: Real, D: DimName + Copy, R: Rotation<Point<N, D>> + Copy> Copy for Isome
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Copy,
|
Owned<N, D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimName, R: Rotation<Point<N, D>> + Clone> Clone for Isometry<N, D, R>
|
impl<N: Real, D: DimName, R: Rotation<Point<N, D>> + Clone> Clone for Isometry<N, D, R>
|
||||||
where
|
where
|
||||||
@ -200,8 +198,7 @@ impl<N: Real, D: DimName, R> Eq for Isometry<N, D, R>
|
|||||||
where
|
where
|
||||||
R: Rotation<Point<N, D>> + Eq,
|
R: Rotation<Point<N, D>> + Eq,
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimName, R> PartialEq for Isometry<N, D, R>
|
impl<N: Real, D: DimName, R> PartialEq for Isometry<N, D, R>
|
||||||
where
|
where
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
use alga::general::{
|
||||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||||
Real};
|
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||||
|
};
|
||||||
use alga::linear::Isometry as AlgaIsometry;
|
use alga::linear::Isometry as AlgaIsometry;
|
||||||
use alga::linear::{AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation,
|
use alga::linear::{
|
||||||
Similarity, Transformation};
|
AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation, Similarity,
|
||||||
|
Transformation,
|
||||||
|
};
|
||||||
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
use base::dimension::DimName;
|
use base::dimension::DimName;
|
||||||
|
@ -4,61 +4,61 @@
|
|||||||
mod op_macros;
|
mod op_macros;
|
||||||
|
|
||||||
mod point;
|
mod point;
|
||||||
mod point_construction;
|
|
||||||
mod point_alias;
|
|
||||||
mod point_ops;
|
|
||||||
mod point_alga;
|
mod point_alga;
|
||||||
|
mod point_alias;
|
||||||
|
mod point_construction;
|
||||||
mod point_conversion;
|
mod point_conversion;
|
||||||
mod point_coordinates;
|
mod point_coordinates;
|
||||||
|
mod point_ops;
|
||||||
|
|
||||||
mod rotation;
|
mod rotation;
|
||||||
mod rotation_construction;
|
|
||||||
mod rotation_ops;
|
|
||||||
mod rotation_alga; // FIXME: implement Rotation methods.
|
mod rotation_alga; // FIXME: implement Rotation methods.
|
||||||
mod rotation_conversion;
|
|
||||||
mod rotation_alias;
|
mod rotation_alias;
|
||||||
|
mod rotation_construction;
|
||||||
|
mod rotation_conversion;
|
||||||
|
mod rotation_ops;
|
||||||
mod rotation_specialization;
|
mod rotation_specialization;
|
||||||
|
|
||||||
mod quaternion;
|
mod quaternion;
|
||||||
mod quaternion_construction;
|
|
||||||
mod quaternion_ops;
|
|
||||||
mod quaternion_alga;
|
mod quaternion_alga;
|
||||||
|
mod quaternion_construction;
|
||||||
mod quaternion_conversion;
|
mod quaternion_conversion;
|
||||||
mod quaternion_coordinates;
|
mod quaternion_coordinates;
|
||||||
|
mod quaternion_ops;
|
||||||
|
|
||||||
mod unit_complex;
|
mod unit_complex;
|
||||||
mod unit_complex_construction;
|
|
||||||
mod unit_complex_ops;
|
|
||||||
mod unit_complex_alga;
|
mod unit_complex_alga;
|
||||||
|
mod unit_complex_construction;
|
||||||
mod unit_complex_conversion;
|
mod unit_complex_conversion;
|
||||||
|
mod unit_complex_ops;
|
||||||
|
|
||||||
mod translation;
|
mod translation;
|
||||||
mod translation_construction;
|
|
||||||
mod translation_ops;
|
|
||||||
mod translation_alga;
|
mod translation_alga;
|
||||||
mod translation_conversion;
|
|
||||||
mod translation_alias;
|
mod translation_alias;
|
||||||
|
mod translation_construction;
|
||||||
|
mod translation_conversion;
|
||||||
|
mod translation_ops;
|
||||||
|
|
||||||
mod isometry;
|
mod isometry;
|
||||||
mod isometry_construction;
|
|
||||||
mod isometry_ops;
|
|
||||||
mod isometry_alga;
|
mod isometry_alga;
|
||||||
mod isometry_conversion;
|
|
||||||
mod isometry_alias;
|
mod isometry_alias;
|
||||||
|
mod isometry_construction;
|
||||||
|
mod isometry_conversion;
|
||||||
|
mod isometry_ops;
|
||||||
|
|
||||||
mod similarity;
|
mod similarity;
|
||||||
mod similarity_construction;
|
|
||||||
mod similarity_ops;
|
|
||||||
mod similarity_alga;
|
mod similarity_alga;
|
||||||
mod similarity_conversion;
|
|
||||||
mod similarity_alias;
|
mod similarity_alias;
|
||||||
|
mod similarity_construction;
|
||||||
|
mod similarity_conversion;
|
||||||
|
mod similarity_ops;
|
||||||
|
|
||||||
mod transform;
|
mod transform;
|
||||||
mod transform_construction;
|
|
||||||
mod transform_ops;
|
|
||||||
mod transform_alga;
|
mod transform_alga;
|
||||||
mod transform_conversion;
|
|
||||||
mod transform_alias;
|
mod transform_alias;
|
||||||
|
mod transform_construction;
|
||||||
|
mod transform_conversion;
|
||||||
|
mod transform_ops;
|
||||||
|
|
||||||
mod reflection;
|
mod reflection;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use std::hash;
|
|||||||
use std::io::{Result as IOResult, Write};
|
use std::io::{Result as IOResult, Write};
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
@ -42,8 +42,7 @@ impl<N: Scalar, D: DimName> Copy for Point<N, D>
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Scalar, D: DimName> Clone for Point<N, D>
|
impl<N: Scalar, D: DimName> Clone for Point<N, D>
|
||||||
where
|
where
|
||||||
@ -241,11 +240,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Scalar + Eq, D: DimName> Eq for Point<N, D>
|
impl<N: Scalar + Eq, D: DimName> Eq for Point<N, D> where DefaultAllocator: Allocator<N, D> {}
|
||||||
where
|
|
||||||
DefaultAllocator: Allocator<N, D>,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Scalar, D: DimName> PartialEq for Point<N, D>
|
impl<N: Scalar, D: DimName> PartialEq for Point<N, D>
|
||||||
where
|
where
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, Real};
|
use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, Real};
|
||||||
use alga::linear::{AffineSpace, EuclideanSpace};
|
use alga::linear::{AffineSpace, EuclideanSpace};
|
||||||
|
|
||||||
use base::{DefaultAllocator, Scalar, VectorN};
|
|
||||||
use base::dimension::DimName;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::DimName;
|
||||||
|
use base::{DefaultAllocator, Scalar, VectorN};
|
||||||
|
|
||||||
use geometry::Point;
|
use geometry::Point;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use std::io::{Result as IOResult, Write};
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use base::storage::Owned;
|
use base::storage::Owned;
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
@ -457,9 +457,11 @@ impl<N: Real> UnitQuaternion<N> {
|
|||||||
/// is not well-defined).
|
/// is not well-defined).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn slerp(&self, other: &UnitQuaternion<N>, t: N) -> UnitQuaternion<N> {
|
pub fn slerp(&self, other: &UnitQuaternion<N>, t: N) -> UnitQuaternion<N> {
|
||||||
Unit::new_unchecked(
|
Unit::new_unchecked(Quaternion::from_vector(
|
||||||
Quaternion::from_vector(Unit::new_unchecked(self.coords).slerp(&Unit::new_unchecked(other.coords), t).unwrap())
|
Unit::new_unchecked(self.coords)
|
||||||
)
|
.slerp(&Unit::new_unchecked(other.coords), t)
|
||||||
|
.unwrap(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the spherical linear interpolation between two unit quaternions or returns `None`
|
/// Computes the spherical linear interpolation between two unit quaternions or returns `None`
|
||||||
@ -479,7 +481,8 @@ impl<N: Real> UnitQuaternion<N> {
|
|||||||
t: N,
|
t: N,
|
||||||
epsilon: N,
|
epsilon: N,
|
||||||
) -> Option<UnitQuaternion<N>> {
|
) -> Option<UnitQuaternion<N>> {
|
||||||
Unit::new_unchecked(self.coords).try_slerp(&Unit::new_unchecked(other.coords), t, epsilon)
|
Unit::new_unchecked(self.coords)
|
||||||
|
.try_slerp(&Unit::new_unchecked(other.coords), t, epsilon)
|
||||||
.map(|q| Unit::new_unchecked(Quaternion::from_vector(q.unwrap())))
|
.map(|q| Unit::new_unchecked(Quaternion::from_vector(q.unwrap())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
use num::Zero;
|
use num::Zero;
|
||||||
|
|
||||||
use alga::general::{AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma,
|
use alga::general::{
|
||||||
AbstractModule, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup,
|
AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma, AbstractModule,
|
||||||
Additive, Id, Identity, Inverse, Module, Multiplicative, Real};
|
AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Additive, Id, Identity, Inverse, Module,
|
||||||
use alga::linear::{AffineTransformation, DirectIsometry, FiniteDimVectorSpace, Isometry,
|
Multiplicative, Real,
|
||||||
NormedSpace, OrthogonalTransformation, ProjectiveTransformation, Rotation,
|
};
|
||||||
Similarity, Transformation, VectorSpace};
|
use alga::linear::{
|
||||||
|
AffineTransformation, DirectIsometry, FiniteDimVectorSpace, Isometry, NormedSpace,
|
||||||
|
OrthogonalTransformation, ProjectiveTransformation, Rotation, Similarity, Transformation,
|
||||||
|
VectorSpace,
|
||||||
|
};
|
||||||
|
|
||||||
use base::{Vector3, Vector4};
|
use base::{Vector3, Vector4};
|
||||||
use geometry::{Point3, Quaternion, UnitQuaternion};
|
use geometry::{Point3, Quaternion, UnitQuaternion};
|
||||||
|
@ -50,15 +50,16 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub,
|
use std::ops::{
|
||||||
SubAssign};
|
Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign,
|
||||||
|
};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
use base::{DefaultAllocator, Unit, Vector, Vector3};
|
|
||||||
use base::storage::Storage;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
use base::dimension::{U1, U3, U4};
|
use base::dimension::{U1, U3, U4};
|
||||||
|
use base::storage::Storage;
|
||||||
|
use base::{DefaultAllocator, Unit, Vector, Vector3};
|
||||||
|
|
||||||
use geometry::{Point3, Quaternion, Rotation, UnitQuaternion};
|
use geometry::{Point3, Quaternion, Rotation, UnitQuaternion};
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use std::hash;
|
|||||||
use std::io::{Result as IOResult, Write};
|
use std::io::{Result as IOResult, Write};
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use base::storage::Owned;
|
use base::storage::Owned;
|
||||||
@ -44,8 +44,7 @@ impl<N: Scalar, D: DimName> Copy for Rotation<N, D>
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
DefaultAllocator: Allocator<N, D, D>,
|
||||||
<DefaultAllocator as Allocator<N, D, D>>::Buffer: Copy,
|
<DefaultAllocator as Allocator<N, D, D>>::Buffer: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Scalar, D: DimName> Clone for Rotation<N, D>
|
impl<N: Scalar, D: DimName> Clone for Rotation<N, D>
|
||||||
where
|
where
|
||||||
@ -187,11 +186,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Scalar + Eq, D: DimName> Eq for Rotation<N, D>
|
impl<N: Scalar + Eq, D: DimName> Eq for Rotation<N, D> where DefaultAllocator: Allocator<N, D, D> {}
|
||||||
where
|
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Scalar + PartialEq, D: DimName> PartialEq for Rotation<N, D>
|
impl<N: Scalar + PartialEq, D: DimName> PartialEq for Rotation<N, D>
|
||||||
where
|
where
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
use alga::general::{
|
||||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||||
Real};
|
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||||
use alga::linear::{self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
};
|
||||||
ProjectiveTransformation, Similarity, Transformation};
|
use alga::linear::{
|
||||||
|
self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
||||||
|
ProjectiveTransformation, Similarity, Transformation,
|
||||||
|
};
|
||||||
|
|
||||||
use base::{DefaultAllocator, VectorN};
|
|
||||||
use base::dimension::DimName;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::DimName;
|
||||||
|
use base::{DefaultAllocator, VectorN};
|
||||||
|
|
||||||
use geometry::{Point, Rotation};
|
use geometry::{Point, Rotation};
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ use num::{One, Zero};
|
|||||||
|
|
||||||
use alga::general::{ClosedAdd, ClosedMul};
|
use alga::general::{ClosedAdd, ClosedMul};
|
||||||
|
|
||||||
use base::{DefaultAllocator, MatrixN, Scalar};
|
|
||||||
use base::dimension::DimName;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::DimName;
|
||||||
|
use base::{DefaultAllocator, MatrixN, Scalar};
|
||||||
|
|
||||||
use geometry::Rotation;
|
use geometry::Rotation;
|
||||||
|
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
* Matrix ×= Rotation
|
* Matrix ×= Rotation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::ops::{Div, DivAssign, Index, Mul, MulAssign};
|
|
||||||
use num::{One, Zero};
|
use num::{One, Zero};
|
||||||
|
use std::ops::{Div, DivAssign, Index, Mul, MulAssign};
|
||||||
|
|
||||||
use alga::general::{ClosedAdd, ClosedMul};
|
use alga::general::{ClosedAdd, ClosedMul};
|
||||||
|
|
||||||
use base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, VectorN};
|
|
||||||
use base::dimension::{Dim, DimName, U1};
|
|
||||||
use base::constraint::{AreMultipliable, ShapeConstraint};
|
|
||||||
use base::storage::Storage;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::constraint::{AreMultipliable, ShapeConstraint};
|
||||||
|
use base::dimension::{Dim, DimName, U1};
|
||||||
|
use base::storage::Storage;
|
||||||
|
use base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, VectorN};
|
||||||
|
|
||||||
use geometry::{Point, Rotation};
|
use geometry::{Point, Rotation};
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use quickcheck::{Arbitrary, Gen};
|
|||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use num::Zero;
|
use num::Zero;
|
||||||
use rand::distributions::{Distribution, Standard, OpenClosed01};
|
use rand::distributions::{Distribution, OpenClosed01, Standard};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::ops::Neg;
|
use std::ops::Neg;
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ impl<N: Real> Rotation3<N> {
|
|||||||
pub fn angle(&self) -> N {
|
pub fn angle(&self) -> N {
|
||||||
((self.matrix()[(0, 0)] + self.matrix()[(1, 1)] + self.matrix()[(2, 2)] - N::one())
|
((self.matrix()[(0, 0)] + self.matrix()[(1, 1)] + self.matrix()[(2, 2)] - N::one())
|
||||||
/ ::convert(2.0))
|
/ ::convert(2.0))
|
||||||
.acos()
|
.acos()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The rotation axis. Returns `None` if the rotation angle is zero or PI.
|
/// The rotation axis. Returns `None` if the rotation angle is zero or PI.
|
||||||
@ -398,9 +398,15 @@ where
|
|||||||
let theta = N::two_pi() * rng.sample(OpenClosed01);
|
let theta = N::two_pi() * rng.sample(OpenClosed01);
|
||||||
let (ts, tc) = theta.sin_cos();
|
let (ts, tc) = theta.sin_cos();
|
||||||
let a = MatrixN::<N, U3>::new(
|
let a = MatrixN::<N, U3>::new(
|
||||||
tc, ts, N::zero(),
|
tc,
|
||||||
-ts, tc, N::zero(),
|
ts,
|
||||||
N::zero(), N::zero(), N::one()
|
N::zero(),
|
||||||
|
-ts,
|
||||||
|
tc,
|
||||||
|
N::zero(),
|
||||||
|
N::zero(),
|
||||||
|
N::zero(),
|
||||||
|
N::one(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Compute a random rotation *of* Z
|
// Compute a random rotation *of* Z
|
||||||
|
@ -5,7 +5,7 @@ use std::hash;
|
|||||||
use std::io::{Result as IOResult, Write};
|
use std::io::{Result as IOResult, Write};
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
@ -25,25 +25,21 @@ use geometry::{Isometry, Point, Translation};
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "N: Serialize,
|
||||||
serialize = "N: Serialize,
|
|
||||||
R: Serialize,
|
R: Serialize,
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Serialize"
|
Owned<N, D>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "N: Deserialize<'de>,
|
||||||
deserialize = "N: Deserialize<'de>,
|
|
||||||
R: Deserialize<'de>,
|
R: Deserialize<'de>,
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Deserialize<'de>"
|
Owned<N, D>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
pub struct Similarity<N: Real, D: DimName, R>
|
pub struct Similarity<N: Real, D: DimName, R>
|
||||||
where
|
where
|
||||||
@ -89,8 +85,7 @@ impl<N: Real, D: DimName + Copy, R: Rotation<Point<N, D>> + Copy> Copy for Simil
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Copy,
|
Owned<N, D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimName, R: Rotation<Point<N, D>> + Clone> Clone for Similarity<N, D, R>
|
impl<N: Real, D: DimName, R: Rotation<Point<N, D>> + Clone> Clone for Similarity<N, D, R>
|
||||||
where
|
where
|
||||||
@ -276,8 +271,7 @@ impl<N: Real, D: DimName, R> Eq for Similarity<N, D, R>
|
|||||||
where
|
where
|
||||||
R: Rotation<Point<N, D>> + Eq,
|
R: Rotation<Point<N, D>> + Eq,
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimName, R> PartialEq for Similarity<N, D, R>
|
impl<N: Real, D: DimName, R> PartialEq for Similarity<N, D, R>
|
||||||
where
|
where
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
use alga::general::{
|
||||||
AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real};
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||||
use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation};
|
AbstractSemigroup, Identity, Inverse, Multiplicative, Real,
|
||||||
|
};
|
||||||
use alga::linear::Similarity as AlgaSimilarity;
|
use alga::linear::Similarity as AlgaSimilarity;
|
||||||
|
use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation};
|
||||||
|
|
||||||
use base::{DefaultAllocator, VectorN};
|
|
||||||
use base::dimension::DimName;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::DimName;
|
||||||
|
use base::{DefaultAllocator, VectorN};
|
||||||
|
|
||||||
use geometry::{Point, Similarity, Translation};
|
use geometry::{Point, Similarity, Translation};
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ use std::ops::{Div, DivAssign, Mul, MulAssign};
|
|||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use alga::linear::Rotation as AlgaRotation;
|
use alga::linear::Rotation as AlgaRotation;
|
||||||
|
|
||||||
use base::{DefaultAllocator, VectorN};
|
|
||||||
use base::dimension::{DimName, U1, U3, U4};
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::{DimName, U1, U3, U4};
|
||||||
|
use base::{DefaultAllocator, VectorN};
|
||||||
|
|
||||||
use geometry::{Isometry, Point, Rotation, Similarity, Translation, UnitQuaternion};
|
use geometry::{Isometry, Point, Rotation, Similarity, Translation, UnitQuaternion};
|
||||||
|
|
||||||
|
@ -3,14 +3,14 @@ use std::fmt::Debug;
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
use base::{DefaultAllocator, MatrixN};
|
use base::allocator::Allocator;
|
||||||
use base::dimension::{DimName, DimNameAdd, DimNameSum, U1};
|
use base::dimension::{DimName, DimNameAdd, DimNameSum, U1};
|
||||||
use base::storage::Owned;
|
use base::storage::Owned;
|
||||||
use base::allocator::Allocator;
|
use base::{DefaultAllocator, MatrixN};
|
||||||
|
|
||||||
/// Trait implemented by phantom types identifying the projective transformation type.
|
/// Trait implemented by phantom types identifying the projective transformation type.
|
||||||
///
|
///
|
||||||
@ -56,18 +56,15 @@ where
|
|||||||
|
|
||||||
/// Tag representing the most general (not necessarily inversible) `Transform` type.
|
/// Tag representing the most general (not necessarily inversible) `Transform` type.
|
||||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||||
pub enum TGeneral {
|
pub enum TGeneral {}
|
||||||
}
|
|
||||||
|
|
||||||
/// Tag representing the most general inversible `Transform` type.
|
/// Tag representing the most general inversible `Transform` type.
|
||||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||||
pub enum TProjective {
|
pub enum TProjective {}
|
||||||
}
|
|
||||||
|
|
||||||
/// Tag representing an affine `Transform`. Its bottom-row is equal to `(0, 0 ... 0, 1)`.
|
/// Tag representing an affine `Transform`. Its bottom-row is equal to `(0, 0 ... 0, 1)`.
|
||||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||||
pub enum TAffine {
|
pub enum TAffine {}
|
||||||
}
|
|
||||||
|
|
||||||
impl TCategory for TGeneral {
|
impl TCategory for TGeneral {
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -104,7 +101,8 @@ impl TCategory for TAffine {
|
|||||||
DefaultAllocator: Allocator<N, D, D>,
|
DefaultAllocator: Allocator<N, D, D>,
|
||||||
{
|
{
|
||||||
let last = D::dim() - 1;
|
let last = D::dim() - 1;
|
||||||
mat.is_invertible() && mat[(last, last)] == N::one()
|
mat.is_invertible()
|
||||||
|
&& mat[(last, last)] == N::one()
|
||||||
&& (0..last).all(|i| mat[(last, i)].is_zero())
|
&& (0..last).all(|i| mat[(last, i)].is_zero())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,8 +175,7 @@ impl<N: Real, D: DimNameAdd<U1> + Copy, C: TCategory> Copy for Transform<N, D, C
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
||||||
Owned<N, DimNameSum<D, U1>, DimNameSum<D, U1>>: Copy,
|
Owned<N, DimNameSum<D, U1>, DimNameSum<D, U1>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimNameAdd<U1>, C: TCategory> Clone for Transform<N, D, C>
|
impl<N: Real, D: DimNameAdd<U1>, C: TCategory> Clone for Transform<N, D, C>
|
||||||
where
|
where
|
||||||
@ -220,11 +217,9 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real + Eq, D: DimNameAdd<U1>, C: TCategory> Eq for Transform<N, D, C>
|
impl<N: Real + Eq, D: DimNameAdd<U1>, C: TCategory> Eq for Transform<N, D, C> where
|
||||||
where
|
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
||||||
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
{}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimNameAdd<U1>, C: TCategory> PartialEq for Transform<N, D, C>
|
impl<N: Real, D: DimNameAdd<U1>, C: TCategory> PartialEq for Transform<N, D, C>
|
||||||
where
|
where
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
use alga::general::{
|
||||||
AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real};
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||||
|
AbstractSemigroup, Identity, Inverse, Multiplicative, Real,
|
||||||
|
};
|
||||||
use alga::linear::{ProjectiveTransformation, Transformation};
|
use alga::linear::{ProjectiveTransformation, Transformation};
|
||||||
|
|
||||||
use base::{DefaultAllocator, VectorN};
|
|
||||||
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||||
|
use base::{DefaultAllocator, VectorN};
|
||||||
|
|
||||||
use geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform};
|
use geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform};
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ use num::One;
|
|||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
use base::{DefaultAllocator, MatrixN};
|
|
||||||
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||||
|
use base::{DefaultAllocator, MatrixN};
|
||||||
|
|
||||||
use geometry::{TCategory, Transform};
|
use geometry::{TCategory, Transform};
|
||||||
|
|
||||||
|
@ -3,13 +3,14 @@ use std::ops::{Div, DivAssign, Index, IndexMut, Mul, MulAssign};
|
|||||||
|
|
||||||
use alga::general::{ClosedAdd, ClosedMul, Real, SubsetOf};
|
use alga::general::{ClosedAdd, ClosedMul, Real, SubsetOf};
|
||||||
|
|
||||||
use base::{DefaultAllocator, MatrixN, Scalar, VectorN};
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
use base::dimension::{DimName, DimNameAdd, DimNameSum, U1, U3, U4};
|
use base::dimension::{DimName, DimNameAdd, DimNameSum, U1, U3, U4};
|
||||||
|
use base::{DefaultAllocator, MatrixN, Scalar, VectorN};
|
||||||
|
|
||||||
use geometry::{Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine,
|
use geometry::{
|
||||||
TCategory, TCategoryMul, TGeneral, TProjective, Transform, Translation,
|
Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine, TCategory,
|
||||||
UnitQuaternion};
|
TCategoryMul, TGeneral, TProjective, Transform, Translation, UnitQuaternion,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -6,7 +6,7 @@ use std::hash;
|
|||||||
use std::io::{Result as IOResult, Write};
|
use std::io::{Result as IOResult, Write};
|
||||||
|
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
use abomonation::Abomonation;
|
use abomonation::Abomonation;
|
||||||
@ -44,8 +44,7 @@ impl<N: Scalar, D: DimName> Copy for Translation<N, D>
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D>,
|
||||||
Owned<N, D>: Copy,
|
Owned<N, D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Scalar, D: DimName> Clone for Translation<N, D>
|
impl<N: Scalar, D: DimName> Clone for Translation<N, D>
|
||||||
where
|
where
|
||||||
@ -153,11 +152,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Scalar + Eq, D: DimName> Eq for Translation<N, D>
|
impl<N: Scalar + Eq, D: DimName> Eq for Translation<N, D> where DefaultAllocator: Allocator<N, D> {}
|
||||||
where
|
|
||||||
DefaultAllocator: Allocator<N, D>,
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Scalar + PartialEq, D: DimName> PartialEq for Translation<N, D>
|
impl<N: Scalar + PartialEq, D: DimName> PartialEq for Translation<N, D>
|
||||||
where
|
where
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
use alga::general::{
|
||||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||||
Real};
|
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||||
use alga::linear::{AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation,
|
};
|
||||||
Similarity, Transformation};
|
|
||||||
use alga::linear::Translation as AlgaTranslation;
|
use alga::linear::Translation as AlgaTranslation;
|
||||||
|
use alga::linear::{
|
||||||
|
AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation, Similarity,
|
||||||
|
Transformation,
|
||||||
|
};
|
||||||
|
|
||||||
use base::{DefaultAllocator, VectorN};
|
|
||||||
use base::dimension::DimName;
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
|
use base::dimension::DimName;
|
||||||
|
use base::{DefaultAllocator, VectorN};
|
||||||
|
|
||||||
use geometry::{Point, Translation};
|
use geometry::{Point, Translation};
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@ use std::ops::{Div, DivAssign, Mul, MulAssign};
|
|||||||
|
|
||||||
use alga::general::{ClosedAdd, ClosedSub};
|
use alga::general::{ClosedAdd, ClosedSub};
|
||||||
|
|
||||||
use base::{DefaultAllocator, Scalar};
|
|
||||||
use base::dimension::{DimName, U1};
|
|
||||||
use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
|
||||||
use base::allocator::{Allocator, SameShapeAllocator};
|
use base::allocator::{Allocator, SameShapeAllocator};
|
||||||
|
use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
||||||
|
use base::dimension::{DimName, U1};
|
||||||
|
use base::{DefaultAllocator, Scalar};
|
||||||
|
|
||||||
use geometry::{Point, Translation};
|
use geometry::{Point, Translation};
|
||||||
|
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
use alga::general::{
|
||||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||||
Real};
|
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||||
use alga::linear::{AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
};
|
||||||
ProjectiveTransformation, Rotation, Similarity, Transformation};
|
use alga::linear::{
|
||||||
|
AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
||||||
|
ProjectiveTransformation, Rotation, Similarity, Transformation,
|
||||||
|
};
|
||||||
|
|
||||||
use base::{DefaultAllocator, Vector2};
|
|
||||||
use base::allocator::Allocator;
|
use base::allocator::Allocator;
|
||||||
use base::dimension::U2;
|
use base::dimension::U2;
|
||||||
|
use base::{DefaultAllocator, Vector2};
|
||||||
use geometry::{Point2, UnitComplex};
|
use geometry::{Point2, UnitComplex};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen};
|
|||||||
|
|
||||||
use num::One;
|
use num::One;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
use rand::distributions::{Distribution, Standard, OpenClosed01};
|
use rand::distributions::{Distribution, OpenClosed01, Standard};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use allocator::Allocator;
|
use allocator::Allocator;
|
||||||
@ -15,31 +15,27 @@ use linalg::householder;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DimMinimum<R, C>: DimSub<U1>,
|
||||||
serialize = "DimMinimum<R, C>: DimSub<U1>,
|
|
||||||
DefaultAllocator: Allocator<N, R, C> +
|
DefaultAllocator: Allocator<N, R, C> +
|
||||||
Allocator<N, DimMinimum<R, C>> +
|
Allocator<N, DimMinimum<R, C>> +
|
||||||
Allocator<N, DimDiff<DimMinimum<R, C>, U1>>,
|
Allocator<N, DimDiff<DimMinimum<R, C>, U1>>,
|
||||||
MatrixMN<N, R, C>: Serialize,
|
MatrixMN<N, R, C>: Serialize,
|
||||||
VectorN<N, DimMinimum<R, C>>: Serialize,
|
VectorN<N, DimMinimum<R, C>>: Serialize,
|
||||||
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Serialize"
|
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DimMinimum<R, C>: DimSub<U1>,
|
||||||
deserialize = "DimMinimum<R, C>: DimSub<U1>,
|
|
||||||
DefaultAllocator: Allocator<N, R, C> +
|
DefaultAllocator: Allocator<N, R, C> +
|
||||||
Allocator<N, DimMinimum<R, C>> +
|
Allocator<N, DimMinimum<R, C>> +
|
||||||
Allocator<N, DimDiff<DimMinimum<R, C>, U1>>,
|
Allocator<N, DimDiff<DimMinimum<R, C>, U1>>,
|
||||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>,
|
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>,
|
||||||
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Deserialize<'de>"
|
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Bidiagonal<N: Real, R: DimMin<C>, C: Dim>
|
pub struct Bidiagonal<N: Real, R: DimMin<C>, C: Dim>
|
||||||
@ -68,8 +64,7 @@ where
|
|||||||
MatrixMN<N, R, C>: Copy,
|
MatrixMN<N, R, C>: Copy,
|
||||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||||
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Copy,
|
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, R: DimMin<C>, C: Dim> Bidiagonal<N, R, C>
|
impl<N: Real, R: DimMin<C>, C: Dim> Bidiagonal<N, R, C>
|
||||||
where
|
where
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
@ -13,21 +13,17 @@ use storage::{Storage, StorageMut};
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, D>,
|
||||||
serialize = "DefaultAllocator: Allocator<N, D>,
|
|
||||||
MatrixN<N, D>: Serialize"
|
MatrixN<N, D>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, D>,
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D>,
|
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
MatrixN<N, D>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Cholesky<N: Real, D: Dim>
|
pub struct Cholesky<N: Real, D: Dim>
|
||||||
@ -41,8 +37,7 @@ impl<N: Real, D: Dim> Copy for Cholesky<N, D>
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
DefaultAllocator: Allocator<N, D, D>,
|
||||||
MatrixN<N, D>: Copy,
|
MatrixN<N, D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimSub<Dynamic>> Cholesky<N, D>
|
impl<N: Real, D: DimSub<Dynamic>> Cholesky<N, D>
|
||||||
where
|
where
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use allocator::Allocator;
|
use allocator::Allocator;
|
||||||
@ -15,25 +15,21 @@ use linalg::PermutationSequence;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Serialize,
|
MatrixMN<N, R, C>: Serialize,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct FullPivLU<N: Real, R: DimMin<C>, C: Dim>
|
pub struct FullPivLU<N: Real, R: DimMin<C>, C: Dim>
|
||||||
@ -50,8 +46,7 @@ where
|
|||||||
DefaultAllocator: Allocator<N, R, C> + Allocator<(usize, usize), DimMinimum<R, C>>,
|
DefaultAllocator: Allocator<N, R, C> + Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Copy,
|
MatrixMN<N, R, C>: Copy,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Copy,
|
PermutationSequence<DimMinimum<R, C>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, R: DimMin<C>, C: Dim> FullPivLU<N, R, C>
|
impl<N: Real, R: DimMin<C>, C: Dim> FullPivLU<N, R, C>
|
||||||
where
|
where
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use allocator::Allocator;
|
use allocator::Allocator;
|
||||||
@ -14,25 +14,21 @@ use linalg::householder;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, DimDiff<D, U1>>,
|
Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Serialize,
|
MatrixN<N, D>: Serialize,
|
||||||
VectorN<N, DimDiff<D, U1>>: Serialize"
|
VectorN<N, DimDiff<D, U1>>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, DimDiff<D, U1>>,
|
Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Deserialize<'de>,
|
MatrixN<N, D>: Deserialize<'de>,
|
||||||
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Hessenberg<N: Real, D: DimSub<U1>>
|
pub struct Hessenberg<N: Real, D: DimSub<U1>>
|
||||||
@ -48,8 +44,7 @@ where
|
|||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Copy,
|
MatrixN<N, D>: Copy,
|
||||||
VectorN<N, DimDiff<D, U1>>: Copy,
|
VectorN<N, DimDiff<D, U1>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimSub<U1>> Hessenberg<N, D>
|
impl<N: Real, D: DimSub<U1>> Hessenberg<N, D>
|
||||||
where
|
where
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
|
||||||
use base::{DefaultAllocator, MatrixN, SquareMatrix};
|
use base::allocator::Allocator;
|
||||||
use base::dimension::Dim;
|
use base::dimension::Dim;
|
||||||
use base::storage::{Storage, StorageMut};
|
use base::storage::{Storage, StorageMut};
|
||||||
use base::allocator::Allocator;
|
use base::{DefaultAllocator, MatrixN, SquareMatrix};
|
||||||
|
|
||||||
use linalg::lu;
|
use linalg::lu;
|
||||||
|
|
||||||
@ -129,52 +129,84 @@ where
|
|||||||
let m = m.data.as_slice();
|
let m = m.data.as_slice();
|
||||||
|
|
||||||
out[(0, 0)] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15]
|
out[(0, 0)] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15]
|
||||||
+ m[9] * m[7] * m[14] + m[13] * m[6] * m[11] - m[13] * m[7] * m[10];
|
+ m[9] * m[7] * m[14]
|
||||||
|
+ m[13] * m[6] * m[11]
|
||||||
|
- m[13] * m[7] * m[10];
|
||||||
|
|
||||||
out[(1, 0)] = -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15]
|
out[(1, 0)] = -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15]
|
||||||
- m[9] * m[3] * m[14] - m[13] * m[2] * m[11] + m[13] * m[3] * m[10];
|
- m[9] * m[3] * m[14]
|
||||||
|
- m[13] * m[2] * m[11]
|
||||||
|
+ m[13] * m[3] * m[10];
|
||||||
|
|
||||||
out[(2, 0)] = m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15]
|
out[(2, 0)] = m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15]
|
||||||
+ m[5] * m[3] * m[14] + m[13] * m[2] * m[7] - m[13] * m[3] * m[6];
|
+ m[5] * m[3] * m[14]
|
||||||
|
+ m[13] * m[2] * m[7]
|
||||||
|
- m[13] * m[3] * m[6];
|
||||||
|
|
||||||
out[(3, 0)] = -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11]
|
out[(3, 0)] = -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11]
|
||||||
- m[5] * m[3] * m[10] - m[9] * m[2] * m[7] + m[9] * m[3] * m[6];
|
- m[5] * m[3] * m[10]
|
||||||
|
- m[9] * m[2] * m[7]
|
||||||
|
+ m[9] * m[3] * m[6];
|
||||||
|
|
||||||
out[(0, 1)] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15]
|
out[(0, 1)] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15]
|
||||||
- m[8] * m[7] * m[14] - m[12] * m[6] * m[11] + m[12] * m[7] * m[10];
|
- m[8] * m[7] * m[14]
|
||||||
|
- m[12] * m[6] * m[11]
|
||||||
|
+ m[12] * m[7] * m[10];
|
||||||
|
|
||||||
out[(1, 1)] = m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15]
|
out[(1, 1)] = m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15]
|
||||||
+ m[8] * m[3] * m[14] + m[12] * m[2] * m[11] - m[12] * m[3] * m[10];
|
+ m[8] * m[3] * m[14]
|
||||||
|
+ m[12] * m[2] * m[11]
|
||||||
|
- m[12] * m[3] * m[10];
|
||||||
|
|
||||||
out[(2, 1)] = -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15]
|
out[(2, 1)] = -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15]
|
||||||
- m[4] * m[3] * m[14] - m[12] * m[2] * m[7] + m[12] * m[3] * m[6];
|
- m[4] * m[3] * m[14]
|
||||||
|
- m[12] * m[2] * m[7]
|
||||||
|
+ m[12] * m[3] * m[6];
|
||||||
|
|
||||||
out[(3, 1)] = m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11]
|
out[(3, 1)] = m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11]
|
||||||
+ m[4] * m[3] * m[10] + m[8] * m[2] * m[7] - m[8] * m[3] * m[6];
|
+ m[4] * m[3] * m[10]
|
||||||
|
+ m[8] * m[2] * m[7]
|
||||||
|
- m[8] * m[3] * m[6];
|
||||||
|
|
||||||
out[(0, 2)] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15]
|
out[(0, 2)] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15]
|
||||||
+ m[8] * m[7] * m[13] + m[12] * m[5] * m[11] - m[12] * m[7] * m[9];
|
+ m[8] * m[7] * m[13]
|
||||||
|
+ m[12] * m[5] * m[11]
|
||||||
|
- m[12] * m[7] * m[9];
|
||||||
|
|
||||||
out[(1, 2)] = -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15]
|
out[(1, 2)] = -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15]
|
||||||
- m[8] * m[3] * m[13] - m[12] * m[1] * m[11] + m[12] * m[3] * m[9];
|
- m[8] * m[3] * m[13]
|
||||||
|
- m[12] * m[1] * m[11]
|
||||||
|
+ m[12] * m[3] * m[9];
|
||||||
|
|
||||||
out[(2, 2)] = m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15]
|
out[(2, 2)] = m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15]
|
||||||
+ m[4] * m[3] * m[13] + m[12] * m[1] * m[7] - m[12] * m[3] * m[5];
|
+ m[4] * m[3] * m[13]
|
||||||
|
+ m[12] * m[1] * m[7]
|
||||||
|
- m[12] * m[3] * m[5];
|
||||||
|
|
||||||
out[(0, 3)] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14]
|
out[(0, 3)] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14]
|
||||||
- m[8] * m[6] * m[13] - m[12] * m[5] * m[10] + m[12] * m[6] * m[9];
|
- m[8] * m[6] * m[13]
|
||||||
|
- m[12] * m[5] * m[10]
|
||||||
|
+ m[12] * m[6] * m[9];
|
||||||
|
|
||||||
out[(3, 2)] = -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11]
|
out[(3, 2)] = -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11]
|
||||||
- m[4] * m[3] * m[9] - m[8] * m[1] * m[7] + m[8] * m[3] * m[5];
|
- m[4] * m[3] * m[9]
|
||||||
|
- m[8] * m[1] * m[7]
|
||||||
|
+ m[8] * m[3] * m[5];
|
||||||
|
|
||||||
out[(1, 3)] = m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14]
|
out[(1, 3)] = m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14]
|
||||||
+ m[8] * m[2] * m[13] + m[12] * m[1] * m[10] - m[12] * m[2] * m[9];
|
+ m[8] * m[2] * m[13]
|
||||||
|
+ m[12] * m[1] * m[10]
|
||||||
|
- m[12] * m[2] * m[9];
|
||||||
|
|
||||||
out[(2, 3)] = -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14]
|
out[(2, 3)] = -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14]
|
||||||
- m[4] * m[2] * m[13] - m[12] * m[1] * m[6] + m[12] * m[2] * m[5];
|
- m[4] * m[2] * m[13]
|
||||||
|
- m[12] * m[1] * m[6]
|
||||||
|
+ m[12] * m[2] * m[5];
|
||||||
|
|
||||||
out[(3, 3)] = m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10]
|
out[(3, 3)] = m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10]
|
||||||
+ m[4] * m[2] * m[9] + m[8] * m[1] * m[6] - m[8] * m[2] * m[5];
|
+ m[4] * m[2] * m[9]
|
||||||
|
+ m[8] * m[1] * m[6]
|
||||||
|
- m[8] * m[2] * m[5];
|
||||||
|
|
||||||
let det = m[0] * out[(0, 0)] + m[1] * out[(0, 1)] + m[2] * out[(0, 2)] + m[3] * out[(0, 3)];
|
let det = m[0] * out[(0, 0)] + m[1] * out[(0, 1)] + m[2] * out[(0, 2)] + m[3] * out[(0, 3)];
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::{Field, Real};
|
use alga::general::{Field, Real};
|
||||||
use allocator::{Allocator, Reallocator};
|
use allocator::{Allocator, Reallocator};
|
||||||
@ -15,25 +15,21 @@ use linalg::PermutationSequence;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Serialize,
|
MatrixMN<N, R, C>: Serialize,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct LU<N: Real, R: DimMin<C>, C: Dim>
|
pub struct LU<N: Real, R: DimMin<C>, C: Dim>
|
||||||
@ -49,8 +45,7 @@ where
|
|||||||
DefaultAllocator: Allocator<N, R, C> + Allocator<(usize, usize), DimMinimum<R, C>>,
|
DefaultAllocator: Allocator<N, R, C> + Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Copy,
|
MatrixMN<N, R, C>: Copy,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Copy,
|
PermutationSequence<DimMinimum<R, C>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
/// Performs a LU decomposition to overwrite `out` with the inverse of `matrix`.
|
/// Performs a LU decomposition to overwrite `out` with the inverse of `matrix`.
|
||||||
///
|
///
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
//! [Reexported at the root of this crate.] Factorization of real matrices.
|
//! [Reexported at the root of this crate.] Factorization of real matrices.
|
||||||
|
|
||||||
mod solve;
|
|
||||||
mod determinant;
|
|
||||||
mod inverse;
|
|
||||||
pub mod householder;
|
|
||||||
pub mod givens;
|
|
||||||
pub mod balancing;
|
pub mod balancing;
|
||||||
|
mod bidiagonal;
|
||||||
|
mod cholesky;
|
||||||
|
mod determinant;
|
||||||
|
mod full_piv_lu;
|
||||||
|
pub mod givens;
|
||||||
|
mod hessenberg;
|
||||||
|
pub mod householder;
|
||||||
|
mod inverse;
|
||||||
|
mod lu;
|
||||||
mod permutation_sequence;
|
mod permutation_sequence;
|
||||||
mod qr;
|
mod qr;
|
||||||
mod hessenberg;
|
|
||||||
mod bidiagonal;
|
|
||||||
mod symmetric_tridiagonal;
|
|
||||||
mod cholesky;
|
|
||||||
mod lu;
|
|
||||||
mod full_piv_lu;
|
|
||||||
mod schur;
|
mod schur;
|
||||||
|
mod solve;
|
||||||
mod svd;
|
mod svd;
|
||||||
mod symmetric_eigen;
|
mod symmetric_eigen;
|
||||||
|
mod symmetric_tridiagonal;
|
||||||
|
|
||||||
//// FIXME: Not complete enough for publishing.
|
//// FIXME: Not complete enough for publishing.
|
||||||
//// This handles only cases where each eigenvalue has multiplicity one.
|
//// This handles only cases where each eigenvalue has multiplicity one.
|
||||||
// mod eigen;
|
// mod eigen;
|
||||||
|
|
||||||
pub use self::permutation_sequence::*;
|
|
||||||
pub use self::qr::*;
|
|
||||||
pub use self::hessenberg::*;
|
|
||||||
pub use self::bidiagonal::*;
|
pub use self::bidiagonal::*;
|
||||||
pub use self::cholesky::*;
|
pub use self::cholesky::*;
|
||||||
pub use self::lu::*;
|
|
||||||
pub use self::full_piv_lu::*;
|
pub use self::full_piv_lu::*;
|
||||||
|
pub use self::hessenberg::*;
|
||||||
|
pub use self::lu::*;
|
||||||
|
pub use self::permutation_sequence::*;
|
||||||
|
pub use self::qr::*;
|
||||||
pub use self::schur::*;
|
pub use self::schur::*;
|
||||||
pub use self::svd::*;
|
pub use self::svd::*;
|
||||||
pub use self::symmetric_tridiagonal::*;
|
|
||||||
pub use self::symmetric_eigen::*;
|
pub use self::symmetric_eigen::*;
|
||||||
|
pub use self::symmetric_tridiagonal::*;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::ClosedNeg;
|
use alga::general::ClosedNeg;
|
||||||
use num::One;
|
use num::One;
|
||||||
@ -15,21 +15,17 @@ use storage::StorageMut;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<(usize, usize), D>,
|
||||||
serialize = "DefaultAllocator: Allocator<(usize, usize), D>,
|
|
||||||
VectorN<(usize, usize), D>: Serialize"
|
VectorN<(usize, usize), D>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<(usize, usize), D>,
|
||||||
deserialize = "DefaultAllocator: Allocator<(usize, usize), D>,
|
|
||||||
VectorN<(usize, usize), D>: Deserialize<'de>"
|
VectorN<(usize, usize), D>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct PermutationSequence<D: Dim>
|
pub struct PermutationSequence<D: Dim>
|
||||||
@ -44,8 +40,7 @@ impl<D: Dim> Copy for PermutationSequence<D>
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<(usize, usize), D>,
|
DefaultAllocator: Allocator<(usize, usize), D>,
|
||||||
VectorN<(usize, usize), D>: Copy,
|
VectorN<(usize, usize), D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: DimName> PermutationSequence<D>
|
impl<D: DimName> PermutationSequence<D>
|
||||||
where
|
where
|
||||||
|
@ -1,28 +1,36 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
|
use allocator::{Allocator, Reallocator};
|
||||||
use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN};
|
use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN};
|
||||||
|
use constraint::{SameNumberOfRows, ShapeConstraint};
|
||||||
use dimension::{Dim, DimMin, DimMinimum, U1};
|
use dimension::{Dim, DimMin, DimMinimum, U1};
|
||||||
use storage::{Storage, StorageMut};
|
use storage::{Storage, StorageMut};
|
||||||
use allocator::{Allocator, Reallocator};
|
|
||||||
use constraint::{SameNumberOfRows, ShapeConstraint};
|
|
||||||
|
|
||||||
use linalg::householder;
|
|
||||||
use geometry::Reflection;
|
use geometry::Reflection;
|
||||||
|
use linalg::householder;
|
||||||
|
|
||||||
/// The QR decomposition of a general matrix.
|
/// The QR decomposition of a general matrix.
|
||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "serde-serialize",
|
#[cfg_attr(
|
||||||
serde(bound(serialize = "DefaultAllocator: Allocator<N, R, C> +
|
feature = "serde-serialize",
|
||||||
|
serde(bound(
|
||||||
|
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
Allocator<N, DimMinimum<R, C>>,
|
Allocator<N, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Serialize,
|
MatrixMN<N, R, C>: Serialize,
|
||||||
VectorN<N, DimMinimum<R, C>>: Serialize")))]
|
VectorN<N, DimMinimum<R, C>>: Serialize"
|
||||||
#[cfg_attr(feature = "serde-serialize",
|
))
|
||||||
serde(bound(deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "serde-serialize",
|
||||||
|
serde(bound(
|
||||||
|
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
Allocator<N, DimMinimum<R, C>>,
|
Allocator<N, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>")))]
|
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
||||||
|
))
|
||||||
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct QR<N: Real, R: DimMin<C>, C: Dim>
|
pub struct QR<N: Real, R: DimMin<C>, C: Dim>
|
||||||
where
|
where
|
||||||
@ -37,8 +45,7 @@ where
|
|||||||
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
|
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Copy,
|
MatrixMN<N, R, C>: Copy,
|
||||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, R: DimMin<C>, C: Dim> QR<N, R, C>
|
impl<N: Real, R: DimMin<C>, C: Dim> QR<N, R, C>
|
||||||
where
|
where
|
||||||
@ -132,8 +139,8 @@ where
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
DimMinimum<R, C>: DimMin<C, Output = DimMinimum<R, C>>,
|
DimMinimum<R, C>: DimMin<C, Output = DimMinimum<R, C>>,
|
||||||
DefaultAllocator: Allocator<N, R, DimMinimum<R, C>>
|
DefaultAllocator:
|
||||||
+ Reallocator<N, R, C, DimMinimum<R, C>, C>,
|
Allocator<N, R, DimMinimum<R, C>> + Reallocator<N, R, C, DimMinimum<R, C>, C>,
|
||||||
{
|
{
|
||||||
(self.q(), self.unpack_r())
|
(self.q(), self.unpack_r())
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
@ -19,21 +19,17 @@ use linalg::Hessenberg;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, D, D>,
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
MatrixN<N, D>: Serialize"
|
MatrixN<N, D>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, D, D>,
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
MatrixN<N, D>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RealSchur<N: Real, D: Dim>
|
pub struct RealSchur<N: Real, D: Dim>
|
||||||
@ -48,8 +44,7 @@ impl<N: Real, D: Dim> Copy for RealSchur<N, D>
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
DefaultAllocator: Allocator<N, D, D>,
|
||||||
MatrixN<N, D>: Copy,
|
MatrixN<N, D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: Dim> RealSchur<N, D>
|
impl<N: Real, D: Dim> RealSchur<N, D>
|
||||||
where
|
where
|
||||||
@ -180,10 +175,10 @@ where
|
|||||||
{
|
{
|
||||||
let krows = cmp::min(k + 4, end + 1);
|
let krows = cmp::min(k + 4, end + 1);
|
||||||
let mut work = work.rows_mut(0, krows);
|
let mut work = work.rows_mut(0, krows);
|
||||||
refl.reflect(&mut t.generic_slice_mut(
|
refl.reflect(
|
||||||
(k, k),
|
&mut t
|
||||||
(U3, Dynamic::new(dim.value() - k)),
|
.generic_slice_mut((k, k), (U3, Dynamic::new(dim.value() - k))),
|
||||||
));
|
);
|
||||||
refl.reflect_rows(
|
refl.reflect_rows(
|
||||||
&mut t.generic_slice_mut((0, k), (Dynamic::new(krows), U3)),
|
&mut t.generic_slice_mut((0, k), (Dynamic::new(krows), U3)),
|
||||||
&mut work,
|
&mut work,
|
||||||
@ -214,10 +209,9 @@ where
|
|||||||
|
|
||||||
{
|
{
|
||||||
let mut work = work.rows_mut(0, end + 1);
|
let mut work = work.rows_mut(0, end + 1);
|
||||||
refl.reflect(&mut t.generic_slice_mut(
|
refl.reflect(
|
||||||
(m, m),
|
&mut t.generic_slice_mut((m, m), (U2, Dynamic::new(dim.value() - m))),
|
||||||
(U2, Dynamic::new(dim.value() - m)),
|
);
|
||||||
));
|
|
||||||
refl.reflect_rows(
|
refl.reflect_rows(
|
||||||
&mut t.generic_slice_mut((0, m), (Dynamic::new(end + 1), U2)),
|
&mut t.generic_slice_mut((0, m), (Dynamic::new(end + 1), U2)),
|
||||||
&mut work,
|
&mut work,
|
||||||
@ -236,10 +230,9 @@ where
|
|||||||
(start, start),
|
(start, start),
|
||||||
(U2, Dynamic::new(dim.value() - start)),
|
(U2, Dynamic::new(dim.value() - start)),
|
||||||
));
|
));
|
||||||
rot.rotate_rows(&mut t.generic_slice_mut(
|
rot.rotate_rows(
|
||||||
(0, start),
|
&mut t.generic_slice_mut((0, start), (Dynamic::new(end + 1), U2)),
|
||||||
(Dynamic::new(end + 1), U2),
|
);
|
||||||
));
|
|
||||||
t[(end, start)] = N::zero();
|
t[(end, start)] = N::zero();
|
||||||
|
|
||||||
if let Some(ref mut q) = q {
|
if let Some(ref mut q) = q {
|
||||||
@ -433,9 +426,11 @@ where
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => if compute_q {
|
None => {
|
||||||
q = Some(MatrixN::identity_generic(dim, dim));
|
if compute_q {
|
||||||
},
|
q = Some(MatrixN::identity_generic(dim, dim));
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((q, m))
|
Some((q, m))
|
||||||
@ -558,7 +553,8 @@ where
|
|||||||
N::default_epsilon(),
|
N::default_epsilon(),
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
if RealSchur::do_eigenvalues(&schur.1, &mut work) {
|
if RealSchur::do_eigenvalues(&schur.1, &mut work) {
|
||||||
Some(work)
|
Some(work)
|
||||||
} else {
|
} else {
|
||||||
@ -581,7 +577,8 @@ where
|
|||||||
N::default_epsilon(),
|
N::default_epsilon(),
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let mut eig = unsafe { VectorN::new_uninitialized_generic(dim, U1) };
|
let mut eig = unsafe { VectorN::new_uninitialized_generic(dim, U1) };
|
||||||
RealSchur::do_complex_eigenvalues(&schur.1, &mut eig);
|
RealSchur::do_complex_eigenvalues(&schur.1, &mut eig);
|
||||||
eig
|
eig
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
use std::ops::MulAssign;
|
use std::ops::MulAssign;
|
||||||
@ -20,31 +20,27 @@ use linalg::Bidiagonal;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<N, DimMinimum<R, C>> +
|
Allocator<N, DimMinimum<R, C>> +
|
||||||
Allocator<N, DimMinimum<R, C>, C> +
|
Allocator<N, DimMinimum<R, C>, C> +
|
||||||
Allocator<N, R, DimMinimum<R, C>>,
|
Allocator<N, R, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, DimMinimum<R, C>>: Serialize,
|
MatrixMN<N, R, DimMinimum<R, C>>: Serialize,
|
||||||
MatrixMN<N, DimMinimum<R, C>, C>: Serialize,
|
MatrixMN<N, DimMinimum<R, C>, C>: Serialize,
|
||||||
VectorN<N, DimMinimum<R, C>>: Serialize"
|
VectorN<N, DimMinimum<R, C>>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<N, DimMinimum<R, C>> +
|
Allocator<N, DimMinimum<R, C>> +
|
||||||
Allocator<N, DimMinimum<R, C>, C> +
|
Allocator<N, DimMinimum<R, C>, C> +
|
||||||
Allocator<N, R, DimMinimum<R, C>>,
|
Allocator<N, R, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, DimMinimum<R, C>>: Deserialize<'de>,
|
MatrixMN<N, R, DimMinimum<R, C>>: Deserialize<'de>,
|
||||||
MatrixMN<N, DimMinimum<R, C>, C>: Deserialize<'de>,
|
MatrixMN<N, DimMinimum<R, C>, C>: Deserialize<'de>,
|
||||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SVD<N: Real, R: DimMin<C>, C: Dim>
|
pub struct SVD<N: Real, R: DimMin<C>, C: Dim>
|
||||||
@ -69,8 +65,7 @@ where
|
|||||||
MatrixMN<N, R, DimMinimum<R, C>>: Copy,
|
MatrixMN<N, R, DimMinimum<R, C>>: Copy,
|
||||||
MatrixMN<N, DimMinimum<R, C>, C>: Copy,
|
MatrixMN<N, DimMinimum<R, C>, C>: Copy,
|
||||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, R: DimMin<C>, C: Dim> SVD<N, R, C>
|
impl<N: Real, R: DimMin<C>, C: Dim> SVD<N, R, C>
|
||||||
where
|
where
|
||||||
@ -489,7 +484,8 @@ where
|
|||||||
/// right- and left- singular vectors have not been computed at construction-time.
|
/// right- and left- singular vectors have not been computed at construction-time.
|
||||||
pub fn recompose(self) -> MatrixMN<N, R, C> {
|
pub fn recompose(self) -> MatrixMN<N, R, C> {
|
||||||
let mut u = self.u.expect("SVD recomposition: U has not been computed.");
|
let mut u = self.u.expect("SVD recomposition: U has not been computed.");
|
||||||
let v_t = self.v_t
|
let v_t = self
|
||||||
|
.v_t
|
||||||
.expect("SVD recomposition: V^t has not been computed.");
|
.expect("SVD recomposition: V^t has not been computed.");
|
||||||
|
|
||||||
for i in 0..self.singular_values.len() {
|
for i in 0..self.singular_values.len() {
|
||||||
@ -545,10 +541,12 @@ where
|
|||||||
eps >= N::zero(),
|
eps >= N::zero(),
|
||||||
"SVD solve: the epsilon must be non-negative."
|
"SVD solve: the epsilon must be non-negative."
|
||||||
);
|
);
|
||||||
let u = self.u
|
let u = self
|
||||||
|
.u
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("SVD solve: U has not been computed.");
|
.expect("SVD solve: U has not been computed.");
|
||||||
let v_t = self.v_t
|
let v_t = self
|
||||||
|
.v_t
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("SVD solve: V^t has not been computed.");
|
.expect("SVD solve: V^t has not been computed.");
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
use std::ops::MulAssign;
|
use std::ops::MulAssign;
|
||||||
@ -18,25 +18,21 @@ use linalg::SymmetricTridiagonal;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, D>,
|
Allocator<N, D>,
|
||||||
VectorN<N, D>: Serialize,
|
VectorN<N, D>: Serialize,
|
||||||
MatrixN<N, D>: Serialize"
|
MatrixN<N, D>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, D>,
|
Allocator<N, D>,
|
||||||
VectorN<N, D>: Deserialize<'de>,
|
VectorN<N, D>: Deserialize<'de>,
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
MatrixN<N, D>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SymmetricEigen<N: Real, D: Dim>
|
pub struct SymmetricEigen<N: Real, D: Dim>
|
||||||
@ -55,8 +51,7 @@ where
|
|||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||||
MatrixN<N, D>: Copy,
|
MatrixN<N, D>: Copy,
|
||||||
VectorN<N, D>: Copy,
|
VectorN<N, D>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: Dim> SymmetricEigen<N, D>
|
impl<N: Real, D: Dim> SymmetricEigen<N, D>
|
||||||
where
|
where
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use allocator::Allocator;
|
use allocator::Allocator;
|
||||||
@ -13,25 +13,21 @@ use linalg::householder;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, DimDiff<D, U1>>,
|
Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Serialize,
|
MatrixN<N, D>: Serialize,
|
||||||
VectorN<N, DimDiff<D, U1>>: Serialize"
|
VectorN<N, DimDiff<D, U1>>: Serialize"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(
|
||||||
bound(
|
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, DimDiff<D, U1>>,
|
Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Deserialize<'de>,
|
MatrixN<N, D>: Deserialize<'de>,
|
||||||
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
||||||
)
|
))
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SymmetricTridiagonal<N: Real, D: DimSub<U1>>
|
pub struct SymmetricTridiagonal<N: Real, D: DimSub<U1>>
|
||||||
@ -47,8 +43,7 @@ where
|
|||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Copy,
|
MatrixN<N, D>: Copy,
|
||||||
VectorN<N, DimDiff<D, U1>>: Copy,
|
VectorN<N, DimDiff<D, U1>>: Copy,
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
impl<N: Real, D: DimSub<U1>> SymmetricTridiagonal<N, D>
|
impl<N: Real, D: DimSub<U1>> SymmetricTridiagonal<N, D>
|
||||||
where
|
where
|
||||||
|
485
src/sparse/cs_matrix.rs
Normal file
485
src/sparse/cs_matrix.rs
Normal file
@ -0,0 +1,485 @@
|
|||||||
|
use alga::general::{ClosedAdd, ClosedMul};
|
||||||
|
use num::{One, Zero};
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
use std::ops::{Add, Mul, Range};
|
||||||
|
|
||||||
|
use allocator::Allocator;
|
||||||
|
use constraint::{AreMultipliable, DimEq, ShapeConstraint};
|
||||||
|
use storage::{Storage, StorageMut};
|
||||||
|
use {DefaultAllocator, Dim, Matrix, MatrixMN, Scalar, Vector, VectorN, U1};
|
||||||
|
|
||||||
|
pub trait CsStorage<N, R, C = U1> {
|
||||||
|
fn shape(&self) -> (R, C);
|
||||||
|
fn nvalues(&self) -> usize;
|
||||||
|
unsafe fn row_index_unchecked(&self, i: usize) -> usize;
|
||||||
|
unsafe fn get_value_unchecked(&self, i: usize) -> &N;
|
||||||
|
fn get_value(&self, i: usize) -> &N;
|
||||||
|
fn row_index(&self, i: usize) -> usize;
|
||||||
|
fn column_range(&self, j: usize) -> Range<usize>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait CsStorageMut<N, R, C = U1>: CsStorage<N, R, C> {
|
||||||
|
/*
|
||||||
|
/// Sets the length of this column without initializing its values and row indices.
|
||||||
|
///
|
||||||
|
/// If the given length is larger than the current one, uninitialized entries are
|
||||||
|
/// added at the end of the column `i`. This will effectively shift all the matrix entries
|
||||||
|
/// of the columns at indices `j` with `j > i`. Therefore this is a `O(n)` operation.
|
||||||
|
/// This is unsafe as the row indices on newly created components may end up being out
|
||||||
|
/// of bounds.
|
||||||
|
unsafe fn set_column_len(&mut self, i: usize, len: usize);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct CsVecStorage<N: Scalar, R: Dim, C: Dim>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Allocator<usize, C>,
|
||||||
|
{
|
||||||
|
shape: (R, C),
|
||||||
|
p: VectorN<usize, C>,
|
||||||
|
i: Vec<usize>,
|
||||||
|
vals: Vec<N>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<N: Scalar, R: Dim, C: Dim> CsStorage<N, R, C> for CsVecStorage<N, R, C>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Allocator<usize, C>,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
|
fn shape(&self) -> (R, C) {
|
||||||
|
self.shape
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn nvalues(&self) -> usize {
|
||||||
|
self.vals.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn column_range(&self, j: usize) -> Range<usize> {
|
||||||
|
let end = if j + 1 == self.p.len() {
|
||||||
|
self.nvalues()
|
||||||
|
} else {
|
||||||
|
self.p[j + 1]
|
||||||
|
};
|
||||||
|
|
||||||
|
self.p[j]..end
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn row_index(&self, i: usize) -> usize {
|
||||||
|
self.i[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn row_index_unchecked(&self, i: usize) -> usize {
|
||||||
|
*self.i.get_unchecked(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn get_value_unchecked(&self, i: usize) -> &N {
|
||||||
|
self.vals.get_unchecked(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_value(&self, i: usize) -> &N {
|
||||||
|
&self.vals[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub struct CsSliceStorage<'a, N: Scalar, R: Dim, C: DimAdd<U1>> {
|
||||||
|
shape: (R, C),
|
||||||
|
p: VectorSlice<usize, DimSum<C, U1>>,
|
||||||
|
i: VectorSlice<usize, Dynamic>,
|
||||||
|
vals: VectorSlice<N, Dynamic>,
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/// A compressed sparse column matrix.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct CsMatrix<N: Scalar, R: Dim, C: Dim, S: CsStorage<N, R, C> = CsVecStorage<N, R, C>> {
|
||||||
|
pub data: S,
|
||||||
|
_phantoms: PhantomData<(N, R, C)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type CsVector<N, R, S> = CsMatrix<N, R, U1, S>;
|
||||||
|
|
||||||
|
impl<N: Scalar, R: Dim, C: Dim> CsMatrix<N, R, C>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Allocator<usize, C>,
|
||||||
|
{
|
||||||
|
pub fn new_uninitialized_generic(nrows: R, ncols: C, nvals: usize) -> Self {
|
||||||
|
let mut i = Vec::with_capacity(nvals);
|
||||||
|
unsafe {
|
||||||
|
i.set_len(nvals);
|
||||||
|
}
|
||||||
|
i.shrink_to_fit();
|
||||||
|
|
||||||
|
let mut vals = Vec::with_capacity(nvals);
|
||||||
|
unsafe {
|
||||||
|
vals.set_len(nvals);
|
||||||
|
}
|
||||||
|
vals.shrink_to_fit();
|
||||||
|
|
||||||
|
CsMatrix {
|
||||||
|
data: CsVecStorage {
|
||||||
|
shape: (nrows, ncols),
|
||||||
|
p: unsafe { VectorN::new_uninitialized_generic(ncols, U1) },
|
||||||
|
i,
|
||||||
|
vals,
|
||||||
|
},
|
||||||
|
_phantoms: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cumsum<D: Dim>(a: &mut VectorN<usize, D>, b: &mut VectorN<usize, D>) -> usize
|
||||||
|
where
|
||||||
|
DefaultAllocator: Allocator<usize, D>,
|
||||||
|
{
|
||||||
|
assert!(a.len() == b.len());
|
||||||
|
let mut sum = 0;
|
||||||
|
|
||||||
|
for i in 0..a.len() {
|
||||||
|
b[i] = sum;
|
||||||
|
sum += a[i];
|
||||||
|
a[i] = b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
sum
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<N: Scalar, R: Dim, C: Dim, S: CsStorage<N, R, C>> CsMatrix<N, R, C, S> {
|
||||||
|
pub fn nvalues(&self) -> usize {
|
||||||
|
self.data.nvalues()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn transpose(&self) -> CsMatrix<N, C, R>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Allocator<usize, R>,
|
||||||
|
{
|
||||||
|
let (nrows, ncols) = self.data.shape();
|
||||||
|
|
||||||
|
let nvals = self.nvalues();
|
||||||
|
let mut res = CsMatrix::new_uninitialized_generic(ncols, nrows, nvals);
|
||||||
|
let mut workspace = Vector::zeros_generic(nrows, U1);
|
||||||
|
|
||||||
|
// Compute p.
|
||||||
|
for i in 0..nvals {
|
||||||
|
let row_id = self.data.row_index(i);
|
||||||
|
workspace[row_id] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = cumsum(&mut workspace, &mut res.data.p);
|
||||||
|
|
||||||
|
// Fill the result.
|
||||||
|
for j in 0..ncols.value() {
|
||||||
|
let column_idx = self.data.column_range(j);
|
||||||
|
|
||||||
|
for vi in column_idx {
|
||||||
|
let row_id = self.data.row_index(vi);
|
||||||
|
let shift = workspace[row_id];
|
||||||
|
|
||||||
|
res.data.vals[shift] = *self.data.get_value(vi);
|
||||||
|
res.data.i[shift] = j;
|
||||||
|
workspace[row_id] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scatter<R2: Dim, C2: Dim>(
|
||||||
|
&self,
|
||||||
|
j: usize,
|
||||||
|
beta: N,
|
||||||
|
timestamps: &mut [usize],
|
||||||
|
timestamp: usize,
|
||||||
|
workspace: &mut [N],
|
||||||
|
mut nz: usize,
|
||||||
|
res: &mut CsMatrix<N, R2, C2>,
|
||||||
|
) -> usize
|
||||||
|
where
|
||||||
|
N: ClosedAdd + ClosedMul,
|
||||||
|
DefaultAllocator: Allocator<usize, C2>,
|
||||||
|
{
|
||||||
|
let column_idx = self.data.column_range(j);
|
||||||
|
|
||||||
|
for vi in column_idx {
|
||||||
|
let i = self.data.row_index(vi);
|
||||||
|
let val = beta * *self.data.get_value(vi);
|
||||||
|
|
||||||
|
if timestamps[i] < timestamp {
|
||||||
|
timestamps[i] = timestamp;
|
||||||
|
res.data.i[nz] = i;
|
||||||
|
nz += 1;
|
||||||
|
workspace[i] = val;
|
||||||
|
} else {
|
||||||
|
workspace[i] += val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nz
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
impl<N: Scalar, R, S> CsVector<N, R, S> {
|
||||||
|
pub fn axpy(&mut self, alpha: N, x: CsVector<N, R, S>, beta: N) {
|
||||||
|
// First, compute the number of non-zero entries.
|
||||||
|
let mut nnzero = 0;
|
||||||
|
|
||||||
|
// Allocate a size large enough.
|
||||||
|
self.data.set_column_len(0, nnzero);
|
||||||
|
|
||||||
|
// Fill with the axpy.
|
||||||
|
let mut i = self.nvalues();
|
||||||
|
let mut j = x.nvalues();
|
||||||
|
let mut k = nnzero - 1;
|
||||||
|
let mut rid1 = self.data.row_index(0, i - 1);
|
||||||
|
let mut rid2 = x.data.row_index(0, j - 1);
|
||||||
|
|
||||||
|
while k > 0 {
|
||||||
|
if rid1 == rid2 {
|
||||||
|
self.data.set_row_index(0, k, rid1);
|
||||||
|
self[k] = alpha * x[j] + beta * self[k];
|
||||||
|
i -= 1;
|
||||||
|
j -= 1;
|
||||||
|
} else if rid1 < rid2 {
|
||||||
|
self.data.set_row_index(0, k, rid1);
|
||||||
|
self[k] = beta * self[i];
|
||||||
|
i -= 1;
|
||||||
|
} else {
|
||||||
|
self.data.set_row_index(0, k, rid2);
|
||||||
|
self[k] = alpha * x[j];
|
||||||
|
j -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
k -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
impl<N: Scalar + Zero + ClosedAdd + ClosedMul, D: Dim, S: StorageMut<N, D>> Vector<N, D, S> {
|
||||||
|
pub fn axpy_cs<D2: Dim, S2>(&mut self, alpha: N, x: &CsVector<N, D2, S2>, beta: N)
|
||||||
|
where
|
||||||
|
S2: CsStorage<N, D2>,
|
||||||
|
ShapeConstraint: DimEq<D, D2>,
|
||||||
|
{
|
||||||
|
if beta.is_zero() {
|
||||||
|
for i in 0..x.nvalues() {
|
||||||
|
unsafe {
|
||||||
|
let k = x.data.row_index_unchecked(i);
|
||||||
|
let y = self.vget_unchecked_mut(k);
|
||||||
|
*y = alpha * *x.data.get_value_unchecked(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i in 0..x.nvalues() {
|
||||||
|
unsafe {
|
||||||
|
let k = x.data.row_index_unchecked(i);
|
||||||
|
let y = self.vget_unchecked_mut(k);
|
||||||
|
*y = alpha * *x.data.get_value_unchecked(i) + beta * *y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn gemv_sparse<R2: Dim, C2: Dim, S2>(&mut self, alpha: N, a: &CsMatrix<N, R2, C2, S2>, x: &DVector<N>, beta: N)
|
||||||
|
where
|
||||||
|
S2: CsStorage<N, R2, C2> {
|
||||||
|
let col2 = a.column(0);
|
||||||
|
let val = unsafe { *x.vget_unchecked(0) };
|
||||||
|
self.axpy_sparse(alpha * val, &col2, beta);
|
||||||
|
|
||||||
|
for j in 1..ncols2 {
|
||||||
|
let col2 = a.column(j);
|
||||||
|
let val = unsafe { *x.vget_unchecked(j) };
|
||||||
|
|
||||||
|
self.axpy_sparse(alpha * val, &col2, N::one());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, N, R1, R2, C1, C2, S1, S2> Mul<&'b CsMatrix<N, R2, C2, S2>>
|
||||||
|
for &'a CsMatrix<N, R1, C1, S1>
|
||||||
|
where
|
||||||
|
N: Scalar + ClosedAdd + ClosedMul + Zero,
|
||||||
|
R1: Dim,
|
||||||
|
C1: Dim,
|
||||||
|
R2: Dim,
|
||||||
|
C2: Dim,
|
||||||
|
S1: CsStorage<N, R1, C1>,
|
||||||
|
S2: CsStorage<N, R2, C2>,
|
||||||
|
ShapeConstraint: AreMultipliable<R1, C1, R2, C2>,
|
||||||
|
DefaultAllocator: Allocator<usize, C2> + Allocator<usize, R1> + Allocator<N, R1>,
|
||||||
|
{
|
||||||
|
type Output = CsMatrix<N, R1, C2>;
|
||||||
|
|
||||||
|
fn mul(self, rhs: &'b CsMatrix<N, R2, C2, S2>) -> CsMatrix<N, R1, C2> {
|
||||||
|
let (nrows1, ncols1) = self.data.shape();
|
||||||
|
let (nrows2, ncols2) = rhs.data.shape();
|
||||||
|
assert_eq!(
|
||||||
|
ncols1.value(),
|
||||||
|
nrows2.value(),
|
||||||
|
"Mismatched dimensions for matrix multiplication."
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut res =
|
||||||
|
CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.nvalues() + rhs.nvalues());
|
||||||
|
let mut timestamps = VectorN::zeros_generic(nrows1, U1);
|
||||||
|
let mut workspace = unsafe { VectorN::new_uninitialized_generic(nrows1, U1) };
|
||||||
|
let mut nz = 0;
|
||||||
|
|
||||||
|
for j in 0..ncols2.value() {
|
||||||
|
res.data.p[j] = nz;
|
||||||
|
let column_idx = rhs.data.column_range(j);
|
||||||
|
let new_size_bound = nz + nrows1.value();
|
||||||
|
res.data.i.resize(new_size_bound, 0);
|
||||||
|
res.data.vals.resize(new_size_bound, N::zero());
|
||||||
|
|
||||||
|
for vi in column_idx {
|
||||||
|
let i = rhs.data.row_index(vi);
|
||||||
|
nz = self.scatter(
|
||||||
|
i,
|
||||||
|
*rhs.data.get_value(vi),
|
||||||
|
timestamps.as_mut_slice(),
|
||||||
|
j + 1,
|
||||||
|
workspace.as_mut_slice(),
|
||||||
|
nz,
|
||||||
|
&mut res,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for p in res.data.p[j]..nz {
|
||||||
|
res.data.vals[p] = workspace[res.data.i[p]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.data.i.truncate(nz);
|
||||||
|
res.data.i.shrink_to_fit();
|
||||||
|
res.data.vals.truncate(nz);
|
||||||
|
res.data.vals.shrink_to_fit();
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, N, R1, R2, C1, C2, S1, S2> Add<&'b CsMatrix<N, R2, C2, S2>>
|
||||||
|
for &'a CsMatrix<N, R1, C1, S1>
|
||||||
|
where
|
||||||
|
N: Scalar + ClosedAdd + ClosedMul + One,
|
||||||
|
R1: Dim,
|
||||||
|
C1: Dim,
|
||||||
|
R2: Dim,
|
||||||
|
C2: Dim,
|
||||||
|
S1: CsStorage<N, R1, C1>,
|
||||||
|
S2: CsStorage<N, R2, C2>,
|
||||||
|
ShapeConstraint: DimEq<R1, R2> + DimEq<C1, C2>,
|
||||||
|
DefaultAllocator: Allocator<usize, C2> + Allocator<usize, R1> + Allocator<N, R1>,
|
||||||
|
{
|
||||||
|
type Output = CsMatrix<N, R1, C2>;
|
||||||
|
|
||||||
|
fn add(self, rhs: &'b CsMatrix<N, R2, C2, S2>) -> CsMatrix<N, R1, C2> {
|
||||||
|
let (nrows1, ncols1) = self.data.shape();
|
||||||
|
let (nrows2, ncols2) = rhs.data.shape();
|
||||||
|
assert_eq!(
|
||||||
|
(nrows1.value(), ncols1.value()),
|
||||||
|
(nrows2.value(), ncols2.value()),
|
||||||
|
"Mismatched dimensions for matrix sum."
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut res =
|
||||||
|
CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.nvalues() + rhs.nvalues());
|
||||||
|
let mut timestamps = VectorN::zeros_generic(nrows1, U1);
|
||||||
|
let mut workspace = unsafe { VectorN::new_uninitialized_generic(nrows1, U1) };
|
||||||
|
let mut nz = 0;
|
||||||
|
|
||||||
|
for j in 0..ncols2.value() {
|
||||||
|
res.data.p[j] = nz;
|
||||||
|
|
||||||
|
nz = self.scatter(
|
||||||
|
j,
|
||||||
|
N::one(),
|
||||||
|
timestamps.as_mut_slice(),
|
||||||
|
j + 1,
|
||||||
|
workspace.as_mut_slice(),
|
||||||
|
nz,
|
||||||
|
&mut res,
|
||||||
|
);
|
||||||
|
|
||||||
|
nz = rhs.scatter(
|
||||||
|
j,
|
||||||
|
N::one(),
|
||||||
|
timestamps.as_mut_slice(),
|
||||||
|
j + 1,
|
||||||
|
workspace.as_mut_slice(),
|
||||||
|
nz,
|
||||||
|
&mut res,
|
||||||
|
);
|
||||||
|
|
||||||
|
for p in res.data.p[j]..nz {
|
||||||
|
res.data.vals[p] = workspace[res.data.i[p]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.data.i.truncate(nz);
|
||||||
|
res.data.i.shrink_to_fit();
|
||||||
|
res.data.vals.truncate(nz);
|
||||||
|
res.data.vals.shrink_to_fit();
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, N: Scalar + Zero, R: Dim, C: Dim, S> From<CsMatrix<N, R, C, S>> for MatrixMN<N, R, C>
|
||||||
|
where
|
||||||
|
S: CsStorage<N, R, C>,
|
||||||
|
DefaultAllocator: Allocator<N, R, C>,
|
||||||
|
{
|
||||||
|
fn from(m: CsMatrix<N, R, C, S>) -> Self {
|
||||||
|
let (nrows, ncols) = m.data.shape();
|
||||||
|
let mut res = MatrixMN::zeros_generic(nrows, ncols);
|
||||||
|
|
||||||
|
for j in 0..ncols.value() {
|
||||||
|
let column_idx = m.data.column_range(j);
|
||||||
|
|
||||||
|
for iv in column_idx {
|
||||||
|
let i = m.data.row_index(iv);
|
||||||
|
res[(i, j)] = *m.data.get_value(iv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, N: Scalar + Zero, R: Dim, C: Dim, S> From<Matrix<N, R, C, S>> for CsMatrix<N, R, C>
|
||||||
|
where
|
||||||
|
S: Storage<N, R, C>,
|
||||||
|
DefaultAllocator: Allocator<N, R, C> + Allocator<usize, C>,
|
||||||
|
{
|
||||||
|
fn from(m: Matrix<N, R, C, S>) -> Self {
|
||||||
|
let (nrows, ncols) = m.data.shape();
|
||||||
|
let nvalues = m.iter().filter(|e| !e.is_zero()).count();
|
||||||
|
let mut res = CsMatrix::new_uninitialized_generic(nrows, ncols, nvalues);
|
||||||
|
let mut nz = 0;
|
||||||
|
|
||||||
|
for j in 0..ncols.value() {
|
||||||
|
let column = m.column(j);
|
||||||
|
res.data.p[j] = nz;
|
||||||
|
|
||||||
|
for i in 0..nrows.value() {
|
||||||
|
if !column[i].is_zero() {
|
||||||
|
res.data.i[nz] = i;
|
||||||
|
res.data.vals[nz] = column[i];
|
||||||
|
nz += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
3
src/sparse/mod.rs
Normal file
3
src/sparse/mod.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub use self::cs_matrix::CsMatrix;
|
||||||
|
|
||||||
|
mod cs_matrix;
|
@ -1,9 +1,9 @@
|
|||||||
use rand::random;
|
use abomonation::{decode, encode, Abomonation};
|
||||||
use abomonation::{Abomonation, encode, decode};
|
|
||||||
use na::{
|
use na::{
|
||||||
DMatrix, Matrix3x4, Point3, Translation3, Rotation3, Isometry3, Quaternion,
|
DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3,
|
||||||
IsometryMatrix3, Similarity3, SimilarityMatrix3
|
SimilarityMatrix3, Translation3,
|
||||||
};
|
};
|
||||||
|
use rand::random;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn abomonate_dmatrix() {
|
fn abomonate_dmatrix() {
|
||||||
@ -39,7 +39,9 @@ fn assert_encode_and_decode<T: Abomonation + PartialEq + Clone>(original_data: T
|
|||||||
|
|
||||||
// Encode
|
// Encode
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
unsafe { encode(&original_data, &mut bytes); }
|
unsafe {
|
||||||
|
encode(&original_data, &mut bytes);
|
||||||
|
}
|
||||||
|
|
||||||
// Drop the original, so that dangling pointers are revealed by the test
|
// Drop the original, so that dangling pointers are revealed by the test
|
||||||
drop(original_data);
|
drop(original_data);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
|
|
||||||
|
use na::{DMatrix, DVector};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use na::{DVector, DMatrix};
|
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
/*
|
/*
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
use alga::linear::Transformation;
|
use alga::linear::Transformation;
|
||||||
use na::{
|
use na::{
|
||||||
self,
|
self, Affine3, Isometry3, Matrix2, Matrix2x3, Matrix2x4, Matrix2x5, Matrix2x6, Matrix3,
|
||||||
|
Matrix3x2, Matrix3x4, Matrix3x5, Matrix3x6, Matrix4, Matrix4x2, Matrix4x3, Matrix4x5,
|
||||||
|
Matrix4x6, Matrix5, Matrix5x2, Matrix5x3, Matrix5x4, Matrix5x6, Matrix6, Matrix6x2, Matrix6x3,
|
||||||
|
Matrix6x4, Matrix6x5, Point3, Projective3, Rotation3, RowVector1, RowVector2, RowVector3,
|
||||||
|
RowVector4, RowVector5, RowVector6, Similarity3, Transform3, Translation3, UnitQuaternion,
|
||||||
Vector1, Vector2, Vector3, Vector4, Vector5, Vector6,
|
Vector1, Vector2, Vector3, Vector4, Vector5, Vector6,
|
||||||
RowVector1, RowVector2, RowVector3, RowVector4, RowVector5, RowVector6,
|
};
|
||||||
Matrix2, Matrix3, Matrix4, Matrix5, Matrix6,
|
|
||||||
Matrix2x3, Matrix2x4, Matrix2x5, Matrix2x6,
|
|
||||||
Matrix3x2, Matrix3x4, Matrix3x5, Matrix3x6,
|
|
||||||
Matrix4x2, Matrix4x3, Matrix4x5, Matrix4x6,
|
|
||||||
Matrix5x2, Matrix5x3, Matrix5x4, Matrix5x6,
|
|
||||||
Matrix6x2, Matrix6x3, Matrix6x4, Matrix6x5,
|
|
||||||
Point3, Translation3, Isometry3, Similarity3, Affine3,
|
|
||||||
Projective3, Transform3, Rotation3, UnitQuaternion};
|
|
||||||
|
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn translation_conversion(t: Translation3<f64>, v: Vector3<f64>, p: Point3<f64>) -> bool {
|
fn translation_conversion(t: Translation3<f64>, v: Vector3<f64>, p: Point3<f64>) -> bool {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
|
mod abomonation;
|
||||||
|
mod blas;
|
||||||
mod conversion;
|
mod conversion;
|
||||||
mod edition;
|
mod edition;
|
||||||
mod matrix;
|
mod matrix;
|
||||||
mod matrix_slice;
|
mod matrix_slice;
|
||||||
mod blas;
|
|
||||||
mod serde;
|
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
|
||||||
mod abomonation;
|
|
||||||
#[cfg(feature = "mint")]
|
#[cfg(feature = "mint")]
|
||||||
mod mint;
|
mod mint;
|
||||||
|
mod serde;
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
#![cfg(feature = "serde-serialize")]
|
#![cfg(feature = "serde-serialize")]
|
||||||
|
|
||||||
use serde_json;
|
|
||||||
use rand;
|
|
||||||
use na::{
|
use na::{
|
||||||
DMatrix,
|
DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3,
|
||||||
Matrix3x4,
|
SimilarityMatrix3, Translation3, Unit,
|
||||||
Point3,
|
|
||||||
Translation3,
|
|
||||||
Rotation3,
|
|
||||||
Isometry3,
|
|
||||||
IsometryMatrix3,
|
|
||||||
Similarity3,
|
|
||||||
SimilarityMatrix3,
|
|
||||||
Quaternion,
|
|
||||||
Unit,
|
|
||||||
};
|
};
|
||||||
|
use rand;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
macro_rules! test_serde(
|
macro_rules! test_serde(
|
||||||
($($test: ident, $ty: ident);* $(;)*) => {$(
|
($($test: ident, $ty: ident);* $(;)*) => {$(
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use alga::linear::{Transformation, ProjectiveTransformation};
|
use alga::linear::{ProjectiveTransformation, Transformation};
|
||||||
use na::{
|
use na::{
|
||||||
Vector3, Point3, Rotation3, Isometry3, Translation3, UnitQuaternion,
|
Isometry2, Isometry3, Point2, Point3, Rotation2, Rotation3, Translation2, Translation3,
|
||||||
Vector2, Point2, Rotation2, Isometry2, Translation2, UnitComplex
|
UnitComplex, UnitQuaternion, Vector2, Vector3,
|
||||||
};
|
};
|
||||||
|
|
||||||
quickcheck!(
|
quickcheck!(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
use num::Zero;
|
|
||||||
use na::{Point3, Vector3, Vector4};
|
use na::{Point3, Vector3, Vector4};
|
||||||
|
use num::Zero;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn point_ops() {
|
fn point_ops() {
|
||||||
@ -8,20 +8,20 @@ fn point_ops() {
|
|||||||
let b = Point3::new(1.0, 2.0, 3.0);
|
let b = Point3::new(1.0, 2.0, 3.0);
|
||||||
let c = Vector3::new(1.0, 2.0, 3.0);
|
let c = Vector3::new(1.0, 2.0, 3.0);
|
||||||
|
|
||||||
assert_eq!( a - b, Vector3::zero());
|
assert_eq!(a - b, Vector3::zero());
|
||||||
assert_eq!(&a - &b, Vector3::zero());
|
assert_eq!(&a - &b, Vector3::zero());
|
||||||
assert_eq!( a - &b, Vector3::zero());
|
assert_eq!(a - &b, Vector3::zero());
|
||||||
assert_eq!(&a - b, Vector3::zero());
|
assert_eq!(&a - b, Vector3::zero());
|
||||||
|
|
||||||
assert_eq!( b - c, Point3::origin());
|
assert_eq!(b - c, Point3::origin());
|
||||||
assert_eq!(&b - &c, Point3::origin());
|
assert_eq!(&b - &c, Point3::origin());
|
||||||
assert_eq!( b - &c, Point3::origin());
|
assert_eq!(b - &c, Point3::origin());
|
||||||
assert_eq!(&b - c, Point3::origin());
|
assert_eq!(&b - c, Point3::origin());
|
||||||
|
|
||||||
assert_eq!( b + c, 2.0 * a);
|
assert_eq!(b + c, 2.0 * a);
|
||||||
assert_eq!(&b + &c, 2.0 * a);
|
assert_eq!(&b + &c, 2.0 * a);
|
||||||
assert_eq!( b + &c, 2.0 * a);
|
assert_eq!(b + &c, 2.0 * a);
|
||||||
assert_eq!(&b + c, 2.0 * a);
|
assert_eq!(&b + c, 2.0 * a);
|
||||||
|
|
||||||
let mut a1 = a;
|
let mut a1 = a;
|
||||||
let mut a2 = a;
|
let mut a2 = a;
|
||||||
@ -58,20 +58,19 @@ fn point_coordinates() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn point_scale() {
|
fn point_scale() {
|
||||||
let pt = Point3::new(1, 2, 3);
|
let pt = Point3::new(1, 2, 3);
|
||||||
let expected = Point3::new(10, 20, 30);
|
let expected = Point3::new(10, 20, 30);
|
||||||
|
|
||||||
assert_eq!(pt * 10, expected);
|
assert_eq!(pt * 10, expected);
|
||||||
assert_eq!(&pt * 10, expected);
|
assert_eq!(&pt * 10, expected);
|
||||||
assert_eq!(10 * pt, expected);
|
assert_eq!(10 * pt, expected);
|
||||||
assert_eq!(10 * &pt, expected);
|
assert_eq!(10 * &pt, expected);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn point_vector_sum() {
|
fn point_vector_sum() {
|
||||||
let pt = Point3::new(1, 2, 3);
|
let pt = Point3::new(1, 2, 3);
|
||||||
let vec = Vector3::new(10, 20, 30);
|
let vec = Vector3::new(10, 20, 30);
|
||||||
let expected = Point3::new(11, 22, 33);
|
let expected = Point3::new(11, 22, 33);
|
||||||
|
|
||||||
assert_eq!(&pt + &vec, expected);
|
assert_eq!(&pt + &vec, expected);
|
||||||
@ -82,15 +81,13 @@ fn point_vector_sum() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_homogeneous() {
|
fn to_homogeneous() {
|
||||||
let a = Point3::new(1.0, 2.0, 3.0);
|
let a = Point3::new(1.0, 2.0, 3.0);
|
||||||
let expected = Vector4::new(1.0, 2.0, 3.0, 1.0);
|
let expected = Vector4::new(1.0, 2.0, 3.0, 1.0);
|
||||||
|
|
||||||
assert_eq!(a.to_homogeneous(), expected);
|
assert_eq!(a.to_homogeneous(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
quickcheck!(
|
quickcheck!(fn point_sub(pt1: Point3<f64>, pt2: Point3<f64>) -> bool {
|
||||||
fn point_sub(pt1: Point3<f64>, pt2: Point3<f64>) -> bool {
|
let dpt = &pt2 - &pt1;
|
||||||
let dpt = &pt2 - &pt1;
|
relative_eq!(pt2, pt1 + dpt, epsilon = 1.0e-7)
|
||||||
relative_eq!(pt2, pt1 + dpt, epsilon = 1.0e-7)
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use na::{Perspective3, Orthographic3};
|
use na::{Orthographic3, Perspective3};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn perspective_inverse() {
|
fn perspective_inverse() {
|
||||||
let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
|
let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
|
||||||
let inv = proj.inverse();
|
let inv = proj.inverse();
|
||||||
|
|
||||||
let id = inv * proj.unwrap();
|
let id = inv * proj.unwrap();
|
||||||
|
|
||||||
@ -13,17 +13,16 @@ fn perspective_inverse() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn orthographic_inverse() {
|
fn orthographic_inverse() {
|
||||||
let proj = Orthographic3::new(1.0, 2.0, -3.0, -2.5, 10.0, 900.0);
|
let proj = Orthographic3::new(1.0, 2.0, -3.0, -2.5, 10.0, 900.0);
|
||||||
let inv = proj.inverse();
|
let inv = proj.inverse();
|
||||||
|
|
||||||
let id = inv * proj.unwrap();
|
let id = inv * proj.unwrap();
|
||||||
|
|
||||||
assert!(id.is_identity(1.0e-7));
|
assert!(id.is_identity(1.0e-7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
mod quickcheck_tests {
|
mod quickcheck_tests {
|
||||||
use na::{Point3, Perspective3, Orthographic3};
|
use na::{Orthographic3, Perspective3, Point3};
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn perspective_project_unproject(pt: Point3<f64>) -> bool {
|
fn perspective_project_unproject(pt: Point3<f64>) -> bool {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use na::{Unit, UnitQuaternion, Quaternion, Vector3, Point3, Rotation3};
|
use na::{Point3, Quaternion, Rotation3, Unit, UnitQuaternion, Vector3};
|
||||||
|
|
||||||
|
|
||||||
quickcheck!(
|
quickcheck!(
|
||||||
/*
|
/*
|
||||||
|
@ -18,9 +18,9 @@ fn angle_3() {
|
|||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
mod quickcheck_tests {
|
mod quickcheck_tests {
|
||||||
use std::f64;
|
|
||||||
use alga::general::Real;
|
use alga::general::Real;
|
||||||
use na::{self, Vector2, Vector3, Rotation2, Rotation3, Unit};
|
use na::{self, Rotation2, Rotation3, Unit, Vector2, Vector3};
|
||||||
|
use std::f64;
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
/*
|
/*
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use alga::linear::{Transformation, ProjectiveTransformation};
|
use alga::linear::{ProjectiveTransformation, Transformation};
|
||||||
use na::{Vector3, Point3, Similarity3, Translation3, Isometry3, UnitQuaternion};
|
use na::{Isometry3, Point3, Similarity3, Translation3, UnitQuaternion, Vector3};
|
||||||
|
|
||||||
quickcheck!(
|
quickcheck!(
|
||||||
fn inverse_is_identity(i: Similarity3<f64>, p: Point3<f64>, v: Vector3<f64>) -> bool {
|
fn inverse_is_identity(i: Similarity3<f64>, p: Point3<f64>, v: Vector3<f64>) -> bool {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use na::{Unit, UnitComplex, Vector2, Point2, Rotation2};
|
use na::{Point2, Rotation2, Unit, UnitComplex, Vector2};
|
||||||
|
|
||||||
quickcheck!(
|
quickcheck!(
|
||||||
|
|
||||||
|
@ -14,5 +14,7 @@ extern crate rand;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
mod core;
|
mod core;
|
||||||
mod linalg;
|
|
||||||
mod geometry;
|
mod geometry;
|
||||||
|
mod linalg;
|
||||||
|
#[cfg(feature = "sparse")]
|
||||||
|
mod sparse;
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use na::{DMatrix, Matrix4};
|
|
||||||
use na::balancing;
|
use na::balancing;
|
||||||
|
use na::{DMatrix, Matrix4};
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn balancing_parlett_reinsch(n: usize) -> bool {
|
fn balancing_parlett_reinsch(n: usize) -> bool {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
|
|
||||||
use na::{DMatrix, Matrix2, Matrix4, Matrix5x3, Matrix3x5};
|
use na::{DMatrix, Matrix2, Matrix3x5, Matrix4, Matrix5x3};
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn bidiagonal(m: DMatrix<f64>) -> bool {
|
fn bidiagonal(m: DMatrix<f64>) -> bool {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#![cfg(all(feature = "arbitrary", feature = "debug"))]
|
#![cfg(all(feature = "arbitrary", feature = "debug"))]
|
||||||
|
|
||||||
use std::cmp;
|
|
||||||
use na::{DMatrix, Matrix4x3, DVector, Vector4};
|
|
||||||
use na::dimension::U4;
|
|
||||||
use na::debug::RandomSDP;
|
use na::debug::RandomSDP;
|
||||||
|
use na::dimension::U4;
|
||||||
|
use na::{DMatrix, DVector, Matrix4x3, Vector4};
|
||||||
|
use std::cmp;
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn cholesky(m: RandomSDP<f64>) -> bool {
|
fn cholesky(m: RandomSDP<f64>) -> bool {
|
||||||
|
@ -2,8 +2,8 @@ use na::DMatrix;
|
|||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
mod quickcheck_tests {
|
mod quickcheck_tests {
|
||||||
use std::cmp;
|
|
||||||
use na::{DMatrix, Matrix2, Matrix3, Matrix4};
|
use na::{DMatrix, Matrix2, Matrix3, Matrix4};
|
||||||
|
use std::cmp;
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn symmetric_eigen(n: usize) -> bool {
|
fn symmetric_eigen(n: usize) -> bool {
|
||||||
@ -62,39 +62,58 @@ mod quickcheck_tests {
|
|||||||
// Test proposed on the issue #176 of rulinalg.
|
// Test proposed on the issue #176 of rulinalg.
|
||||||
#[test]
|
#[test]
|
||||||
fn symmetric_eigen_singular_24x24() {
|
fn symmetric_eigen_singular_24x24() {
|
||||||
let m = DMatrix::from_row_slice(24, 24, &[
|
let m = DMatrix::from_row_slice(
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
24,
|
||||||
-1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
24,
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
&[
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0,
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0,
|
||||||
0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0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0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
0.0,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let eig = m.clone().symmetric_eigen();
|
let eig = m.clone().symmetric_eigen();
|
||||||
let recomp = eig.recompose();
|
let recomp = eig.recompose();
|
||||||
|
|
||||||
assert!(relative_eq!(m.lower_triangle(), recomp.lower_triangle(), epsilon = 1.0e-5));
|
assert!(relative_eq!(
|
||||||
|
m.lower_triangle(),
|
||||||
|
recomp.lower_triangle(),
|
||||||
|
epsilon = 1.0e-5
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #[cfg(feature = "arbitrary")]
|
// #[cfg(feature = "arbitrary")]
|
||||||
// quickcheck! {
|
// quickcheck! {
|
||||||
// FIXME: full eigendecomposition is not implemented yet because of its complexity when some
|
// FIXME: full eigendecomposition is not implemented yet because of its complexity when some
|
||||||
@ -167,16 +186,16 @@ fn symmetric_eigen_singular_24x24() {
|
|||||||
// MatrixN<f64, D>: Display,
|
// MatrixN<f64, D>: Display,
|
||||||
// VectorN<f64, D>: Display {
|
// VectorN<f64, D>: Display {
|
||||||
// let mv = &m * &eig.eigenvectors;
|
// let mv = &m * &eig.eigenvectors;
|
||||||
//
|
//
|
||||||
// println!("eigenvalues: {}eigenvectors: {}", eig.eigenvalues, eig.eigenvectors);
|
// println!("eigenvalues: {}eigenvectors: {}", eig.eigenvalues, eig.eigenvectors);
|
||||||
//
|
//
|
||||||
// let dim = m.nrows();
|
// let dim = m.nrows();
|
||||||
// for i in 0 .. dim {
|
// for i in 0 .. dim {
|
||||||
// let mut col = eig.eigenvectors.column_mut(i);
|
// let mut col = eig.eigenvectors.column_mut(i);
|
||||||
// col *= eig.eigenvalues[i];
|
// col *= eig.eigenvalues[i];
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// println!("{}{:.5}{:.5}", m, mv, eig.eigenvectors);
|
// println!("{}{:.5}{:.5}", m, mv, eig.eigenvectors);
|
||||||
//
|
//
|
||||||
// relative_eq!(eig.eigenvectors, mv, epsilon = 1.0e-5)
|
// relative_eq!(eig.eigenvectors, mv, epsilon = 1.0e-5)
|
||||||
// }
|
// }
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
|
|
||||||
use std::cmp;
|
|
||||||
use na::{DMatrix, Matrix2, Matrix4};
|
use na::{DMatrix, Matrix2, Matrix4};
|
||||||
|
use std::cmp;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hessenberg_simple() {
|
fn hessenberg_simple() {
|
||||||
let m = Matrix2::new(1.0, 0.0,
|
let m = Matrix2::new(1.0, 0.0, 1.0, 3.0);
|
||||||
1.0, 3.0);
|
|
||||||
let hess = m.hessenberg();
|
let hess = m.hessenberg();
|
||||||
let (p, h) = hess.unpack();
|
let (p, h) = hess.unpack();
|
||||||
assert!(relative_eq!(m, p * h * p.transpose(), epsilon = 1.0e-7))
|
assert!(relative_eq!(m, p * h * p.transpose(), epsilon = 1.0e-7))
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
mod inverse;
|
|
||||||
mod solve;
|
|
||||||
mod qr;
|
|
||||||
mod cholesky;
|
|
||||||
mod hessenberg;
|
|
||||||
mod lu;
|
|
||||||
mod full_piv_lu;
|
|
||||||
mod bidiagonal;
|
|
||||||
mod real_schur;
|
|
||||||
mod svd;
|
|
||||||
mod balancing;
|
mod balancing;
|
||||||
mod tridiagonal;
|
mod bidiagonal;
|
||||||
|
mod cholesky;
|
||||||
mod eigen;
|
mod eigen;
|
||||||
|
mod full_piv_lu;
|
||||||
|
mod hessenberg;
|
||||||
|
mod inverse;
|
||||||
|
mod lu;
|
||||||
|
mod qr;
|
||||||
|
mod real_schur;
|
||||||
|
mod solve;
|
||||||
|
mod svd;
|
||||||
|
mod tridiagonal;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#![cfg(feature = "arbitrary")]
|
#![cfg(feature = "arbitrary")]
|
||||||
|
|
||||||
|
use na::{DMatrix, DVector, Matrix3x5, Matrix4, Matrix4x3, Matrix5x3, Vector4};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use na::{DMatrix, Matrix4, Matrix4x3, Matrix5x3, Matrix3x5,
|
|
||||||
DVector, Vector4};
|
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn qr(m: DMatrix<f64>) -> bool {
|
fn qr(m: DMatrix<f64>) -> bool {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use na::{Matrix4, Matrix4x5};
|
use na::{Matrix4, Matrix4x5};
|
||||||
|
|
||||||
fn unzero_diagonal(a: &mut Matrix4<f64>) {
|
fn unzero_diagonal(a: &mut Matrix4<f64>) {
|
||||||
for i in 0 .. 4 {
|
for i in 0..4 {
|
||||||
if a[(i, i)] < 1.0e-7 {
|
if a[(i, i)] < 1.0e-7 {
|
||||||
a[(i, i)] = 1.0;
|
a[(i, i)] = 1.0;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ use na::{DMatrix, Matrix6};
|
|||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
mod quickcheck_tests {
|
mod quickcheck_tests {
|
||||||
|
use na::{
|
||||||
|
DMatrix, DVector, Matrix2, Matrix2x5, Matrix3, Matrix3x5, Matrix4, Matrix5x2, Matrix5x3,
|
||||||
|
};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use na::{DMatrix, Matrix2, Matrix3, Matrix4, Matrix5x2, Matrix5x3, Matrix2x5, Matrix3x5, DVector};
|
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn svd(m: DMatrix<f64>) -> bool {
|
fn svd(m: DMatrix<f64>) -> bool {
|
||||||
@ -143,31 +145,47 @@ mod quickcheck_tests {
|
|||||||
// Test proposed on the issue #176 of rulinalg.
|
// Test proposed on the issue #176 of rulinalg.
|
||||||
#[test]
|
#[test]
|
||||||
fn svd_singular() {
|
fn svd_singular() {
|
||||||
let m = DMatrix::from_row_slice(24, 24, &[
|
let m = DMatrix::from_row_slice(
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
24,
|
||||||
-1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
24,
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
&[
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0,
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0,
|
||||||
0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.0, 0.0, 0.0, 0.0,
|
||||||
|
0.0,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let svd = m.clone().svd(true, true);
|
let svd = m.clone().svd(true, true);
|
||||||
let (u, s, v_t) = (svd.u.unwrap(), svd.singular_values, svd.v_t.unwrap());
|
let (u, s, v_t) = (svd.u.unwrap(), svd.singular_values, svd.v_t.unwrap());
|
||||||
@ -184,33 +202,48 @@ fn svd_singular() {
|
|||||||
// Same as the previous test but with one additional row.
|
// Same as the previous test but with one additional row.
|
||||||
#[test]
|
#[test]
|
||||||
fn svd_singular_vertical() {
|
fn svd_singular_vertical() {
|
||||||
let m = DMatrix::from_row_slice(25, 24, &[
|
let m = DMatrix::from_row_slice(
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
25,
|
||||||
-1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
24,
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
&[
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0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 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 0.0, 0.0, 0.0, -4.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0,
|
||||||
|
-4.0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0,
|
||||||
|
0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let svd = m.clone().svd(true, true);
|
let svd = m.clone().svd(true, true);
|
||||||
let (u, s, v_t) = (svd.u.unwrap(), svd.singular_values, svd.v_t.unwrap());
|
let (u, s, v_t) = (svd.u.unwrap(), svd.singular_values, svd.v_t.unwrap());
|
||||||
@ -223,31 +256,48 @@ fn svd_singular_vertical() {
|
|||||||
// Same as the previous test but with one additional column.
|
// Same as the previous test but with one additional column.
|
||||||
#[test]
|
#[test]
|
||||||
fn svd_singular_horizontal() {
|
fn svd_singular_horizontal() {
|
||||||
let m = DMatrix::from_row_slice(24, 25, &[
|
let m = DMatrix::from_row_slice(
|
||||||
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0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 0.0,
|
||||||
|
0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let svd = m.clone().svd(true, true);
|
let svd = m.clone().svd(true, true);
|
||||||
let (u, s, v_t) = (svd.u.unwrap(), svd.singular_values, svd.v_t.unwrap());
|
let (u, s, v_t) = (svd.u.unwrap(), svd.singular_values, svd.v_t.unwrap());
|
||||||
@ -257,7 +307,6 @@ fn svd_singular_horizontal() {
|
|||||||
assert!(relative_eq!(m, &u * ds * &v_t, epsilon = 1.0e-5));
|
assert!(relative_eq!(m, &u * ds * &v_t, epsilon = 1.0e-5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn svd_zeros() {
|
fn svd_zeros() {
|
||||||
let m = DMatrix::from_element(10, 10, 0.0);
|
let m = DMatrix::from_element(10, 10, 0.0);
|
||||||
@ -283,47 +332,100 @@ fn svd_identity() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn svd_with_delimited_subproblem() {
|
fn svd_with_delimited_subproblem() {
|
||||||
let mut m = DMatrix::<f64>::from_element(10, 10, 0.0);
|
let mut m = DMatrix::<f64>::from_element(10, 10, 0.0);
|
||||||
m[(0,0)] = 1.0; m[(0,1)] = 2.0;
|
m[(0, 0)] = 1.0;
|
||||||
m[(1,1)] = 0.0; m[(1,2)] = 3.0;
|
m[(0, 1)] = 2.0;
|
||||||
m[(2,2)] = 4.0; m[(2,3)] = 5.0;
|
m[(1, 1)] = 0.0;
|
||||||
m[(3,3)] = 6.0; m[(3,4)] = 0.0;
|
m[(1, 2)] = 3.0;
|
||||||
m[(4,4)] = 8.0; m[(3,5)] = 9.0;
|
m[(2, 2)] = 4.0;
|
||||||
m[(5,5)] = 10.0; m[(3,6)] = 11.0;
|
m[(2, 3)] = 5.0;
|
||||||
m[(6,6)] = 12.0; m[(3,7)] = 12.0;
|
m[(3, 3)] = 6.0;
|
||||||
m[(7,7)] = 14.0; m[(3,8)] = 13.0;
|
m[(3, 4)] = 0.0;
|
||||||
m[(8,8)] = 16.0; m[(3,9)] = 17.0;
|
m[(4, 4)] = 8.0;
|
||||||
m[(9,9)] = 18.0;
|
m[(3, 5)] = 9.0;
|
||||||
|
m[(5, 5)] = 10.0;
|
||||||
|
m[(3, 6)] = 11.0;
|
||||||
|
m[(6, 6)] = 12.0;
|
||||||
|
m[(3, 7)] = 12.0;
|
||||||
|
m[(7, 7)] = 14.0;
|
||||||
|
m[(3, 8)] = 13.0;
|
||||||
|
m[(8, 8)] = 16.0;
|
||||||
|
m[(3, 9)] = 17.0;
|
||||||
|
m[(9, 9)] = 18.0;
|
||||||
let svd = m.clone().svd(true, true);
|
let svd = m.clone().svd(true, true);
|
||||||
assert!(relative_eq!(m, svd.recompose(), epsilon = 1.0e-7));
|
assert!(relative_eq!(m, svd.recompose(), epsilon = 1.0e-7));
|
||||||
|
|
||||||
// Rectangular versions.
|
// Rectangular versions.
|
||||||
let mut m = DMatrix::<f64>::from_element(15, 10, 0.0);
|
let mut m = DMatrix::<f64>::from_element(15, 10, 0.0);
|
||||||
m[(0,0)] = 1.0; m[(0,1)] = 2.0;
|
m[(0, 0)] = 1.0;
|
||||||
m[(1,1)] = 0.0; m[(1,2)] = 3.0;
|
m[(0, 1)] = 2.0;
|
||||||
m[(2,2)] = 4.0; m[(2,3)] = 5.0;
|
m[(1, 1)] = 0.0;
|
||||||
m[(3,3)] = 6.0; m[(3,4)] = 0.0;
|
m[(1, 2)] = 3.0;
|
||||||
m[(4,4)] = 8.0; m[(3,5)] = 9.0;
|
m[(2, 2)] = 4.0;
|
||||||
m[(5,5)] = 10.0; m[(3,6)] = 11.0;
|
m[(2, 3)] = 5.0;
|
||||||
m[(6,6)] = 12.0; m[(3,7)] = 12.0;
|
m[(3, 3)] = 6.0;
|
||||||
m[(7,7)] = 14.0; m[(3,8)] = 13.0;
|
m[(3, 4)] = 0.0;
|
||||||
m[(8,8)] = 16.0; m[(3,9)] = 17.0;
|
m[(4, 4)] = 8.0;
|
||||||
m[(9,9)] = 18.0;
|
m[(3, 5)] = 9.0;
|
||||||
|
m[(5, 5)] = 10.0;
|
||||||
|
m[(3, 6)] = 11.0;
|
||||||
|
m[(6, 6)] = 12.0;
|
||||||
|
m[(3, 7)] = 12.0;
|
||||||
|
m[(7, 7)] = 14.0;
|
||||||
|
m[(3, 8)] = 13.0;
|
||||||
|
m[(8, 8)] = 16.0;
|
||||||
|
m[(3, 9)] = 17.0;
|
||||||
|
m[(9, 9)] = 18.0;
|
||||||
let svd = m.clone().svd(true, true);
|
let svd = m.clone().svd(true, true);
|
||||||
assert!(relative_eq!(m, svd.recompose(), epsilon = 1.0e-7));
|
assert!(relative_eq!(m, svd.recompose(), epsilon = 1.0e-7));
|
||||||
|
|
||||||
let svd = m.transpose().svd(true, true);
|
let svd = m.transpose().svd(true, true);
|
||||||
assert!(relative_eq!(m.transpose(), svd.recompose(), epsilon = 1.0e-7));
|
assert!(relative_eq!(
|
||||||
|
m.transpose(),
|
||||||
|
svd.recompose(),
|
||||||
|
epsilon = 1.0e-7
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn svd_fail() {
|
fn svd_fail() {
|
||||||
let m = Matrix6::new(
|
let m = Matrix6::new(
|
||||||
0.9299319121545955, 0.9955870335651049, 0.8824725266413644, 0.28966880207132295, 0.06102723649846409, 0.9311880746048009,
|
0.9299319121545955,
|
||||||
0.5938395242304351, 0.8398522876024204, 0.06672831951963198, 0.9941213119963099, 0.9431846038057834, 0.8159885168706427,
|
0.9955870335651049,
|
||||||
0.9121962883152357, 0.6471119669367571, 0.4823309702814407, 0.6420516076705516, 0.7731203925207113, 0.7424069470756647,
|
0.8824725266413644,
|
||||||
0.07311092531259344, 0.5579247949052946, 0.14518764691585773, 0.03502980663114896, 0.7991329455957719, 0.4929930019965745,
|
0.28966880207132295,
|
||||||
0.12293810556077789, 0.6617084679545999, 0.9002240700227326, 0.027153062135304884, 0.3630189466989524, 0.18207502727558866,
|
0.06102723649846409,
|
||||||
0.843196731466686, 0.08951878746549924, 0.7533450877576973, 0.009558876499740077, 0.9429679490873482, 0.9355764454129878);
|
0.9311880746048009,
|
||||||
|
0.5938395242304351,
|
||||||
|
0.8398522876024204,
|
||||||
|
0.06672831951963198,
|
||||||
|
0.9941213119963099,
|
||||||
|
0.9431846038057834,
|
||||||
|
0.8159885168706427,
|
||||||
|
0.9121962883152357,
|
||||||
|
0.6471119669367571,
|
||||||
|
0.4823309702814407,
|
||||||
|
0.6420516076705516,
|
||||||
|
0.7731203925207113,
|
||||||
|
0.7424069470756647,
|
||||||
|
0.07311092531259344,
|
||||||
|
0.5579247949052946,
|
||||||
|
0.14518764691585773,
|
||||||
|
0.03502980663114896,
|
||||||
|
0.7991329455957719,
|
||||||
|
0.4929930019965745,
|
||||||
|
0.12293810556077789,
|
||||||
|
0.6617084679545999,
|
||||||
|
0.9002240700227326,
|
||||||
|
0.027153062135304884,
|
||||||
|
0.3630189466989524,
|
||||||
|
0.18207502727558866,
|
||||||
|
0.843196731466686,
|
||||||
|
0.08951878746549924,
|
||||||
|
0.7533450877576973,
|
||||||
|
0.009558876499740077,
|
||||||
|
0.9429679490873482,
|
||||||
|
0.9355764454129878,
|
||||||
|
);
|
||||||
let svd = m.clone().svd(true, true);
|
let svd = m.clone().svd(true, true);
|
||||||
println!("Singular values: {}", svd.singular_values);
|
println!("Singular values: {}", svd.singular_values);
|
||||||
println!("u: {:.5}", svd.u.unwrap());
|
println!("u: {:.5}", svd.u.unwrap());
|
||||||
|
Loading…
Reference in New Issue
Block a user