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::matrix_slice::{SliceStorage, SliceStorageMut};
|
||||
use base::Matrix;
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
use std::any::Any;
|
||||
|
||||
use base::{DefaultAllocator, Scalar};
|
||||
use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
||||
use base::dimension::{Dim, U1};
|
||||
use base::storage::ContiguousStorageMut;
|
||||
use base::{DefaultAllocator, Scalar};
|
||||
|
||||
/// A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()`
|
||||
/// 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 ×
|
||||
/// CFrom) elements to a smaller or larger size (RTo, CTo).
|
||||
pub trait Reallocator<N: Scalar, RFrom: Dim, CFrom: Dim, RTo: Dim, CTo: Dim>
|
||||
: Allocator<N, RFrom, CFrom> + Allocator<N, RTo, CTo> {
|
||||
pub trait Reallocator<N: Scalar, RFrom: Dim, CFrom: Dim, RTo: Dim, CTo: Dim>:
|
||||
Allocator<N, RFrom, CFrom> + Allocator<N, RTo, CTo>
|
||||
{
|
||||
/// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer
|
||||
/// `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.
|
||||
/// Restricts the given number of rows and columns to be respectively the same.
|
||||
pub trait SameShapeAllocator<N, R1, C1, R2, C2>
|
||||
: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>
|
||||
pub trait SameShapeAllocator<N, R1, C1, R2, C2>:
|
||||
Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>
|
||||
where
|
||||
R1: Dim,
|
||||
R2: Dim,
|
||||
|
@ -78,13 +79,12 @@ where
|
|||
N: Scalar,
|
||||
DefaultAllocator: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>,
|
||||
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
// XXX: Bad name.
|
||||
/// Restricts the given number of rows to be equal.
|
||||
pub trait SameShapeVectorAllocator<N, R1, R2>
|
||||
: Allocator<N, R1> + Allocator<N, SameShapeR<R1, R2>> + SameShapeAllocator<N, R1, U1, R2, U1>
|
||||
pub trait SameShapeVectorAllocator<N, R1, R2>:
|
||||
Allocator<N, R1> + Allocator<N, SameShapeR<R1, R2>> + SameShapeAllocator<N, R1, U1, R2, U1>
|
||||
where
|
||||
R1: Dim,
|
||||
R2: Dim,
|
||||
|
@ -100,5 +100,4 @@ where
|
|||
N: Scalar,
|
||||
DefaultAllocator: Allocator<N, R1, U1> + Allocator<N, SameShapeR<R1, R2>>,
|
||||
ShapeConstraint: SameNumberOfRows<R1, R2>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
|
|
@ -14,7 +14,6 @@ use base::storage::{Storage, StorageMut};
|
|||
use base::{DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector};
|
||||
|
||||
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.
|
||||
///
|
||||
/// # Examples:
|
||||
|
@ -685,13 +684,19 @@ where
|
|||
// 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
|
||||
// better for statically-sized matrices.
|
||||
let is_dynamic = R1::is::<Dynamic>() || C1::is::<Dynamic>() || R2::is::<Dynamic>()
|
||||
|| C2::is::<Dynamic>() || R3::is::<Dynamic>()
|
||||
let is_dynamic = R1::is::<Dynamic>()
|
||||
|| C1::is::<Dynamic>()
|
||||
|| R2::is::<Dynamic>()
|
||||
|| C2::is::<Dynamic>()
|
||||
|| R3::is::<Dynamic>()
|
||||
|| C3::is::<Dynamic>();
|
||||
// Threshold determined empirically.
|
||||
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
|
||||
{
|
||||
if N::is::<f32>() {
|
||||
|
|
|
@ -7,15 +7,18 @@
|
|||
|
||||
use num::One;
|
||||
|
||||
use base::{DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector,
|
||||
Vector3, VectorN};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{DimName, DimNameDiff, DimNameSub, U1};
|
||||
use base::storage::{Storage, StorageMut};
|
||||
use base::allocator::Allocator;
|
||||
use geometry::{Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point3, Rotation2,
|
||||
Rotation3};
|
||||
use base::{
|
||||
DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, Vector3,
|
||||
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;
|
||||
|
||||
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>>,
|
||||
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);
|
||||
let post_translation =
|
||||
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 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 n = normalizer.tr_dot(&pt.coords) + unsafe {
|
||||
*self.get_unchecked(D::dim() - 1, D::dim() - 1)
|
||||
};
|
||||
let n = normalizer.tr_dot(&pt.coords)
|
||||
+ unsafe { *self.get_unchecked(D::dim() - 1, D::dim() - 1) };
|
||||
|
||||
if !n.is_zero() {
|
||||
return transform * (pt / n) + translation;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Non-conventional componentwise operators.
|
||||
// Non-conventional component-wise operators.
|
||||
|
||||
use num::{Signed, Zero};
|
||||
use std::ops::{Add, Mul};
|
||||
|
|
|
@ -8,11 +8,9 @@ pub struct ShapeConstraint;
|
|||
/// Constraints `C1` and `R2` to be equivalent.
|
||||
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
|
||||
where
|
||||
ShapeConstraint: DimEq<C1, R2>,
|
||||
{
|
||||
}
|
||||
impl<R1: Dim, C1: Dim, R2: Dim, C2: Dim> AreMultipliable<R1, C1, R2, C2> for ShapeConstraint where
|
||||
ShapeConstraint: DimEq<C1, R2>
|
||||
{}
|
||||
|
||||
/// Constraints `D1` and `D2` to be equivalent.
|
||||
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
|
||||
/// entities (e.g. square matrices).
|
||||
pub trait SameDimension<D1: Dim, D2: Dim>
|
||||
: SameNumberOfRows<D1, D2> + SameNumberOfColumns<D1, D2> {
|
||||
pub trait SameDimension<D1: Dim, D2: Dim>:
|
||||
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
|
||||
/// constant.
|
||||
type Representative: Dim;
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use base::{Matrix, Scalar};
|
||||
use base::dimension::{U1, U2, U3, U4, U5, U6};
|
||||
use base::storage::{ContiguousStorage, ContiguousStorageMut};
|
||||
use base::{Matrix, Scalar};
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::cmp;
|
|||
use std::fmt::Debug;
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
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")]
|
||||
|
|
|
@ -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();
|
||||
|
||||
unsafe {
|
||||
let ptr_in = m.data
|
||||
let ptr_in = m
|
||||
.data
|
||||
.ptr()
|
||||
.offset((copied_value_start * 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() {
|
||||
let ptr_in = res.data.ptr().offset((i * nrows.value()) as isize);
|
||||
let ptr_out = res.data
|
||||
let ptr_out = res
|
||||
.data
|
||||
.ptr_mut()
|
||||
.offset(((i + ninsert.value()) * nrows.value()) as isize);
|
||||
|
||||
|
|
|
@ -3,13 +3,12 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
|
||||
use base::Scalar;
|
||||
use base::dimension::Dim;
|
||||
use base::storage::{Storage, StorageMut};
|
||||
use base::Scalar;
|
||||
|
||||
macro_rules! iterator {
|
||||
(struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => {
|
||||
|
||||
/// 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>> {
|
||||
ptr: $Ptr,
|
||||
|
@ -17,7 +16,7 @@ macro_rules! iterator {
|
|||
inner_end: $Ptr,
|
||||
size: usize, // We can't use an end pointer here because a stride might be zero.
|
||||
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
|
||||
|
@ -36,12 +35,14 @@ macro_rules! iterator {
|
|||
inner_end: unsafe { ptr.offset(inner_offset as isize) },
|
||||
size: shape.0.value() * shape.1.value(),
|
||||
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;
|
||||
|
||||
#[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]
|
||||
fn len(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
iterator!(struct MatrixIter for Storage.ptr -> *const N, &'a N, &'a S);
|
||||
|
|
|
@ -107,8 +107,7 @@ where
|
|||
R::Value: Mul<C::Value>,
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
GenericArray<N, Prod<R::Value, C::Value>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N, R, C> Clone for MatrixArray<N, R, C>
|
||||
where
|
||||
|
@ -133,8 +132,7 @@ where
|
|||
C: DimName,
|
||||
R::Value: Mul<C::Value>,
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N, R, C> PartialEq for MatrixArray<N, R, C>
|
||||
where
|
||||
|
@ -234,8 +232,7 @@ where
|
|||
R::Value: Mul<C::Value>,
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
unsafe impl<N, R, C> ContiguousStorageMut<N, R, C> for MatrixArray<N, R, C>
|
||||
where
|
||||
|
@ -245,8 +242,7 @@ where
|
|||
R::Value: Mul<C::Value>,
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
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>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
||||
{
|
||||
}
|
||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorage<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||
{}
|
||||
|
||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
||||
{
|
||||
}
|
||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||
{}
|
||||
|
||||
unsafe impl<N: Scalar, R: DimName> StorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||
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>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
||||
{
|
||||
}
|
||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorage<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||
{}
|
||||
|
||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
||||
{
|
||||
}
|
||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||
{}
|
||||
|
|
|
@ -12,7 +12,6 @@ pub mod storage;
|
|||
|
||||
mod alias;
|
||||
mod alias_slice;
|
||||
mod swizzle;
|
||||
mod cg;
|
||||
mod componentwise;
|
||||
mod construction;
|
||||
|
@ -27,6 +26,7 @@ mod matrix_slice;
|
|||
mod matrix_vec;
|
||||
mod properties;
|
||||
mod scalar;
|
||||
mod swizzle;
|
||||
mod unit;
|
||||
|
||||
#[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 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 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::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]
|
||||
pub fn amin(&self) -> N {
|
||||
let mut it = self.iter();
|
||||
let mut min = it.next()
|
||||
let mut min = it
|
||||
.next()
|
||||
.expect("amin: empty matrices not supported.")
|
||||
.abs();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::any::Any;
|
||||
use std::any::TypeId;
|
||||
use std::fmt::Debug;
|
||||
use std::any::Any;
|
||||
|
||||
/// The basic scalar type for all structures of `nalgebra`.
|
||||
///
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
use std::fmt::Debug;
|
||||
use std::mem;
|
||||
|
||||
use base::Scalar;
|
||||
use base::allocator::{Allocator, SameShapeC, SameShapeR};
|
||||
use base::default_allocator::DefaultAllocator;
|
||||
use base::dimension::{Dim, U1};
|
||||
use base::allocator::{Allocator, SameShapeC, SameShapeR};
|
||||
use base::Scalar;
|
||||
|
||||
/*
|
||||
* 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
|
||||
/// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because
|
||||
/// failing to comply to this may cause Undefined Behaviors.
|
||||
pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>
|
||||
: Storage<N, R, C> {
|
||||
pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>:
|
||||
Storage<N, R, C>
|
||||
{
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because
|
||||
/// failing to comply to this may cause Undefined Behaviors.
|
||||
pub unsafe trait ContiguousStorageMut<N: Scalar, R: Dim, C: Dim = U1>
|
||||
: ContiguousStorage<N, R, C> + StorageMut<N, R, C> {
|
||||
pub unsafe trait ContiguousStorageMut<N: Scalar, R: Dim, C: Dim = U1>:
|
||||
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 typenum::{self, Cmp, Greater};
|
||||
|
||||
|
||||
macro_rules! impl_swizzle {
|
||||
($(where $BaseDim: ident: $name: ident() -> $Result: ident[$($i: expr),*]);*) => {
|
||||
$(
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::io::{Result as IOResult, Write};
|
|||
use std::marker::PhantomData;
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use abomonation::Abomonation;
|
||||
|
@ -26,23 +26,19 @@ use geometry::{Point, Translation};
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "R: Serialize,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "R: Deserialize<'de>,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
pub struct Isometry<N: Real, D: DimName, R>
|
||||
where
|
||||
|
@ -54,7 +50,10 @@ where
|
|||
pub translation: Translation<N, D>,
|
||||
|
||||
// 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>,
|
||||
}
|
||||
|
||||
|
@ -98,8 +97,7 @@ impl<N: Real, D: DimName + Copy, R: Rotation<Point<N, D>> + Copy> Copy for Isome
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimName, R: Rotation<Point<N, D>> + Clone> Clone for Isometry<N, D, R>
|
||||
where
|
||||
|
@ -200,8 +198,7 @@ impl<N: Real, D: DimName, R> Eq for Isometry<N, D, R>
|
|||
where
|
||||
R: Rotation<Point<N, D>> + Eq,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimName, R> PartialEq for Isometry<N, D, R>
|
||||
where
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
||||
Real};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||
};
|
||||
use alga::linear::Isometry as AlgaIsometry;
|
||||
use alga::linear::{AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation,
|
||||
Similarity, Transformation};
|
||||
use alga::linear::{
|
||||
AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation, Similarity,
|
||||
Transformation,
|
||||
};
|
||||
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::DimName;
|
||||
|
|
|
@ -4,61 +4,61 @@
|
|||
mod op_macros;
|
||||
|
||||
mod point;
|
||||
mod point_construction;
|
||||
mod point_alias;
|
||||
mod point_ops;
|
||||
mod point_alga;
|
||||
mod point_alias;
|
||||
mod point_construction;
|
||||
mod point_conversion;
|
||||
mod point_coordinates;
|
||||
mod point_ops;
|
||||
|
||||
mod rotation;
|
||||
mod rotation_construction;
|
||||
mod rotation_ops;
|
||||
mod rotation_alga; // FIXME: implement Rotation methods.
|
||||
mod rotation_conversion;
|
||||
mod rotation_alias;
|
||||
mod rotation_construction;
|
||||
mod rotation_conversion;
|
||||
mod rotation_ops;
|
||||
mod rotation_specialization;
|
||||
|
||||
mod quaternion;
|
||||
mod quaternion_construction;
|
||||
mod quaternion_ops;
|
||||
mod quaternion_alga;
|
||||
mod quaternion_construction;
|
||||
mod quaternion_conversion;
|
||||
mod quaternion_coordinates;
|
||||
mod quaternion_ops;
|
||||
|
||||
mod unit_complex;
|
||||
mod unit_complex_construction;
|
||||
mod unit_complex_ops;
|
||||
mod unit_complex_alga;
|
||||
mod unit_complex_construction;
|
||||
mod unit_complex_conversion;
|
||||
mod unit_complex_ops;
|
||||
|
||||
mod translation;
|
||||
mod translation_construction;
|
||||
mod translation_ops;
|
||||
mod translation_alga;
|
||||
mod translation_conversion;
|
||||
mod translation_alias;
|
||||
mod translation_construction;
|
||||
mod translation_conversion;
|
||||
mod translation_ops;
|
||||
|
||||
mod isometry;
|
||||
mod isometry_construction;
|
||||
mod isometry_ops;
|
||||
mod isometry_alga;
|
||||
mod isometry_conversion;
|
||||
mod isometry_alias;
|
||||
mod isometry_construction;
|
||||
mod isometry_conversion;
|
||||
mod isometry_ops;
|
||||
|
||||
mod similarity;
|
||||
mod similarity_construction;
|
||||
mod similarity_ops;
|
||||
mod similarity_alga;
|
||||
mod similarity_conversion;
|
||||
mod similarity_alias;
|
||||
mod similarity_construction;
|
||||
mod similarity_conversion;
|
||||
mod similarity_ops;
|
||||
|
||||
mod transform;
|
||||
mod transform_construction;
|
||||
mod transform_ops;
|
||||
mod transform_alga;
|
||||
mod transform_conversion;
|
||||
mod transform_alias;
|
||||
mod transform_construction;
|
||||
mod transform_conversion;
|
||||
mod transform_ops;
|
||||
|
||||
mod reflection;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::hash;
|
|||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use abomonation::Abomonation;
|
||||
|
@ -42,8 +42,7 @@ impl<N: Scalar, D: DimName> Copy for Point<N, D>
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Scalar, D: DimName> Clone for Point<N, D>
|
||||
where
|
||||
|
@ -241,11 +240,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Scalar + Eq, D: DimName> Eq for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
}
|
||||
impl<N: Scalar + Eq, D: DimName> Eq for Point<N, D> where DefaultAllocator: Allocator<N, D> {}
|
||||
|
||||
impl<N: Scalar, D: DimName> PartialEq for Point<N, D>
|
||||
where
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, Real};
|
||||
use alga::linear::{AffineSpace, EuclideanSpace};
|
||||
|
||||
use base::{DefaultAllocator, Scalar, VectorN};
|
||||
use base::dimension::DimName;
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::DimName;
|
||||
use base::{DefaultAllocator, Scalar, VectorN};
|
||||
|
||||
use geometry::Point;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::io::{Result as IOResult, Write};
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use base::storage::Owned;
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use abomonation::Abomonation;
|
||||
|
@ -457,9 +457,11 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// is not well-defined).
|
||||
#[inline]
|
||||
pub fn slerp(&self, other: &UnitQuaternion<N>, t: N) -> UnitQuaternion<N> {
|
||||
Unit::new_unchecked(
|
||||
Quaternion::from_vector(Unit::new_unchecked(self.coords).slerp(&Unit::new_unchecked(other.coords), t).unwrap())
|
||||
)
|
||||
Unit::new_unchecked(Quaternion::from_vector(
|
||||
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`
|
||||
|
@ -479,7 +481,8 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
t: N,
|
||||
epsilon: 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())))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
use num::Zero;
|
||||
|
||||
use alga::general::{AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma,
|
||||
AbstractModule, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup,
|
||||
Additive, Id, Identity, Inverse, Module, Multiplicative, Real};
|
||||
use alga::linear::{AffineTransformation, DirectIsometry, FiniteDimVectorSpace, Isometry,
|
||||
NormedSpace, OrthogonalTransformation, ProjectiveTransformation, Rotation,
|
||||
Similarity, Transformation, VectorSpace};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma, AbstractModule,
|
||||
AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Additive, Id, Identity, Inverse, Module,
|
||||
Multiplicative, Real,
|
||||
};
|
||||
use alga::linear::{
|
||||
AffineTransformation, DirectIsometry, FiniteDimVectorSpace, Isometry, NormedSpace,
|
||||
OrthogonalTransformation, ProjectiveTransformation, Rotation, Similarity, Transformation,
|
||||
VectorSpace,
|
||||
};
|
||||
|
||||
use base::{Vector3, Vector4};
|
||||
use geometry::{Point3, Quaternion, UnitQuaternion};
|
||||
|
|
|
@ -50,15 +50,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub,
|
||||
SubAssign};
|
||||
use std::ops::{
|
||||
Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign,
|
||||
};
|
||||
|
||||
use alga::general::Real;
|
||||
|
||||
use base::{DefaultAllocator, Unit, Vector, Vector3};
|
||||
use base::storage::Storage;
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{U1, U3, U4};
|
||||
use base::storage::Storage;
|
||||
use base::{DefaultAllocator, Unit, Vector, Vector3};
|
||||
|
||||
use geometry::{Point3, Quaternion, Rotation, UnitQuaternion};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::hash;
|
|||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use base::storage::Owned;
|
||||
|
@ -44,8 +44,7 @@ impl<N: Scalar, D: DimName> Copy for Rotation<N, D>
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
<DefaultAllocator as Allocator<N, D, D>>::Buffer: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Scalar, D: DimName> Clone for Rotation<N, D>
|
||||
where
|
||||
|
@ -187,11 +186,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Scalar + Eq, D: DimName> Eq for Rotation<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
{
|
||||
}
|
||||
impl<N: Scalar + Eq, D: DimName> Eq for Rotation<N, D> where DefaultAllocator: Allocator<N, D, D> {}
|
||||
|
||||
impl<N: Scalar + PartialEq, D: DimName> PartialEq for Rotation<N, D>
|
||||
where
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
||||
Real};
|
||||
use alga::linear::{self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
||||
ProjectiveTransformation, Similarity, Transformation};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||
};
|
||||
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::dimension::DimName;
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
|
||||
use geometry::{Point, Rotation};
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ use num::{One, Zero};
|
|||
|
||||
use alga::general::{ClosedAdd, ClosedMul};
|
||||
|
||||
use base::{DefaultAllocator, MatrixN, Scalar};
|
||||
use base::dimension::DimName;
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::DimName;
|
||||
use base::{DefaultAllocator, MatrixN, Scalar};
|
||||
|
||||
use geometry::Rotation;
|
||||
|
||||
|
|
|
@ -17,16 +17,16 @@
|
|||
* Matrix ×= Rotation
|
||||
*/
|
||||
|
||||
use std::ops::{Div, DivAssign, Index, Mul, MulAssign};
|
||||
use num::{One, Zero};
|
||||
use std::ops::{Div, DivAssign, Index, Mul, MulAssign};
|
||||
|
||||
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::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};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use quickcheck::{Arbitrary, Gen};
|
|||
|
||||
use alga::general::Real;
|
||||
use num::Zero;
|
||||
use rand::distributions::{Distribution, Standard, OpenClosed01};
|
||||
use rand::distributions::{Distribution, OpenClosed01, Standard};
|
||||
use rand::Rng;
|
||||
use std::ops::Neg;
|
||||
|
||||
|
@ -398,9 +398,15 @@ where
|
|||
let theta = N::two_pi() * rng.sample(OpenClosed01);
|
||||
let (ts, tc) = theta.sin_cos();
|
||||
let a = MatrixN::<N, U3>::new(
|
||||
tc, ts, N::zero(),
|
||||
-ts, tc, N::zero(),
|
||||
N::zero(), N::zero(), N::one()
|
||||
tc,
|
||||
ts,
|
||||
N::zero(),
|
||||
-ts,
|
||||
tc,
|
||||
N::zero(),
|
||||
N::zero(),
|
||||
N::zero(),
|
||||
N::one(),
|
||||
);
|
||||
|
||||
// Compute a random rotation *of* Z
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::hash;
|
|||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
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",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "N: Serialize,
|
||||
R: Serialize,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "N: Deserialize<'de>,
|
||||
R: Deserialize<'de>,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
pub struct Similarity<N: Real, D: DimName, R>
|
||||
where
|
||||
|
@ -89,8 +85,7 @@ impl<N: Real, D: DimName + Copy, R: Rotation<Point<N, D>> + Copy> Copy for Simil
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimName, R: Rotation<Point<N, D>> + Clone> Clone for Similarity<N, D, R>
|
||||
where
|
||||
|
@ -276,8 +271,7 @@ impl<N: Real, D: DimName, R> Eq for Similarity<N, D, R>
|
|||
where
|
||||
R: Rotation<Point<N, D>> + Eq,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimName, R> PartialEq for Similarity<N, D, R>
|
||||
where
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
||||
AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real};
|
||||
use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||
AbstractSemigroup, Identity, Inverse, Multiplicative, Real,
|
||||
};
|
||||
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::dimension::DimName;
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
|
||||
use geometry::{Point, Similarity, Translation};
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::ops::{Div, DivAssign, Mul, MulAssign};
|
|||
use alga::general::Real;
|
||||
use alga::linear::Rotation as AlgaRotation;
|
||||
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
use base::dimension::{DimName, U1, U3, U4};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{DimName, U1, U3, U4};
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
|
||||
use geometry::{Isometry, Point, Rotation, Similarity, Translation, UnitQuaternion};
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::fmt::Debug;
|
|||
use std::marker::PhantomData;
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use alga::general::Real;
|
||||
|
||||
use base::{DefaultAllocator, MatrixN};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{DimName, DimNameAdd, DimNameSum, U1};
|
||||
use base::storage::Owned;
|
||||
use base::allocator::Allocator;
|
||||
use base::{DefaultAllocator, MatrixN};
|
||||
|
||||
/// 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.
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum TGeneral {
|
||||
}
|
||||
pub enum TGeneral {}
|
||||
|
||||
/// Tag representing the most general inversible `Transform` type.
|
||||
#[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)`.
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum TAffine {
|
||||
}
|
||||
pub enum TAffine {}
|
||||
|
||||
impl TCategory for TGeneral {
|
||||
#[inline]
|
||||
|
@ -104,7 +101,8 @@ impl TCategory for TAffine {
|
|||
DefaultAllocator: Allocator<N, D, D>,
|
||||
{
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +175,7 @@ impl<N: Real, D: DimNameAdd<U1> + Copy, C: TCategory> Copy for Transform<N, D, C
|
|||
where
|
||||
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
||||
Owned<N, DimNameSum<D, U1>, DimNameSum<D, U1>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimNameAdd<U1>, C: TCategory> Clone for Transform<N, D, C>
|
||||
where
|
||||
|
@ -220,11 +217,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Real + Eq, D: DimNameAdd<U1>, C: TCategory> Eq for Transform<N, D, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>,
|
||||
{
|
||||
}
|
||||
impl<N: Real + Eq, D: DimNameAdd<U1>, C: TCategory> Eq for Transform<N, D, C> where
|
||||
DefaultAllocator: Allocator<N, DimNameSum<D, U1>, DimNameSum<D, U1>>
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimNameAdd<U1>, C: TCategory> PartialEq for Transform<N, D, C>
|
||||
where
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
||||
AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||
AbstractSemigroup, Identity, Inverse, Multiplicative, Real,
|
||||
};
|
||||
use alga::linear::{ProjectiveTransformation, Transformation};
|
||||
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
|
||||
use geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform};
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ use num::One;
|
|||
|
||||
use alga::general::Real;
|
||||
|
||||
use base::{DefaultAllocator, MatrixN};
|
||||
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||
use base::{DefaultAllocator, MatrixN};
|
||||
|
||||
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 base::{DefaultAllocator, MatrixN, Scalar, VectorN};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::{DimName, DimNameAdd, DimNameSum, U1, U3, U4};
|
||||
use base::{DefaultAllocator, MatrixN, Scalar, VectorN};
|
||||
|
||||
use geometry::{Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine,
|
||||
TCategory, TCategoryMul, TGeneral, TProjective, Transform, Translation,
|
||||
UnitQuaternion};
|
||||
use geometry::{
|
||||
Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine, TCategory,
|
||||
TCategoryMul, TGeneral, TProjective, Transform, Translation, UnitQuaternion,
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::hash;
|
|||
use std::io::{Result as IOResult, Write};
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
use abomonation::Abomonation;
|
||||
|
@ -44,8 +44,7 @@ impl<N: Scalar, D: DimName> Copy for Translation<N, D>
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Scalar, D: DimName> Clone for Translation<N, D>
|
||||
where
|
||||
|
@ -153,11 +152,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Scalar + Eq, D: DimName> Eq for Translation<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
}
|
||||
impl<N: Scalar + Eq, D: DimName> Eq for Translation<N, D> where DefaultAllocator: Allocator<N, D> {}
|
||||
|
||||
impl<N: Scalar + PartialEq, D: DimName> PartialEq for Translation<N, D>
|
||||
where
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
||||
Real};
|
||||
use alga::linear::{AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation,
|
||||
Similarity, Transformation};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||
};
|
||||
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::dimension::DimName;
|
||||
use base::{DefaultAllocator, VectorN};
|
||||
|
||||
use geometry::{Point, Translation};
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ use std::ops::{Div, DivAssign, Mul, MulAssign};
|
|||
|
||||
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::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
||||
use base::dimension::{DimName, U1};
|
||||
use base::{DefaultAllocator, Scalar};
|
||||
|
||||
use geometry::{Point, Translation};
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid,
|
||||
AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative,
|
||||
Real};
|
||||
use alga::linear::{AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
||||
ProjectiveTransformation, Rotation, Similarity, Transformation};
|
||||
use alga::general::{
|
||||
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
||||
AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real,
|
||||
};
|
||||
use alga::linear::{
|
||||
AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
||||
ProjectiveTransformation, Rotation, Similarity, Transformation,
|
||||
};
|
||||
|
||||
use base::{DefaultAllocator, Vector2};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::U2;
|
||||
use base::{DefaultAllocator, Vector2};
|
||||
use geometry::{Point2, UnitComplex};
|
||||
|
||||
/*
|
||||
|
|
|
@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen};
|
|||
|
||||
use num::One;
|
||||
use num_complex::Complex;
|
||||
use rand::distributions::{Distribution, Standard, OpenClosed01};
|
||||
use rand::distributions::{Distribution, OpenClosed01, Standard};
|
||||
use rand::Rng;
|
||||
|
||||
use alga::general::Real;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::Real;
|
||||
use allocator::Allocator;
|
||||
|
@ -15,8 +15,7 @@ use linalg::householder;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DimMinimum<R, C>: DimSub<U1>,
|
||||
DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<N, DimMinimum<R, C>> +
|
||||
|
@ -24,13 +23,11 @@ use linalg::householder;
|
|||
MatrixMN<N, R, C>: Serialize,
|
||||
VectorN<N, DimMinimum<R, C>>: Serialize,
|
||||
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DimMinimum<R, C>: DimSub<U1>,
|
||||
DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<N, DimMinimum<R, C>> +
|
||||
|
@ -38,8 +35,7 @@ use linalg::householder;
|
|||
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>,
|
||||
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Bidiagonal<N: Real, R: DimMin<C>, C: Dim>
|
||||
|
@ -68,8 +64,7 @@ where
|
|||
MatrixMN<N, R, C>: Copy,
|
||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||
VectorN<N, DimDiff<DimMinimum<R, C>, U1>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, R: DimMin<C>, C: Dim> Bidiagonal<N, R, C>
|
||||
where
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
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",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D>,
|
||||
MatrixN<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D>,
|
||||
MatrixN<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Cholesky<N: Real, D: Dim>
|
||||
|
@ -41,8 +37,7 @@ impl<N: Real, D: Dim> Copy for Cholesky<N, D>
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
MatrixN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimSub<Dynamic>> Cholesky<N, D>
|
||||
where
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::Real;
|
||||
use allocator::Allocator;
|
||||
|
@ -15,25 +15,21 @@ use linalg::PermutationSequence;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Serialize,
|
||||
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
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>>,
|
||||
MatrixMN<N, R, C>: Copy,
|
||||
PermutationSequence<DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, R: DimMin<C>, C: Dim> FullPivLU<N, R, C>
|
||||
where
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::Real;
|
||||
use allocator::Allocator;
|
||||
|
@ -14,25 +14,21 @@ use linalg::householder;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Serialize,
|
||||
VectorN<N, DimDiff<D, U1>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Deserialize<'de>,
|
||||
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Hessenberg<N: Real, D: DimSub<U1>>
|
||||
|
@ -48,8 +44,7 @@ where
|
|||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Copy,
|
||||
VectorN<N, DimDiff<D, U1>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimSub<U1>> Hessenberg<N, D>
|
||||
where
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use alga::general::Real;
|
||||
|
||||
use base::{DefaultAllocator, MatrixN, SquareMatrix};
|
||||
use base::allocator::Allocator;
|
||||
use base::dimension::Dim;
|
||||
use base::storage::{Storage, StorageMut};
|
||||
use base::allocator::Allocator;
|
||||
use base::{DefaultAllocator, MatrixN, SquareMatrix};
|
||||
|
||||
use linalg::lu;
|
||||
|
||||
|
@ -129,52 +129,84 @@ where
|
|||
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]
|
||||
+ 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]
|
||||
- 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]
|
||||
+ 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]
|
||||
- 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]
|
||||
- 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]
|
||||
+ 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]
|
||||
- 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]
|
||||
+ 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]
|
||||
+ 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]
|
||||
- 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]
|
||||
+ 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]
|
||||
- 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]
|
||||
- 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]
|
||||
+ 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]
|
||||
- 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]
|
||||
+ 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)];
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::{Field, Real};
|
||||
use allocator::{Allocator, Reallocator};
|
||||
|
@ -15,25 +15,21 @@ use linalg::PermutationSequence;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Serialize,
|
||||
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<(usize, usize), DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
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>>,
|
||||
MatrixMN<N, R, C>: Copy,
|
||||
PermutationSequence<DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/// 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.
|
||||
|
||||
mod solve;
|
||||
mod determinant;
|
||||
mod inverse;
|
||||
pub mod householder;
|
||||
pub mod givens;
|
||||
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 qr;
|
||||
mod hessenberg;
|
||||
mod bidiagonal;
|
||||
mod symmetric_tridiagonal;
|
||||
mod cholesky;
|
||||
mod lu;
|
||||
mod full_piv_lu;
|
||||
mod schur;
|
||||
mod solve;
|
||||
mod svd;
|
||||
mod symmetric_eigen;
|
||||
mod symmetric_tridiagonal;
|
||||
|
||||
//// FIXME: Not complete enough for publishing.
|
||||
//// This handles only cases where each eigenvalue has multiplicity one.
|
||||
// mod eigen;
|
||||
|
||||
pub use self::permutation_sequence::*;
|
||||
pub use self::qr::*;
|
||||
pub use self::hessenberg::*;
|
||||
pub use self::bidiagonal::*;
|
||||
pub use self::cholesky::*;
|
||||
pub use self::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::svd::*;
|
||||
pub use self::symmetric_tridiagonal::*;
|
||||
pub use self::symmetric_eigen::*;
|
||||
pub use self::symmetric_tridiagonal::*;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::ClosedNeg;
|
||||
use num::One;
|
||||
|
@ -15,21 +15,17 @@ use storage::StorageMut;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<(usize, usize), D>,
|
||||
VectorN<(usize, usize), D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<(usize, usize), D>,
|
||||
VectorN<(usize, usize), D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PermutationSequence<D: Dim>
|
||||
|
@ -44,8 +40,7 @@ impl<D: Dim> Copy for PermutationSequence<D>
|
|||
where
|
||||
DefaultAllocator: Allocator<(usize, usize), D>,
|
||||
VectorN<(usize, usize), D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<D: DimName> PermutationSequence<D>
|
||||
where
|
||||
|
|
|
@ -1,28 +1,36 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::Real;
|
||||
use allocator::{Allocator, Reallocator};
|
||||
use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN};
|
||||
use constraint::{SameNumberOfRows, ShapeConstraint};
|
||||
use dimension::{Dim, DimMin, DimMinimum, U1};
|
||||
use storage::{Storage, StorageMut};
|
||||
use allocator::{Allocator, Reallocator};
|
||||
use constraint::{SameNumberOfRows, ShapeConstraint};
|
||||
|
||||
use linalg::householder;
|
||||
use geometry::Reflection;
|
||||
use linalg::householder;
|
||||
|
||||
/// The QR decomposition of a general matrix.
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "serde-serialize",
|
||||
serde(bound(serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<N, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Serialize,
|
||||
VectorN<N, DimMinimum<R, C>>: Serialize")))]
|
||||
#[cfg_attr(feature = "serde-serialize",
|
||||
serde(bound(deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
VectorN<N, DimMinimum<R, C>>: Serialize"
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<N, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>")))]
|
||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct QR<N: Real, R: DimMin<C>, C: Dim>
|
||||
where
|
||||
|
@ -37,8 +45,7 @@ where
|
|||
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Copy,
|
||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, R: DimMin<C>, C: Dim> QR<N, R, C>
|
||||
where
|
||||
|
@ -132,8 +139,8 @@ where
|
|||
)
|
||||
where
|
||||
DimMinimum<R, C>: DimMin<C, Output = DimMinimum<R, C>>,
|
||||
DefaultAllocator: Allocator<N, R, DimMinimum<R, C>>
|
||||
+ Reallocator<N, R, C, DimMinimum<R, C>, C>,
|
||||
DefaultAllocator:
|
||||
Allocator<N, R, DimMinimum<R, C>> + Reallocator<N, R, C, DimMinimum<R, C>, C>,
|
||||
{
|
||||
(self.q(), self.unpack_r())
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::Real;
|
||||
use num_complex::Complex;
|
||||
|
@ -19,21 +19,17 @@ use linalg::Hessenberg;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D>,
|
||||
MatrixN<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D>,
|
||||
MatrixN<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RealSchur<N: Real, D: Dim>
|
||||
|
@ -48,8 +44,7 @@ impl<N: Real, D: Dim> Copy for RealSchur<N, D>
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
MatrixN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: Dim> RealSchur<N, D>
|
||||
where
|
||||
|
@ -180,10 +175,10 @@ where
|
|||
{
|
||||
let krows = cmp::min(k + 4, end + 1);
|
||||
let mut work = work.rows_mut(0, krows);
|
||||
refl.reflect(&mut t.generic_slice_mut(
|
||||
(k, k),
|
||||
(U3, Dynamic::new(dim.value() - k)),
|
||||
));
|
||||
refl.reflect(
|
||||
&mut t
|
||||
.generic_slice_mut((k, k), (U3, Dynamic::new(dim.value() - k))),
|
||||
);
|
||||
refl.reflect_rows(
|
||||
&mut t.generic_slice_mut((0, k), (Dynamic::new(krows), U3)),
|
||||
&mut work,
|
||||
|
@ -214,10 +209,9 @@ where
|
|||
|
||||
{
|
||||
let mut work = work.rows_mut(0, end + 1);
|
||||
refl.reflect(&mut t.generic_slice_mut(
|
||||
(m, m),
|
||||
(U2, Dynamic::new(dim.value() - m)),
|
||||
));
|
||||
refl.reflect(
|
||||
&mut t.generic_slice_mut((m, m), (U2, Dynamic::new(dim.value() - m))),
|
||||
);
|
||||
refl.reflect_rows(
|
||||
&mut t.generic_slice_mut((0, m), (Dynamic::new(end + 1), U2)),
|
||||
&mut work,
|
||||
|
@ -236,10 +230,9 @@ where
|
|||
(start, start),
|
||||
(U2, Dynamic::new(dim.value() - start)),
|
||||
));
|
||||
rot.rotate_rows(&mut t.generic_slice_mut(
|
||||
(0, start),
|
||||
(Dynamic::new(end + 1), U2),
|
||||
));
|
||||
rot.rotate_rows(
|
||||
&mut t.generic_slice_mut((0, start), (Dynamic::new(end + 1), U2)),
|
||||
);
|
||||
t[(end, start)] = N::zero();
|
||||
|
||||
if let Some(ref mut q) = q {
|
||||
|
@ -433,9 +426,11 @@ where
|
|||
));
|
||||
}
|
||||
}
|
||||
None => if compute_q {
|
||||
None => {
|
||||
if compute_q {
|
||||
q = Some(MatrixN::identity_generic(dim, dim));
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Some((q, m))
|
||||
|
@ -558,7 +553,8 @@ where
|
|||
N::default_epsilon(),
|
||||
0,
|
||||
false,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
if RealSchur::do_eigenvalues(&schur.1, &mut work) {
|
||||
Some(work)
|
||||
} else {
|
||||
|
@ -581,7 +577,8 @@ where
|
|||
N::default_epsilon(),
|
||||
0,
|
||||
false,
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
let mut eig = unsafe { VectorN::new_uninitialized_generic(dim, U1) };
|
||||
RealSchur::do_complex_eigenvalues(&schur.1, &mut eig);
|
||||
eig
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num_complex::Complex;
|
||||
use std::ops::MulAssign;
|
||||
|
@ -20,8 +20,7 @@ use linalg::Bidiagonal;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<N, DimMinimum<R, C>> +
|
||||
Allocator<N, DimMinimum<R, C>, C> +
|
||||
|
@ -29,13 +28,11 @@ use linalg::Bidiagonal;
|
|||
MatrixMN<N, R, DimMinimum<R, C>>: Serialize,
|
||||
MatrixMN<N, DimMinimum<R, C>, C>: Serialize,
|
||||
VectorN<N, DimMinimum<R, C>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<N, DimMinimum<R, C>> +
|
||||
Allocator<N, DimMinimum<R, C>, C> +
|
||||
|
@ -43,8 +40,7 @@ use linalg::Bidiagonal;
|
|||
MatrixMN<N, R, DimMinimum<R, C>>: Deserialize<'de>,
|
||||
MatrixMN<N, DimMinimum<R, C>, C>: Deserialize<'de>,
|
||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SVD<N: Real, R: DimMin<C>, C: Dim>
|
||||
|
@ -69,8 +65,7 @@ where
|
|||
MatrixMN<N, R, DimMinimum<R, C>>: Copy,
|
||||
MatrixMN<N, DimMinimum<R, C>, C>: Copy,
|
||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, R: DimMin<C>, C: Dim> SVD<N, R, C>
|
||||
where
|
||||
|
@ -489,7 +484,8 @@ where
|
|||
/// right- and left- singular vectors have not been computed at construction-time.
|
||||
pub fn recompose(self) -> MatrixMN<N, R, C> {
|
||||
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.");
|
||||
|
||||
for i in 0..self.singular_values.len() {
|
||||
|
@ -545,10 +541,12 @@ where
|
|||
eps >= N::zero(),
|
||||
"SVD solve: the epsilon must be non-negative."
|
||||
);
|
||||
let u = self.u
|
||||
let u = self
|
||||
.u
|
||||
.as_ref()
|
||||
.expect("SVD solve: U has not been computed.");
|
||||
let v_t = self.v_t
|
||||
let v_t = self
|
||||
.v_t
|
||||
.as_ref()
|
||||
.expect("SVD solve: V^t has not been computed.");
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num_complex::Complex;
|
||||
use std::ops::MulAssign;
|
||||
|
@ -18,25 +18,21 @@ use linalg::SymmetricTridiagonal;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
Allocator<N, D>,
|
||||
VectorN<N, D>: Serialize,
|
||||
MatrixN<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
Allocator<N, D>,
|
||||
VectorN<N, D>: Deserialize<'de>,
|
||||
MatrixN<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SymmetricEigen<N: Real, D: Dim>
|
||||
|
@ -55,8 +51,7 @@ where
|
|||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
MatrixN<N, D>: Copy,
|
||||
VectorN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: Dim> SymmetricEigen<N, D>
|
||||
where
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use alga::general::Real;
|
||||
use allocator::Allocator;
|
||||
|
@ -13,25 +13,21 @@ use linalg::householder;
|
|||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Serialize,
|
||||
VectorN<N, DimDiff<D, U1>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Deserialize<'de>,
|
||||
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SymmetricTridiagonal<N: Real, D: DimSub<U1>>
|
||||
|
@ -47,8 +43,7 @@ where
|
|||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Copy,
|
||||
VectorN<N, DimDiff<D, U1>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: Real, D: DimSub<U1>> SymmetricTridiagonal<N, D>
|
||||
where
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
pub use self::cs_matrix::CsMatrix;
|
||||
|
||||
mod cs_matrix;
|
|
@ -1,9 +1,9 @@
|
|||
use rand::random;
|
||||
use abomonation::{Abomonation, encode, decode};
|
||||
use abomonation::{decode, encode, Abomonation};
|
||||
use na::{
|
||||
DMatrix, Matrix3x4, Point3, Translation3, Rotation3, Isometry3, Quaternion,
|
||||
IsometryMatrix3, Similarity3, SimilarityMatrix3
|
||||
DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3,
|
||||
SimilarityMatrix3, Translation3,
|
||||
};
|
||||
use rand::random;
|
||||
|
||||
#[test]
|
||||
fn abomonate_dmatrix() {
|
||||
|
@ -39,7 +39,9 @@ fn assert_encode_and_decode<T: Abomonation + PartialEq + Clone>(original_data: T
|
|||
|
||||
// Encode
|
||||
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(original_data);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
|
||||
use na::{DMatrix, DVector};
|
||||
use std::cmp;
|
||||
use na::{DVector, DMatrix};
|
||||
|
||||
quickcheck! {
|
||||
/*
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
use alga::linear::Transformation;
|
||||
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,
|
||||
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!{
|
||||
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 edition;
|
||||
mod matrix;
|
||||
mod matrix_slice;
|
||||
mod blas;
|
||||
mod serde;
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
mod abomonation;
|
||||
#[cfg(feature = "mint")]
|
||||
mod mint;
|
||||
mod serde;
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
#![cfg(feature = "serde-serialize")]
|
||||
|
||||
use serde_json;
|
||||
use rand;
|
||||
use na::{
|
||||
DMatrix,
|
||||
Matrix3x4,
|
||||
Point3,
|
||||
Translation3,
|
||||
Rotation3,
|
||||
Isometry3,
|
||||
IsometryMatrix3,
|
||||
Similarity3,
|
||||
SimilarityMatrix3,
|
||||
Quaternion,
|
||||
Unit,
|
||||
DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3,
|
||||
SimilarityMatrix3, Translation3, Unit,
|
||||
};
|
||||
use rand;
|
||||
use serde_json;
|
||||
|
||||
macro_rules! test_serde(
|
||||
($($test: ident, $ty: ident);* $(;)*) => {$(
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use alga::linear::{Transformation, ProjectiveTransformation};
|
||||
use alga::linear::{ProjectiveTransformation, Transformation};
|
||||
use na::{
|
||||
Vector3, Point3, Rotation3, Isometry3, Translation3, UnitQuaternion,
|
||||
Vector2, Point2, Rotation2, Isometry2, Translation2, UnitComplex
|
||||
Isometry2, Isometry3, Point2, Point3, Rotation2, Rotation3, Translation2, Translation3,
|
||||
UnitComplex, UnitQuaternion, Vector2, Vector3,
|
||||
};
|
||||
|
||||
quickcheck!(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
use num::Zero;
|
||||
use na::{Point3, Vector3, Vector4};
|
||||
use num::Zero;
|
||||
|
||||
#[test]
|
||||
fn point_ops() {
|
||||
|
@ -65,7 +65,6 @@ fn point_scale() {
|
|||
assert_eq!(&pt * 10, expected);
|
||||
assert_eq!(10 * pt, expected);
|
||||
assert_eq!(10 * &pt, expected);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -88,9 +87,7 @@ fn to_homogeneous() {
|
|||
assert_eq!(a.to_homogeneous(), expected);
|
||||
}
|
||||
|
||||
quickcheck!(
|
||||
fn point_sub(pt1: Point3<f64>, pt2: Point3<f64>) -> bool {
|
||||
quickcheck!(fn point_sub(pt1: Point3<f64>, pt2: Point3<f64>) -> bool {
|
||||
let dpt = &pt2 - &pt1;
|
||||
relative_eq!(pt2, pt1 + dpt, epsilon = 1.0e-7)
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use na::{Perspective3, Orthographic3};
|
||||
use na::{Orthographic3, Perspective3};
|
||||
|
||||
#[test]
|
||||
fn perspective_inverse() {
|
||||
|
@ -20,10 +20,9 @@ fn orthographic_inverse() {
|
|||
assert!(id.is_identity(1.0e-7));
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
mod quickcheck_tests {
|
||||
use na::{Point3, Perspective3, Orthographic3};
|
||||
use na::{Orthographic3, Perspective3, Point3};
|
||||
|
||||
quickcheck!{
|
||||
fn perspective_project_unproject(pt: Point3<f64>) -> bool {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use na::{Unit, UnitQuaternion, Quaternion, Vector3, Point3, Rotation3};
|
||||
|
||||
use na::{Point3, Quaternion, Rotation3, Unit, UnitQuaternion, Vector3};
|
||||
|
||||
quickcheck!(
|
||||
/*
|
||||
|
|
|
@ -18,9 +18,9 @@ fn angle_3() {
|
|||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
mod quickcheck_tests {
|
||||
use std::f64;
|
||||
use alga::general::Real;
|
||||
use na::{self, Vector2, Vector3, Rotation2, Rotation3, Unit};
|
||||
use na::{self, Rotation2, Rotation3, Unit, Vector2, Vector3};
|
||||
use std::f64;
|
||||
|
||||
quickcheck! {
|
||||
/*
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use alga::linear::{Transformation, ProjectiveTransformation};
|
||||
use na::{Vector3, Point3, Similarity3, Translation3, Isometry3, UnitQuaternion};
|
||||
use alga::linear::{ProjectiveTransformation, Transformation};
|
||||
use na::{Isometry3, Point3, Similarity3, Translation3, UnitQuaternion, Vector3};
|
||||
|
||||
quickcheck!(
|
||||
fn inverse_is_identity(i: Similarity3<f64>, p: Point3<f64>, v: Vector3<f64>) -> bool {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use na::{Unit, UnitComplex, Vector2, Point2, Rotation2};
|
||||
use na::{Point2, Rotation2, Unit, UnitComplex, Vector2};
|
||||
|
||||
quickcheck!(
|
||||
|
||||
|
|
|
@ -14,5 +14,7 @@ extern crate rand;
|
|||
extern crate serde_json;
|
||||
|
||||
mod core;
|
||||
mod linalg;
|
||||
mod geometry;
|
||||
mod linalg;
|
||||
#[cfg(feature = "sparse")]
|
||||
mod sparse;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use std::cmp;
|
||||
|
||||
use na::{DMatrix, Matrix4};
|
||||
use na::balancing;
|
||||
use na::{DMatrix, Matrix4};
|
||||
|
||||
quickcheck! {
|
||||
fn balancing_parlett_reinsch(n: usize) -> bool {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
|
||||
use na::{DMatrix, Matrix2, Matrix4, Matrix5x3, Matrix3x5};
|
||||
use na::{DMatrix, Matrix2, Matrix3x5, Matrix4, Matrix5x3};
|
||||
|
||||
quickcheck! {
|
||||
fn bidiagonal(m: DMatrix<f64>) -> bool {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#![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::dimension::U4;
|
||||
use na::{DMatrix, DVector, Matrix4x3, Vector4};
|
||||
use std::cmp;
|
||||
|
||||
quickcheck! {
|
||||
fn cholesky(m: RandomSDP<f64>) -> bool {
|
||||
|
|
|
@ -2,8 +2,8 @@ use na::DMatrix;
|
|||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
mod quickcheck_tests {
|
||||
use std::cmp;
|
||||
use na::{DMatrix, Matrix2, Matrix3, Matrix4};
|
||||
use std::cmp;
|
||||
|
||||
quickcheck! {
|
||||
fn symmetric_eigen(n: usize) -> bool {
|
||||
|
@ -62,39 +62,58 @@ mod quickcheck_tests {
|
|||
// Test proposed on the issue #176 of rulinalg.
|
||||
#[test]
|
||||
fn symmetric_eigen_singular_24x24() {
|
||||
let m = DMatrix::from_row_slice(24, 24, &[
|
||||
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,
|
||||
-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,
|
||||
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
||||
0.0, -4.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, 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, 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, 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,
|
||||
],
|
||||
);
|
||||
|
||||
let eig = m.clone().symmetric_eigen();
|
||||
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")]
|
||||
// quickcheck! {
|
||||
// FIXME: full eigendecomposition is not implemented yet because of its complexity when some
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#![cfg(feature = "arbitrary")]
|
||||
|
||||
use std::cmp;
|
||||
use na::{DMatrix, Matrix2, Matrix4};
|
||||
use std::cmp;
|
||||
|
||||
#[test]
|
||||
fn hessenberg_simple() {
|
||||
let m = Matrix2::new(1.0, 0.0,
|
||||
1.0, 3.0);
|
||||
let m = Matrix2::new(1.0, 0.0, 1.0, 3.0);
|
||||
let hess = m.hessenberg();
|
||||
let (p, h) = hess.unpack();
|
||||
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 tridiagonal;
|
||||
mod bidiagonal;
|
||||
mod cholesky;
|
||||
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")]
|
||||
|
||||
use na::{DMatrix, DVector, Matrix3x5, Matrix4, Matrix4x3, Matrix5x3, Vector4};
|
||||
use std::cmp;
|
||||
use na::{DMatrix, Matrix4, Matrix4x3, Matrix5x3, Matrix3x5,
|
||||
DVector, Vector4};
|
||||
|
||||
quickcheck! {
|
||||
fn qr(m: DMatrix<f64>) -> bool {
|
||||
|
|
|
@ -2,8 +2,10 @@ use na::{DMatrix, Matrix6};
|
|||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
mod quickcheck_tests {
|
||||
use na::{
|
||||
DMatrix, DVector, Matrix2, Matrix2x5, Matrix3, Matrix3x5, Matrix4, Matrix5x2, Matrix5x3,
|
||||
};
|
||||
use std::cmp;
|
||||
use na::{DMatrix, Matrix2, Matrix3, Matrix4, Matrix5x2, Matrix5x3, Matrix2x5, Matrix3x5, DVector};
|
||||
|
||||
quickcheck! {
|
||||
fn svd(m: DMatrix<f64>) -> bool {
|
||||
|
@ -143,31 +145,47 @@ mod quickcheck_tests {
|
|||
// Test proposed on the issue #176 of rulinalg.
|
||||
#[test]
|
||||
fn svd_singular() {
|
||||
let m = DMatrix::from_row_slice(24, 24, &[
|
||||
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,
|
||||
-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,
|
||||
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,
|
||||
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, -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, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, -4.0, 0.0, 0.0, 0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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 (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.
|
||||
#[test]
|
||||
fn svd_singular_vertical() {
|
||||
let m = DMatrix::from_row_slice(25, 24, &[
|
||||
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,
|
||||
-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,
|
||||
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,
|
||||
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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 0.0, 0.0, 0.0, 0.0, 0.0, 0.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, 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 (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.
|
||||
#[test]
|
||||
fn svd_singular_horizontal() {
|
||||
let m = DMatrix::from_row_slice(24, 25, &[
|
||||
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,
|
||||
-1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 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0.0, 0.0,
|
||||
],
|
||||
);
|
||||
|
||||
let svd = m.clone().svd(true, true);
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn svd_zeros() {
|
||||
let m = DMatrix::from_element(10, 10, 0.0);
|
||||
|
@ -283,47 +332,100 @@ fn svd_identity() {
|
|||
#[test]
|
||||
fn svd_with_delimited_subproblem() {
|
||||
let mut m = DMatrix::<f64>::from_element(10, 10, 0.0);
|
||||
m[(0,0)] = 1.0; m[(0,1)] = 2.0;
|
||||
m[(1,1)] = 0.0; m[(1,2)] = 3.0;
|
||||
m[(2,2)] = 4.0; m[(2,3)] = 5.0;
|
||||
m[(3,3)] = 6.0; m[(3,4)] = 0.0;
|
||||
m[(4,4)] = 8.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[(0, 0)] = 1.0;
|
||||
m[(0, 1)] = 2.0;
|
||||
m[(1, 1)] = 0.0;
|
||||
m[(1, 2)] = 3.0;
|
||||
m[(2, 2)] = 4.0;
|
||||
m[(2, 3)] = 5.0;
|
||||
m[(3, 3)] = 6.0;
|
||||
m[(3, 4)] = 0.0;
|
||||
m[(4, 4)] = 8.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);
|
||||
assert!(relative_eq!(m, svd.recompose(), epsilon = 1.0e-7));
|
||||
|
||||
// Rectangular versions.
|
||||
let mut m = DMatrix::<f64>::from_element(15, 10, 0.0);
|
||||
m[(0,0)] = 1.0; m[(0,1)] = 2.0;
|
||||
m[(1,1)] = 0.0; m[(1,2)] = 3.0;
|
||||
m[(2,2)] = 4.0; m[(2,3)] = 5.0;
|
||||
m[(3,3)] = 6.0; m[(3,4)] = 0.0;
|
||||
m[(4,4)] = 8.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[(0, 0)] = 1.0;
|
||||
m[(0, 1)] = 2.0;
|
||||
m[(1, 1)] = 0.0;
|
||||
m[(1, 2)] = 3.0;
|
||||
m[(2, 2)] = 4.0;
|
||||
m[(2, 3)] = 5.0;
|
||||
m[(3, 3)] = 6.0;
|
||||
m[(3, 4)] = 0.0;
|
||||
m[(4, 4)] = 8.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);
|
||||
assert!(relative_eq!(m, svd.recompose(), epsilon = 1.0e-7));
|
||||
|
||||
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]
|
||||
fn svd_fail() {
|
||||
let m = Matrix6::new(
|
||||
0.9299319121545955, 0.9955870335651049, 0.8824725266413644, 0.28966880207132295, 0.06102723649846409, 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);
|
||||
0.9299319121545955,
|
||||
0.9955870335651049,
|
||||
0.8824725266413644,
|
||||
0.28966880207132295,
|
||||
0.06102723649846409,
|
||||
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);
|
||||
println!("Singular values: {}", svd.singular_values);
|
||||
println!("u: {:.5}", svd.u.unwrap());
|
||||
|
|
Loading…
Reference in New Issue