Add rustfmt.toml and run it.
This commit is contained in:
parent
5ea612ef96
commit
14ad10a7e0
@ -1,7 +1,7 @@
|
||||
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10};
|
||||
use rand::{IsaacRng, Rng};
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, U10, Vector2, Vector3, Vector4};
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[path = "../common/macros.rs"]
|
||||
mod macros;
|
||||
@ -189,18 +189,10 @@ fn mat_mul_mat(bench: &mut Bencher) {
|
||||
|
||||
#[bench]
|
||||
fn mat100_from_fn(bench: &mut Bencher) {
|
||||
bench.iter(|| {
|
||||
DMatrix::from_fn(100, 100, |a, b| {
|
||||
a + b
|
||||
})
|
||||
})
|
||||
bench.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn mat500_from_fn(bench: &mut Bencher) {
|
||||
bench.iter(|| {
|
||||
DMatrix::from_fn(500, 500, |a, b| {
|
||||
a + b
|
||||
})
|
||||
})
|
||||
bench.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b))
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
|
||||
use rand::{IsaacRng, Rng};
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
use test::{self, Bencher};
|
||||
use typenum::U10000;
|
||||
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
|
||||
#[path = "../common/macros.rs"]
|
||||
mod macros;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use rand::{IsaacRng, Rng};
|
||||
use test::{self, Bencher};
|
||||
use na::{Quaternion, UnitQuaternion, Vector3};
|
||||
use rand::{IsaacRng, Rng};
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[path = "../common/macros.rs"]
|
||||
mod macros;
|
||||
|
@ -6,12 +6,12 @@ extern crate rand;
|
||||
extern crate test;
|
||||
extern crate typenum;
|
||||
|
||||
use rand::{IsaacRng, Rng};
|
||||
use na::DMatrix;
|
||||
use rand::{IsaacRng, Rng};
|
||||
|
||||
mod core;
|
||||
mod linalg;
|
||||
mod geometry;
|
||||
mod linalg;
|
||||
|
||||
fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix<f64> {
|
||||
let mut rng = IsaacRng::new_unseeded();
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{Bidiagonal, DMatrix, Matrix4};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[path = "../common/macros.rs"]
|
||||
mod macros;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{Cholesky, DMatrix, DVector};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn cholesky_100x100(bh: &mut Bencher) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, DVector, FullPivLU};
|
||||
use test::{self, Bencher};
|
||||
|
||||
// Without unpack.
|
||||
#[bench]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, Hessenberg, Matrix4};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[path = "../common/macros.rs"]
|
||||
mod macros;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, DVector, LU};
|
||||
use test::{self, Bencher};
|
||||
|
||||
// Without unpack.
|
||||
#[bench]
|
||||
|
@ -1,11 +1,11 @@
|
||||
mod solve;
|
||||
mod cholesky;
|
||||
mod qr;
|
||||
mod hessenberg;
|
||||
mod bidiagonal;
|
||||
mod lu;
|
||||
mod cholesky;
|
||||
mod full_piv_lu;
|
||||
mod svd;
|
||||
mod hessenberg;
|
||||
mod lu;
|
||||
mod qr;
|
||||
mod schur;
|
||||
mod solve;
|
||||
mod svd;
|
||||
mod symmetric_eigen;
|
||||
// mod eigen;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, DVector, Matrix4, QR};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[path = "../common/macros.rs"]
|
||||
mod macros;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{Matrix4, RealSchur};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn schur_decompose_4x4(bh: &mut Bencher) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::Bencher;
|
||||
use na::{DMatrix, DVector};
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn solve_l_triangular_100x100(bh: &mut Bencher) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{Matrix4, SVD};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn svd_decompose_4x4(bh: &mut Bencher) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{Matrix4, SymmetricEigen};
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn symmetric_eigen_decompose_4x4(bh: &mut Bencher) {
|
||||
|
@ -2,15 +2,13 @@ extern crate alga;
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use alga::linear::FiniteDimInnerSpace;
|
||||
use na::{DefaultAllocator, Real, Unit, Vector2, Vector3, VectorN};
|
||||
use na::allocator::Allocator;
|
||||
use na::dimension::Dim;
|
||||
use na::{DefaultAllocator, Real, Unit, Vector2, Vector3, VectorN};
|
||||
|
||||
/// Reflects a vector wrt. the hyperplane with normal `plane_normal`.
|
||||
fn reflect_wrt_hyperplane_with_algebraic_genericity<V>(plane_normal: &Unit<V>, vector: &V) -> V
|
||||
where
|
||||
V: FiniteDimInnerSpace + Copy,
|
||||
{
|
||||
where V: FiniteDimInnerSpace + Copy {
|
||||
let n = plane_normal.as_ref(); // Get the underlying vector of type `V`.
|
||||
*vector - *n * (n.dot(vector) * na::convert(2.0))
|
||||
}
|
||||
@ -31,9 +29,7 @@ where
|
||||
|
||||
/// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`.
|
||||
fn reflect_wrt_hyperplane2<N>(plane_normal: &Unit<Vector2<N>>, vector: &Vector2<N>) -> Vector2<N>
|
||||
where
|
||||
N: Real,
|
||||
{
|
||||
where N: Real {
|
||||
let n = plane_normal.as_ref(); // Get the underlying Vector2
|
||||
vector - n * (n.dot(vector) * na::convert(2.0))
|
||||
}
|
||||
@ -41,9 +37,7 @@ where
|
||||
/// Reflects a 3D vector wrt. the 3D plane with normal `plane_normal`.
|
||||
/// /!\ This is an exact replicate of `reflect_wrt_hyperplane2, but for 3D.
|
||||
fn reflect_wrt_hyperplane3<N>(plane_normal: &Unit<Vector3<N>>, vector: &Vector3<N>) -> Vector3<N>
|
||||
where
|
||||
N: Real,
|
||||
{
|
||||
where N: Real {
|
||||
let n = plane_normal.as_ref(); // Get the underlying Vector3
|
||||
vector - n * (n.dot(vector) * na::convert(2.0))
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
extern crate approx;
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use std::f32;
|
||||
use na::{Isometry2, Point2, Vector2};
|
||||
use std::f32;
|
||||
|
||||
fn use_dedicated_types() {
|
||||
let iso = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
|
||||
|
@ -9,9 +9,7 @@ use na::{Id, Isometry3, Point3, Vector3};
|
||||
* intermediate value.
|
||||
*/
|
||||
fn complicated_algorithm<T>(v: &Vector3<f32>, t: &T, n: usize) -> Vector3<f32>
|
||||
where
|
||||
T: Transformation<Point3<f32>>,
|
||||
{
|
||||
where T: Transformation<Point3<f32>> {
|
||||
let mut result = *v;
|
||||
|
||||
// Do lots of operations involving t.
|
||||
|
@ -48,11 +48,10 @@ fn main() {
|
||||
4,
|
||||
3,
|
||||
[
|
||||
// Components listed column-by-column.
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0
|
||||
].iter()
|
||||
// Components listed column-by-column.
|
||||
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
|
||||
]
|
||||
.iter()
|
||||
.cloned(),
|
||||
);
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
extern crate approx;
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use std::f32;
|
||||
use na::{Isometry2, Point2, Vector2};
|
||||
use std::f32;
|
||||
|
||||
fn main() {
|
||||
let t = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
|
||||
|
@ -22,9 +22,7 @@ use traits::{Alloc, Dimension, Number};
|
||||
///
|
||||
/// * [`sign`](fn.sign.html)
|
||||
pub fn abs<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>) -> TMat<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.abs()
|
||||
}
|
||||
|
||||
@ -46,9 +44,7 @@ where
|
||||
/// * [`round`](fn.round.html)
|
||||
/// * [`trunc`](fn.trunc.html)
|
||||
pub fn ceil<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.ceil())
|
||||
}
|
||||
|
||||
@ -98,9 +94,7 @@ pub fn clamp_scalar<N: Number>(x: N, min_val: N, max_val: N) -> N {
|
||||
/// * [`clamp_scalar`](fn.clamp_scalar.html)
|
||||
/// * [`clamp_vec`](fn.clamp_vec.html)
|
||||
pub fn clamp<N: Number, D: Dimension>(x: &TVec<N, D>, min_val: N, max_val: N) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| na::clamp(x, min_val, max_val))
|
||||
}
|
||||
|
||||
@ -173,9 +167,7 @@ pub fn float_bits_to_int(v: f32) -> i32 {
|
||||
/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html)
|
||||
/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html)
|
||||
pub fn float_bits_to_int_vec<D: Dimension>(v: &TVec<f32, D>) -> TVec<i32, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<f32, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(float_bits_to_int)
|
||||
}
|
||||
|
||||
@ -210,9 +202,7 @@ pub fn float_bits_to_uint(v: f32) -> u32 {
|
||||
/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html)
|
||||
/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html)
|
||||
pub fn float_bits_to_uint_vec<D: Dimension>(v: &TVec<f32, D>) -> TVec<u32, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<f32, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(float_bits_to_uint)
|
||||
}
|
||||
|
||||
@ -233,9 +223,7 @@ where
|
||||
/// * [`round`](fn.round.html)
|
||||
/// * [`trunc`](fn.trunc.html)
|
||||
pub fn floor<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.floor())
|
||||
}
|
||||
|
||||
@ -262,9 +250,7 @@ where
|
||||
/// * [`round`](fn.round.html)
|
||||
/// * [`trunc`](fn.trunc.html)
|
||||
pub fn fract<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.fract())
|
||||
}
|
||||
|
||||
@ -307,9 +293,7 @@ pub fn int_bits_to_float(v: i32) -> f32 {
|
||||
/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html)
|
||||
/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html)
|
||||
pub fn int_bits_to_float_vec<D: Dimension>(v: &TVec<i32, D>) -> TVec<f32, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<f32, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(int_bits_to_float)
|
||||
}
|
||||
|
||||
@ -368,9 +352,7 @@ pub fn mix_scalar<N: Number>(x: N, y: N, a: N) -> N {
|
||||
/// * [`mix_scalar`](fn.mix_scalar.html)
|
||||
/// * [`mix_vec`](fn.mix_vec.html)
|
||||
pub fn mix<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, a: N) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x * (N::one() - a) + y * a
|
||||
}
|
||||
|
||||
@ -443,9 +425,7 @@ pub fn lerp_scalar<N: Number>(x: N, y: N, a: N) -> N {
|
||||
/// * [`lerp_scalar`](fn.lerp_scalar.html)
|
||||
/// * [`lerp_vec`](fn.lerp_vec.html)
|
||||
pub fn lerp<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, a: N) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
mix(x, y, a)
|
||||
}
|
||||
|
||||
@ -488,9 +468,7 @@ where
|
||||
///
|
||||
/// * [`modf`](fn.modf.html)
|
||||
pub fn modf_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x % y)
|
||||
}
|
||||
|
||||
@ -522,9 +500,7 @@ pub fn modf<N: Number>(x: N, i: N) -> N {
|
||||
/// * [`fract`](fn.fract.html)
|
||||
/// * [`trunc`](fn.trunc.html)
|
||||
pub fn round<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.round())
|
||||
}
|
||||
|
||||
@ -548,9 +524,7 @@ where
|
||||
/// * [`abs`](fn.abs.html)
|
||||
///
|
||||
pub fn sign<N: Number, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| if x.is_zero() { N::zero() } else { x.signum() })
|
||||
}
|
||||
|
||||
@ -576,17 +550,13 @@ pub fn step_scalar<N: Number>(edge: N, x: N) -> N {
|
||||
|
||||
/// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0.
|
||||
pub fn step<N: Number, D: Dimension>(edge: N, x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| step_scalar(edge, x))
|
||||
}
|
||||
|
||||
/// Returns 0.0 if `x[i] < edge[i]`, otherwise it returns 1.0.
|
||||
pub fn step_vec<N: Number, D: Dimension>(edge: &TVec<N, D>, x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
edge.zip_map(x, step_scalar)
|
||||
}
|
||||
|
||||
@ -607,9 +577,7 @@ where
|
||||
/// * [`fract`](fn.fract.html)
|
||||
/// * [`round`](fn.round.html)
|
||||
pub fn trunc<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.trunc())
|
||||
}
|
||||
|
||||
@ -644,8 +612,6 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 {
|
||||
/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html)
|
||||
/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html)
|
||||
pub fn uint_bits_to_float<D: Dimension>(v: &TVec<u32, D>) -> TVec<f32, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<f32, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(uint_bits_to_float_scalar)
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use na::{Scalar, Real, U2, U3, U4};
|
||||
use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
|
||||
TMat4, TMat4x2, TMat4x3};
|
||||
@ -34,7 +36,8 @@ pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> TVec4<N> {
|
||||
|
||||
|
||||
/// Create a new 2x2 matrix.
|
||||
pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
pub fn mat2<N: Scalar>(m11: N, m12: N,
|
||||
m21: N, m22: N) -> TMat2<N> {
|
||||
TMat::<N, U2, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
@ -42,7 +45,8 @@ pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
}
|
||||
|
||||
/// Create a new 2x2 matrix.
|
||||
pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
pub fn mat2x2<N: Scalar>(m11: N, m12: N,
|
||||
m21: N, m22: N) -> TMat2<N> {
|
||||
TMat::<N, U2, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
@ -50,7 +54,8 @@ pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
}
|
||||
|
||||
/// Create a new 2x3 matrix.
|
||||
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3<N> {
|
||||
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N,
|
||||
m21: N, m22: N, m23: N) -> TMat2x3<N> {
|
||||
TMat::<N, U2, U3>::new(
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
@ -58,7 +63,8 @@ pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat
|
||||
}
|
||||
|
||||
/// Create a new 2x4 matrix.
|
||||
pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> TMat2x4<N> {
|
||||
pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
||||
m21: N, m22: N, m23: N, m24: N) -> TMat2x4<N> {
|
||||
TMat::<N, U2, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
@ -66,7 +72,9 @@ pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
|
||||
}
|
||||
|
||||
/// Create a new 3x3 matrix.
|
||||
pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3<N> {
|
||||
pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N,
|
||||
m21: N, m22: N, m23: N,
|
||||
m31: N, m32: N, m33: N) -> TMat3<N> {
|
||||
TMat::<N, U3, U3>::new(
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
@ -75,7 +83,9 @@ pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m
|
||||
}
|
||||
|
||||
/// Create a new 3x2 matrix.
|
||||
pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2<N> {
|
||||
pub fn mat3x2<N: Scalar>(m11: N, m12: N,
|
||||
m21: N, m22: N,
|
||||
m31: N, m32: N) -> TMat3x2<N> {
|
||||
TMat::<N, U3, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
@ -84,7 +94,9 @@ pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat
|
||||
}
|
||||
|
||||
/// Create a new 3x3 matrix.
|
||||
pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3<N> {
|
||||
pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N,
|
||||
m21: N, m22: N, m23: N,
|
||||
m31: N, m32: N, m33: N) -> TMat3<N> {
|
||||
TMat::<N, U3, U3>::new(
|
||||
m11, m12, m13,
|
||||
m31, m32, m33,
|
||||
@ -93,7 +105,9 @@ pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N,
|
||||
}
|
||||
|
||||
/// Create a new 3x4 matrix.
|
||||
pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N) -> TMat3x4<N> {
|
||||
pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
||||
m21: N, m22: N, m23: N, m24: N,
|
||||
m31: N, m32: N, m33: N, m34: N) -> TMat3x4<N> {
|
||||
TMat::<N, U3, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
@ -102,7 +116,10 @@ pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
|
||||
}
|
||||
|
||||
/// Create a new 4x2 matrix.
|
||||
pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> TMat4x2<N> {
|
||||
pub fn mat4x2<N: Scalar>(m11: N, m12: N,
|
||||
m21: N, m22: N,
|
||||
m31: N, m32: N,
|
||||
m41: N, m42: N) -> TMat4x2<N> {
|
||||
TMat::<N, U4, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
@ -112,7 +129,10 @@ pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N,
|
||||
}
|
||||
|
||||
/// Create a new 4x3 matrix.
|
||||
pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N, m41: N, m42: N, m43: N) -> TMat4x3<N> {
|
||||
pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N,
|
||||
m21: N, m22: N, m23: N,
|
||||
m31: N, m32: N, m33: N,
|
||||
m41: N, m42: N, m43: N) -> TMat4x3<N> {
|
||||
TMat::<N, U4, U3>::new(
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
@ -122,7 +142,10 @@ pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N,
|
||||
}
|
||||
|
||||
/// Create a new 4x4 matrix.
|
||||
pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
||||
pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
||||
m21: N, m22: N, m23: N, m24: N,
|
||||
m31: N, m32: N, m33: N, m34: N,
|
||||
m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
||||
TMat::<N, U4, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
@ -132,7 +155,10 @@ pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
|
||||
}
|
||||
|
||||
/// Create a new 4x4 matrix.
|
||||
pub fn mat4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
||||
pub fn mat4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
|
||||
m21: N, m22: N, m23: N, m24: N,
|
||||
m31: N, m32: N, m33: N, m34: N,
|
||||
m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
||||
TMat::<N, U4, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
|
@ -8,9 +8,7 @@ use traits::{Alloc, Dimension};
|
||||
///
|
||||
/// * [`exp2`](fn.exp2.html)
|
||||
pub fn exp<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.exp())
|
||||
}
|
||||
|
||||
@ -20,9 +18,7 @@ where
|
||||
///
|
||||
/// * [`exp`](fn.exp.html)
|
||||
pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.exp2())
|
||||
}
|
||||
|
||||
@ -32,9 +28,7 @@ where
|
||||
///
|
||||
/// * [`sqrt`](fn.sqrt.html)
|
||||
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| N::one() / x.sqrt())
|
||||
}
|
||||
|
||||
@ -44,9 +38,7 @@ where
|
||||
///
|
||||
/// * [`log2`](fn.log2.html)
|
||||
pub fn log<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.ln())
|
||||
}
|
||||
|
||||
@ -56,17 +48,13 @@ where
|
||||
///
|
||||
/// * [`log`](fn.log.html)
|
||||
pub fn log2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.log2())
|
||||
}
|
||||
|
||||
/// Component-wise power.
|
||||
pub fn pow<N: Real, D: Dimension>(base: &TVec<N, D>, exponent: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
base.zip_map(exponent, |b, e| b.powf(e))
|
||||
}
|
||||
|
||||
@ -79,8 +67,6 @@ where
|
||||
/// * [`inversesqrt`](fn.inversesqrt.html)
|
||||
/// * [`pow`](fn.pow.html)
|
||||
pub fn sqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.sqrt())
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ pub fn project<N: Real>(
|
||||
model: &TMat4<N>,
|
||||
proj: &TMat4<N>,
|
||||
viewport: TVec4<N>,
|
||||
) -> TVec3<N> {
|
||||
) -> TVec3<N>
|
||||
{
|
||||
project_no(obj, model, proj, viewport)
|
||||
}
|
||||
|
||||
@ -72,7 +73,8 @@ pub fn project_no<N: Real>(
|
||||
model: &TMat4<N>,
|
||||
proj: &TMat4<N>,
|
||||
viewport: TVec4<N>,
|
||||
) -> TVec3<N> {
|
||||
) -> TVec3<N>
|
||||
{
|
||||
let proj = project_zo(obj, model, proj, viewport);
|
||||
TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5))
|
||||
}
|
||||
@ -100,7 +102,8 @@ pub fn project_zo<N: Real>(
|
||||
model: &TMat4<N>,
|
||||
proj: &TMat4<N>,
|
||||
viewport: TVec4<N>,
|
||||
) -> TVec3<N> {
|
||||
) -> TVec3<N>
|
||||
{
|
||||
let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one());
|
||||
let scale = N::one() / normalized.w;
|
||||
|
||||
@ -132,7 +135,8 @@ pub fn unproject<N: Real>(
|
||||
model: &TMat4<N>,
|
||||
proj: &TMat4<N>,
|
||||
viewport: TVec4<N>,
|
||||
) -> TVec3<N> {
|
||||
) -> TVec3<N>
|
||||
{
|
||||
unproject_no(win, model, proj, viewport)
|
||||
}
|
||||
|
||||
@ -159,7 +163,8 @@ pub fn unproject_no<N: Real>(
|
||||
model: &TMat4<N>,
|
||||
proj: &TMat4<N>,
|
||||
viewport: TVec4<N>,
|
||||
) -> TVec3<N> {
|
||||
) -> TVec3<N>
|
||||
{
|
||||
let _2: N = na::convert(2.0);
|
||||
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
||||
let pt = TVec4::new(
|
||||
@ -196,7 +201,8 @@ pub fn unproject_zo<N: Real>(
|
||||
model: &TMat4<N>,
|
||||
proj: &TMat4<N>,
|
||||
viewport: TVec4<N>,
|
||||
) -> TVec3<N> {
|
||||
) -> TVec3<N>
|
||||
{
|
||||
let _2: N = na::convert(2.0);
|
||||
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
||||
let pt = TVec4::new(
|
||||
|
@ -5,9 +5,7 @@ use traits::{Alloc, Dimension, Number};
|
||||
|
||||
/// The identity matrix.
|
||||
pub fn identity<N: Number, D: Dimension>() -> TMat<N, D, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
TMat::<N, D, D>::identity()
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,7 @@ use traits::{Alloc, Dimension, Number};
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn max<N: Number, D: Dimension>(a: &TVec<N, D>, b: N) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
a.map(|a| na::sup(&a, &b))
|
||||
}
|
||||
|
||||
@ -37,9 +35,7 @@ where
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn max2<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
na::sup(a, b)
|
||||
}
|
||||
|
||||
@ -57,9 +53,7 @@ where
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn max3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
max2(&max2(a, b), c)
|
||||
}
|
||||
|
||||
@ -102,9 +96,7 @@ where
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn min<N: Number, D: Dimension>(x: &TVec<N, D>, y: N) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| na::inf(&x, &y))
|
||||
}
|
||||
|
||||
@ -122,9 +114,7 @@ where
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn min2<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
na::inf(x, y)
|
||||
}
|
||||
|
||||
@ -142,9 +132,7 @@ where
|
||||
/// * [`min2`](fn.min2.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn min3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
min2(&min2(a, b), c)
|
||||
}
|
||||
|
||||
|
@ -14,17 +14,13 @@ pub fn cross<N: Number, D: Dimension>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
|
||||
///
|
||||
/// * [`distance2`](fn.distance2.html)
|
||||
pub fn distance<N: Real, D: Dimension>(p0: &TVec<N, D>, p1: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
(p1 - p0).norm()
|
||||
}
|
||||
|
||||
/// The dot product of two vectors.
|
||||
pub fn dot<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.dot(y)
|
||||
}
|
||||
|
||||
@ -54,9 +50,7 @@ where
|
||||
/// * [`magnitude`](fn.magnitude.html)
|
||||
/// * [`magnitude2`](fn.magnitude2.html)
|
||||
pub fn length<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm()
|
||||
}
|
||||
|
||||
@ -70,34 +64,26 @@ where
|
||||
/// * [`magnitude2`](fn.magnitude2.html)
|
||||
/// * [`nalgebra::norm`](../nalgebra/fn.norm.html)
|
||||
pub fn magnitude<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm()
|
||||
}
|
||||
|
||||
/// Normalizes a vector.
|
||||
pub fn normalize<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.normalize()
|
||||
}
|
||||
|
||||
/// For the incident vector `i` and surface orientation `n`, returns the reflection direction : `result = i - 2.0 * dot(n, i) * n`.
|
||||
pub fn reflect_vec<N: Number, D: Dimension>(i: &TVec<N, D>, n: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
let _2 = N::one() + N::one();
|
||||
i - n * (n.dot(i) * _2)
|
||||
}
|
||||
|
||||
/// For the incident vector `i` and surface normal `n`, and the ratio of indices of refraction `eta`, return the refraction vector.
|
||||
pub fn refract_vec<N: Real, D: Dimension>(i: &TVec<N, D>, n: &TVec<N, D>, eta: N) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
let ni = n.dot(i);
|
||||
let k = N::one() - eta * eta * (N::one() - ni * ni);
|
||||
|
||||
|
@ -10,7 +10,10 @@ use traits::{Alloc, Dimension};
|
||||
/// * [`row`](fn.row.html)
|
||||
/// * [`set_column`](fn.set_column.html)
|
||||
/// * [`set_row`](fn.set_row.html)
|
||||
pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, R>
|
||||
pub fn column<N: Scalar, R: Dimension, C: Dimension>(
|
||||
m: &TMat<N, R, C>,
|
||||
index: usize,
|
||||
) -> TVec<N, R>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
@ -45,9 +48,7 @@ where
|
||||
/// * [`set_column`](fn.set_column.html)
|
||||
/// * [`set_row`](fn.set_row.html)
|
||||
pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, C>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.row(index).into_owned().transpose()
|
||||
}
|
||||
|
||||
|
@ -5,18 +5,14 @@ use traits::{Alloc, Dimension};
|
||||
|
||||
/// Fast matrix inverse for affine matrix.
|
||||
pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
// FIXME: this should be optimized.
|
||||
m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros)
|
||||
}
|
||||
|
||||
/// Compute the transpose of the inverse of a matrix.
|
||||
pub fn inverse_transpose<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
m.try_inverse()
|
||||
.unwrap_or_else(TMat::<_, D, D>::zeros)
|
||||
.transpose()
|
||||
|
@ -384,16 +384,12 @@ pub fn make_vec4<N: Scalar>(ptr: &[N]) -> TVec4<N> {
|
||||
|
||||
/// Converts a matrix or vector to a slice arranged in column-major order.
|
||||
pub fn value_ptr<N: Scalar, R: Dimension, C: Dimension>(x: &TMat<N, R, C>) -> &[N]
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.as_slice()
|
||||
}
|
||||
|
||||
/// Converts a matrix or vector to a mutable slice arranged in column-major order.
|
||||
pub fn value_ptr_mut<N: Scalar, R: Dimension, C: Dimension>(x: &mut TMat<N, R, C>) -> &mut [N]
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.as_mut_slice()
|
||||
}
|
||||
|
@ -22,9 +22,7 @@ use traits::{Alloc, Dimension, Number};
|
||||
/// * [`comp_min`](fn.comp_min.html)
|
||||
/// * [`comp_mul`](fn.comp_mul.html)
|
||||
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::zero(), |x, y| x + *y)
|
||||
}
|
||||
|
||||
@ -51,9 +49,7 @@ where
|
||||
/// * [`max3`](fn.max3.html)
|
||||
/// * [`max4`](fn.max4.html)
|
||||
pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::min_value(), |x, y| na::sup(&x, y))
|
||||
}
|
||||
|
||||
@ -80,9 +76,7 @@ where
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::max_value(), |x, y| na::inf(&x, y))
|
||||
}
|
||||
|
||||
@ -105,9 +99,7 @@ where
|
||||
/// * [`comp_max`](fn.comp_max.html)
|
||||
/// * [`comp_min`](fn.comp_min.html)
|
||||
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::one(), |x, y| x * *y)
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,7 @@ use traits::{Alloc, Dimension};
|
||||
///
|
||||
/// * [`distance`](fn.distance.html)
|
||||
pub fn distance2<N: Real, D: Dimension>(p0: &TVec<N, D>, p1: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
(p1 - p0).norm_squared()
|
||||
}
|
||||
|
||||
@ -23,9 +21,7 @@ where
|
||||
/// * [`l2_distance`](fn.l2_distance.html)
|
||||
/// * [`l2_norm`](fn.l2_norm.html)
|
||||
pub fn l1_distance<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
l1_norm(&(y - x))
|
||||
}
|
||||
|
||||
@ -40,9 +36,7 @@ where
|
||||
/// * [`l2_distance`](fn.l2_distance.html)
|
||||
/// * [`l2_norm`](fn.l2_norm.html)
|
||||
pub fn l1_norm<N: Real, D: Dimension>(v: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
::comp_add(&v.abs())
|
||||
}
|
||||
|
||||
@ -61,9 +55,7 @@ where
|
||||
/// * [`magnitude`](fn.magnitude.html)
|
||||
/// * [`magnitude2`](fn.magnitude2.html)
|
||||
pub fn l2_distance<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
l2_norm(&(y - x))
|
||||
}
|
||||
|
||||
@ -84,9 +76,7 @@ where
|
||||
/// * [`magnitude`](fn.magnitude.html)
|
||||
/// * [`magnitude2`](fn.magnitude2.html)
|
||||
pub fn l2_norm<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm()
|
||||
}
|
||||
|
||||
@ -102,9 +92,7 @@ where
|
||||
/// * [`magnitude`](fn.magnitude.html)
|
||||
/// * [`magnitude2`](fn.magnitude2.html)
|
||||
pub fn length2<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm_squared()
|
||||
}
|
||||
|
||||
@ -120,9 +108,7 @@ where
|
||||
/// * [`magnitude`](fn.magnitude.html)
|
||||
/// * [`nalgebra::norm_squared`](../nalgebra/fn.norm_squared.html)
|
||||
pub fn magnitude2<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm_squared()
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,7 @@ use traits::{Alloc, Dimension};
|
||||
///
|
||||
/// * [`normalize_dot`](fn.normalize_dot.html`)
|
||||
pub fn fast_normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
// XXX: improve those.
|
||||
x.normalize().dot(&y.normalize())
|
||||
}
|
||||
@ -24,9 +22,7 @@ where
|
||||
///
|
||||
/// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`)
|
||||
pub fn normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
// XXX: improve those.
|
||||
x.normalize().dot(&y.normalize())
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ use traits::{Alloc, Dimension};
|
||||
|
||||
/// The angle between two vectors.
|
||||
pub fn angle<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.angle(y)
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,11 @@ pub fn are_collinear2d<N: Number>(v0: &TVec2<N>, v1: &TVec2<N>, epsilon: N) -> b
|
||||
}
|
||||
|
||||
/// Returns `true` if two vectors are orthogonal (up to an epsilon).
|
||||
pub fn are_orthogonal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
|
||||
pub fn are_orthogonal<N: Number, D: Dimension>(
|
||||
v0: &TVec<N, D>,
|
||||
v1: &TVec<N, D>,
|
||||
epsilon: N,
|
||||
) -> bool
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
@ -36,24 +40,18 @@ where
|
||||
|
||||
/// Returns `true` if all the components of `v` are zero (up to an epsilon).
|
||||
pub fn is_comp_null<N: Number, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon))
|
||||
}
|
||||
|
||||
/// Returns `true` if `v` has a magnitude of 1 (up to an epsilon).
|
||||
pub fn is_normalized<N: Real, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon)
|
||||
}
|
||||
|
||||
/// Returns `true` if `v` is zero (up to an epsilon).
|
||||
pub fn is_null<N: Number, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
abs_diff_eq!(*v, TVec::<N, D>::zeros(), epsilon = epsilon)
|
||||
}
|
||||
|
@ -110,8 +110,6 @@
|
||||
and keep in mind it is possible to convert, e.g., an `Isometry3` to a `Mat4` and vice-versa (see the [conversions section](#conversions)).
|
||||
*/
|
||||
|
||||
#![doc(html_favicon_url = "http://nalgebra.org/img/favicon.ico")]
|
||||
|
||||
extern crate num_traits as num;
|
||||
#[macro_use]
|
||||
extern crate approx;
|
||||
@ -122,9 +120,8 @@ pub use aliases::*;
|
||||
pub use common::{
|
||||
abs, ceil, clamp, clamp_scalar, clamp_vec, float_bits_to_int, float_bits_to_int_vec,
|
||||
float_bits_to_uint, float_bits_to_uint_vec, floor, fract, int_bits_to_float,
|
||||
int_bits_to_float_vec, lerp, lerp_scalar, lerp_vec, mix, mix_scalar, mix_vec, modf, modf_vec,
|
||||
round, sign, smoothstep, step, step_scalar, step_vec, trunc, uint_bits_to_float,
|
||||
uint_bits_to_float_scalar,
|
||||
int_bits_to_float_vec, mix, modf, modf_vec, round, sign, smoothstep, step, step_scalar,
|
||||
step_vec, trunc, uint_bits_to_float, uint_bits_to_float_scalar,
|
||||
};
|
||||
pub use constructors::*;
|
||||
pub use exponential::{exp, exp2, inversesqrt, log, log2, pow, sqrt};
|
||||
|
@ -5,17 +5,13 @@ use traits::{Alloc, Dimension, Number};
|
||||
|
||||
/// The determinant of the matrix `m`.
|
||||
pub fn determinant<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> N
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
m.determinant()
|
||||
}
|
||||
|
||||
/// The inverse of the matrix `m`.
|
||||
pub fn inverse<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> TMat<N, D, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
m.clone()
|
||||
.try_inverse()
|
||||
.unwrap_or_else(TMat::<N, D, D>::zeros)
|
||||
@ -45,8 +41,6 @@ where
|
||||
|
||||
/// The transpose of the matrix `m`.
|
||||
pub fn transpose<N: Scalar, R: Dimension, C: Dimension>(x: &TMat<N, R, C>) -> TMat<N, C, R>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.transpose()
|
||||
}
|
||||
|
@ -50,8 +50,7 @@ pub trait Alloc<N: Scalar, R: Dimension, C: Dimension = U1>:
|
||||
{
|
||||
}
|
||||
|
||||
impl<N: Scalar, R: Dimension, C: Dimension, T> Alloc<N, R, C> for T where
|
||||
T: Allocator<N, R>
|
||||
impl<N: Scalar, R: Dimension, C: Dimension, T> Alloc<N, R, C> for T where T: Allocator<N, R>
|
||||
+ Allocator<N, C>
|
||||
+ Allocator<N, U1, R>
|
||||
+ Allocator<N, U1, C>
|
||||
|
@ -5,120 +5,90 @@ use traits::{Alloc, Dimension};
|
||||
|
||||
/// Component-wise arc-cosinus.
|
||||
pub fn acos<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.acos())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic arc-cosinus.
|
||||
pub fn acosh<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.acosh())
|
||||
}
|
||||
|
||||
/// Component-wise arc-sinus.
|
||||
pub fn asin<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.asin())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic arc-sinus.
|
||||
pub fn asinh<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.asinh())
|
||||
}
|
||||
|
||||
/// Component-wise arc-tangent of `y / x`.
|
||||
pub fn atan2<N: Real, D: Dimension>(y: &TVec<N, D>, x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
y.zip_map(x, |y, x| y.atan2(x))
|
||||
}
|
||||
|
||||
/// Component-wise arc-tangent.
|
||||
pub fn atan<N: Real, D: Dimension>(y_over_x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
y_over_x.map(|e| e.atan())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic arc-tangent.
|
||||
pub fn atanh<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.atanh())
|
||||
}
|
||||
|
||||
/// Component-wise cosinus.
|
||||
pub fn cos<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.cos())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic cosinus.
|
||||
pub fn cosh<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.cosh())
|
||||
}
|
||||
|
||||
/// Component-wise conversion from radians to degrees.
|
||||
pub fn degrees<N: Real, D: Dimension>(radians: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
radians.map(|e| e * na::convert(180.0) / N::pi())
|
||||
}
|
||||
|
||||
/// Component-wise conversion fro degrees to radians.
|
||||
pub fn radians<N: Real, D: Dimension>(degrees: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
degrees.map(|e| e * N::pi() / na::convert(180.0))
|
||||
}
|
||||
|
||||
/// Component-wise sinus.
|
||||
pub fn sin<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.sin())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic sinus.
|
||||
pub fn sinh<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.sinh())
|
||||
}
|
||||
|
||||
/// Component-wise tangent.
|
||||
pub fn tan<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.tan())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic tangent.
|
||||
pub fn tanh<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.tanh())
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ use traits::{Alloc, Dimension, Number};
|
||||
/// * [`any`](fn.any.html)
|
||||
/// * [`not`](fn.not.html)
|
||||
pub fn all<D: Dimension>(v: &TVec<bool, D>) -> bool
|
||||
where
|
||||
DefaultAllocator: Alloc<bool, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<bool, D> {
|
||||
v.iter().all(|x| *x)
|
||||
}
|
||||
|
||||
@ -48,9 +46,7 @@ where
|
||||
/// * [`all`](fn.all.html)
|
||||
/// * [`not`](fn.not.html)
|
||||
pub fn any<D: Dimension>(v: &TVec<bool, D>) -> bool
|
||||
where
|
||||
DefaultAllocator: Alloc<bool, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<bool, D> {
|
||||
v.iter().any(|x| *x)
|
||||
}
|
||||
|
||||
@ -74,9 +70,7 @@ where
|
||||
/// * [`not`](fn.not.html)
|
||||
/// * [`not_equal`](fn.not_equal.html)
|
||||
pub fn equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x == y)
|
||||
}
|
||||
|
||||
@ -100,9 +94,7 @@ where
|
||||
/// * [`not`](fn.not.html)
|
||||
/// * [`not_equal`](fn.not_equal.html)
|
||||
pub fn greater_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x > y)
|
||||
}
|
||||
|
||||
@ -125,7 +117,10 @@ where
|
||||
/// * [`less_than_equal`](fn.less_than_equal.html)
|
||||
/// * [`not`](fn.not.html)
|
||||
/// * [`not_equal`](fn.not_equal.html)
|
||||
pub fn greater_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
pub fn greater_than_equal<N: Number, D: Dimension>(
|
||||
x: &TVec<N, D>,
|
||||
y: &TVec<N, D>,
|
||||
) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
@ -152,9 +147,7 @@ where
|
||||
/// * [`not`](fn.not.html)
|
||||
/// * [`not_equal`](fn.not_equal.html)
|
||||
pub fn less_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x < y)
|
||||
}
|
||||
|
||||
@ -178,9 +171,7 @@ where
|
||||
/// * [`not`](fn.not.html)
|
||||
/// * [`not_equal`](fn.not_equal.html)
|
||||
pub fn less_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x <= y)
|
||||
}
|
||||
|
||||
@ -205,9 +196,7 @@ where
|
||||
/// * [`less_than_equal`](fn.less_than_equal.html)
|
||||
/// * [`not_equal`](fn.not_equal.html)
|
||||
pub fn not<D: Dimension>(v: &TVec<bool, D>) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<bool, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<bool, D> {
|
||||
v.map(|x| !x)
|
||||
}
|
||||
|
||||
@ -231,8 +220,6 @@ where
|
||||
/// * [`less_than_equal`](fn.less_than_equal.html)
|
||||
/// * [`not`](fn.not.html)
|
||||
pub fn not_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x != y)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, Matrix4};
|
||||
use nl::Hessenberg;
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn hessenberg_decompose_100x100(bh: &mut Bencher) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, Matrix4};
|
||||
use nl::LU;
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn lu_decompose_100x100(bh: &mut Bencher) {
|
||||
|
@ -1,3 +1,3 @@
|
||||
mod qr;
|
||||
mod lu;
|
||||
mod hessenberg;
|
||||
mod lu;
|
||||
mod qr;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use test::{self, Bencher};
|
||||
use na::{DMatrix, Matrix4};
|
||||
use nl::QR;
|
||||
use test::{self, Bencher};
|
||||
|
||||
#[bench]
|
||||
fn qr_decompose_100x100(bh: &mut Bencher) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num::Zero;
|
||||
use num_complex::Complex;
|
||||
@ -15,26 +15,21 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D>,
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D>,
|
||||
MatrixN<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D>,
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D>,
|
||||
MatrixN<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Cholesky<N: Scalar, D: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
l: MatrixN<N, D>,
|
||||
}
|
||||
@ -43,12 +38,10 @@ impl<N: Scalar, D: Dim> Copy for Cholesky<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
MatrixN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: CholeskyScalar + Zero, D: Dim> Cholesky<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
/// Computes the cholesky decomposition of the given symmetric-definite-positive square
|
||||
/// matrix.
|
||||
@ -124,9 +117,7 @@ where
|
||||
/// Solves in-place the symmetric-definite-positive linear system `self * x = b`, where `x` is
|
||||
/// the unknown to be determined.
|
||||
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R2, C2>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R2, C2> {
|
||||
let dim = self.l.nrows();
|
||||
|
||||
assert!(
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num::Zero;
|
||||
use num_complex::Complex;
|
||||
@ -18,28 +18,23 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
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(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
VectorN<N, D>: Serialize,
|
||||
MatrixN<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Eigen<N: Scalar, D: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>
|
||||
{
|
||||
/// The eigenvalues of the decomposed matrix.
|
||||
pub eigenvalues: VectorN<N, D>,
|
||||
@ -54,12 +49,10 @@ where
|
||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
||||
VectorN<N, D>: Copy,
|
||||
MatrixN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: EigenScalar + Real, D: Dim> Eigen<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
||||
{
|
||||
/// Computes the eigenvalues and eigenvectors of the square matrix `m`.
|
||||
///
|
||||
@ -68,7 +61,8 @@ where
|
||||
mut m: MatrixN<N, D>,
|
||||
left_eigenvectors: bool,
|
||||
eigenvectors: bool,
|
||||
) -> Option<Eigen<N, D>> {
|
||||
) -> Option<Eigen<N, D>>
|
||||
{
|
||||
assert!(
|
||||
m.is_square(),
|
||||
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
||||
@ -234,9 +228,7 @@ where
|
||||
///
|
||||
/// Panics if the eigenvalue computation does not converge.
|
||||
pub fn complex_eigenvalues(mut m: MatrixN<N, D>) -> VectorN<Complex<N>, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<Complex<N>, D>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<Complex<N>, D> {
|
||||
assert!(
|
||||
m.is_square(),
|
||||
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
||||
|
@ -13,30 +13,25 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
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(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
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: Scalar, D: DimSub<U1>>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
|
||||
{
|
||||
h: MatrixN<N, D>,
|
||||
tau: VectorN<N, DimDiff<D, U1>>,
|
||||
@ -47,12 +42,10 @@ where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||
MatrixN<N, D>: Copy,
|
||||
VectorN<N, DimDiff<D, U1>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
|
||||
{
|
||||
/// Computes the hessenberg decomposition of the matrix `m`.
|
||||
pub fn new(mut m: MatrixN<N, D>) -> Hessenberg<N, D> {
|
||||
@ -104,8 +97,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: HessenbergReal + Zero, D: DimSub<U1>> Hessenberg<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
||||
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
|
||||
{
|
||||
/// Computes the matrices `(Q, H)` of this decomposition.
|
||||
#[inline]
|
||||
|
@ -20,30 +20,25 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<i32, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Serialize,
|
||||
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
Allocator<i32, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LU<N: Scalar, R: DimMin<C>, C: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<i32, DimMinimum<R, C>> + Allocator<N, R, C>,
|
||||
where DefaultAllocator: Allocator<i32, DimMinimum<R, C>> + Allocator<N, R, C>
|
||||
{
|
||||
lu: MatrixMN<N, R, C>,
|
||||
p: VectorN<i32, DimMinimum<R, C>>,
|
||||
@ -54,8 +49,7 @@ where
|
||||
DefaultAllocator: Allocator<N, R, C> + Allocator<i32, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Copy,
|
||||
VectorN<i32, DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: LUScalar, R: Dim, C: Dim> LU<N, R, C>
|
||||
where
|
||||
@ -139,9 +133,7 @@ where
|
||||
/// Applies the permutation matrix to a given matrix or vector in-place.
|
||||
#[inline]
|
||||
pub fn permute<C2: Dim>(&self, rhs: &mut MatrixMN<N, R, C2>)
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C2>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C2> {
|
||||
let (nrows, ncols) = rhs.shape();
|
||||
|
||||
N::xlaswp(
|
||||
@ -156,9 +148,7 @@ where
|
||||
}
|
||||
|
||||
fn generic_solve_mut<R2: Dim, C2: Dim>(&self, trans: u8, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2> {
|
||||
let dim = self.lu.nrows();
|
||||
|
||||
assert!(
|
||||
@ -246,9 +236,7 @@ where
|
||||
///
|
||||
/// Returns `false` if no solution was found (the decomposed matrix is singular).
|
||||
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2> {
|
||||
self.generic_solve_mut(b'N', b)
|
||||
}
|
||||
|
||||
@ -257,9 +245,7 @@ where
|
||||
///
|
||||
/// Returns `false` if no solution was found (the decomposed matrix is singular).
|
||||
pub fn solve_transpose_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2> {
|
||||
self.generic_solve_mut(b'T', b)
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num::Zero;
|
||||
use num_complex::Complex;
|
||||
@ -16,30 +16,25 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||
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> +
|
||||
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>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct QR<N: Scalar, R: DimMin<C>, C: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
|
||||
where DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>
|
||||
{
|
||||
qr: MatrixMN<N, R, C>,
|
||||
tau: VectorN<N, DimMinimum<R, C>>,
|
||||
@ -50,15 +45,13 @@ where
|
||||
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
|
||||
MatrixMN<N, R, C>: Copy,
|
||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: QRScalar + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>
|
||||
where DefaultAllocator: Allocator<N, R, C>
|
||||
+ Allocator<N, R, DimMinimum<R, C>>
|
||||
+ Allocator<N, DimMinimum<R, C>, C>
|
||||
+ Allocator<N, DimMinimum<R, C>>,
|
||||
+ Allocator<N, DimMinimum<R, C>>
|
||||
{
|
||||
/// Computes the QR decomposition of the matrix `m`.
|
||||
pub fn new(mut m: MatrixMN<N, R, C>) -> QR<N, R, C> {
|
||||
@ -105,11 +98,10 @@ where
|
||||
}
|
||||
|
||||
impl<N: QRReal + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>
|
||||
where DefaultAllocator: Allocator<N, R, C>
|
||||
+ Allocator<N, R, DimMinimum<R, C>>
|
||||
+ Allocator<N, DimMinimum<R, C>, C>
|
||||
+ Allocator<N, DimMinimum<R, C>>,
|
||||
+ Allocator<N, DimMinimum<R, C>>
|
||||
{
|
||||
/// Retrieves the matrices `(Q, R)` of this decompositions.
|
||||
pub fn unpack(
|
||||
@ -131,7 +123,8 @@ where
|
||||
return MatrixMN::from_element_generic(nrows, min_nrows_ncols, N::zero());
|
||||
}
|
||||
|
||||
let mut q = self.qr
|
||||
let mut q = self
|
||||
.qr
|
||||
.generic_slice((0, 0), (nrows, min_nrows_ncols))
|
||||
.into_owned();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num::Zero;
|
||||
use num_complex::Complex;
|
||||
@ -18,28 +18,23 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
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(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
serde(bound(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
VectorN<N, D>: Serialize,
|
||||
MatrixN<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RealSchur<N: Scalar, D: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>
|
||||
{
|
||||
re: VectorN<N, D>,
|
||||
im: VectorN<N, D>,
|
||||
@ -52,12 +47,10 @@ where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
MatrixN<N, D>: Copy,
|
||||
VectorN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: RealSchurScalar + Real, D: Dim> RealSchur<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
||||
{
|
||||
/// Computes the eigenvalues and real Schur form of the matrix `m`.
|
||||
///
|
||||
@ -152,9 +145,7 @@ where
|
||||
|
||||
/// Computes the complex eigenvalues of the decomposed matrix.
|
||||
pub fn complex_eigenvalues(&self) -> VectorN<Complex<N>, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<Complex<N>, D>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<Complex<N>, D> {
|
||||
let mut out = unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1) };
|
||||
|
||||
for i in 0..out.len() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num::Signed;
|
||||
use std::cmp;
|
||||
@ -15,34 +15,29 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
||||
Allocator<N, R, R> +
|
||||
Allocator<N, C, C>,
|
||||
MatrixN<N, R>: Serialize,
|
||||
MatrixN<N, C>: Serialize,
|
||||
VectorN<N, DimMinimum<R, C>>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
||||
serde(bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
||||
Allocator<N, R, R> +
|
||||
Allocator<N, C, C>,
|
||||
MatrixN<N, R>: Deserialize<'de>,
|
||||
MatrixN<N, C>: Deserialize<'de>,
|
||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SVD<N: Scalar, R: DimMin<C>, C: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, R> + Allocator<N, DimMinimum<R, C>> + Allocator<N, C, C>,
|
||||
where DefaultAllocator: Allocator<N, R, R> + Allocator<N, DimMinimum<R, C>> + Allocator<N, C, C>
|
||||
{
|
||||
/// The left-singular vectors `U` of this SVD.
|
||||
pub u: MatrixN<N, R>, // FIXME: should be MatrixMN<N, R, DimMinimum<R, C>>
|
||||
@ -58,28 +53,25 @@ where
|
||||
MatrixMN<N, R, R>: Copy,
|
||||
MatrixMN<N, C, C>: Copy,
|
||||
VectorN<N, DimMinimum<R, C>>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex<f32>`, `Complex<f64>`)
|
||||
/// supported by the Singular Value Decompotition.
|
||||
pub trait SVDScalar<R: DimMin<C>, C: Dim>: Scalar
|
||||
where
|
||||
DefaultAllocator: Allocator<Self, R, R>
|
||||
where DefaultAllocator: Allocator<Self, R, R>
|
||||
+ Allocator<Self, R, C>
|
||||
+ Allocator<Self, DimMinimum<R, C>>
|
||||
+ Allocator<Self, C, C>,
|
||||
+ Allocator<Self, C, C>
|
||||
{
|
||||
/// Computes the SVD decomposition of `m`.
|
||||
fn compute(m: MatrixMN<Self, R, C>) -> Option<SVD<Self, R, C>>;
|
||||
}
|
||||
|
||||
impl<N: SVDScalar<R, C>, R: DimMin<C>, C: Dim> SVD<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, R>
|
||||
where DefaultAllocator: Allocator<N, R, R>
|
||||
+ Allocator<N, R, C>
|
||||
+ Allocator<N, DimMinimum<R, C>>
|
||||
+ Allocator<N, C, C>,
|
||||
+ Allocator<N, C, C>
|
||||
{
|
||||
/// Computes the Singular Value Decomposition of `matrix`.
|
||||
pub fn new(m: MatrixMN<N, R, C>) -> Option<Self> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use num::Zero;
|
||||
use std::ops::MulAssign;
|
||||
@ -18,30 +18,25 @@ use lapack;
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
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(
|
||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||
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: Scalar, D: Dim>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>
|
||||
{
|
||||
/// The eigenvectors of the decomposed matrix.
|
||||
pub eigenvectors: MatrixN<N, D>,
|
||||
@ -55,12 +50,10 @@ where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
MatrixN<N, D>: Copy,
|
||||
VectorN<N, D>: Copy,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
impl<N: SymmetricEigenScalar + Real, D: Dim> SymmetricEigen<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
||||
{
|
||||
/// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`.
|
||||
///
|
||||
@ -89,7 +82,8 @@ where
|
||||
fn do_decompose(
|
||||
mut m: MatrixN<N, D>,
|
||||
eigenvectors: bool,
|
||||
) -> Option<(VectorN<N, D>, Option<MatrixN<N, D>>)> {
|
||||
) -> Option<(VectorN<N, D>, Option<MatrixN<N, D>>)>
|
||||
{
|
||||
assert!(
|
||||
m.is_square(),
|
||||
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::cmp;
|
||||
|
||||
use nl::Cholesky;
|
||||
use na::{DMatrix, DVector, Matrix3, Matrix4, Matrix4x3, Vector4};
|
||||
use nl::Cholesky;
|
||||
|
||||
quickcheck!{
|
||||
fn cholesky(m: DMatrix<f64>) -> bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::cmp;
|
||||
|
||||
use nl::LU;
|
||||
use na::{DMatrix, DVector, Matrix3x4, Matrix4, Matrix4x3, Vector4};
|
||||
use nl::LU;
|
||||
|
||||
quickcheck!{
|
||||
fn lup(m: DMatrix<f64>) -> bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod real_eigensystem;
|
||||
mod symmetric_eigen;
|
||||
mod cholesky;
|
||||
mod lu;
|
||||
mod qr;
|
||||
mod svd;
|
||||
mod real_eigensystem;
|
||||
mod real_schur;
|
||||
mod svd;
|
||||
mod symmetric_eigen;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nl::QR;
|
||||
use na::{DMatrix, Matrix4x3};
|
||||
use nl::QR;
|
||||
|
||||
quickcheck!{
|
||||
fn qr(m: DMatrix<f64>) -> bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::cmp;
|
||||
|
||||
use nl::Eigen;
|
||||
use na::{DMatrix, Matrix4};
|
||||
use nl::Eigen;
|
||||
|
||||
quickcheck!{
|
||||
fn eigensystem(n: usize) -> bool {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::cmp;
|
||||
use nl::RealSchur;
|
||||
use na::{DMatrix, Matrix4};
|
||||
use nl::RealSchur;
|
||||
use std::cmp;
|
||||
|
||||
quickcheck! {
|
||||
fn schur(n: usize) -> bool {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nl::SVD;
|
||||
use na::{DMatrix, Matrix3x4};
|
||||
use nl::SVD;
|
||||
|
||||
quickcheck!{
|
||||
fn svd(m: DMatrix<f64>) -> bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::cmp;
|
||||
|
||||
use nl::SymmetricEigen;
|
||||
use na::{DMatrix, Matrix4};
|
||||
use nl::SymmetricEigen;
|
||||
|
||||
quickcheck!{
|
||||
fn symmetric_eigen(n: usize) -> bool {
|
||||
|
3
rustfmt.toml
Normal file
3
rustfmt.toml
Normal file
@ -0,0 +1,3 @@
|
||||
unstable_features = true
|
||||
indent_style = "Block"
|
||||
where_single_line = true
|
@ -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:
|
||||
@ -162,8 +161,7 @@ impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matri
|
||||
}
|
||||
|
||||
impl<N, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S>
|
||||
where
|
||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
||||
where N: Scalar + Zero + ClosedAdd + ClosedMul
|
||||
{
|
||||
/// The dot product between two vectors or matrices (seen as vectors).
|
||||
///
|
||||
@ -325,9 +323,7 @@ where
|
||||
}
|
||||
|
||||
fn array_axpy<N>(y: &mut [N], a: N, x: &[N], beta: N, stride1: usize, stride2: usize, len: usize)
|
||||
where
|
||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
||||
{
|
||||
where N: Scalar + Zero + ClosedAdd + ClosedMul {
|
||||
for i in 0..len {
|
||||
unsafe {
|
||||
let y = y.get_unchecked_mut(i * stride1);
|
||||
@ -337,9 +333,7 @@ where
|
||||
}
|
||||
|
||||
fn array_ax<N>(y: &mut [N], a: N, x: &[N], stride1: usize, stride2: usize, len: usize)
|
||||
where
|
||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
||||
{
|
||||
where N: Scalar + Zero + ClosedAdd + ClosedMul {
|
||||
for i in 0..len {
|
||||
unsafe {
|
||||
*y.get_unchecked_mut(i * stride1) = a * *x.get_unchecked(i * stride2);
|
||||
@ -577,8 +571,7 @@ where
|
||||
}
|
||||
|
||||
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
|
||||
where
|
||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
||||
where N: Scalar + Zero + ClosedAdd + ClosedMul
|
||||
{
|
||||
/// Computes `self = alpha * x * y.transpose() + beta * self`.
|
||||
///
|
||||
@ -685,13 +678,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>() {
|
||||
@ -812,8 +811,7 @@ where
|
||||
}
|
||||
|
||||
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
|
||||
where
|
||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
||||
where N: Scalar + Zero + ClosedAdd + ClosedMul
|
||||
{
|
||||
/// Computes `self = alpha * x * y.transpose() + beta * self`, where `self` is a **symmetric**
|
||||
/// matrix.
|
||||
@ -871,8 +869,7 @@ where
|
||||
}
|
||||
|
||||
impl<N, D1: Dim, S: StorageMut<N, D1, D1>> SquareMatrix<N, D1, S>
|
||||
where
|
||||
N: Scalar + Zero + One + ClosedAdd + ClosedMul,
|
||||
where N: Scalar + Zero + One + ClosedAdd + ClosedMul
|
||||
{
|
||||
/// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`.
|
||||
///
|
||||
|
@ -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>
|
||||
@ -235,9 +238,7 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
||||
/// Computes in-place the transformation equal to `self` followed by an uniform scaling factor.
|
||||
#[inline]
|
||||
pub fn append_scaling_mut(&mut self, scaling: N)
|
||||
where
|
||||
D: DimNameSub<U1>,
|
||||
{
|
||||
where D: DimNameSub<U1> {
|
||||
let mut to_scale = self.fixed_rows_mut::<DimNameDiff<D, U1>>(0);
|
||||
to_scale *= scaling;
|
||||
}
|
||||
@ -245,9 +246,7 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
||||
/// Computes in-place the transformation equal to an uniform scaling factor followed by `self`.
|
||||
#[inline]
|
||||
pub fn prepend_scaling_mut(&mut self, scaling: N)
|
||||
where
|
||||
D: DimNameSub<U1>,
|
||||
{
|
||||
where D: DimNameSub<U1> {
|
||||
let mut to_scale = self.fixed_columns_mut::<DimNameDiff<D, U1>>(0);
|
||||
to_scale *= scaling;
|
||||
}
|
||||
@ -302,7 +301,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;
|
||||
@ -315,16 +315,16 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
||||
}
|
||||
|
||||
impl<N: Real, D: DimNameSub<U1>> Transformation<Point<N, DimNameDiff<D, U1>>> for MatrixN<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
+ Allocator<N, DimNameDiff<D, U1>>
|
||||
+ Allocator<N, DimNameDiff<D, U1>, DimNameDiff<D, U1>>,
|
||||
+ Allocator<N, DimNameDiff<D, U1>, DimNameDiff<D, U1>>
|
||||
{
|
||||
#[inline]
|
||||
fn transform_vector(
|
||||
&self,
|
||||
v: &VectorN<N, DimNameDiff<D, U1>>,
|
||||
) -> VectorN<N, DimNameDiff<D, U1>> {
|
||||
) -> VectorN<N, DimNameDiff<D, U1>>
|
||||
{
|
||||
let transform = self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0);
|
||||
let normalizer = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0);
|
||||
let n = normalizer.tr_dot(&v);
|
||||
@ -341,9 +341,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;
|
||||
|
@ -8,11 +8,8 @@ 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 +67,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;
|
||||
|
@ -26,8 +26,7 @@ use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vector, Ve
|
||||
*
|
||||
*/
|
||||
impl<N: Scalar, R: Dim, C: Dim> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
where DefaultAllocator: Allocator<N, R, C>
|
||||
{
|
||||
/// Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics
|
||||
/// if `nrows != R::to_usize()` or `ncols != C::to_usize()`.
|
||||
@ -55,18 +54,14 @@ where
|
||||
/// Creates a matrix with all its elements set to 0.
|
||||
#[inline]
|
||||
pub fn zeros_generic(nrows: R, ncols: C) -> Self
|
||||
where
|
||||
N: Zero,
|
||||
{
|
||||
where N: Zero {
|
||||
Self::from_element_generic(nrows, ncols, N::zero())
|
||||
}
|
||||
|
||||
/// Creates a matrix with all its elements filled by an iterator.
|
||||
#[inline]
|
||||
pub fn from_iterator_generic<I>(nrows: R, ncols: C, iter: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = N>,
|
||||
{
|
||||
where I: IntoIterator<Item = N> {
|
||||
Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter))
|
||||
}
|
||||
|
||||
@ -105,9 +100,7 @@ where
|
||||
/// coordinates.
|
||||
#[inline]
|
||||
pub fn from_fn_generic<F>(nrows: R, ncols: C, mut f: F) -> Self
|
||||
where
|
||||
F: FnMut(usize, usize) -> N,
|
||||
{
|
||||
where F: FnMut(usize, usize) -> N {
|
||||
let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols) };
|
||||
|
||||
for j in 0..ncols.value() {
|
||||
@ -125,9 +118,7 @@ where
|
||||
/// to the identity matrix. All other entries are set to zero.
|
||||
#[inline]
|
||||
pub fn identity_generic(nrows: R, ncols: C) -> Self
|
||||
where
|
||||
N: Zero + One,
|
||||
{
|
||||
where N: Zero + One {
|
||||
Self::from_diagonal_element_generic(nrows, ncols, N::one())
|
||||
}
|
||||
|
||||
@ -137,9 +128,7 @@ where
|
||||
/// to the identity matrix. All other entries are set to zero.
|
||||
#[inline]
|
||||
pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: N) -> Self
|
||||
where
|
||||
N: Zero + One,
|
||||
{
|
||||
where N: Zero + One {
|
||||
let mut res = Self::zeros_generic(nrows, ncols);
|
||||
|
||||
for i in 0..::min(nrows.value(), ncols.value()) {
|
||||
@ -155,9 +144,7 @@ where
|
||||
/// Panics if `elts.len()` is larger than the minimum among `nrows` and `ncols`.
|
||||
#[inline]
|
||||
pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[N]) -> Self
|
||||
where
|
||||
N: Zero,
|
||||
{
|
||||
where N: Zero {
|
||||
let mut res = Self::zeros_generic(nrows, ncols);
|
||||
assert!(
|
||||
elts.len() <= ::min(nrows.value(), ncols.value()),
|
||||
@ -189,9 +176,7 @@ where
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn from_rows<SB>(rows: &[Matrix<N, U1, C, SB>]) -> Self
|
||||
where
|
||||
SB: Storage<N, U1, C>,
|
||||
{
|
||||
where SB: Storage<N, U1, C> {
|
||||
assert!(rows.len() > 0, "At least one row must be given.");
|
||||
let nrows = R::try_to_usize().unwrap_or(rows.len());
|
||||
let ncols = rows[0].len();
|
||||
@ -231,9 +216,7 @@ where
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn from_columns<SB>(columns: &[Vector<N, R, SB>]) -> Self
|
||||
where
|
||||
SB: Storage<N, R>,
|
||||
{
|
||||
where SB: Storage<N, R> {
|
||||
assert!(columns.len() > 0, "At least one column must be given.");
|
||||
let ncols = C::try_to_usize().unwrap_or(columns.len());
|
||||
let nrows = columns[0].len();
|
||||
@ -259,9 +242,7 @@ where
|
||||
#[inline]
|
||||
#[cfg(feature = "std")]
|
||||
pub fn new_random_generic(nrows: R, ncols: C) -> Self
|
||||
where
|
||||
Standard: Distribution<N>,
|
||||
{
|
||||
where Standard: Distribution<N> {
|
||||
Self::from_fn_generic(nrows, ncols, |_, _| rand::random())
|
||||
}
|
||||
|
||||
@ -272,7 +253,8 @@ where
|
||||
ncols: C,
|
||||
distribution: &mut Distr,
|
||||
rng: &mut G,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng))
|
||||
}
|
||||
}
|
||||
@ -302,9 +284,7 @@ where
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn from_diagonal<SB: Storage<N, D>>(diag: &Vector<N, D, SB>) -> Self
|
||||
where
|
||||
N: Zero,
|
||||
{
|
||||
where N: Zero {
|
||||
let (dim, _) = diag.data.shape();
|
||||
let mut res = Self::zeros_generic(dim, dim);
|
||||
|
||||
@ -929,9 +909,7 @@ where
|
||||
/// The column vector with a 1 as its first component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn x() -> Self
|
||||
where
|
||||
R::Value: Cmp<typenum::U0, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U0, Output = Greater> {
|
||||
let mut res = Self::zeros();
|
||||
unsafe {
|
||||
*res.vget_unchecked_mut(0) = N::one();
|
||||
@ -943,9 +921,7 @@ where
|
||||
/// The column vector with a 1 as its second component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn y() -> Self
|
||||
where
|
||||
R::Value: Cmp<typenum::U1, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U1, Output = Greater> {
|
||||
let mut res = Self::zeros();
|
||||
unsafe {
|
||||
*res.vget_unchecked_mut(1) = N::one();
|
||||
@ -957,9 +933,7 @@ where
|
||||
/// The column vector with a 1 as its third component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn z() -> Self
|
||||
where
|
||||
R::Value: Cmp<typenum::U2, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U2, Output = Greater> {
|
||||
let mut res = Self::zeros();
|
||||
unsafe {
|
||||
*res.vget_unchecked_mut(2) = N::one();
|
||||
@ -971,9 +945,7 @@ where
|
||||
/// The column vector with a 1 as its fourth component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn w() -> Self
|
||||
where
|
||||
R::Value: Cmp<typenum::U3, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U3, Output = Greater> {
|
||||
let mut res = Self::zeros();
|
||||
unsafe {
|
||||
*res.vget_unchecked_mut(3) = N::one();
|
||||
@ -985,9 +957,7 @@ where
|
||||
/// The column vector with a 1 as its fifth component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn a() -> Self
|
||||
where
|
||||
R::Value: Cmp<typenum::U4, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U4, Output = Greater> {
|
||||
let mut res = Self::zeros();
|
||||
unsafe {
|
||||
*res.vget_unchecked_mut(4) = N::one();
|
||||
@ -999,9 +969,7 @@ where
|
||||
/// The column vector with a 1 as its sixth component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn b() -> Self
|
||||
where
|
||||
R::Value: Cmp<typenum::U5, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U5, Output = Greater> {
|
||||
let mut res = Self::zeros();
|
||||
unsafe {
|
||||
*res.vget_unchecked_mut(5) = N::one();
|
||||
@ -1013,54 +981,42 @@ where
|
||||
/// The unit column vector with a 1 as its first component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn x_axis() -> Unit<Self>
|
||||
where
|
||||
R::Value: Cmp<typenum::U0, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U0, Output = Greater> {
|
||||
Unit::new_unchecked(Self::x())
|
||||
}
|
||||
|
||||
/// The unit column vector with a 1 as its second component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn y_axis() -> Unit<Self>
|
||||
where
|
||||
R::Value: Cmp<typenum::U1, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U1, Output = Greater> {
|
||||
Unit::new_unchecked(Self::y())
|
||||
}
|
||||
|
||||
/// The unit column vector with a 1 as its third component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn z_axis() -> Unit<Self>
|
||||
where
|
||||
R::Value: Cmp<typenum::U2, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U2, Output = Greater> {
|
||||
Unit::new_unchecked(Self::z())
|
||||
}
|
||||
|
||||
/// The unit column vector with a 1 as its fourth component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn w_axis() -> Unit<Self>
|
||||
where
|
||||
R::Value: Cmp<typenum::U3, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U3, Output = Greater> {
|
||||
Unit::new_unchecked(Self::w())
|
||||
}
|
||||
|
||||
/// The unit column vector with a 1 as its fifth component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn a_axis() -> Unit<Self>
|
||||
where
|
||||
R::Value: Cmp<typenum::U4, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U4, Output = Greater> {
|
||||
Unit::new_unchecked(Self::a())
|
||||
}
|
||||
|
||||
/// The unit column vector with a 1 as its sixth component, and zero elsewhere.
|
||||
#[inline]
|
||||
pub fn b_axis() -> Unit<Self>
|
||||
where
|
||||
R::Value: Cmp<typenum::U5, Output = Greater>,
|
||||
{
|
||||
where R::Value: Cmp<typenum::U5, Output = Greater> {
|
||||
Unit::new_unchecked(Self::b())
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
||||
ncols: C,
|
||||
rstride: RStride,
|
||||
cstride: CStride,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
let data = SliceStorage::from_raw_parts(
|
||||
data.as_ptr().offset(start as isize),
|
||||
(nrows, ncols),
|
||||
@ -42,7 +43,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
||||
ncols: C,
|
||||
rstride: RStride,
|
||||
cstride: CStride,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
// NOTE: The assertion implements the following formula, but without subtractions to avoid
|
||||
// underflow panics:
|
||||
// len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1
|
||||
@ -73,7 +75,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
||||
ncols: C,
|
||||
rstride: RStride,
|
||||
cstride: CStride,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
let data = SliceStorageMut::from_raw_parts(
|
||||
data.as_mut_ptr().offset(start as isize),
|
||||
(nrows, ncols),
|
||||
@ -93,7 +96,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
||||
ncols: C,
|
||||
rstride: RStride,
|
||||
cstride: CStride,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
// NOTE: The assertion implements the following formula, but without subtractions to avoid
|
||||
// underflow panics:
|
||||
// len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1
|
||||
@ -120,7 +124,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> {
|
||||
start: usize,
|
||||
nrows: R,
|
||||
ncols: C,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
|
||||
}
|
||||
|
||||
@ -145,7 +150,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> {
|
||||
start: usize,
|
||||
nrows: R,
|
||||
ncols: C,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
{
|
||||
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -54,7 +54,8 @@ where
|
||||
nrows: R,
|
||||
ncols: C,
|
||||
iter: I,
|
||||
) -> Self::Buffer {
|
||||
) -> Self::Buffer
|
||||
{
|
||||
let mut res = unsafe { Self::allocate_uninitialized(nrows, ncols) };
|
||||
let mut count = 0;
|
||||
|
||||
@ -93,7 +94,8 @@ impl<N: Scalar, C: Dim> Allocator<N, Dynamic, C> for DefaultAllocator {
|
||||
nrows: Dynamic,
|
||||
ncols: C,
|
||||
iter: I,
|
||||
) -> Self::Buffer {
|
||||
) -> Self::Buffer
|
||||
{
|
||||
let it = iter.into_iter();
|
||||
let res: Vec<N> = it.collect();
|
||||
assert!(res.len() == nrows.value() * ncols.value(),
|
||||
@ -123,7 +125,8 @@ impl<N: Scalar, R: DimName> Allocator<N, R, Dynamic> for DefaultAllocator {
|
||||
nrows: R,
|
||||
ncols: Dynamic,
|
||||
iter: I,
|
||||
) -> Self::Buffer {
|
||||
) -> Self::Buffer
|
||||
{
|
||||
let it = iter.into_iter();
|
||||
let res: Vec<N> = it.collect();
|
||||
assert!(res.len() == nrows.value() * ncols.value(),
|
||||
@ -154,7 +157,8 @@ where
|
||||
rto: RTo,
|
||||
cto: CTo,
|
||||
buf: <Self as Allocator<N, RFrom, CFrom>>::Buffer,
|
||||
) -> MatrixArray<N, RTo, CTo> {
|
||||
) -> MatrixArray<N, RTo, CTo>
|
||||
{
|
||||
let mut res = <Self as Allocator<N, RTo, CTo>>::allocate_uninitialized(rto, cto);
|
||||
|
||||
let (rfrom, cfrom) = buf.shape();
|
||||
@ -182,7 +186,8 @@ where
|
||||
rto: Dynamic,
|
||||
cto: CTo,
|
||||
buf: MatrixArray<N, RFrom, CFrom>,
|
||||
) -> MatrixVec<N, Dynamic, CTo> {
|
||||
) -> MatrixVec<N, Dynamic, CTo>
|
||||
{
|
||||
let mut res = <Self as Allocator<N, Dynamic, CTo>>::allocate_uninitialized(rto, cto);
|
||||
|
||||
let (rfrom, cfrom) = buf.shape();
|
||||
@ -210,7 +215,8 @@ where
|
||||
rto: RTo,
|
||||
cto: Dynamic,
|
||||
buf: MatrixArray<N, RFrom, CFrom>,
|
||||
) -> MatrixVec<N, RTo, Dynamic> {
|
||||
) -> MatrixVec<N, RTo, Dynamic>
|
||||
{
|
||||
let mut res = <Self as Allocator<N, RTo, Dynamic>>::allocate_uninitialized(rto, cto);
|
||||
|
||||
let (rfrom, cfrom) = buf.shape();
|
||||
@ -233,7 +239,8 @@ impl<N: Scalar, CFrom: Dim, CTo: Dim> Reallocator<N, Dynamic, CFrom, Dynamic, CT
|
||||
rto: Dynamic,
|
||||
cto: CTo,
|
||||
buf: MatrixVec<N, Dynamic, CFrom>,
|
||||
) -> MatrixVec<N, Dynamic, CTo> {
|
||||
) -> MatrixVec<N, Dynamic, CTo>
|
||||
{
|
||||
let new_buf = buf.resize(rto.value() * cto.value());
|
||||
MatrixVec::new(rto, cto, new_buf)
|
||||
}
|
||||
@ -248,7 +255,8 @@ impl<N: Scalar, CFrom: Dim, RTo: DimName> Reallocator<N, Dynamic, CFrom, RTo, Dy
|
||||
rto: RTo,
|
||||
cto: Dynamic,
|
||||
buf: MatrixVec<N, Dynamic, CFrom>,
|
||||
) -> MatrixVec<N, RTo, Dynamic> {
|
||||
) -> MatrixVec<N, RTo, Dynamic>
|
||||
{
|
||||
let new_buf = buf.resize(rto.value() * cto.value());
|
||||
MatrixVec::new(rto, cto, new_buf)
|
||||
}
|
||||
@ -263,7 +271,8 @@ impl<N: Scalar, RFrom: DimName, CTo: Dim> Reallocator<N, RFrom, Dynamic, Dynamic
|
||||
rto: Dynamic,
|
||||
cto: CTo,
|
||||
buf: MatrixVec<N, RFrom, Dynamic>,
|
||||
) -> MatrixVec<N, Dynamic, CTo> {
|
||||
) -> MatrixVec<N, Dynamic, CTo>
|
||||
{
|
||||
let new_buf = buf.resize(rto.value() * cto.value());
|
||||
MatrixVec::new(rto, cto, new_buf)
|
||||
}
|
||||
@ -278,7 +287,8 @@ impl<N: Scalar, RFrom: DimName, RTo: DimName> Reallocator<N, RFrom, Dynamic, RTo
|
||||
rto: RTo,
|
||||
cto: Dynamic,
|
||||
buf: MatrixVec<N, RFrom, Dynamic>,
|
||||
) -> MatrixVec<N, RTo, Dynamic> {
|
||||
) -> MatrixVec<N, RTo, Dynamic>
|
||||
{
|
||||
let new_buf = buf.resize(rto.value() * cto.value());
|
||||
MatrixVec::new(rto, cto, new_buf)
|
||||
}
|
||||
|
@ -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")]
|
||||
@ -30,9 +30,7 @@ impl Dynamic {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl Serialize for Dynamic {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
self.value.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@ -40,9 +38,7 @@ impl Serialize for Dynamic {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<'de> Deserialize<'de> for Dynamic {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
where D: Deserializer<'de> {
|
||||
usize::deserialize(deserializer).map(|x| Dynamic { value: x })
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,7 @@ impl<N: Scalar + Zero, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Extracts the upper triangular part of this matrix (including the diagonal).
|
||||
#[inline]
|
||||
pub fn upper_triangle(&self) -> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
let mut res = self.clone_owned();
|
||||
res.fill_lower_triangle(N::zero(), 1);
|
||||
|
||||
@ -28,9 +26,7 @@ impl<N: Scalar + Zero, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Extracts the upper triangular part of this matrix (including the diagonal).
|
||||
#[inline]
|
||||
pub fn lower_triangle(&self) -> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
let mut res = self.clone_owned();
|
||||
res.fill_upper_triangle(N::zero(), 1);
|
||||
|
||||
@ -50,9 +46,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Fills `self` with the identity matrix.
|
||||
#[inline]
|
||||
pub fn fill_with_identity(&mut self)
|
||||
where
|
||||
N: Zero + One,
|
||||
{
|
||||
where N: Zero + One {
|
||||
self.fill(N::zero());
|
||||
self.fill_diagonal(N::one());
|
||||
}
|
||||
@ -285,7 +279,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 +443,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);
|
||||
|
||||
@ -549,9 +545,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix<N>
|
||||
where
|
||||
DefaultAllocator: Reallocator<N, R, C, Dynamic, Dynamic>,
|
||||
{
|
||||
where DefaultAllocator: Reallocator<N, R, C, Dynamic, Dynamic> {
|
||||
self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val)
|
||||
}
|
||||
|
||||
@ -560,9 +554,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more
|
||||
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
|
||||
pub fn fixed_resize<R2: DimName, C2: DimName>(self, val: N) -> MatrixMN<N, R2, C2>
|
||||
where
|
||||
DefaultAllocator: Reallocator<N, R, C, R2, C2>,
|
||||
{
|
||||
where DefaultAllocator: Reallocator<N, R, C, R2, C2> {
|
||||
self.resize_generic(R2::name(), C2::name(), val)
|
||||
}
|
||||
|
||||
@ -640,7 +632,8 @@ unsafe fn compress_rows<N: Scalar>(
|
||||
ncols: usize,
|
||||
i: usize,
|
||||
nremove: usize,
|
||||
) {
|
||||
)
|
||||
{
|
||||
let new_nrows = nrows - nremove;
|
||||
|
||||
if new_nrows == 0 || ncols == 0 {
|
||||
@ -679,7 +672,8 @@ unsafe fn extend_rows<N: Scalar>(
|
||||
ncols: usize,
|
||||
i: usize,
|
||||
ninsert: usize,
|
||||
) {
|
||||
)
|
||||
{
|
||||
let new_nrows = nrows + ninsert;
|
||||
|
||||
if new_nrows == 0 || ncols == 0 {
|
||||
|
@ -18,9 +18,7 @@ pub fn reject<G: Gen, F: FnMut(&T) -> bool, T: Arbitrary>(g: &mut G, f: F) -> T
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
pub fn reject_rand<G: Rng + ?Sized, F: FnMut(&T) -> bool, T>(g: &mut G, f: F) -> T
|
||||
where
|
||||
Standard: Distribution<T>,
|
||||
{
|
||||
where Standard: Distribution<T> {
|
||||
use std::iter;
|
||||
iter::repeat(()).map(|_| g.gen()).find(f).unwrap()
|
||||
}
|
||||
|
@ -3,21 +3,20 @@
|
||||
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,
|
||||
ptr: $Ptr,
|
||||
inner_ptr: $Ptr,
|
||||
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)>
|
||||
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)>,
|
||||
}
|
||||
|
||||
// FIXME: we need to specialize for the case where the matrix storage is owned (in which
|
||||
@ -25,23 +24,25 @@ macro_rules! iterator {
|
||||
impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage<N, R, C>> $Name<'a, N, R, C, S> {
|
||||
/// Creates a new iterator for the given matrix storage.
|
||||
pub fn new(storage: $SRef) -> $Name<'a, N, R, C, S> {
|
||||
let shape = storage.shape();
|
||||
let shape = storage.shape();
|
||||
let strides = storage.strides();
|
||||
let inner_offset = shape.0.value() * strides.0.value();
|
||||
let ptr = storage.$ptr();
|
||||
|
||||
$Name {
|
||||
ptr: ptr,
|
||||
ptr: ptr,
|
||||
inner_ptr: ptr,
|
||||
inner_end: unsafe { ptr.offset(inner_offset as isize) },
|
||||
size: shape.0.value() * shape.1.value(),
|
||||
strides: strides,
|
||||
_phantoms: PhantomData
|
||||
size: shape.0.value() * shape.1.value(),
|
||||
strides: strides,
|
||||
_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);
|
||||
|
@ -99,9 +99,7 @@ where
|
||||
S: Serialize,
|
||||
{
|
||||
fn serialize<T>(&self, serializer: T) -> Result<T::Ok, T::Error>
|
||||
where
|
||||
T: Serializer,
|
||||
{
|
||||
where T: Serializer {
|
||||
self.data.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@ -115,9 +113,7 @@ where
|
||||
S: Deserialize<'de>,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
where D: Deserializer<'de> {
|
||||
S::deserialize(deserializer).map(|x| Matrix {
|
||||
data: x,
|
||||
_phantoms: PhantomData,
|
||||
@ -319,9 +315,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Moves this matrix into one that owns its data.
|
||||
#[inline]
|
||||
pub fn into_owned(self) -> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
Matrix::from_data(self.data.into_owned())
|
||||
}
|
||||
|
||||
@ -355,9 +349,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Clones this matrix to one that owns its data.
|
||||
#[inline]
|
||||
pub fn clone_owned(&self) -> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
Matrix::from_data(self.data.clone_owned())
|
||||
}
|
||||
|
||||
@ -393,9 +385,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Returns a matrix containing the result of `f` applied to each of its entries.
|
||||
#[inline]
|
||||
pub fn map<N2: Scalar, F: FnMut(N) -> N2>(&self, mut f: F) -> MatrixMN<N2, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N2, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N2, R, C> {
|
||||
let (nrows, ncols) = self.data.shape();
|
||||
|
||||
let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols) };
|
||||
@ -541,9 +531,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Transposes `self`.
|
||||
#[inline]
|
||||
pub fn transpose(&self) -> MatrixMN<N, C, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, C, R>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, C, R> {
|
||||
let (nrows, ncols) = self.data.shape();
|
||||
|
||||
unsafe {
|
||||
@ -666,9 +654,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Replaces each component of `self` by the result of a closure `f` applied on it.
|
||||
#[inline]
|
||||
pub fn apply<F: FnMut(N) -> N>(&mut self, mut f: F)
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
let (nrows, ncols) = self.shape();
|
||||
|
||||
for j in 0..ncols {
|
||||
@ -765,9 +751,7 @@ impl<N: Real, R: Dim, C: Dim, S: Storage<Complex<N>, R, C>> Matrix<Complex<N>, R
|
||||
/// The conjugate transposition of `self`.
|
||||
#[inline]
|
||||
pub fn conjugate_transpose(&self) -> MatrixMN<Complex<N>, C, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<Complex<N>, C, R>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<Complex<N>, C, R> {
|
||||
let (nrows, ncols) = self.data.shape();
|
||||
|
||||
unsafe {
|
||||
@ -808,9 +792,7 @@ impl<N: Scalar, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S> {
|
||||
/// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0.
|
||||
#[inline]
|
||||
pub fn diagonal(&self) -> VectorN<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, D> {
|
||||
assert!(
|
||||
self.is_square(),
|
||||
"Unable to get the diagonal of a non-square matrix."
|
||||
@ -831,9 +813,7 @@ impl<N: Scalar, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S> {
|
||||
/// Computes a trace of a square matrix, i.e., the sum of its diagonal elements.
|
||||
#[inline]
|
||||
pub fn trace(&self) -> N
|
||||
where
|
||||
N: Ring,
|
||||
{
|
||||
where N: Ring {
|
||||
assert!(
|
||||
self.is_square(),
|
||||
"Cannot compute the trace of non-square matrix."
|
||||
@ -855,9 +835,7 @@ impl<N: Scalar + Zero, D: DimAdd<U1>, S: Storage<N, D>> Vector<N, D, S> {
|
||||
/// coordinates.
|
||||
#[inline]
|
||||
pub fn to_homogeneous(&self) -> VectorN<N, DimSum<D, U1>>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, DimSum<D, U1>>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, DimSum<D, U1>> {
|
||||
let len = self.len();
|
||||
let hnrows = DimSum::<D, U1>::from_usize(len + 1);
|
||||
let mut res = unsafe { VectorN::<N, _>::new_uninitialized_generic(hnrows, U1) };
|
||||
@ -923,7 +901,8 @@ where
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
) -> bool
|
||||
{
|
||||
self.relative_eq(other, epsilon, max_relative)
|
||||
}
|
||||
}
|
||||
@ -1220,8 +1199,7 @@ impl<N: Scalar + Ring, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
}
|
||||
|
||||
impl<N: Real, S: Storage<N, U3>> Vector<N, U3, S>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, U3>,
|
||||
where DefaultAllocator: Allocator<N, U3>
|
||||
{
|
||||
/// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`.
|
||||
#[inline]
|
||||
@ -1311,18 +1289,14 @@ impl<N: Real, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
/// Returns a normalized version of this matrix.
|
||||
#[inline]
|
||||
pub fn normalize(&self) -> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
self / self.norm()
|
||||
}
|
||||
|
||||
/// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`.
|
||||
#[inline]
|
||||
pub fn try_normalize(&self, min_norm: N) -> Option<MatrixMN<N, R, C>>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
let n = self.norm();
|
||||
|
||||
if n <= min_norm {
|
||||
@ -1446,7 +1420,8 @@ where
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
) -> bool
|
||||
{
|
||||
self.as_ref()
|
||||
.relative_eq(other.as_ref(), epsilon, max_relative)
|
||||
}
|
||||
|
@ -146,8 +146,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Real, R: DimName, C: DimName> NormedSpace for MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
where DefaultAllocator: Allocator<N, R, C>
|
||||
{
|
||||
#[inline]
|
||||
fn norm_squared(&self) -> N {
|
||||
@ -181,8 +180,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Real, R: DimName, C: DimName> InnerSpace for MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
where DefaultAllocator: Allocator<N, R, C>
|
||||
{
|
||||
type Real = N;
|
||||
|
||||
@ -202,8 +200,7 @@ where
|
||||
// − use `x()` instead of `::canonical_basis_element`
|
||||
// − use `::new(x, y, z)` instead of `::from_slice`
|
||||
impl<N: Real, R: DimName, C: DimName> FiniteDimInnerSpace for MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
where DefaultAllocator: Allocator<N, R, C>
|
||||
{
|
||||
#[inline]
|
||||
fn orthonormalize(vs: &mut [MatrixMN<N, R, C>]) -> usize {
|
||||
@ -236,9 +233,7 @@ where
|
||||
|
||||
#[inline]
|
||||
fn orthonormal_subspace_basis<F>(vs: &[Self], mut f: F)
|
||||
where
|
||||
F: FnMut(&Self) -> bool,
|
||||
{
|
||||
where F: FnMut(&Self) -> bool {
|
||||
// FIXME: is this necessary?
|
||||
assert!(
|
||||
vs.len() <= Self::dimension(),
|
||||
|
@ -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
|
||||
@ -184,17 +182,13 @@ where
|
||||
|
||||
#[inline]
|
||||
fn into_owned(self) -> Owned<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clone_owned(&self) -> Owned<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
let it = self.iter().cloned();
|
||||
|
||||
DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it)
|
||||
@ -234,8 +228,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 +238,7 @@ where
|
||||
R::Value: Mul<C::Value>,
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/*
|
||||
*
|
||||
@ -264,9 +256,7 @@ where
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?;
|
||||
|
||||
for e in self.iter() {
|
||||
@ -287,9 +277,7 @@ where
|
||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||
{
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
where D: Deserializer<'a> {
|
||||
deserializer.deserialize_seq(MatrixArrayVisitor::new())
|
||||
}
|
||||
}
|
||||
@ -334,9 +322,7 @@ where
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<MatrixArray<N, R, C>, V::Error>
|
||||
where
|
||||
V: SeqAccess<'a>,
|
||||
{
|
||||
where V: SeqAccess<'a> {
|
||||
let mut out: Self::Value = unsafe { mem::uninitialized() };
|
||||
let mut curr = 0;
|
||||
|
||||
|
@ -206,7 +206,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
start: (usize, usize),
|
||||
shape: (usize, usize),
|
||||
steps: (usize, usize),
|
||||
) {
|
||||
)
|
||||
{
|
||||
let my_shape = self.shape();
|
||||
// NOTE: we don't do any subtraction to avoid underflow for zero-sized matrices.
|
||||
//
|
||||
@ -803,7 +804,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
pub fn rows_range<RowRange: SliceRange<R>>(
|
||||
&self,
|
||||
rows: RowRange,
|
||||
) -> MatrixSlice<N, RowRange::Size, C, S::RStride, S::CStride> {
|
||||
) -> MatrixSlice<N, RowRange::Size, C, S::RStride, S::CStride>
|
||||
{
|
||||
self.slice_range(rows, ..)
|
||||
}
|
||||
|
||||
@ -812,7 +814,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
pub fn columns_range<ColRange: SliceRange<C>>(
|
||||
&self,
|
||||
cols: ColRange,
|
||||
) -> MatrixSlice<N, R, ColRange::Size, S::RStride, S::CStride> {
|
||||
) -> MatrixSlice<N, R, ColRange::Size, S::RStride, S::CStride>
|
||||
{
|
||||
self.slice_range(.., cols)
|
||||
}
|
||||
}
|
||||
@ -841,7 +844,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
||||
pub fn rows_range_mut<RowRange: SliceRange<R>>(
|
||||
&mut self,
|
||||
rows: RowRange,
|
||||
) -> MatrixSliceMut<N, RowRange::Size, C, S::RStride, S::CStride> {
|
||||
) -> MatrixSliceMut<N, RowRange::Size, C, S::RStride, S::CStride>
|
||||
{
|
||||
self.slice_range_mut(rows, ..)
|
||||
}
|
||||
|
||||
@ -850,7 +854,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
||||
pub fn columns_range_mut<ColRange: SliceRange<C>>(
|
||||
&mut self,
|
||||
cols: ColRange,
|
||||
) -> MatrixSliceMut<N, R, ColRange::Size, S::RStride, S::CStride> {
|
||||
) -> MatrixSliceMut<N, R, ColRange::Size, S::RStride, S::CStride>
|
||||
{
|
||||
self.slice_range_mut(.., cols)
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +94,7 @@ impl<N, R: Dim, C: Dim> Deref for MatrixVec<N, R, C> {
|
||||
*
|
||||
*/
|
||||
unsafe impl<N: Scalar, C: Dim> Storage<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
||||
where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||
{
|
||||
type RStride = U1;
|
||||
type CStride = Dynamic;
|
||||
@ -122,17 +121,13 @@ where
|
||||
|
||||
#[inline]
|
||||
fn into_owned(self) -> Owned<N, Dynamic, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, Dynamic, C> {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clone_owned(&self) -> Owned<N, Dynamic, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, Dynamic, C> {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
@ -143,8 +138,7 @@ where
|
||||
}
|
||||
|
||||
unsafe impl<N: Scalar, R: DimName> Storage<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
||||
where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||
{
|
||||
type RStride = U1;
|
||||
type CStride = R;
|
||||
@ -171,17 +165,13 @@ where
|
||||
|
||||
#[inline]
|
||||
fn into_owned(self) -> Owned<N, R, Dynamic>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, Dynamic> {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clone_owned(&self) -> Owned<N, R, Dynamic>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, Dynamic>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, Dynamic> {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
@ -197,8 +187,7 @@ where
|
||||
*
|
||||
*/
|
||||
unsafe impl<N: Scalar, C: Dim> StorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
||||
where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||
{
|
||||
#[inline]
|
||||
fn ptr_mut(&mut self) -> *mut N {
|
||||
@ -211,21 +200,14 @@ 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
|
||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
||||
where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||
{
|
||||
#[inline]
|
||||
fn ptr_mut(&mut self) -> *mut N {
|
||||
@ -253,14 +235,8 @@ 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};
|
||||
|
||||
/*
|
||||
*
|
||||
@ -722,9 +724,7 @@ impl<N: Scalar + ClosedAdd, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C,
|
||||
/// Adds a scalar to `self`.
|
||||
#[inline]
|
||||
pub fn add_scalar(&self, rhs: N) -> MatrixMN<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>,
|
||||
{
|
||||
where DefaultAllocator: Allocator<N, R, C> {
|
||||
let mut res = self.clone_owned();
|
||||
res.add_scalar_mut(rhs);
|
||||
res
|
||||
@ -733,9 +733,7 @@ impl<N: Scalar + ClosedAdd, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C,
|
||||
/// Adds a scalar to `self` in-place.
|
||||
#[inline]
|
||||
pub fn add_scalar_mut(&mut self, rhs: N)
|
||||
where
|
||||
S: StorageMut<N, R, C>,
|
||||
{
|
||||
where S: StorageMut<N, R, C> {
|
||||
for e in self.iter_mut() {
|
||||
*e += rhs
|
||||
}
|
||||
@ -783,7 +781,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();
|
||||
|
||||
|
@ -100,8 +100,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
||||
}
|
||||
|
||||
impl<N: Real, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
/// Checks that this matrix is orthogonal and has a determinant equal to 1.
|
||||
#[inline]
|
||||
|
@ -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.
|
||||
@ -105,13 +105,11 @@ pub unsafe trait Storage<N: Scalar, R: Dim, C: Dim = U1>: Debug + Sized {
|
||||
|
||||
/// Builds a matrix data storage that does not contain any reference.
|
||||
fn into_owned(self) -> Owned<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>;
|
||||
where DefaultAllocator: Allocator<N, R, C>;
|
||||
|
||||
/// Clones this data storage to one that does not contain any reference.
|
||||
fn clone_owned(&self) -> Owned<N, R, C>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, R, C>;
|
||||
where DefaultAllocator: Allocator<N, R, C>;
|
||||
}
|
||||
|
||||
/// Trait implemented by matrix data storage that can provide a mutable access to its elements.
|
||||
@ -177,8 +175,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 +185,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),*]);*) => {
|
||||
$(
|
||||
@ -64,4 +63,4 @@ impl_swizzle!(
|
||||
where U2: zzx() -> Vector3[2, 2, 0];
|
||||
where U2: zzy() -> Vector3[2, 2, 1];
|
||||
where U2: zzz() -> Vector3[2, 2, 2]
|
||||
);
|
||||
);
|
||||
|
@ -25,9 +25,7 @@ pub struct Unit<T> {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<T: Serialize> Serialize for Unit<T> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
self.value.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@ -35,9 +33,7 @@ impl<T: Serialize> Serialize for Unit<T> {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
where D: Deserializer<'de> {
|
||||
T::deserialize(deserializer).map(|x| Unit { value: x })
|
||||
}
|
||||
}
|
||||
@ -143,8 +139,7 @@ impl<T> AsRef<T> for Unit<T> {
|
||||
*
|
||||
*/
|
||||
impl<T: NormedSpace> SubsetOf<T> for Unit<T>
|
||||
where
|
||||
T::Field: RelativeEq,
|
||||
where T::Field: RelativeEq
|
||||
{
|
||||
#[inline]
|
||||
fn to_superset(&self) -> T {
|
||||
|
@ -13,15 +13,13 @@ use num_complex::Complex;
|
||||
/// A random orthogonal matrix.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RandomOrthogonal<N: Real, D: Dim = Dynamic>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
m: MatrixN<N, D>,
|
||||
}
|
||||
|
||||
impl<N: Real, D: Dim> RandomOrthogonal<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
/// Retrieve the generated matrix.
|
||||
pub fn unwrap(self) -> MatrixN<N, D> {
|
||||
|
@ -13,15 +13,13 @@ use debug::RandomOrthogonal;
|
||||
/// A random, well-conditioned, symmetric definite-positive matrix.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RandomSDP<N: Real, D: Dim = Dynamic>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
m: MatrixN<N, D>,
|
||||
}
|
||||
|
||||
impl<N: Real, D: Dim> RandomSDP<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D, D>,
|
||||
where DefaultAllocator: Allocator<N, D, D>
|
||||
{
|
||||
/// Retrieve the generated matrix.
|
||||
pub fn unwrap(self) -> MatrixN<N, D> {
|
||||
|
@ -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,27 +26,22 @@ use geometry::{Point, Translation};
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
serialize = "R: Serialize,
|
||||
serde(bound(
|
||||
serialize = "R: Serialize,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Serialize"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
serde(
|
||||
bound(
|
||||
deserialize = "R: Deserialize<'de>,
|
||||
serde(bound(
|
||||
deserialize = "R: Deserialize<'de>,
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
Owned<N, D>: Deserialize<'de>"
|
||||
)
|
||||
)
|
||||
))
|
||||
)]
|
||||
pub struct Isometry<N: Real, D: DimName, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// The pure rotational part of this isometry.
|
||||
pub rotation: R,
|
||||
@ -54,7 +49,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,12 +96,10 @@ 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
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
@ -112,8 +108,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Real, D: DimName, R: Rotation<Point<N, D>>> Isometry<N, D, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// Creates a new isometry from its rotational and translational parts.
|
||||
#[inline]
|
||||
@ -177,8 +172,7 @@ where
|
||||
// This is OK since all constructors of the isometry enforce the Rotation bound already (and
|
||||
// explicit struct construction is prevented by the dummy ZST field).
|
||||
impl<N: Real, D: DimName, R> Isometry<N, D, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// Converts this isometry into its equivalent homogeneous transformation matrix.
|
||||
#[inline]
|
||||
@ -200,8 +194,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
|
||||
@ -251,7 +244,8 @@ where
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
) -> bool
|
||||
{
|
||||
self.translation
|
||||
.relative_eq(&other.translation, epsilon, max_relative)
|
||||
&& self
|
||||
|
@ -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;
|
||||
|
@ -20,8 +20,7 @@ use geometry::{
|
||||
};
|
||||
|
||||
impl<N: Real, D: DimName, R: AlgaRotation<Point<N, D>>> Isometry<N, D, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// Creates a new identity isometry.
|
||||
#[inline]
|
||||
@ -39,8 +38,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Real, D: DimName, R: AlgaRotation<Point<N, D>>> One for Isometry<N, D, R>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// Creates a new identity isometry.
|
||||
#[inline]
|
||||
|
@ -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;
|
||||
|
||||
|
@ -46,9 +46,7 @@ impl<N: Real> PartialEq for Orthographic3<N> {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<N: Real + Serialize> Serialize for Orthographic3<N> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
self.matrix.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@ -56,9 +54,7 @@ impl<N: Real + Serialize> Serialize for Orthographic3<N> {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<'a, N: Real + Deserialize<'a>> Deserialize<'a> for Orthographic3<N> {
|
||||
fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>
|
||||
where
|
||||
Des: Deserializer<'a>,
|
||||
{
|
||||
where Des: Deserializer<'a> {
|
||||
let matrix = Matrix4::<N>::deserialize(deserializer)?;
|
||||
|
||||
Ok(Orthographic3::from_matrix_unchecked(matrix))
|
||||
@ -238,9 +234,7 @@ impl<N: Real> Orthographic3<N> {
|
||||
/// Projects a vector. Faster than matrix multiplication.
|
||||
#[inline]
|
||||
pub fn project_vector<SB>(&self, p: &Vector<N, U3, SB>) -> Vector3<N>
|
||||
where
|
||||
SB: Storage<N, U3>,
|
||||
{
|
||||
where SB: Storage<N, U3> {
|
||||
Vector3::new(
|
||||
self.matrix[(0, 0)] * p[0],
|
||||
self.matrix[(1, 1)] * p[1],
|
||||
@ -325,8 +319,7 @@ impl<N: Real> Orthographic3<N> {
|
||||
}
|
||||
|
||||
impl<N: Real> Distribution<Orthographic3<N>> for Standard
|
||||
where
|
||||
Standard: Distribution<N>,
|
||||
where Standard: Distribution<N>
|
||||
{
|
||||
fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> Orthographic3<N> {
|
||||
let left = r.gen();
|
||||
@ -342,8 +335,7 @@ where
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<N: Real + Arbitrary> Arbitrary for Orthographic3<N>
|
||||
where
|
||||
Matrix4<N>: Send,
|
||||
where Matrix4<N>: Send
|
||||
{
|
||||
fn arbitrary<G: Gen>(g: &mut G) -> Self {
|
||||
let left = Arbitrary::arbitrary(g);
|
||||
|
@ -47,9 +47,7 @@ impl<N: Real> PartialEq for Perspective3<N> {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<N: Real + Serialize> Serialize for Perspective3<N> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
self.matrix.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@ -57,9 +55,7 @@ impl<N: Real + Serialize> Serialize for Perspective3<N> {
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<'a, N: Real + Deserialize<'a>> Deserialize<'a> for Perspective3<N> {
|
||||
fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>
|
||||
where
|
||||
Des: Deserializer<'a>,
|
||||
{
|
||||
where Des: Deserializer<'a> {
|
||||
let matrix = Matrix4::<N>::deserialize(deserializer)?;
|
||||
|
||||
Ok(Perspective3::from_matrix_unchecked(matrix))
|
||||
@ -207,9 +203,7 @@ impl<N: Real> Perspective3<N> {
|
||||
/// Projects a vector. Faster than matrix multiplication.
|
||||
#[inline]
|
||||
pub fn project_vector<SB>(&self, p: &Vector<N, U3, SB>) -> Vector3<N>
|
||||
where
|
||||
SB: Storage<N, U3>,
|
||||
{
|
||||
where SB: Storage<N, U3> {
|
||||
let inverse_denom = -N::one() / p[2];
|
||||
Vector3::new(
|
||||
self.matrix[(0, 0)] * p[0] * inverse_denom,
|
||||
@ -260,8 +254,7 @@ impl<N: Real> Perspective3<N> {
|
||||
}
|
||||
|
||||
impl<N: Real> Distribution<Perspective3<N>> for Standard
|
||||
where
|
||||
Standard: Distribution<N>,
|
||||
where Standard: Distribution<N>
|
||||
{
|
||||
fn sample<'a, R: Rng + ?Sized>(&self, r: &'a mut R) -> Perspective3<N> {
|
||||
let znear = r.gen();
|
||||
|
@ -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;
|
||||
@ -21,8 +21,7 @@ use base::{DefaultAllocator, Scalar, VectorN};
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct Point<N: Scalar, D: DimName>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// The coordinates of this point, i.e., the shift from the origin.
|
||||
pub coords: VectorN<N, D>,
|
||||
@ -42,8 +41,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
|
||||
@ -63,9 +61,7 @@ where
|
||||
<DefaultAllocator as Allocator<N, D>>::Buffer: Serialize,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
self.coords.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@ -77,9 +73,7 @@ where
|
||||
<DefaultAllocator as Allocator<N, D>>::Buffer: Deserialize<'a>,
|
||||
{
|
||||
fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>
|
||||
where
|
||||
Des: Deserializer<'a>,
|
||||
{
|
||||
where Des: Deserializer<'a> {
|
||||
let coords = VectorN::<N, D>::deserialize(deserializer)?;
|
||||
|
||||
Ok(Point::from_coordinates(coords))
|
||||
@ -108,8 +102,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Scalar, D: DimName> Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// Clones this point into one that owns its data.
|
||||
#[inline]
|
||||
@ -219,7 +212,8 @@ where
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
) -> bool
|
||||
{
|
||||
self.coords
|
||||
.relative_eq(&other.coords, epsilon, max_relative)
|
||||
}
|
||||
@ -241,15 +235,10 @@ 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
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self, right: &Self) -> bool {
|
||||
@ -258,8 +247,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Scalar + PartialOrd, D: DimName> PartialOrd for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
@ -293,8 +281,7 @@ where
|
||||
*
|
||||
*/
|
||||
impl<N: Scalar + fmt::Display, D: DimName> fmt::Display for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "{{"));
|
||||
|
@ -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;
|
||||
|
||||
@ -16,8 +16,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Real, D: DimName> EuclideanSpace for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
type Coordinates = VectorN<N, D>;
|
||||
type Real = N;
|
||||
|
@ -13,8 +13,7 @@ use base::{DefaultAllocator, Scalar, VectorN};
|
||||
use geometry::Point;
|
||||
|
||||
impl<N: Scalar, D: DimName> Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
/// Creates a new point with uninitialized coordinates.
|
||||
#[inline]
|
||||
@ -25,9 +24,7 @@ where
|
||||
/// Creates a new point with all coordinates equal to zero.
|
||||
#[inline]
|
||||
pub fn origin() -> Self
|
||||
where
|
||||
N: Zero,
|
||||
{
|
||||
where N: Zero {
|
||||
Self::from_coordinates(VectorN::from_element(N::zero()))
|
||||
}
|
||||
|
||||
@ -63,8 +60,7 @@ where
|
||||
*
|
||||
*/
|
||||
impl<N: Scalar + Bounded, D: DimName> Bounded for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
#[inline]
|
||||
fn max_value() -> Self {
|
||||
|
@ -19,8 +19,7 @@ use geometry::Point;
|
||||
*
|
||||
*/
|
||||
impl<N: Scalar, D: DimName> Index<usize> for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
type Output = N;
|
||||
|
||||
@ -31,8 +30,7 @@ where
|
||||
}
|
||||
|
||||
impl<N: Scalar, D: DimName> IndexMut<usize> for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
#[inline]
|
||||
fn index_mut(&mut self, i: usize) -> &mut Self::Output {
|
||||
@ -46,8 +44,7 @@ where
|
||||
*
|
||||
*/
|
||||
impl<N: Scalar + ClosedNeg, D: DimName> Neg for Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
type Output = Point<N, D>;
|
||||
|
||||
@ -58,8 +55,7 @@ where
|
||||
}
|
||||
|
||||
impl<'a, N: Scalar + ClosedNeg, D: DimName> Neg for &'a Point<N, D>
|
||||
where
|
||||
DefaultAllocator: Allocator<N, D>,
|
||||
where DefaultAllocator: Allocator<N, D>
|
||||
{
|
||||
type Output = Point<N, D>;
|
||||
|
||||
|
@ -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;
|
||||
@ -32,8 +32,7 @@ pub struct Quaternion<N: Real> {
|
||||
|
||||
#[cfg(feature = "abomonation-serialize")]
|
||||
impl<N: Real> Abomonation for Quaternion<N>
|
||||
where
|
||||
Vector4<N>: Abomonation,
|
||||
where Vector4<N>: Abomonation
|
||||
{
|
||||
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
|
||||
self.coords.entomb(writer)
|
||||
@ -75,26 +74,20 @@ impl<N: Real> Clone for Quaternion<N> {
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<N: Real> Serialize for Quaternion<N>
|
||||
where
|
||||
Owned<N, U4>: Serialize,
|
||||
where Owned<N, U4>: Serialize
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
where S: Serializer {
|
||||
self.coords.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde-serialize")]
|
||||
impl<'a, N: Real> Deserialize<'a> for Quaternion<N>
|
||||
where
|
||||
Owned<N, U4>: Deserialize<'a>,
|
||||
where Owned<N, U4>: Deserialize<'a>
|
||||
{
|
||||
fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>
|
||||
where
|
||||
Des: Deserializer<'a>,
|
||||
{
|
||||
where Des: Deserializer<'a> {
|
||||
let coords = Vector4::<N>::deserialize(deserializer)?;
|
||||
|
||||
Ok(Quaternion::from_vector(coords))
|
||||
@ -337,7 +330,8 @@ impl<N: Real + RelativeEq<Epsilon = N>> RelativeEq for Quaternion<N> {
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
) -> bool
|
||||
{
|
||||
self.as_vector().relative_eq(other.as_vector(), epsilon, max_relative) ||
|
||||
// Account for the double-covering of S², i.e. q = -q
|
||||
self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.relative_eq(&-*b, epsilon, max_relative))
|
||||
@ -457,9 +451,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`
|
||||
@ -478,8 +474,10 @@ impl<N: Real> UnitQuaternion<N> {
|
||||
other: &UnitQuaternion<N>,
|
||||
t: N,
|
||||
epsilon: N,
|
||||
) -> Option<UnitQuaternion<N>> {
|
||||
Unit::new_unchecked(self.coords).try_slerp(&Unit::new_unchecked(other.coords), t, epsilon)
|
||||
) -> Option<UnitQuaternion<N>>
|
||||
{
|
||||
Unit::new_unchecked(self.coords)
|
||||
.try_slerp(&Unit::new_unchecked(other.coords), t, epsilon)
|
||||
.map(|q| Unit::new_unchecked(Quaternion::from_vector(q.unwrap())))
|
||||
}
|
||||
|
||||
@ -659,7 +657,8 @@ impl<N: Real + RelativeEq<Epsilon = N>> RelativeEq for UnitQuaternion<N> {
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
) -> bool
|
||||
{
|
||||
self.as_ref()
|
||||
.relative_eq(other.as_ref(), epsilon, max_relative)
|
||||
}
|
||||
|
@ -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};
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user