Merge pull request #869 from dimforge/dev

Release v0.26.0
This commit is contained in:
Sébastien Crozet 2021-04-12 16:27:28 +02:00 committed by GitHub
commit 156f292917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
245 changed files with 10114 additions and 10556 deletions

View File

@ -34,6 +34,8 @@ jobs:
run: cargo build --no-default-features;
- name: Build (default features)
run: cargo build;
- name: Build --features serde-serialize
run: cargo build --features serde-serialize
- name: Build --all-features
run: cargo build --all-features;
- name: Build nalgebra-glm
@ -55,7 +57,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: test nalgebra-glm
run: cargo test -p nalgebra-glm --features arbitrary,rand,serde-serialize,abomonation-serialize,sparse,debug,io,compare,libm,proptest-support,slow-tests;
run: cargo test -p nalgebra-glm --features arbitrary,serde-serialize,abomonation-serialize;
test-nalgebra-sparse:
runs-on: ubuntu-latest
steps:

View File

@ -4,6 +4,50 @@ documented here.
This project adheres to [Semantic Versioning](https://semver.org/).
## [0.26.0]
This releases integrates `min-const-generics` to nalgebra. See
[our blog post](https://dimforge.com/blog/2021/04/12/nalgebra-const-generics)
for details about this release.
### Added
- Add type aliases for unit vector, e.g., `UnitVector3`.
- Add a `pow` and `pow_mut` function to square matrices.
- Add `Cholesky::determinant` to compute the determinant of a matrix decomposed
with Cholesky.
- Add the `serde-serialize-no-std` feature to enable serialization of static matrices/vectors
with serde, but without requiring `std`.
### Modified
- The `serde` crate isn't enabled by default now. Enable the `serde-serialize` or the
`serde-serialize-no-std` features instead.
- The `Const<const D: usize>` type has been introduced to represent dimensions known
at compile-time. This replaces the type-level integers from `typenum` as well as
the `U1, U2, ..., U127` types from `nalgebra`. These `U1, U2, ..., U127` are now
just aliases for `Const<D>`, e.g., `type U2 = Const<2>`.
- The `ArrayStorage` now uses a standard array `[[T; R]; C]` instead of a `GenericArray`.
- Many trait bounds were changed to accommodate const-generics. Most of these changes
should be transparent wrt. non-generic code.
- The `MatrixMN` alias has been deprecated. Use `OMatrix` or `SMatrix` instead.
- The `MatrixN<T, D>` alias has been deprecated. Use `OMatrix<T, D, D>` or `SMatrix` instead.
- The `VectorN<T, D>` alias has been deprecated. Use `OVector` or `SVector` instead.
- The `Point`, `Translation`, `Isometry`, `Similarity`, and `Transformation` types now take an
integer for their dimension (instead of a type-level integer).
- The type parameter order of `Isometry`, `Similarity`, `Transformation` changed to put
the integer dimensions in the last position (this is required by the compiler).
- The `::new` constructors of translations, points, matrices, and vectors of dimensions `<= 6`
are now `const fn`, making them usable to define constant globals. The `Quaternion::new`
constructor is also a `const fn` now.
## [0.25.4]
### Fixed
- Fix a compilation error when only the `serde-serialize` feature is enabled.
## [0.25.3]
### Added
- The `Vector::simd_cap_magnitude` method to cap the magnitude of the a vector with
SIMD components.
## [0.25.2]
### Added
- A `convert-glam` cargo feature to enable implementations of `From` traits to convert

View File

@ -1,6 +1,6 @@
[package]
name = "nalgebra"
version = "0.25.2"
version = "0.26.0"
authors = [ "Sébastien Crozet <developer@crozet.re>" ]
description = "General-purpose linear algebra library with transformations and statically-sized or dynamically-sized matrices."
@ -22,28 +22,35 @@ name = "nalgebra"
path = "src/lib.rs"
[features]
default = [ "std" ]
std = [ "matrixmultiply", "simba/std" ]
sparse = [ ]
debug = [ "approx/num-complex", "rand" ]
alloc = [ ]
io = [ "pest", "pest_derive" ]
default = [ "std" ]
std = [ "matrixmultiply", "simba/std" ]
sparse = [ ]
debug = [ "approx/num-complex", "rand" ]
alloc = [ ]
io = [ "pest", "pest_derive" ]
compare = [ "matrixcompare-core" ]
libm = [ "simba/libm" ]
libm = [ "simba/libm" ]
libm-force = [ "simba/libm_force" ]
no_unsound_assume_init = [ ]
# Conversion
convert-mint = [ "mint" ]
convert-glam = [ "glam" ]
convert-glam-unchecked = [ "convert-glam" ] # Unable edgy conversions like Mat4 -> Isometry3
convert-glam-unchecked = [ "convert-glam" ] # Enable edgy conversions like Mat4 -> Isometry3
convert-bytemuck = [ "bytemuck" ]
# Serialization
serde-serialize = [ "serde", "num-complex/serde" ]
abomonation-serialize = [ "abomonation" ]
## To use serde in a #[no-std] environment, enable the
## `serde-serialize-no-std` feature instead of `serde-serialize`.
## Serialization of dynamically-sized matrices/vectors require
## `serde-serialize`.
serde-serialize-no-std = [ "serde", "num-complex/serde" ]
serde-serialize = [ "serde-serialize-no-std", "serde/std" ]
abomonation-serialize = [ "abomonation" ]
# Randomness
## To use rand in a #[no-std] environment, enable the
## `rand-no-std` feature instead of `rand`.
rand-no-std = [ "rand-package" ]
rand = [ "rand-no-std", "rand-package/std", "rand-package/std_rng", "rand_distr" ]
@ -54,7 +61,6 @@ slow-tests = []
[dependencies]
typenum = "1.12"
generic-array = "0.14"
rand-package = { package = "rand", version = "0.8", optional = true, default-features = false }
num-traits = { version = "0.2", default-features = false }
num-complex = { version = "0.3", default-features = false }
@ -79,11 +85,7 @@ proptest = { version = "1", optional = true, default-features = false, features
serde_json = "1.0"
rand_xorshift = "0.3"
rand_isaac = "0.3"
### Uncomment this line before running benchmarks.
### We can't just let this uncommented because that would break
### compilation for #[no-std] because of the terrible Cargo bug
### https://github.com/rust-lang/cargo/issues/4866
#criterion = "0.2.10"
criterion = "0.2.10"
# For matrix comparison macro
matrixcompare = "0.2.0"
@ -91,6 +93,11 @@ itertools = "0.10"
[workspace]
members = [ "nalgebra-lapack", "nalgebra-glm", "nalgebra-sparse" ]
resolver = "2"
[[example]]
name = "matrixcompare"
required-features = ["compare"]
[[bench]]
name = "nalgebra_bench"

View File

@ -30,10 +30,10 @@
-----
## Gold sponsors
## Platinum sponsors
Rapier is supported by:
<p>
<a href="https://embark-studios.com">
<img src="https://www.embark.dev/img/logo_black.png" width="301px">
<img src="https://www.embark.dev/img/logo_black.png" width="401px">
</a>
</p>

View File

@ -60,7 +60,7 @@ macro_rules! bench_unop_na(
i = (i + 1) & (LEN - 1);
unsafe {
test::black_box(na::$unop(elems.get_unchecked(i)))
std::hint::black_box(na::$unop(elems.get_unchecked(i)))
}
}));
}
@ -82,7 +82,7 @@ macro_rules! bench_unop(
i = (i + 1) & (LEN - 1);
unsafe {
test::black_box(elems.get_unchecked_mut(i).$unop())
std::hint::black_box(elems.get_unchecked_mut(i).$unop())
}
}));
}
@ -105,7 +105,7 @@ macro_rules! bench_construction(
unsafe {
let res = $constructor($(*$args.get_unchecked(i),)*);
test::black_box(res)
std::hint::black_box(res)
}
}));
}

View File

@ -1,4 +1,4 @@
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10};
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, OMatrix, Vector2, Vector3, Vector4, U10};
use rand::Rng;
use rand_isaac::IsaacRng;
use std::ops::{Add, Div, Mul, Sub};
@ -116,8 +116,8 @@ fn mat10_mul_mat10(bench: &mut criterion::Criterion) {
}
fn mat10_mul_mat10_static(bench: &mut criterion::Criterion) {
let a = MatrixN::<f64, U10>::new_random();
let b = MatrixN::<f64, U10>::new_random();
let a = OMatrix::<f64, U10, U10>::new_random();
let b = OMatrix::<f64, U10, U10>::new_random();
bench.bench_function("mat10_mul_mat10_static", move |bh| bh.iter(|| &a * &b));
}
@ -198,7 +198,7 @@ fn mat_mul_mat(bench: &mut criterion::Criterion) {
bench.bench_function("mat_mul_mat", move |bh| {
bh.iter(|| {
test::black_box(a.mul_to(&b, &mut ab));
std::hint::black_box(a.mul_to(&b, &mut ab));
})
});
}

View File

@ -1,8 +1,7 @@
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
use na::{DVector, SVector, Vector2, Vector3, Vector4};
use rand::Rng;
use rand_isaac::IsaacRng;
use std::ops::{Add, Div, Mul, Sub};
use typenum::U10000;
#[path = "../common/macros.rs"]
mod macros;
@ -45,8 +44,8 @@ bench_unop!(vec2_normalize, Vector2<f32>, normalize);
bench_unop!(vec3_normalize, Vector3<f32>, normalize);
bench_unop!(vec4_normalize, Vector4<f32>, normalize);
bench_binop_ref!(vec10000_dot_f64, VectorN<f64, U10000>, VectorN<f64, U10000>, dot);
bench_binop_ref!(vec10000_dot_f32, VectorN<f32, U10000>, VectorN<f32, U10000>, dot);
bench_binop_ref!(vec10000_dot_f64, SVector<f64, 10000>, SVector<f64, 10000>, dot);
bench_binop_ref!(vec10000_dot_f32, SVector<f32, 10000>, SVector<f32, 10000>, dot);
fn vec10000_axpy_f64(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
@ -82,8 +81,8 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {
bh.bench_function("vec10000_axpy_f64_slice", move |bh| {
bh.iter(|| {
let mut a = a.fixed_rows_mut::<U10000>(0);
let b = b.fixed_rows::<U10000>(0);
let mut a = a.fixed_rows_mut::<10000>(0);
let b = b.fixed_rows::<10000>(0);
a.axpy(n, &b, 1.0)
})
@ -93,11 +92,11 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) {
fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) {
use rand::SeedableRng;
let mut rng = IsaacRng::seed_from_u64(0);
let mut a = VectorN::<f64, U10000>::new_random();
let b = VectorN::<f64, U10000>::new_random();
let mut a = SVector::<f64, 10000>::new_random();
let b = SVector::<f64, 10000>::new_random();
let n = rng.gen::<f64>();
// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)).
// NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(OVector...)).
bh.bench_function("vec10000_axpy_f64_static", move |bh| {
bh.iter(|| a.axpy(n, &b, 1.0))
});

View File

@ -2,10 +2,7 @@
#![allow(unused_macros)]
extern crate nalgebra as na;
extern crate rand;
extern crate rand_isaac;
extern crate test;
extern crate typenum;
extern crate rand_package as rand;
#[macro_use]
extern crate criterion;

View File

@ -7,35 +7,35 @@ mod macros;
fn bidiagonalize_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("bidiagonalize_100x100", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}
fn bidiagonalize_100x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 500);
bh.bench_function("bidiagonalize_100x500", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}
fn bidiagonalize_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("bidiagonalize_4x4", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}
fn bidiagonalize_500x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 100);
bh.bench_function("bidiagonalize_500x100", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}
fn bidiagonalize_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("bidiagonalize_500x500", move |bh| {
bh.iter(|| test::black_box(Bidiagonal::new(m.clone())))
bh.iter(|| std::hint::black_box(Bidiagonal::new(m.clone())))
});
}

View File

@ -5,7 +5,7 @@ fn cholesky_100x100(bh: &mut criterion::Criterion) {
let m = &m * m.transpose();
bh.bench_function("cholesky_100x100", move |bh| {
bh.iter(|| test::black_box(Cholesky::new(m.clone())))
bh.iter(|| std::hint::black_box(Cholesky::new(m.clone())))
});
}
@ -14,7 +14,7 @@ fn cholesky_500x500(bh: &mut criterion::Criterion) {
let m = &m * m.transpose();
bh.bench_function("cholesky_500x500", move |bh| {
bh.iter(|| test::black_box(Cholesky::new(m.clone())))
bh.iter(|| std::hint::black_box(Cholesky::new(m.clone())))
});
}

View File

@ -4,21 +4,21 @@ use na::{DMatrix, DVector, FullPivLU};
fn full_piv_lu_decompose_10x10(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(10, 10);
bh.bench_function("full_piv_lu_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(FullPivLU::new(m.clone())))
bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
});
}
fn full_piv_lu_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("full_piv_lu_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(FullPivLU::new(m.clone())))
bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
});
}
fn full_piv_lu_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("full_piv_lu_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(FullPivLU::new(m.clone())))
bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
});
}
@ -63,7 +63,7 @@ fn full_piv_lu_inverse_10x10(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());
bh.bench_function("full_piv_lu_inverse_10x10", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}
@ -72,7 +72,7 @@ fn full_piv_lu_inverse_100x100(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());
bh.bench_function("full_piv_lu_inverse_100x100", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}
@ -81,7 +81,7 @@ fn full_piv_lu_inverse_500x500(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());
bh.bench_function("full_piv_lu_inverse_500x500", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}
@ -90,7 +90,7 @@ fn full_piv_lu_determinant_10x10(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());
bh.bench_function("full_piv_lu_determinant_10x10", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}
@ -99,7 +99,7 @@ fn full_piv_lu_determinant_100x100(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());
bh.bench_function("full_piv_lu_determinant_100x100", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}
@ -108,7 +108,7 @@ fn full_piv_lu_determinant_500x500(bh: &mut criterion::Criterion) {
let lu = FullPivLU::new(m.clone());
bh.bench_function("full_piv_lu_determinant_500x500", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}

View File

@ -7,28 +7,28 @@ mod macros;
fn hessenberg_decompose_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("hessenberg_decompose_4x4", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}
fn hessenberg_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("hessenberg_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}
fn hessenberg_decompose_200x200(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(200, 200);
bh.bench_function("hessenberg_decompose_200x200", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}
fn hessenberg_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("hessenberg_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
});
}

View File

@ -4,21 +4,21 @@ use na::{DMatrix, DVector, LU};
fn lu_decompose_10x10(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(10, 10);
bh.bench_function("lu_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
});
}
fn lu_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("lu_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
});
}
fn lu_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("lu_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
});
}
@ -63,7 +63,7 @@ fn lu_inverse_10x10(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());
bh.bench_function("lu_inverse_10x10", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}
@ -72,7 +72,7 @@ fn lu_inverse_100x100(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());
bh.bench_function("lu_inverse_100x100", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}
@ -81,7 +81,7 @@ fn lu_inverse_500x500(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());
bh.bench_function("lu_inverse_500x500", move |bh| {
bh.iter(|| test::black_box(lu.try_inverse()))
bh.iter(|| std::hint::black_box(lu.try_inverse()))
});
}
@ -90,7 +90,7 @@ fn lu_determinant_10x10(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());
bh.bench_function("lu_determinant_10x10", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}
@ -99,7 +99,7 @@ fn lu_determinant_100x100(bh: &mut criterion::Criterion) {
let lu = LU::new(m.clone());
bh.bench_function("lu_determinant_100x100", move |bh| {
bh.iter(|| test::black_box(lu.determinant()))
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}
@ -107,7 +107,9 @@ fn lu_determinant_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
let lu = LU::new(m.clone());
bh.bench_function("", move |bh| bh.iter(|| test::black_box(lu.determinant())));
bh.bench_function("", move |bh| {
bh.iter(|| std::hint::black_box(lu.determinant()))
});
}
criterion_group!(

View File

@ -7,35 +7,35 @@ mod macros;
fn qr_decompose_100x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.bench_function("qr_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
});
}
fn qr_decompose_100x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(100, 500);
bh.bench_function("qr_decompose_100x500", move |bh| {
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
});
}
fn qr_decompose_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("qr_decompose_4x4", move |bh| {
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
});
}
fn qr_decompose_500x100(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 100);
bh.bench_function("qr_decompose_500x100", move |bh| {
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
});
}
fn qr_decompose_500x500(bh: &mut criterion::Criterion) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.bench_function("qr_decompose_500x500", move |bh| {
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
});
}
@ -121,7 +121,7 @@ fn qr_inverse_10x10(bh: &mut criterion::Criterion) {
let qr = QR::new(m.clone());
bh.bench_function("qr_inverse_10x10", move |bh| {
bh.iter(|| test::black_box(qr.try_inverse()))
bh.iter(|| std::hint::black_box(qr.try_inverse()))
});
}
@ -130,7 +130,7 @@ fn qr_inverse_100x100(bh: &mut criterion::Criterion) {
let qr = QR::new(m.clone());
bh.bench_function("qr_inverse_100x100", move |bh| {
bh.iter(|| test::black_box(qr.try_inverse()))
bh.iter(|| std::hint::black_box(qr.try_inverse()))
});
}
@ -139,7 +139,7 @@ fn qr_inverse_500x500(bh: &mut criterion::Criterion) {
let qr = QR::new(m.clone());
bh.bench_function("qr_inverse_500x500", move |bh| {
bh.iter(|| test::black_box(qr.try_inverse()))
bh.iter(|| std::hint::black_box(qr.try_inverse()))
});
}

View File

@ -3,56 +3,56 @@ use na::{Matrix4, Schur};
fn schur_decompose_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("schur_decompose_4x4", move |bh| {
bh.iter(|| test::black_box(Schur::new(m.clone())))
bh.iter(|| std::hint::black_box(Schur::new(m.clone())))
});
}
fn schur_decompose_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("schur_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(Schur::new(m.clone())))
bh.iter(|| std::hint::black_box(Schur::new(m.clone())))
});
}
fn schur_decompose_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("schur_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(Schur::new(m.clone())))
bh.iter(|| std::hint::black_box(Schur::new(m.clone())))
});
}
fn schur_decompose_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("schur_decompose_200x200", move |bh| {
bh.iter(|| test::black_box(Schur::new(m.clone())))
bh.iter(|| std::hint::black_box(Schur::new(m.clone())))
});
}
fn eigenvalues_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("eigenvalues_4x4", move |bh| {
bh.iter(|| test::black_box(m.complex_eigenvalues()))
bh.iter(|| std::hint::black_box(m.complex_eigenvalues()))
});
}
fn eigenvalues_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("eigenvalues_10x10", move |bh| {
bh.iter(|| test::black_box(m.complex_eigenvalues()))
bh.iter(|| std::hint::black_box(m.complex_eigenvalues()))
});
}
fn eigenvalues_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("eigenvalues_100x100", move |bh| {
bh.iter(|| test::black_box(m.complex_eigenvalues()))
bh.iter(|| std::hint::black_box(m.complex_eigenvalues()))
});
}
fn eigenvalues_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("eigenvalues_200x200", move |bh| {
bh.iter(|| test::black_box(m.complex_eigenvalues()))
bh.iter(|| std::hint::black_box(m.complex_eigenvalues()))
});
}

View File

@ -3,112 +3,112 @@ use na::{Matrix4, SVD};
fn svd_decompose_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("svd_decompose_4x4", move |bh| {
bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))
bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
});
}
fn svd_decompose_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("svd_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))
bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
});
}
fn svd_decompose_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("svd_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))
bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
});
}
fn svd_decompose_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("svd_decompose_200x200", move |bh| {
bh.iter(|| test::black_box(SVD::new(m.clone(), true, true)))
bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
});
}
fn rank_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("rank_4x4", move |bh| {
bh.iter(|| test::black_box(m.rank(1.0e-10)))
bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
});
}
fn rank_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("rank_10x10", move |bh| {
bh.iter(|| test::black_box(m.rank(1.0e-10)))
bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
});
}
fn rank_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("rank_100x100", move |bh| {
bh.iter(|| test::black_box(m.rank(1.0e-10)))
bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
});
}
fn rank_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("rank_200x200", move |bh| {
bh.iter(|| test::black_box(m.rank(1.0e-10)))
bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
});
}
fn singular_values_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("singular_values_4x4", move |bh| {
bh.iter(|| test::black_box(m.singular_values()))
bh.iter(|| std::hint::black_box(m.singular_values()))
});
}
fn singular_values_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("singular_values_10x10", move |bh| {
bh.iter(|| test::black_box(m.singular_values()))
bh.iter(|| std::hint::black_box(m.singular_values()))
});
}
fn singular_values_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("singular_values_100x100", move |bh| {
bh.iter(|| test::black_box(m.singular_values()))
bh.iter(|| std::hint::black_box(m.singular_values()))
});
}
fn singular_values_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("singular_values_200x200", move |bh| {
bh.iter(|| test::black_box(m.singular_values()))
bh.iter(|| std::hint::black_box(m.singular_values()))
});
}
fn pseudo_inverse_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("pseudo_inverse_4x4", move |bh| {
bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))
bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
});
}
fn pseudo_inverse_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("pseudo_inverse_10x10", move |bh| {
bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))
bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
});
}
fn pseudo_inverse_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("pseudo_inverse_100x100", move |bh| {
bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))
bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
});
}
fn pseudo_inverse_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("pseudo_inverse_200x200", move |bh| {
bh.iter(|| test::black_box(m.clone().pseudo_inverse(1.0e-10)))
bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
});
}

View File

@ -3,28 +3,28 @@ use na::{Matrix4, SymmetricEigen};
fn symmetric_eigen_decompose_4x4(bh: &mut criterion::Criterion) {
let m = Matrix4::<f64>::new_random();
bh.bench_function("symmetric_eigen_decompose_4x4", move |bh| {
bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))
bh.iter(|| std::hint::black_box(SymmetricEigen::new(m.clone())))
});
}
fn symmetric_eigen_decompose_10x10(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(10, 10);
bh.bench_function("symmetric_eigen_decompose_10x10", move |bh| {
bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))
bh.iter(|| std::hint::black_box(SymmetricEigen::new(m.clone())))
});
}
fn symmetric_eigen_decompose_100x100(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(100, 100);
bh.bench_function("symmetric_eigen_decompose_100x100", move |bh| {
bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))
bh.iter(|| std::hint::black_box(SymmetricEigen::new(m.clone())))
});
}
fn symmetric_eigen_decompose_200x200(bh: &mut criterion::Criterion) {
let m = crate::reproductible_dmatrix(200, 200);
bh.bench_function("symmetric_eigen_decompose_200x200", move |bh| {
bh.iter(|| test::black_box(SymmetricEigen::new(m.clone())))
bh.iter(|| std::hint::black_box(SymmetricEigen::new(m.clone())))
});
}

View File

@ -4,7 +4,7 @@ version = "0.0.0"
authors = [ "You" ]
[dependencies]
nalgebra = "0.21.0"
nalgebra = "0.26.0"
[[bin]]
name = "example"

View File

@ -2,26 +2,26 @@ extern crate nalgebra as na;
use na::allocator::Allocator;
use na::dimension::Dim;
use na::{DefaultAllocator, RealField, Unit, Vector2, Vector3, VectorN};
use na::{DefaultAllocator, OVector, RealField, Unit, Vector2, Vector3};
/// Reflects a vector wrt. the hyperplane with normal `plane_normal`.
fn reflect_wrt_hyperplane_with_dimensional_genericity<N: RealField, D: Dim>(
plane_normal: &Unit<VectorN<N, D>>,
vector: &VectorN<N, D>,
) -> VectorN<N, D>
fn reflect_wrt_hyperplane_with_dimensional_genericity<T: RealField, D: Dim>(
plane_normal: &Unit<OVector<T, D>>,
vector: &OVector<T, D>,
) -> OVector<T, D>
where
N: RealField,
T: RealField,
D: Dim,
DefaultAllocator: Allocator<N, D>,
DefaultAllocator: Allocator<T, D>,
{
let n = plane_normal.as_ref(); // Get the underlying V.
vector - n * (n.dot(vector) * na::convert(2.0))
}
/// 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>
fn reflect_wrt_hyperplane2<T>(plane_normal: &Unit<Vector2<T>>, vector: &Vector2<T>) -> Vector2<T>
where
N: RealField,
T: RealField,
{
let n = plane_normal.as_ref(); // Get the underlying Vector2
vector - n * (n.dot(vector) * na::convert(2.0))
@ -29,9 +29,9 @@ 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>
fn reflect_wrt_hyperplane3<T>(plane_normal: &Unit<Vector3<T>>, vector: &Vector3<T>) -> Vector3<T>
where
N: RealField,
T: RealField,
{
let n = plane_normal.as_ref(); // Get the underlying Vector3
vector - n * (n.dot(vector) * na::convert(2.0))

View File

@ -2,20 +2,20 @@ extern crate nalgebra as na;
use matrixcompare::comparators::{AbsoluteElementwiseComparator, ExactElementwiseComparator};
use matrixcompare::compare_matrices;
use na::{MatrixMN, U3, U4};
use na::{OMatrix, U3, U4};
fn compare_integers_fail() {
println!("Comparing two integer matrices.");
#[rustfmt::skip]
let a = MatrixMN::<_, U3, U4>::from_row_slice(&[
let a = OMatrix::<_, U3, U4>::from_row_slice(&[
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, -2, 11
]);
#[rustfmt::skip]
let b = MatrixMN::<_, U3, U4>::from_row_slice(&[
let b = OMatrix::<_, U3, U4>::from_row_slice(&[
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11
@ -29,14 +29,14 @@ fn compare_integers_fail() {
fn compare_different_size() {
println!("Comparing matrices of different size.");
#[rustfmt::skip]
let a = MatrixMN::<_, U3, U3>::from_row_slice(&[
let a = OMatrix::<_, U3, U3>::from_row_slice(&[
0, 1, 2,
4, 5, 6,
8, 9, 10,
]);
#[rustfmt::skip]
let b = MatrixMN::<_, U3, U4>::from_row_slice(&[
let b = OMatrix::<_, U3, U4>::from_row_slice(&[
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11
@ -51,14 +51,14 @@ fn compare_f64_abs_tol_fail() {
println!("Comparing two f64 matrices.");
#[rustfmt::skip]
let a = MatrixMN::<f64, U3, U3>::from_row_slice(&[
let a = OMatrix::<f64, U3, U3>::from_row_slice(&[
0.0, 1.0, 2.0 + 1e-10,
4.0, 5.0, 6.0,
8.0, 9.0, 10.0,
]);
#[rustfmt::skip]
let b = MatrixMN::<_, U3, U3>::from_row_slice(&[
let b = OMatrix::<_, U3, U3>::from_row_slice(&[
0.0, 1.0, 2.0,
4.0, 5.0, 6.0,
8.0, 9.0, 10.0

View File

@ -2,7 +2,7 @@
extern crate nalgebra as na;
use na::{DMatrix, Dynamic, Matrix2x3, Matrix3x2, U2, U3};
use na::{DMatrix, Dynamic, Matrix2x3, Matrix3x2, Const};
fn main() {
// Matrices can be reshaped in-place without moving or copying values.
@ -16,7 +16,7 @@ fn main() {
1.2, 2.3
);
let m3 = m1.reshape_generic(U3, U2);
let m3 = m1.reshape_generic(Const::<3>, Const::<2>);
assert_eq!(m3, m2);
// Note that, for statically sized matrices, invalid reshapes will not compile:

View File

@ -3,15 +3,15 @@ extern crate nalgebra as na;
use na::{Scalar, Vector3};
use simba::scalar::RealField;
fn print_vector<N: Scalar>(m: &Vector3<N>) {
fn print_vector<T: Scalar>(m: &Vector3<T>) {
println!("{:?}", m)
}
fn print_norm<N: RealField>(v: &Vector3<N>) {
fn print_norm<T: RealField>(v: &Vector3<T>) {
// NOTE: alternatively, nalgebra already defines `v.norm()`.
let norm = v.dot(v).sqrt();
// The RealField bound implies that N is Display so we can
// The RealField bound implies that T is Display so we can
// use "{}" instead of "{:?}" for the format string.
println!("{}", norm)
}

View File

@ -1,6 +1,6 @@
[package]
name = "nalgebra-glm"
version = "0.11.0"
version = "0.12.0"
authors = ["sebcrozet <developer@crozet.re>"]
description = "A computer-graphics oriented API for nalgebra, inspired by the C++ GLM library."
@ -17,14 +17,14 @@ edition = "2018"
maintenance = { status = "actively-developed" }
[features]
default = [ "std" ]
std = [ "nalgebra/std", "simba/std" ]
arbitrary = [ "nalgebra/arbitrary" ]
serde-serialize = [ "nalgebra/serde-serialize" ]
default = [ "std" ]
std = [ "nalgebra/std", "simba/std" ]
arbitrary = [ "nalgebra/arbitrary" ]
serde-serialize = [ "nalgebra/serde-serialize-no-std" ]
abomonation-serialize = [ "nalgebra/abomonation-serialize" ]
[dependencies]
num-traits = { version = "0.2", default-features = false }
approx = { version = "0.4", default-features = false }
simba = { version = "0.4", default-features = false }
nalgebra = { path = "..", version = "0.25", default-features = false }
nalgebra = { path = "..", version = "0.26", default-features = false }

View File

@ -1,9 +1,9 @@
use na::{
Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3,
MatrixMN, Quaternion, VectorN, U1, U2, U3, U4,
Quaternion, SMatrix, SVector,
};
/// A matrix with components of type `N`. It has `R` rows, and `C` columns.
/// A matrix with components of type `T`. It has `R` rows, and `C` columns.
///
/// In this library, vectors, represented as [`TVec`](type.TVec.html) and
/// friends, are also matrices. Operations that operate on a matrix will
@ -24,8 +24,8 @@ use na::{
/// * [`TMat4x3`](type.TMat4x3.html)
/// * [`TMat4x4`](type.TMat4x4.html)
/// * [`TVec`](type.TVec.html)
pub type TMat<N, R, C> = MatrixMN<N, R, C>;
/// A column vector with components of type `N`. It has `D` rows (and one column).
pub type TMat<T, const R: usize, const C: usize> = SMatrix<T, R, C>;
/// A column vector with components of type `T`. It has `D` rows (and one column).
///
/// In this library, vectors are represented as a single column matrix, so
/// operations on [`TMat`](type.TMat.html) are also valid on vectors.
@ -37,11 +37,11 @@ pub type TMat<N, R, C> = MatrixMN<N, R, C>;
/// * [`TVec2`](type.TVec2.html)
/// * [`TVec3`](type.TVec3.html)
/// * [`TVec4`](type.TVec4.html)
pub type TVec<N, R> = VectorN<N, R>;
/// A quaternion with components of type `N`.
pub type Qua<N> = Quaternion<N>;
pub type TVec<T, const R: usize> = SVector<T, R>;
/// A quaternion with components of type `T`.
pub type Qua<T> = Quaternion<T>;
/// A 1D vector with components of type `N`.
/// A 1D vector with components of type `T`.
///
/// # See also:
///
@ -69,8 +69,8 @@ pub type Qua<N> = Quaternion<N>;
/// * [`U64Vec1`](type.U64Vec1.html)
/// * [`U8Vec1`](type.U8Vec1.html)
/// * [`Vec1`](type.Vec1.html)
pub type TVec1<N> = TVec<N, U1>;
/// A 2D vector with components of type `N`.
pub type TVec1<T> = TVec<T, 1>;
/// A 2D vector with components of type `T`.
///
/// # See also:
///
@ -99,8 +99,8 @@ pub type TVec1<N> = TVec<N, U1>;
/// * [`U64Vec2`](type.U64Vec2.html)
/// * [`U8Vec2`](type.U8Vec2.html)
/// * [`Vec2`](type.Vec2.html)
pub type TVec2<N> = TVec<N, U2>;
/// A 3D vector with components of type `N`.
pub type TVec2<T> = TVec<T, 2>;
/// A 3D vector with components of type `T`.
///
/// # See also:
///
@ -129,8 +129,8 @@ pub type TVec2<N> = TVec<N, U2>;
/// * [`U64Vec3`](type.U64Vec3.html)
/// * [`U8Vec3`](type.U8Vec3.html)
/// * [`Vec3`](type.Vec3.html)
pub type TVec3<N> = TVec<N, U3>;
/// A 4D vector with components of type `N`.
pub type TVec3<T> = TVec<T, 3>;
/// A 4D vector with components of type `T`.
///
/// # See also:
///
@ -158,7 +158,7 @@ pub type TVec3<N> = TVec<N, U3>;
/// * [`U64Vec4`](type.U64Vec4.html)
/// * [`U8Vec4`](type.U8Vec4.html)
/// * [`Vec4`](type.Vec4.html)
pub type TVec4<N> = TVec<N, U4>;
pub type TVec4<T> = TVec<T, 4>;
/// A 1D vector with boolean components.
pub type BVec1 = TVec1<bool>;
/// A 2D vector with boolean components.
@ -268,31 +268,31 @@ pub type I8Vec3 = TVec3<i8>;
/// A 4D vector with `i8` components.
pub type I8Vec4 = TVec4<i8>;
/// A 2x2 matrix with components of type `N`.
pub type TMat2<N> = Matrix2<N>;
/// A 2x2 matrix with components of type `N`.
pub type TMat2x2<N> = Matrix2<N>;
/// A 2x3 matrix with components of type `N`.
pub type TMat2x3<N> = Matrix2x3<N>;
/// A 2x4 matrix with components of type `N`.
pub type TMat2x4<N> = Matrix2x4<N>;
/// A 3x3 matrix with components of type `N`.
pub type TMat3<N> = Matrix3<N>;
/// A 3x2 matrix with components of type `N`.
pub type TMat3x2<N> = Matrix3x2<N>;
/// A 3x3 matrix with components of type `N`.
pub type TMat3x3<N> = Matrix3<N>;
/// A 3x4 matrix with components of type `N`.
pub type TMat3x4<N> = Matrix3x4<N>;
/// A 4x4 matrix with components of type `N`.
pub type TMat4<N> = Matrix4<N>;
/// A 4x2 matrix with components of type `N`.
pub type TMat4x2<N> = Matrix4x2<N>;
/// A 4x3 matrix with components of type `N`.
pub type TMat4x3<N> = Matrix4x3<N>;
/// A 4x4 matrix with components of type `N`.
pub type TMat4x4<N> = Matrix4<N>;
/// A 2x2 matrix with components of type `N`.
/// A 2x2 matrix with components of type `T`.
pub type TMat2<T> = Matrix2<T>;
/// A 2x2 matrix with components of type `T`.
pub type TMat2x2<T> = Matrix2<T>;
/// A 2x3 matrix with components of type `T`.
pub type TMat2x3<T> = Matrix2x3<T>;
/// A 2x4 matrix with components of type `T`.
pub type TMat2x4<T> = Matrix2x4<T>;
/// A 3x3 matrix with components of type `T`.
pub type TMat3<T> = Matrix3<T>;
/// A 3x2 matrix with components of type `T`.
pub type TMat3x2<T> = Matrix3x2<T>;
/// A 3x3 matrix with components of type `T`.
pub type TMat3x3<T> = Matrix3<T>;
/// A 3x4 matrix with components of type `T`.
pub type TMat3x4<T> = Matrix3x4<T>;
/// A 4x4 matrix with components of type `T`.
pub type TMat4<T> = Matrix4<T>;
/// A 4x2 matrix with components of type `T`.
pub type TMat4x2<T> = Matrix4x2<T>;
/// A 4x3 matrix with components of type `T`.
pub type TMat4x3<T> = Matrix4x3<T>;
/// A 4x4 matrix with components of type `T`.
pub type TMat4x4<T> = Matrix4<T>;
/// A 2x2 matrix with components of type `T`.
pub type DMat2 = Matrix2<f64>;
/// A 2x2 matrix with `f64` components.
pub type DMat2x2 = Matrix2<f64>;

View File

@ -1,9 +1,9 @@
use core::mem;
use na::{self, DefaultAllocator, RealField};
use na::{self, RealField};
use num::FromPrimitive;
use crate::aliases::{TMat, TVec};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`.
///
@ -21,10 +21,7 @@ use crate::traits::{Alloc, Dimension, Number};
/// # See also:
///
/// * [`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>,
{
pub fn abs<T: Number, const R: usize, const C: usize>(x: &TMat<T, R, C>) -> TMat<T, R, C> {
x.abs()
}
@ -45,10 +42,7 @@ where
/// * [`fract`](fn.fract.html)
/// * [`round`](fn.round.html)
/// * [`trunc`](fn.trunc.html)
pub fn ceil<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn ceil<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|x| x.ceil())
}
@ -73,7 +67,7 @@ where
///
/// * [`clamp`](fn.clamp.html)
/// * [`clamp_vec`](fn.clamp_vec.html)
pub fn clamp_scalar<N: Number>(x: N, min_val: N, max_val: N) -> N {
pub fn clamp_scalar<T: Number>(x: T, min_val: T, max_val: T) -> T {
na::clamp(x, min_val, max_val)
}
@ -97,10 +91,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>,
{
pub fn clamp<T: Number, const D: usize>(x: &TVec<T, D>, min_val: T, max_val: T) -> TVec<T, D> {
x.map(|x| na::clamp(x, min_val, max_val))
}
@ -131,14 +122,11 @@ where
///
/// * [`clamp_scalar`](fn.clamp_scalar.html)
/// * [`clamp`](fn.clamp.html)
pub fn clamp_vec<N: Number, D: Dimension>(
x: &TVec<N, D>,
min_val: &TVec<N, D>,
max_val: &TVec<N, D>,
) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn clamp_vec<T: Number, const D: usize>(
x: &TVec<T, D>,
min_val: &TVec<T, D>,
max_val: &TVec<T, D>,
) -> TVec<T, D> {
x.zip_zip_map(min_val, max_val, |a, min, max| na::clamp(a, min, max))
}
@ -172,10 +160,7 @@ pub fn float_bits_to_int(v: f32) -> i32 {
/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html)
/// * [`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>,
{
pub fn float_bits_to_int_vec<const D: usize>(v: &TVec<f32, D>) -> TVec<i32, D> {
v.map(float_bits_to_int)
}
@ -209,10 +194,7 @@ pub fn float_bits_to_uint(v: f32) -> u32 {
/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html)
/// * [`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>,
{
pub fn float_bits_to_uint_vec<const D: usize>(v: &TVec<f32, D>) -> TVec<u32, D> {
v.map(float_bits_to_uint)
}
@ -232,15 +214,12 @@ where
/// * [`fract`](fn.fract.html)
/// * [`round`](fn.round.html)
/// * [`trunc`](fn.trunc.html)
pub fn floor<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn floor<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|x| x.floor())
}
//// TODO: should be implemented for TVec/TMat?
//pub fn fma<N: Number>(a: N, b: N, c: N) -> N {
//pub fn fma<T: Number>(a: T, b: T, c: T) -> T {
// // TODO: use an actual FMA
// a * b + c
//}
@ -261,16 +240,13 @@ where
/// * [`floor`](fn.floor.html)
/// * [`round`](fn.round.html)
/// * [`trunc`](fn.trunc.html)
pub fn fract<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn fract<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|x| x.fract())
}
//// TODO: should be implemented for TVec/TMat?
///// Returns the (significant, exponent) of this float number.
//pub fn frexp<N: RealField>(x: N, exp: N) -> (N, N) {
//pub fn frexp<T: RealField>(x: T, exp: T) -> (T, T) {
// // TODO: is there a better approach?
// let e = x.log2().ceil();
// (x * (-e).exp2(), e)
@ -306,27 +282,22 @@ pub fn int_bits_to_float(v: i32) -> f32 {
/// * [`int_bits_to_float`](fn.int_bits_to_float.html)
/// * [`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>,
{
pub fn int_bits_to_float_vec<const D: usize>(v: &TVec<i32, D>) -> TVec<f32, D> {
v.map(int_bits_to_float)
}
//pub fn isinf<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<bool, D>
// where DefaultAllocator: Alloc<N, D> {
//pub fn isinf<T: Scalar, const D: usize>(x: &TVec<T, D>) -> TVec<bool, D> {
// unimplemented!()
//
//}
//
//pub fn isnan<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<bool, D>
// where DefaultAllocator: Alloc<N, D> {
//pub fn isnan<T: Scalar, const D: usize>(x: &TVec<T, D>) -> TVec<bool, D> {
// unimplemented!()
//
//}
///// Returns the (significant, exponent) of this float number.
//pub fn ldexp<N: RealField>(x: N, exp: N) -> N {
//pub fn ldexp<T: RealField>(x: T, exp: T) -> T {
// // TODO: is there a better approach?
// x * (exp).exp2()
//}
@ -346,8 +317,8 @@ where
///
/// * [`mix`](fn.mix.html)
/// * [`mix_vec`](fn.mix_vec.html)
pub fn mix_scalar<N: Number>(x: N, y: N, a: N) -> N {
x * (N::one() - a) + y * a
pub fn mix_scalar<T: Number>(x: T, y: T, a: T) -> T {
x * (T::one() - a) + y * a
}
/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the vectors x and y using the scalar value a.
@ -367,11 +338,8 @@ 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>,
{
x * (N::one() - a) + y * a
pub fn mix<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>, a: T) -> TVec<T, D> {
x * (T::one() - a) + y * a
}
/// Returns `x * (1.0 - a) + y * a`, i.e., the component-wise linear blend of `x` and `y` using the components of
@ -393,15 +361,12 @@ where
///
/// * [`mix_scalar`](fn.mix_scalar.html)
/// * [`mix`](fn.mix.html)
pub fn mix_vec<N: Number, D: Dimension>(
x: &TVec<N, D>,
y: &TVec<N, D>,
a: &TVec<N, D>,
) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
x.component_mul(&(TVec::<N, D>::repeat(N::one()) - a)) + y.component_mul(&a)
pub fn mix_vec<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
a: &TVec<T, D>,
) -> TVec<T, D> {
x.component_mul(&(TVec::<T, D>::repeat(T::one()) - a)) + y.component_mul(&a)
}
/// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the scalars x and y using the scalar value a.
@ -420,7 +385,7 @@ where
///
/// * [`lerp`](fn.lerp.html)
/// * [`lerp_vec`](fn.lerp_vec.html)
pub fn lerp_scalar<N: Number>(x: N, y: N, a: N) -> N {
pub fn lerp_scalar<T: Number>(x: T, y: T, a: T) -> T {
mix_scalar(x, y, a)
}
@ -442,10 +407,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>,
{
pub fn lerp<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>, a: T) -> TVec<T, D> {
mix(x, y, a)
}
@ -469,14 +431,11 @@ where
///
/// * [`lerp_scalar`](fn.lerp_scalar.html)
/// * [`lerp`](fn.lerp.html)
pub fn lerp_vec<N: Number, D: Dimension>(
x: &TVec<N, D>,
y: &TVec<N, D>,
a: &TVec<N, D>,
) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn lerp_vec<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
a: &TVec<T, D>,
) -> TVec<T, D> {
mix_vec(x, y, a)
}
@ -487,10 +446,7 @@ where
/// # See also:
///
/// * [`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>,
{
pub fn modf_vec<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<T, D> {
x.zip_map(y, |x, y| x % y)
}
@ -499,7 +455,7 @@ where
/// # See also:
///
/// * [`modf_vec`](fn.modf_vec.html)
pub fn modf<N: Number>(x: N, i: N) -> N {
pub fn modf<T: Number>(x: T, i: T) -> T {
x % i
}
@ -521,15 +477,11 @@ pub fn modf<N: Number>(x: N, i: N) -> N {
/// * [`floor`](fn.floor.html)
/// * [`fract`](fn.fract.html)
/// * [`trunc`](fn.trunc.html)
pub fn round<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn round<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|x| x.round())
}
//pub fn roundEven<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
// where DefaultAllocator: Alloc<N, D> {
//pub fn roundEven<T: Scalar, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
// unimplemented!()
//}
@ -547,46 +499,37 @@ where
///
/// * [`abs`](fn.abs.html)
///
pub fn sign<N: Number, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
x.map(|x| if x.is_zero() { N::zero() } else { x.signum() })
pub fn sign<T: Number, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|x| if x.is_zero() { T::zero() } else { x.signum() })
}
/// Returns 0.0 if `x <= edge0` and `1.0 if x >= edge1` and performs smooth Hermite interpolation between 0 and 1 when `edge0 < x < edge1`.
///
/// This is useful in cases where you would want a threshold function with a smooth transition.
/// This is equivalent to: `let result = clamp((x - edge0) / (edge1 - edge0), 0, 1); return t * t * (3 - 2 * t);` Results are undefined if `edge0 >= edge1`.
pub fn smoothstep<N: Number>(edge0: N, edge1: N, x: N) -> N {
let _3: N = FromPrimitive::from_f64(3.0).unwrap();
let _2: N = FromPrimitive::from_f64(2.0).unwrap();
let t = na::clamp((x - edge0) / (edge1 - edge0), N::zero(), N::one());
pub fn smoothstep<T: Number>(edge0: T, edge1: T, x: T) -> T {
let _3: T = FromPrimitive::from_f64(3.0).unwrap();
let _2: T = FromPrimitive::from_f64(2.0).unwrap();
let t = na::clamp((x - edge0) / (edge1 - edge0), T::zero(), T::one());
t * t * (_3 - t * _2)
}
/// Returns 0.0 if `x < edge`, otherwise it returns 1.0.
pub fn step_scalar<N: Number>(edge: N, x: N) -> N {
pub fn step_scalar<T: Number>(edge: T, x: T) -> T {
if edge > x {
N::zero()
T::zero()
} else {
N::one()
T::one()
}
}
/// 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>,
{
pub fn step<T: Number, const D: usize>(edge: T, x: &TVec<T, D>) -> TVec<T, 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>,
{
pub fn step_vec<T: Number, const D: usize>(edge: &TVec<T, D>, x: &TVec<T, D>) -> TVec<T, D> {
edge.zip_map(x, step_scalar)
}
@ -606,10 +549,7 @@ where
/// * [`floor`](fn.floor.html)
/// * [`fract`](fn.fract.html)
/// * [`round`](fn.round.html)
pub fn trunc<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn trunc<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|x| x.trunc())
}
@ -643,9 +583,6 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 {
/// * [`int_bits_to_float`](fn.int_bits_to_float.html)
/// * [`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>,
{
pub fn uint_bits_to_float<const D: usize>(v: &TVec<u32, D>) -> TVec<f32, D> {
v.map(uint_bits_to_float_scalar)
}

View File

@ -2,7 +2,7 @@ use crate::aliases::{
Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
TVec2, TVec3, TVec4,
};
use na::{RealField, Scalar, U2, U3, U4};
use na::{RealField, Scalar};
/// Creates a new 1D vector.
///
@ -14,30 +14,30 @@ use na::{RealField, Scalar, U2, U3, U4};
/// # use nalgebra_glm as glm;
/// let v = glm::vec1(true);
/// ```
pub fn vec1<N: Scalar>(x: N) -> TVec1<N> {
pub fn vec1<T: Scalar>(x: T) -> TVec1<T> {
TVec1::new(x)
}
/// Creates a new 2D vector.
pub fn vec2<N: Scalar>(x: N, y: N) -> TVec2<N> {
pub fn vec2<T: Scalar>(x: T, y: T) -> TVec2<T> {
TVec2::new(x, y)
}
/// Creates a new 3D vector.
pub fn vec3<N: Scalar>(x: N, y: N, z: N) -> TVec3<N> {
pub fn vec3<T: Scalar>(x: T, y: T, z: T) -> TVec3<T> {
TVec3::new(x, y, z)
}
/// Creates a new 4D vector.
pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> TVec4<N> {
pub fn vec4<T: Scalar>(x: T, y: T, z: T, w: T) -> TVec4<T> {
TVec4::new(x, y, z, w)
}
/// Create a new 2x2 matrix.
#[rustfmt::skip]
pub fn mat2<N: Scalar>(m11: N, m12: N,
m21: N, m22: N) -> TMat2<N> {
TMat::<N, U2, U2>::new(
pub fn mat2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T) -> TMat2<T> {
TMat::<T, 2, 2>::new(
m11, m12,
m21, m22,
)
@ -45,9 +45,9 @@ pub fn mat2<N: Scalar>(m11: N, m12: N,
/// Create a new 2x2 matrix.
#[rustfmt::skip]
pub fn mat2x2<N: Scalar>(m11: N, m12: N,
m21: N, m22: N) -> TMat2<N> {
TMat::<N, U2, U2>::new(
pub fn mat2x2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T) -> TMat2<T> {
TMat::<T, 2, 2>::new(
m11, m12,
m21, m22,
)
@ -55,9 +55,9 @@ pub fn mat2x2<N: Scalar>(m11: N, m12: N,
/// Create a new 2x3 matrix.
#[rustfmt::skip]
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N,
m21: N, m22: N, m23: N) -> TMat2x3<N> {
TMat::<N, U2, U3>::new(
pub fn mat2x3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T) -> TMat2x3<T> {
TMat::<T, 2, 3>::new(
m11, m12, m13,
m21, m22, m23,
)
@ -65,9 +65,9 @@ pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N,
/// Create a new 2x4 matrix.
#[rustfmt::skip]
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(
pub fn mat2x4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T) -> TMat2x4<T> {
TMat::<T, 2, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
)
@ -75,10 +75,10 @@ pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
/// Create a new 3x3 matrix.
#[rustfmt::skip]
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(
pub fn mat3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T) -> TMat3<T> {
TMat::<T, 3, 3>::new(
m11, m12, m13,
m21, m22, m23,
m31, m32, m33,
@ -87,10 +87,10 @@ pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N,
/// Create a new 3x2 matrix.
#[rustfmt::skip]
pub fn mat3x2<N: Scalar>(m11: N, m12: N,
m21: N, m22: N,
m31: N, m32: N) -> TMat3x2<N> {
TMat::<N, U3, U2>::new(
pub fn mat3x2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T,
m31: T, m32: T) -> TMat3x2<T> {
TMat::<T, 3, 2>::new(
m11, m12,
m21, m22,
m31, m32,
@ -99,10 +99,10 @@ pub fn mat3x2<N: Scalar>(m11: N, m12: N,
/// Create a new 3x3 matrix.
#[rustfmt::skip]
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(
pub fn mat3x3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T) -> TMat3<T> {
TMat::<T, 3, 3>::new(
m11, m12, m13,
m31, m32, m33,
m21, m22, m23,
@ -111,10 +111,10 @@ pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N,
/// Create a new 3x4 matrix.
#[rustfmt::skip]
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(
pub fn mat3x4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T) -> TMat3x4<T> {
TMat::<T, 3, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
@ -123,11 +123,11 @@ pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
/// Create a new 4x2 matrix.
#[rustfmt::skip]
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(
pub fn mat4x2<T: Scalar>(m11: T, m12: T,
m21: T, m22: T,
m31: T, m32: T,
m41: T, m42: T) -> TMat4x2<T> {
TMat::<T, 4, 2>::new(
m11, m12,
m21, m22,
m31, m32,
@ -137,11 +137,11 @@ pub fn mat4x2<N: Scalar>(m11: N, m12: N,
/// Create a new 4x3 matrix.
#[rustfmt::skip]
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(
pub fn mat4x3<T: Scalar>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T,
m41: T, m42: T, m43: T) -> TMat4x3<T> {
TMat::<T, 4, 3>::new(
m11, m12, m13,
m21, m22, m23,
m31, m32, m33,
@ -151,11 +151,11 @@ pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N,
/// Create a new 4x4 matrix.
#[rustfmt::skip]
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(
pub fn mat4x4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T) -> TMat4<T> {
TMat::<T, 4, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
@ -165,11 +165,11 @@ pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
/// Create a new 4x4 matrix.
#[rustfmt::skip]
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(
pub fn mat4<T: Scalar>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T) -> TMat4<T> {
TMat::<T, 4, 4>::new(
m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
@ -178,6 +178,6 @@ pub fn mat4<N: Scalar>(m11: N, m12: N, m13: N, m14: N,
}
/// Creates a new quaternion.
pub fn quat<N: RealField>(x: N, y: N, z: N, w: N) -> Qua<N> {
pub fn quat<T: RealField>(x: T, y: T, z: T, w: T) -> Qua<T> {
Qua::new(w, x, y, z)
}

View File

@ -1,16 +1,12 @@
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension};
use na::{DefaultAllocator, RealField};
use na::RealField;
/// Component-wise exponential.
///
/// # See also:
///
/// * [`exp2`](fn.exp2.html)
pub fn exp<N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn exp<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.exp())
}
@ -19,10 +15,7 @@ where
/// # See also:
///
/// * [`exp`](fn.exp.html)
pub fn exp2<N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn exp2<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.exp2())
}
@ -31,11 +24,8 @@ where
/// # See also:
///
/// * [`sqrt`](fn.sqrt.html)
pub fn inversesqrt<N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
v.map(|x| N::one() / x.sqrt())
pub fn inversesqrt<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| T::one() / x.sqrt())
}
/// Component-wise logarithm.
@ -43,10 +33,7 @@ where
/// # See also:
///
/// * [`log2`](fn.log2.html)
pub fn log<N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn log<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.ln())
}
@ -55,18 +42,12 @@ where
/// # See also:
///
/// * [`log`](fn.log.html)
pub fn log2<N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn log2<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.log2())
}
/// Component-wise power.
pub fn pow<N: RealField, D: Dimension>(base: &TVec<N, D>, exponent: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn pow<T: RealField, const D: usize>(base: &TVec<T, D>, exponent: &TVec<T, D>) -> TVec<T, D> {
base.zip_map(exponent, |b, e| b.powf(e))
}
@ -78,9 +59,6 @@ where
/// * [`exp2`](fn.exp2.html)
/// * [`inversesqrt`](fn.inversesqrt.html)
/// * [`pow`](fn.pow.html)
pub fn sqrt<N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn sqrt<T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
v.map(|x| x.sqrt())
}

View File

@ -1,51 +1,51 @@
use crate::aliases::TMat4;
use na::RealField;
//pub fn frustum<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//pub fn frustum_lh<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_lh<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_lr_no<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_lr_no<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_lh_zo<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_lh_zo<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_no<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_no<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_rh<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_rh<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_rh_no<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_rh_no<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_rh_zo<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_rh_zo<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn frustum_zo<N: RealField>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
//pub fn frustum_zo<T: RealField>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4<T> {
// unimplemented!()
//}
//pub fn infinite_perspective<N: RealField>(fovy: N, aspect: N, near: N) -> TMat4<N> {
//pub fn infinite_perspective<T: RealField>(fovy: T, aspect: T, near: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn infinite_perspective_lh<N: RealField>(fovy: N, aspect: N, near: N) -> TMat4<N> {
//pub fn infinite_perspective_lh<T: RealField>(fovy: T, aspect: T, near: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn infinite_ortho<N: RealField>(left: N, right: N, bottom: N, top: N) -> TMat4<N> {
//pub fn infinite_ortho<T: RealField>(left: T, right: T, bottom: T, top: T) -> TMat4<T> {
// unimplemented!()
//}
@ -60,7 +60,7 @@ use na::RealField;
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
pub fn ortho<T: RealField>(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4<T> {
ortho_rh_no(left, right, bottom, top, znear, zfar)
}
@ -75,7 +75,7 @@ pub fn ortho<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zfar:
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_lh<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
pub fn ortho_lh<T: RealField>(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4<T> {
ortho_lh_no(left, right, bottom, top, znear, zfar)
}
@ -90,16 +90,16 @@ pub fn ortho_lh<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zf
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_lh_no<N: RealField>(
left: N,
right: N,
bottom: N,
top: N,
znear: N,
zfar: N,
) -> TMat4<N> {
let two: N = crate::convert(2.0);
let mut mat: TMat4<N> = TMat4::<N>::identity();
pub fn ortho_lh_no<T: RealField>(
left: T,
right: T,
bottom: T,
top: T,
znear: T,
zfar: T,
) -> TMat4<T> {
let two: T = crate::convert(2.0);
let mut mat: TMat4<T> = TMat4::<T>::identity();
mat[(0, 0)] = two / (right - left);
mat[(0, 3)] = -(right + left) / (right - left);
@ -122,17 +122,17 @@ pub fn ortho_lh_no<N: RealField>(
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_lh_zo<N: RealField>(
left: N,
right: N,
bottom: N,
top: N,
znear: N,
zfar: N,
) -> TMat4<N> {
let one: N = N::one();
let two: N = crate::convert(2.0);
let mut mat: TMat4<N> = TMat4::<N>::identity();
pub fn ortho_lh_zo<T: RealField>(
left: T,
right: T,
bottom: T,
top: T,
znear: T,
zfar: T,
) -> TMat4<T> {
let one: T = T::one();
let two: T = crate::convert(2.0);
let mut mat: TMat4<T> = TMat4::<T>::identity();
mat[(0, 0)] = two / (right - left);
mat[(0, 3)] = -(right + left) / (right - left);
@ -155,7 +155,7 @@ pub fn ortho_lh_zo<N: RealField>(
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_no<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
pub fn ortho_no<T: RealField>(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4<T> {
ortho_rh_no(left, right, bottom, top, znear, zfar)
}
@ -170,7 +170,7 @@ pub fn ortho_no<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zf
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_rh<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
pub fn ortho_rh<T: RealField>(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4<T> {
ortho_rh_no(left, right, bottom, top, znear, zfar)
}
@ -185,16 +185,16 @@ pub fn ortho_rh<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zf
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_rh_no<N: RealField>(
left: N,
right: N,
bottom: N,
top: N,
znear: N,
zfar: N,
) -> TMat4<N> {
let two: N = crate::convert(2.0);
let mut mat: TMat4<N> = TMat4::<N>::identity();
pub fn ortho_rh_no<T: RealField>(
left: T,
right: T,
bottom: T,
top: T,
znear: T,
zfar: T,
) -> TMat4<T> {
let two: T = crate::convert(2.0);
let mut mat: TMat4<T> = TMat4::<T>::identity();
mat[(0, 0)] = two / (right - left);
mat[(0, 3)] = -(right + left) / (right - left);
@ -217,17 +217,17 @@ pub fn ortho_rh_no<N: RealField>(
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_rh_zo<N: RealField>(
left: N,
right: N,
bottom: N,
top: N,
znear: N,
zfar: N,
) -> TMat4<N> {
let one: N = N::one();
let two: N = crate::convert(2.0);
let mut mat: TMat4<N> = TMat4::<N>::identity();
pub fn ortho_rh_zo<T: RealField>(
left: T,
right: T,
bottom: T,
top: T,
znear: T,
zfar: T,
) -> TMat4<T> {
let one: T = T::one();
let two: T = crate::convert(2.0);
let mut mat: TMat4<T> = TMat4::<T>::identity();
mat[(0, 0)] = two / (right - left);
mat[(0, 3)] = -(right + left) / (right - left);
@ -250,7 +250,7 @@ pub fn ortho_rh_zo<N: RealField>(
/// * `znear` - Distance from the viewer to the near clipping plane
/// * `zfar` - Distance from the viewer to the far clipping plane
///
pub fn ortho_zo<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4<N> {
pub fn ortho_zo<T: RealField>(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4<T> {
ortho_rh_zo(left, right, bottom, top, znear, zfar)
}
@ -264,7 +264,7 @@ pub fn ortho_zo<N: RealField>(left: N, right: N, bottom: N, top: N, znear: N, zf
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov<N: RealField>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_fov<T: RealField>(fov: T, width: T, height: T, near: T, far: T) -> TMat4<T> {
perspective_fov_rh_no(fov, width, height, near, far)
}
@ -278,7 +278,7 @@ pub fn perspective_fov<N: RealField>(fov: N, width: N, height: N, near: N, far:
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_lh<N: RealField>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_fov_lh<T: RealField>(fov: T, width: T, height: T, near: T, far: T) -> TMat4<T> {
perspective_fov_lh_no(fov, width, height, near, far)
}
@ -292,16 +292,16 @@ pub fn perspective_fov_lh<N: RealField>(fov: N, width: N, height: N, near: N, fa
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_lh_no<N: RealField>(
fov: N,
width: N,
height: N,
near: N,
far: N,
) -> TMat4<N> {
assert!(width > N::zero(), "The width must be greater than zero");
assert!(height > N::zero(), "The height must be greater than zero.");
assert!(fov > N::zero(), "The fov must be greater than zero");
pub fn perspective_fov_lh_no<T: RealField>(
fov: T,
width: T,
height: T,
near: T,
far: T,
) -> TMat4<T> {
assert!(width > T::zero(), "The width must be greater than zero");
assert!(height > T::zero(), "The height must be greater than zero.");
assert!(fov > T::zero(), "The fov must be greater than zero");
let mut mat = TMat4::zeros();
@ -313,7 +313,7 @@ pub fn perspective_fov_lh_no<N: RealField>(
mat[(1, 1)] = h;
mat[(2, 2)] = (far + near) / (far - near);
mat[(2, 3)] = -(far * near * crate::convert(2.0)) / (far - near);
mat[(3, 2)] = N::one();
mat[(3, 2)] = T::one();
mat
}
@ -328,16 +328,16 @@ pub fn perspective_fov_lh_no<N: RealField>(
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_lh_zo<N: RealField>(
fov: N,
width: N,
height: N,
near: N,
far: N,
) -> TMat4<N> {
assert!(width > N::zero(), "The width must be greater than zero");
assert!(height > N::zero(), "The height must be greater than zero.");
assert!(fov > N::zero(), "The fov must be greater than zero");
pub fn perspective_fov_lh_zo<T: RealField>(
fov: T,
width: T,
height: T,
near: T,
far: T,
) -> TMat4<T> {
assert!(width > T::zero(), "The width must be greater than zero");
assert!(height > T::zero(), "The height must be greater than zero.");
assert!(fov > T::zero(), "The fov must be greater than zero");
let mut mat = TMat4::zeros();
@ -349,7 +349,7 @@ pub fn perspective_fov_lh_zo<N: RealField>(
mat[(1, 1)] = h;
mat[(2, 2)] = far / (far - near);
mat[(2, 3)] = -(far * near) / (far - near);
mat[(3, 2)] = N::one();
mat[(3, 2)] = T::one();
mat
}
@ -364,7 +364,7 @@ pub fn perspective_fov_lh_zo<N: RealField>(
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_no<N: RealField>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_fov_no<T: RealField>(fov: T, width: T, height: T, near: T, far: T) -> TMat4<T> {
perspective_fov_rh_no(fov, width, height, near, far)
}
@ -378,7 +378,7 @@ pub fn perspective_fov_no<N: RealField>(fov: N, width: N, height: N, near: N, fa
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_rh<N: RealField>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_fov_rh<T: RealField>(fov: T, width: T, height: T, near: T, far: T) -> TMat4<T> {
perspective_fov_rh_no(fov, width, height, near, far)
}
@ -392,16 +392,16 @@ pub fn perspective_fov_rh<N: RealField>(fov: N, width: N, height: N, near: N, fa
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_rh_no<N: RealField>(
fov: N,
width: N,
height: N,
near: N,
far: N,
) -> TMat4<N> {
assert!(width > N::zero(), "The width must be greater than zero");
assert!(height > N::zero(), "The height must be greater than zero.");
assert!(fov > N::zero(), "The fov must be greater than zero");
pub fn perspective_fov_rh_no<T: RealField>(
fov: T,
width: T,
height: T,
near: T,
far: T,
) -> TMat4<T> {
assert!(width > T::zero(), "The width must be greater than zero");
assert!(height > T::zero(), "The height must be greater than zero.");
assert!(fov > T::zero(), "The fov must be greater than zero");
let mut mat = TMat4::zeros();
@ -413,7 +413,7 @@ pub fn perspective_fov_rh_no<N: RealField>(
mat[(1, 1)] = h;
mat[(2, 2)] = -(far + near) / (far - near);
mat[(2, 3)] = -(far * near * crate::convert(2.0)) / (far - near);
mat[(3, 2)] = -N::one();
mat[(3, 2)] = -T::one();
mat
}
@ -428,16 +428,16 @@ pub fn perspective_fov_rh_no<N: RealField>(
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_rh_zo<N: RealField>(
fov: N,
width: N,
height: N,
near: N,
far: N,
) -> TMat4<N> {
assert!(width > N::zero(), "The width must be greater than zero");
assert!(height > N::zero(), "The height must be greater than zero.");
assert!(fov > N::zero(), "The fov must be greater than zero");
pub fn perspective_fov_rh_zo<T: RealField>(
fov: T,
width: T,
height: T,
near: T,
far: T,
) -> TMat4<T> {
assert!(width > T::zero(), "The width must be greater than zero");
assert!(height > T::zero(), "The height must be greater than zero.");
assert!(fov > T::zero(), "The fov must be greater than zero");
let mut mat = TMat4::zeros();
@ -449,7 +449,7 @@ pub fn perspective_fov_rh_zo<N: RealField>(
mat[(1, 1)] = h;
mat[(2, 2)] = far / (near - far);
mat[(2, 3)] = -(far * near) / (far - near);
mat[(3, 2)] = -N::one();
mat[(3, 2)] = -T::one();
mat
}
@ -464,7 +464,7 @@ pub fn perspective_fov_rh_zo<N: RealField>(
/// * `near` - Distance from the viewer to the near clipping plane
/// * `far` - Distance from the viewer to the far clipping plane
///
pub fn perspective_fov_zo<N: RealField>(fov: N, width: N, height: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_fov_zo<T: RealField>(fov: T, width: T, height: T, near: T, far: T) -> TMat4<T> {
perspective_fov_rh_zo(fov, width, height, near, far)
}
@ -479,7 +479,7 @@ pub fn perspective_fov_zo<N: RealField>(fov: N, width: N, height: N, near: N, fa
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
// TODO: Breaking change - revert back to proper glm conventions?
//
// Prior to changes to support configuring the behaviour of this function it was simply
@ -508,7 +508,7 @@ pub fn perspective<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_lh<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_lh<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
perspective_lh_no(aspect, fovy, near, far)
}
@ -523,19 +523,19 @@ pub fn perspective_lh<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_lh_no<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_lh_no<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
assert!(
!relative_eq!(far - near, N::zero()),
!relative_eq!(far - near, T::zero()),
"The near-plane and far-plane must not be superimposed."
);
assert!(
!relative_eq!(aspect, N::zero()),
!relative_eq!(aspect, T::zero()),
"The aspect ratio must not be zero."
);
let one = N::one();
let two: N = crate::convert(2.0);
let mut mat: TMat4<N> = TMat4::zeros();
let one = T::one();
let two: T = crate::convert(2.0);
let mut mat: TMat4<T> = TMat4::zeros();
let tan_half_fovy = (fovy / two).tan();
@ -559,19 +559,19 @@ pub fn perspective_lh_no<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> T
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_lh_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_lh_zo<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
assert!(
!relative_eq!(far - near, N::zero()),
!relative_eq!(far - near, T::zero()),
"The near-plane and far-plane must not be superimposed."
);
assert!(
!relative_eq!(aspect, N::zero()),
!relative_eq!(aspect, T::zero()),
"The aspect ratio must not be zero."
);
let one = N::one();
let two: N = crate::convert(2.0);
let mut mat: TMat4<N> = TMat4::zeros();
let one = T::one();
let two: T = crate::convert(2.0);
let mut mat: TMat4<T> = TMat4::zeros();
let tan_half_fovy = (fovy / two).tan();
@ -595,7 +595,7 @@ pub fn perspective_lh_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> T
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_no<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_no<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
perspective_rh_no(aspect, fovy, near, far)
}
@ -610,7 +610,7 @@ pub fn perspective_no<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_rh<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_rh<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
perspective_rh_no(aspect, fovy, near, far)
}
@ -625,19 +625,19 @@ pub fn perspective_rh<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_rh_no<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_rh_no<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
assert!(
!relative_eq!(far - near, N::zero()),
!relative_eq!(far - near, T::zero()),
"The near-plane and far-plane must not be superimposed."
);
assert!(
!relative_eq!(aspect, N::zero()),
!relative_eq!(aspect, T::zero()),
"The aspect ratio must not be zero."
);
let negone = -N::one();
let one = N::one();
let two: N = crate::convert(2.0);
let negone = -T::one();
let one = T::one();
let two: T = crate::convert(2.0);
let mut mat = TMat4::zeros();
let tan_half_fovy = (fovy / two).tan();
@ -662,18 +662,18 @@ pub fn perspective_rh_no<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> T
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_rh_zo<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
assert!(
!relative_eq!(far - near, N::zero()),
!relative_eq!(far - near, T::zero()),
"The near-plane and far-plane must not be superimposed."
);
assert!(
!relative_eq!(aspect, N::zero()),
!relative_eq!(aspect, T::zero()),
"The aspect ratio must not be zero."
);
let negone = -N::one();
let one = N::one();
let negone = -T::one();
let one = T::one();
let two = crate::convert(2.0);
let mut mat = TMat4::zeros();
@ -699,7 +699,7 @@ pub fn perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> T
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn perspective_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
pub fn perspective_zo<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
perspective_rh_zo(aspect, fovy, near, far)
}
@ -713,15 +713,15 @@ pub fn perspective_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat
///
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
pub fn infinite_perspective_rh_no<N: RealField>(aspect: N, fovy: N, near: N) -> TMat4<N> {
let f = N::one() / (fovy * na::convert(0.5)).tan();
pub fn infinite_perspective_rh_no<T: RealField>(aspect: T, fovy: T, near: T) -> TMat4<T> {
let f = T::one() / (fovy * na::convert(0.5)).tan();
let mut mat = TMat4::zeros();
mat[(0, 0)] = f / aspect;
mat[(1, 1)] = f;
mat[(2, 2)] = -N::one();
mat[(2, 2)] = -T::one();
mat[(2, 3)] = -near * na::convert(2.0);
mat[(3, 2)] = -N::one();
mat[(3, 2)] = -T::one();
mat
}
@ -738,15 +738,15 @@ pub fn infinite_perspective_rh_no<N: RealField>(aspect: N, fovy: N, near: N) ->
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
///
// https://discourse.nphysics.org/t/reversed-z-and-infinite-zfar-in-projections/341/2
pub fn infinite_perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N) -> TMat4<N> {
let f = N::one() / (fovy * na::convert(0.5)).tan();
pub fn infinite_perspective_rh_zo<T: RealField>(aspect: T, fovy: T, near: T) -> TMat4<T> {
let f = T::one() / (fovy * na::convert(0.5)).tan();
let mut mat = TMat4::zeros();
mat[(0, 0)] = f / aspect;
mat[(1, 1)] = f;
mat[(2, 2)] = -N::one();
mat[(2, 2)] = -T::one();
mat[(2, 3)] = -near;
mat[(3, 2)] = -N::one();
mat[(3, 2)] = -T::one();
mat
}
@ -763,8 +763,8 @@ pub fn infinite_perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N) ->
/// # Important note
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
// NOTE: The variants `_no` of reversed perspective are not useful.
pub fn reversed_perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N, far: N) -> TMat4<N> {
let one = N::one();
pub fn reversed_perspective_rh_zo<T: RealField>(aspect: T, fovy: T, near: T, far: T) -> TMat4<T> {
let one = T::one();
let two = crate::convert(2.0);
let mut mat = TMat4::zeros();
@ -791,22 +791,22 @@ pub fn reversed_perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N, far
/// The `aspect` and `fovy` argument are interchanged compared to the original GLM API.
// Credit: https://discourse.nphysics.org/t/reversed-z-and-infinite-zfar-in-projections/341/2
// NOTE: The variants `_no` of reversed perspective are not useful.
pub fn reversed_infinite_perspective_rh_zo<N: RealField>(aspect: N, fovy: N, near: N) -> TMat4<N> {
let f = N::one() / (fovy * na::convert(0.5)).tan();
pub fn reversed_infinite_perspective_rh_zo<T: RealField>(aspect: T, fovy: T, near: T) -> TMat4<T> {
let f = T::one() / (fovy * na::convert(0.5)).tan();
let mut mat = TMat4::zeros();
mat[(0, 0)] = f / aspect;
mat[(1, 1)] = f;
mat[(2, 3)] = near;
mat[(3, 2)] = -N::one();
mat[(3, 2)] = -T::one();
mat
}
//pub fn tweaked_infinite_perspective<N: RealField>(fovy: N, aspect: N, near: N) -> TMat4<N> {
//pub fn tweaked_infinite_perspective<T: RealField>(fovy: T, aspect: T, near: T) -> TMat4<T> {
// unimplemented!()
//}
//
//pub fn tweaked_infinite_perspective_ep<N: RealField>(fovy: N, aspect: N, near: N, ep: N) -> TMat4<N> {
//pub fn tweaked_infinite_perspective_ep<T: RealField>(fovy: T, aspect: T, near: T, ep: T) -> TMat4<T> {
// unimplemented!()
//}

View File

@ -1,4 +1,4 @@
use na::{self, RealField, U3};
use na::{self, RealField};
use crate::aliases::{TMat4, TVec2, TVec3, TVec4};
@ -9,22 +9,22 @@ use crate::aliases::{TMat4, TVec2, TVec3, TVec4};
/// * `center` - Specify the center of a picking region in window coordinates.
/// * `delta` - Specify the width and height, respectively, of the picking region in window coordinates.
/// * `viewport` - Rendering viewport.
pub fn pick_matrix<N: RealField>(
center: &TVec2<N>,
delta: &TVec2<N>,
viewport: &TVec4<N>,
) -> TMat4<N> {
pub fn pick_matrix<T: RealField>(
center: &TVec2<T>,
delta: &TVec2<T>,
viewport: &TVec4<T>,
) -> TMat4<T> {
let shift = TVec3::new(
(viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x,
(viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y,
N::zero(),
T::zero(),
);
let result = TMat4::new_translation(&shift);
result.prepend_nonuniform_scaling(&TVec3::new(
viewport.z / delta.x,
viewport.w / delta.y,
N::one(),
T::one(),
))
}
@ -45,12 +45,12 @@ pub fn pick_matrix<N: RealField>(
/// * [`unproject`](fn.unproject.html)
/// * [`unproject_no`](fn.unproject_no.html)
/// * [`unproject_zo`](fn.unproject_zo.html)
pub fn project<N: RealField>(
obj: &TVec3<N>,
model: &TMat4<N>,
proj: &TMat4<N>,
viewport: TVec4<N>,
) -> TVec3<N> {
pub fn project<T: RealField>(
obj: &TVec3<T>,
model: &TMat4<T>,
proj: &TMat4<T>,
viewport: TVec4<T>,
) -> TVec3<T> {
project_no(obj, model, proj, viewport)
}
@ -72,12 +72,12 @@ pub fn project<N: RealField>(
/// * [`unproject`](fn.unproject.html)
/// * [`unproject_no`](fn.unproject_no.html)
/// * [`unproject_zo`](fn.unproject_zo.html)
pub fn project_no<N: RealField>(
obj: &TVec3<N>,
model: &TMat4<N>,
proj: &TMat4<N>,
viewport: TVec4<N>,
) -> TVec3<N> {
pub fn project_no<T: RealField>(
obj: &TVec3<T>,
model: &TMat4<T>,
proj: &TMat4<T>,
viewport: TVec4<T>,
) -> TVec3<T> {
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,18 +100,18 @@ pub fn project_no<N: RealField>(
/// * [`unproject`](fn.unproject.html)
/// * [`unproject_no`](fn.unproject_no.html)
/// * [`unproject_zo`](fn.unproject_zo.html)
pub fn project_zo<N: RealField>(
obj: &TVec3<N>,
model: &TMat4<N>,
proj: &TMat4<N>,
viewport: TVec4<N>,
) -> TVec3<N> {
let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one());
let scale = N::one() / normalized.w;
pub fn project_zo<T: RealField>(
obj: &TVec3<T>,
model: &TMat4<T>,
proj: &TMat4<T>,
viewport: TVec4<T>,
) -> TVec3<T> {
let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, T::one());
let scale = T::one() / normalized.w;
TVec3::new(
viewport.x + (viewport.z * (normalized.x * scale + N::one()) * na::convert(0.5)),
viewport.y + (viewport.w * (normalized.y * scale + N::one()) * na::convert(0.5)),
viewport.x + (viewport.z * (normalized.x * scale + T::one()) * na::convert(0.5)),
viewport.y + (viewport.w * (normalized.y * scale + T::one()) * na::convert(0.5)),
normalized.z * scale,
)
}
@ -133,12 +133,12 @@ pub fn project_zo<N: RealField>(
/// * [`project_zo`](fn.project_zo.html)
/// * [`unproject_no`](fn.unproject_no.html)
/// * [`unproject_zo`](fn.unproject_zo.html)
pub fn unproject<N: RealField>(
win: &TVec3<N>,
model: &TMat4<N>,
proj: &TMat4<N>,
viewport: TVec4<N>,
) -> TVec3<N> {
pub fn unproject<T: RealField>(
win: &TVec3<T>,
model: &TMat4<T>,
proj: &TMat4<T>,
viewport: TVec4<T>,
) -> TVec3<T> {
unproject_no(win, model, proj, viewport)
}
@ -160,23 +160,23 @@ pub fn unproject<N: RealField>(
/// * [`project_zo`](fn.project_zo.html)
/// * [`unproject`](fn.unproject.html)
/// * [`unproject_zo`](fn.unproject_zo.html)
pub fn unproject_no<N: RealField>(
win: &TVec3<N>,
model: &TMat4<N>,
proj: &TMat4<N>,
viewport: TVec4<N>,
) -> TVec3<N> {
let _2: N = na::convert(2.0);
pub fn unproject_no<T: RealField>(
win: &TVec3<T>,
model: &TMat4<T>,
proj: &TMat4<T>,
viewport: TVec4<T>,
) -> TVec3<T> {
let _2: T = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
let pt = TVec4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(),
_2 * win.z - N::one(),
N::one(),
_2 * (win.x - viewport.x) / viewport.z - T::one(),
_2 * (win.y - viewport.y) / viewport.w - T::one(),
_2 * win.z - T::one(),
T::one(),
);
let result = transform * pt;
result.fixed_rows::<U3>(0) / result.w
result.fixed_rows::<3>(0) / result.w
}
/// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates.
@ -197,21 +197,21 @@ pub fn unproject_no<N: RealField>(
/// * [`project_zo`](fn.project_zo.html)
/// * [`unproject`](fn.unproject.html)
/// * [`unproject_no`](fn.unproject_no.html)
pub fn unproject_zo<N: RealField>(
win: &TVec3<N>,
model: &TMat4<N>,
proj: &TMat4<N>,
viewport: TVec4<N>,
) -> TVec3<N> {
let _2: N = na::convert(2.0);
pub fn unproject_zo<T: RealField>(
win: &TVec3<T>,
model: &TMat4<T>,
proj: &TMat4<T>,
viewport: TVec4<T>,
) -> TVec3<T> {
let _2: T = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
let pt = TVec4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(),
_2 * (win.x - viewport.x) / viewport.z - T::one(),
_2 * (win.y - viewport.y) / viewport.w - T::one(),
win.z,
N::one(),
T::one(),
);
let result = transform * pt;
result.fixed_rows::<U3>(0) / result.w
result.fixed_rows::<3>(0) / result.w
}

View File

@ -1,21 +1,16 @@
use na::DefaultAllocator;
use crate::aliases::{TMat, TVec};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// Perform a component-wise equal-to comparison of two matrices.
///
/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
pub fn equal_columns<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
) -> TVec<bool, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn equal_columns<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
) -> TVec<bool, C> {
let mut res = TVec::<_, C>::repeat(false);
for i in 0..C::dim() {
for i in 0..C {
res[i] = x.column(i) == y.column(i)
}
@ -25,31 +20,25 @@ where
/// Returns the component-wise comparison of `|x - y| < epsilon`.
///
/// True if this expression is satisfied.
pub fn equal_columns_eps<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
epsilon: N,
) -> TVec<bool, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn equal_columns_eps<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
epsilon: T,
) -> TVec<bool, C> {
equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
}
/// Returns the component-wise comparison on each matrix column `|x - y| < epsilon`.
///
/// True if this expression is satisfied.
pub fn equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
epsilon: &TVec<N, C>,
) -> TVec<bool, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn equal_columns_eps_vec<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
epsilon: &TVec<T, C>,
) -> TVec<bool, C> {
let mut res = TVec::<_, C>::repeat(false);
for i in 0..C::dim() {
for i in 0..C {
res[i] = (x.column(i) - y.column(i)).abs() < TVec::<_, R>::repeat(epsilon[i])
}
@ -59,16 +48,13 @@ where
/// Perform a component-wise not-equal-to comparison of two matrices.
///
/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
pub fn not_equal_columns<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
) -> TVec<bool, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn not_equal_columns<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
) -> TVec<bool, C> {
let mut res = TVec::<_, C>::repeat(false);
for i in 0..C::dim() {
for i in 0..C {
res[i] = x.column(i) != y.column(i)
}
@ -78,31 +64,25 @@ where
/// Returns the component-wise comparison of `|x - y| < epsilon`.
///
/// True if this expression is not satisfied.
pub fn not_equal_columns_eps<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
epsilon: N,
) -> TVec<bool, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn not_equal_columns_eps<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
epsilon: T,
) -> TVec<bool, C> {
not_equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
}
/// Returns the component-wise comparison of `|x - y| >= epsilon`.
///
/// True if this expression is not satisfied.
pub fn not_equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
epsilon: &TVec<N, C>,
) -> TVec<bool, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn not_equal_columns_eps_vec<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
epsilon: &TVec<T, C>,
) -> TVec<bool, C> {
let mut res = TVec::<_, C>::repeat(false);
for i in 0..C::dim() {
for i in 0..C {
res[i] = (x.column(i) - y.column(i)).abs() >= TVec::<_, R>::repeat(epsilon[i])
}

View File

@ -1,14 +1,11 @@
use na::{DefaultAllocator, Point3, RealField, Rotation3, Unit};
use na::{Point3, RealField, Rotation3, Unit};
use crate::aliases::{TMat, TMat4, TVec, TVec3};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// The identity matrix.
pub fn identity<N: Number, D: Dimension>() -> TMat<N, D, D>
where
DefaultAllocator: Alloc<N, D, D>,
{
TMat::<N, D, D>::identity()
pub fn identity<T: Number, const D: usize>() -> TMat<T, D, D> {
TMat::<T, D, D>::identity()
}
/// Build a look at view matrix based on the right handedness.
@ -23,7 +20,7 @@ where
///
/// * [`look_at_lh`](fn.look_at_lh.html)
/// * [`look_at_rh`](fn.look_at_rh.html)
pub fn look_at<N: RealField>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
pub fn look_at<T: RealField>(eye: &TVec3<T>, center: &TVec3<T>, up: &TVec3<T>) -> TMat4<T> {
look_at_rh(eye, center, up)
}
@ -39,7 +36,7 @@ pub fn look_at<N: RealField>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -
///
/// * [`look_at`](fn.look_at.html)
/// * [`look_at_rh`](fn.look_at_rh.html)
pub fn look_at_lh<N: RealField>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
pub fn look_at_lh<T: RealField>(eye: &TVec3<T>, center: &TVec3<T>, up: &TVec3<T>) -> TMat4<T> {
TMat::look_at_lh(&Point3::from(*eye), &Point3::from(*center), up)
}
@ -55,7 +52,7 @@ pub fn look_at_lh<N: RealField>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>
///
/// * [`look_at`](fn.look_at.html)
/// * [`look_at_lh`](fn.look_at_lh.html)
pub fn look_at_rh<N: RealField>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
pub fn look_at_rh<T: RealField>(eye: &TVec3<T>, center: &TVec3<T>, up: &TVec3<T>) -> TMat4<T> {
TMat::look_at_rh(&Point3::from(*eye), &Point3::from(*center), up)
}
@ -74,7 +71,7 @@ pub fn look_at_rh<N: RealField>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>
/// * [`rotate_z`](fn.rotate_z.html)
/// * [`scale`](fn.scale.html)
/// * [`translate`](fn.translate.html)
pub fn rotate<N: RealField>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
pub fn rotate<T: RealField>(m: &TMat4<T>, angle: T, axis: &TVec3<T>) -> TMat4<T> {
m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous()
}
@ -92,7 +89,7 @@ pub fn rotate<N: RealField>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N>
/// * [`rotate_z`](fn.rotate_z.html)
/// * [`scale`](fn.scale.html)
/// * [`translate`](fn.translate.html)
pub fn rotate_x<N: RealField>(m: &TMat4<N>, angle: N) -> TMat4<N> {
pub fn rotate_x<T: RealField>(m: &TMat4<T>, angle: T) -> TMat4<T> {
rotate(m, angle, &TVec::x())
}
@ -110,7 +107,7 @@ pub fn rotate_x<N: RealField>(m: &TMat4<N>, angle: N) -> TMat4<N> {
/// * [`rotate_z`](fn.rotate_z.html)
/// * [`scale`](fn.scale.html)
/// * [`translate`](fn.translate.html)
pub fn rotate_y<N: RealField>(m: &TMat4<N>, angle: N) -> TMat4<N> {
pub fn rotate_y<T: RealField>(m: &TMat4<T>, angle: T) -> TMat4<T> {
rotate(m, angle, &TVec::y())
}
@ -128,7 +125,7 @@ pub fn rotate_y<N: RealField>(m: &TMat4<N>, angle: N) -> TMat4<N> {
/// * [`rotate_y`](fn.rotate_y.html)
/// * [`scale`](fn.scale.html)
/// * [`translate`](fn.translate.html)
pub fn rotate_z<N: RealField>(m: &TMat4<N>, angle: N) -> TMat4<N> {
pub fn rotate_z<T: RealField>(m: &TMat4<T>, angle: T) -> TMat4<T> {
rotate(m, angle, &TVec::z())
}
@ -146,7 +143,7 @@ pub fn rotate_z<N: RealField>(m: &TMat4<N>, angle: N) -> TMat4<N> {
/// * [`rotate_y`](fn.rotate_y.html)
/// * [`rotate_z`](fn.rotate_z.html)
/// * [`translate`](fn.translate.html)
pub fn scale<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
pub fn scale<T: Number>(m: &TMat4<T>, v: &TVec3<T>) -> TMat4<T> {
m.prepend_nonuniform_scaling(v)
}
@ -164,6 +161,6 @@ pub fn scale<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
/// * [`rotate_y`](fn.rotate_y.html)
/// * [`rotate_z`](fn.rotate_z.html)
/// * [`scale`](fn.scale.html)
pub fn translate<N: Number>(m: &TMat4<N>, v: &TVec3<N>) -> TMat4<N> {
pub fn translate<T: Number>(m: &TMat4<T>, v: &TVec3<T>) -> TMat4<T> {
m.prepend_translation(v)
}

View File

@ -3,34 +3,34 @@ use na::{self, RealField, Unit};
use crate::aliases::Qua;
/// The conjugate of `q`.
pub fn quat_conjugate<N: RealField>(q: &Qua<N>) -> Qua<N> {
pub fn quat_conjugate<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.conjugate()
}
/// The inverse of `q`.
pub fn quat_inverse<N: RealField>(q: &Qua<N>) -> Qua<N> {
pub fn quat_inverse<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.try_inverse().unwrap_or_else(na::zero)
}
//pub fn quat_isinf<N: RealField>(x: &Qua<N>) -> TVec<bool, U4> {
//pub fn quat_isinf<T: RealField>(x: &Qua<T>) -> TVec<bool, U4> {
// x.coords.map(|e| e.is_inf())
//}
//pub fn quat_isnan<N: RealField>(x: &Qua<N>) -> TVec<bool, U4> {
//pub fn quat_isnan<T: RealField>(x: &Qua<T>) -> TVec<bool, U4> {
// x.coords.map(|e| e.is_nan())
//}
/// Interpolate linearly between `x` and `y`.
pub fn quat_lerp<N: RealField>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
pub fn quat_lerp<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
x.lerp(y, a)
}
//pub fn quat_mix<N: RealField>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
// x * (N::one() - a) + y * a
//pub fn quat_mix<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
// x * (T::one() - a) + y * a
//}
/// Interpolate spherically between `x` and `y`.
pub fn quat_slerp<N: RealField>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
pub fn quat_slerp<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
Unit::new_normalize(*x)
.slerp(&Unit::new_normalize(*y), a)
.into_inner()

View File

@ -3,26 +3,26 @@ use na::RealField;
use crate::aliases::Qua;
/// Multiplies two quaternions.
pub fn quat_cross<N: RealField>(q1: &Qua<N>, q2: &Qua<N>) -> Qua<N> {
pub fn quat_cross<T: RealField>(q1: &Qua<T>, q2: &Qua<T>) -> Qua<T> {
q1 * q2
}
/// The scalar product of two quaternions.
pub fn quat_dot<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> N {
pub fn quat_dot<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> T {
x.dot(y)
}
/// The magnitude of the quaternion `q`.
pub fn quat_length<N: RealField>(q: &Qua<N>) -> N {
pub fn quat_length<T: RealField>(q: &Qua<T>) -> T {
q.norm()
}
/// The magnitude of the quaternion `q`.
pub fn quat_magnitude<N: RealField>(q: &Qua<N>) -> N {
pub fn quat_magnitude<T: RealField>(q: &Qua<T>) -> T {
q.norm()
}
/// Normalizes the quaternion `q`.
pub fn quat_normalize<N: RealField>(q: &Qua<N>) -> Qua<N> {
pub fn quat_normalize<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.normalize()
}

View File

@ -1,23 +1,23 @@
use na::{RealField, U4};
use na::RealField;
use crate::aliases::{Qua, TVec};
/// Component-wise equality comparison between two quaternions.
pub fn quat_equal<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
pub fn quat_equal<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> TVec<bool, 4> {
crate::equal(&x.coords, &y.coords)
}
/// Component-wise approximate equality comparison between two quaternions.
pub fn quat_equal_eps<N: RealField>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> TVec<bool, U4> {
pub fn quat_equal_eps<T: RealField>(x: &Qua<T>, y: &Qua<T>, epsilon: T) -> TVec<bool, 4> {
crate::equal_eps(&x.coords, &y.coords, epsilon)
}
/// Component-wise non-equality comparison between two quaternions.
pub fn quat_not_equal<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
pub fn quat_not_equal<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> TVec<bool, 4> {
crate::not_equal(&x.coords, &y.coords)
}
/// Component-wise approximate non-equality comparison between two quaternions.
pub fn quat_not_equal_eps<N: RealField>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> TVec<bool, U4> {
pub fn quat_not_equal_eps<T: RealField>(x: &Qua<T>, y: &Qua<T>, epsilon: T) -> TVec<bool, 4> {
crate::not_equal_eps(&x.coords, &y.coords, epsilon)
}

View File

@ -3,25 +3,25 @@ use na::{RealField, Unit, UnitQuaternion};
use crate::aliases::{Qua, TVec3};
/// Computes the quaternion exponential.
pub fn quat_exp<N: RealField>(q: &Qua<N>) -> Qua<N> {
pub fn quat_exp<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.exp()
}
/// Computes the quaternion logarithm.
pub fn quat_log<N: RealField>(q: &Qua<N>) -> Qua<N> {
pub fn quat_log<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.ln()
}
/// Raises the quaternion `q` to the power `y`.
pub fn quat_pow<N: RealField>(q: &Qua<N>, y: N) -> Qua<N> {
pub fn quat_pow<T: RealField>(q: &Qua<T>, y: T) -> Qua<T> {
q.powf(y)
}
/// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`.
pub fn quat_rotate<N: RealField>(q: &Qua<N>, angle: N, axis: &TVec3<N>) -> Qua<N> {
pub fn quat_rotate<T: RealField>(q: &Qua<T>, angle: T, axis: &TVec3<T>) -> Qua<T> {
q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner()
}
//pub fn quat_sqrt<N: RealField>(q: &Qua<N>) -> Qua<N> {
//pub fn quat_sqrt<T: RealField>(q: &Qua<T>) -> Qua<T> {
// unimplemented!()
//}

View File

@ -3,17 +3,17 @@ use na::{RealField, Unit, UnitQuaternion};
use crate::aliases::{Qua, TVec3};
/// The rotation angle of this quaternion assumed to be normalized.
pub fn quat_angle<N: RealField>(x: &Qua<N>) -> N {
pub fn quat_angle<T: RealField>(x: &Qua<T>) -> T {
UnitQuaternion::from_quaternion(*x).angle()
}
/// Creates a quaternion from an axis and an angle.
pub fn quat_angle_axis<N: RealField>(angle: N, axis: &TVec3<N>) -> Qua<N> {
pub fn quat_angle_axis<T: RealField>(angle: T, axis: &TVec3<T>) -> Qua<T> {
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner()
}
/// The rotation axis of a quaternion assumed to be normalized.
pub fn quat_axis<N: RealField>(x: &Qua<N>) -> TVec3<N> {
pub fn quat_axis<T: RealField>(x: &Qua<T>) -> TVec3<T> {
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
a.into_inner()
} else {

View File

@ -15,7 +15,7 @@ use crate::traits::Number;
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
pub fn max2_scalar<N: Number>(a: N, b: N) -> N {
pub fn max2_scalar<T: Number>(a: T, b: T) -> T {
if a >= b {
a
} else {
@ -38,7 +38,7 @@ pub fn max2_scalar<N: Number>(a: N, b: N) -> N {
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
pub fn min2_scalar<N: Number>(a: N, b: N) -> N {
pub fn min2_scalar<T: Number>(a: T, b: T) -> T {
if a <= b {
a
} else {
@ -61,7 +61,7 @@ pub fn min2_scalar<N: Number>(a: N, b: N) -> N {
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
pub fn max3_scalar<N: Number>(a: N, b: N, c: N) -> N {
pub fn max3_scalar<T: Number>(a: T, b: T, c: T) -> T {
max2_scalar(max2_scalar(a, b), c)
}
@ -80,7 +80,7 @@ pub fn max3_scalar<N: Number>(a: N, b: N, c: N) -> N {
/// * [`max3_scalar`](fn.max3_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
pub fn max4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
pub fn max4_scalar<T: Number>(a: T, b: T, c: T, d: T) -> T {
max2_scalar(max2_scalar(a, b), max2_scalar(c, d))
}
@ -99,7 +99,7 @@ pub fn max4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
/// * [`max3_scalar`](fn.max3_scalar.html)
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
pub fn min3_scalar<N: Number>(a: N, b: N, c: N) -> N {
pub fn min3_scalar<T: Number>(a: T, b: T, c: T) -> T {
min2_scalar(min2_scalar(a, b), c)
}
@ -118,6 +118,6 @@ pub fn min3_scalar<N: Number>(a: N, b: N, c: N) -> N {
/// * [`max3_scalar`](fn.max3_scalar.html)
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
pub fn min4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
pub fn min4_scalar<T: Number>(a: T, b: T, c: T, d: T) -> T {
min2_scalar(min2_scalar(a, b), min2_scalar(c, d))
}

View File

@ -2,8 +2,8 @@ use approx::AbsDiffEq;
use na::RealField;
/// Default epsilon value used for approximate comparison.
pub fn epsilon<N: AbsDiffEq<Epsilon = N>>() -> N {
N::default_epsilon()
pub fn epsilon<T: AbsDiffEq<Epsilon = T>>() -> T {
T::default_epsilon()
}
/// The value of PI.
@ -22,6 +22,6 @@ pub fn epsilon<N: AbsDiffEq<Epsilon = N>>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn pi<N: RealField>() -> N {
N::pi()
pub fn pi<T: RealField>() -> T {
T::pi()
}

View File

@ -1,7 +1,5 @@
use na::{self, DefaultAllocator};
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// Component-wise maximum between a vector and a scalar.
///
@ -16,10 +14,7 @@ use crate::traits::{Alloc, Dimension, Number};
/// * [`min2`](fn.min2.html)
/// * [`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>,
{
pub fn max<T: Number, const D: usize>(a: &TVec<T, D>, b: T) -> TVec<T, D> {
a.map(|a| crate::max2_scalar(a, b))
}
@ -36,10 +31,7 @@ where
/// * [`min2`](fn.min2.html)
/// * [`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>,
{
pub fn max2<T: Number, const D: usize>(a: &TVec<T, D>, b: &TVec<T, D>) -> TVec<T, D> {
a.zip_map(b, |a, b| crate::max2_scalar(a, b))
}
@ -56,10 +48,11 @@ where
/// * [`min2`](fn.min2.html)
/// * [`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>,
{
pub fn max3<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
) -> TVec<T, D> {
max2(&max2(a, b), c)
}
@ -76,15 +69,12 @@ where
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
pub fn max4<N: Number, D: Dimension>(
a: &TVec<N, D>,
b: &TVec<N, D>,
c: &TVec<N, D>,
d: &TVec<N, D>,
) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn max4<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
d: &TVec<T, D>,
) -> TVec<T, D> {
max2(&max2(a, b), &max2(c, d))
}
@ -101,10 +91,7 @@ where
/// * [`min2`](fn.min2.html)
/// * [`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>,
{
pub fn min<T: Number, const D: usize>(x: &TVec<T, D>, y: T) -> TVec<T, D> {
x.map(|x| crate::min2_scalar(x, y))
}
@ -121,10 +108,7 @@ where
/// * [`min`](fn.min.html)
/// * [`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>,
{
pub fn min2<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<T, D> {
x.zip_map(y, |a, b| crate::min2_scalar(a, b))
}
@ -141,10 +125,11 @@ where
/// * [`min`](fn.min.html)
/// * [`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>,
{
pub fn min3<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
) -> TVec<T, D> {
min2(&min2(a, b), c)
}
@ -161,14 +146,11 @@ where
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
pub fn min4<N: Number, D: Dimension>(
a: &TVec<N, D>,
b: &TVec<N, D>,
c: &TVec<N, D>,
d: &TVec<N, D>,
) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn min4<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
d: &TVec<T, D>,
) -> TVec<T, D> {
min2(&min2(a, b), &min2(c, d))
}

View File

@ -1,7 +1,5 @@
use na::DefaultAllocator;
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// Component-wise approximate equality of two vectors, using a scalar epsilon.
///
@ -10,14 +8,11 @@ use crate::traits::{Alloc, Dimension, Number};
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
/// * [`not_equal_eps`](fn.not_equal_eps.html)
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
pub fn equal_eps<N: Number, D: Dimension>(
x: &TVec<N, D>,
y: &TVec<N, D>,
epsilon: N,
) -> TVec<bool, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn equal_eps<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
epsilon: T,
) -> TVec<bool, D> {
x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon))
}
@ -28,14 +23,11 @@ where
/// * [`equal_eps`](fn.equal_eps.html)
/// * [`not_equal_eps`](fn.not_equal_eps.html)
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
pub fn equal_eps_vec<N: Number, D: Dimension>(
x: &TVec<N, D>,
y: &TVec<N, D>,
epsilon: &TVec<N, D>,
) -> TVec<bool, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn equal_eps_vec<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
epsilon: &TVec<T, D>,
) -> TVec<bool, D> {
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_eq!(x, y, epsilon = eps))
}
@ -46,14 +38,11 @@ where
/// * [`equal_eps`](fn.equal_eps.html)
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
pub fn not_equal_eps<N: Number, D: Dimension>(
x: &TVec<N, D>,
y: &TVec<N, D>,
epsilon: N,
) -> TVec<bool, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn not_equal_eps<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
epsilon: T,
) -> TVec<bool, D> {
x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon))
}
@ -64,13 +53,10 @@ where
/// * [`equal_eps`](fn.equal_eps.html)
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
/// * [`not_equal_eps`](fn.not_equal_eps.html)
pub fn not_equal_eps_vec<N: Number, D: Dimension>(
x: &TVec<N, D>,
y: &TVec<N, D>,
epsilon: &TVec<N, D>,
) -> TVec<bool, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn not_equal_eps_vec<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
epsilon: &TVec<T, D>,
) -> TVec<bool, D> {
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_ne!(x, y, epsilon = eps))
}

View File

@ -1,10 +1,10 @@
use na::{DefaultAllocator, RealField};
use na::RealField;
use crate::aliases::{TVec, TVec3};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// The cross product of two vectors.
pub fn cross<N: Number>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
pub fn cross<T: Number>(x: &TVec3<T>, y: &TVec3<T>) -> TVec3<T> {
x.cross(y)
}
@ -13,31 +13,22 @@ pub fn cross<N: Number>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
/// # See also:
///
/// * [`distance2`](fn.distance2.html)
pub fn distance<N: RealField, D: Dimension>(p0: &TVec<N, D>, p1: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn distance<T: RealField, const D: usize>(p0: &TVec<T, D>, p1: &TVec<T, D>) -> T {
(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>,
{
pub fn dot<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> T {
x.dot(y)
}
/// If `dot(nref, i) < 0.0`, return `n`, otherwise, return `-n`.
pub fn faceforward<N: Number, D: Dimension>(
n: &TVec<N, D>,
i: &TVec<N, D>,
nref: &TVec<N, D>,
) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
if nref.dot(i) < N::zero() {
pub fn faceforward<T: Number, const D: usize>(
n: &TVec<T, D>,
i: &TVec<T, D>,
nref: &TVec<T, D>,
) -> TVec<T, D> {
if nref.dot(i) < T::zero() {
n.clone()
} else {
-n.clone()
@ -53,10 +44,7 @@ where
/// * [`length2`](fn.length2.html)
/// * [`magnitude`](fn.magnitude.html)
/// * [`magnitude2`](fn.magnitude2.html)
pub fn length<N: RealField, D: Dimension>(x: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn length<T: RealField, const D: usize>(x: &TVec<T, D>) -> T {
x.norm()
}
@ -69,39 +57,31 @@ where
/// * [`length`](fn.length.html)
/// * [`magnitude2`](fn.magnitude2.html)
/// * [`nalgebra::norm`](../nalgebra/fn.norm.html)
pub fn magnitude<N: RealField, D: Dimension>(x: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn magnitude<T: RealField, const D: usize>(x: &TVec<T, D>) -> T {
x.norm()
}
/// Normalizes a vector.
pub fn normalize<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn normalize<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, 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>,
{
let _2 = N::one() + N::one();
pub fn reflect_vec<T: Number, const D: usize>(i: &TVec<T, D>, n: &TVec<T, D>) -> TVec<T, D> {
let _2 = T::one() + T::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: RealField, D: Dimension>(i: &TVec<N, D>, n: &TVec<N, D>, eta: N) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn refract_vec<T: RealField, const D: usize>(
i: &TVec<T, D>,
n: &TVec<T, D>,
eta: T,
) -> TVec<T, D> {
let ni = n.dot(i);
let k = N::one() - eta * eta * (N::one() - ni * ni);
let k = T::one() - eta * eta * (T::one() - ni * ni);
if k < N::zero() {
if k < T::zero() {
TVec::<_, D>::zeros()
} else {
i * eta - n * (eta * dot(n, i) + k.sqrt())

View File

@ -1,6 +1,5 @@
use na::{Scalar, DefaultAllocator};
use na::{DefaultAllocator, Scalar};
use crate::traits::{Alloc, Dimension};
use crate::aliases::*;
pub fn bitfieldDeinterleave(x: u16) -> U8Vec2 {
@ -19,8 +18,11 @@ pub fn bitfieldFillOne<IU>(Value: IU, FirstBit: i32, BitCount: i32) -> IU {
unimplemented!()
}
pub fn bitfieldFillOne2<N: Scalar, D: Dimension>(Value: &TVec<N, D>, FirstBit: i32, BitCount: i32) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldFillOne2<T: Scalar, const D: usize>(
Value: &TVec<T, D>,
FirstBit: i32,
BitCount: i32,
) -> TVec<T, D> {
unimplemented!()
}
@ -28,8 +30,11 @@ pub fn bitfieldFillZero<IU>(Value: IU, FirstBit: i32, BitCount: i32) -> IU {
unimplemented!()
}
pub fn bitfieldFillZero2<N: Scalar, D: Dimension>(Value: &TVec<N, D>, FirstBit: i32, BitCount: i32) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldFillZero2<T: Scalar, const D: usize>(
Value: &TVec<T, D>,
FirstBit: i32,
BitCount: i32,
) -> TVec<T, D> {
unimplemented!()
}
@ -113,8 +118,7 @@ pub fn bitfieldRotateLeft<IU>(In: IU, Shift: i32) -> IU {
unimplemented!()
}
pub fn bitfieldRotateLeft2<N: Scalar, D: Dimension>(In: &TVec<N, D>, Shift: i32) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldRotateLeft2<T: Scalar, const D: usize>(In: &TVec<T, D>, Shift: i32) -> TVec<T, D> {
unimplemented!()
}
@ -122,8 +126,7 @@ pub fn bitfieldRotateRight<IU>(In: IU, Shift: i32) -> IU {
unimplemented!()
}
pub fn bitfieldRotateRight2<N: Scalar, D: Dimension>(In: &TVec<N, D>, Shift: i32) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldRotateRight2<T: Scalar, const D: usize>(In: &TVec<T, D>, Shift: i32) -> TVec<T, D> {
unimplemented!()
}
@ -131,7 +134,6 @@ pub fn mask<IU>(Bits: IU) -> IU {
unimplemented!()
}
pub fn mask2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn mask2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<T, D> {
unimplemented!()
}

View File

@ -3,13 +3,13 @@ use na::{self, RealField};
/// The Euler constant.
///
/// This is a shorthand alias for [`euler`](fn.euler.html).
pub fn e<N: RealField>() -> N {
N::e()
pub fn e<T: RealField>() -> T {
T::e()
}
/// The Euler constant.
pub fn euler<N: RealField>() -> N {
N::e()
pub fn euler<T: RealField>() -> T {
T::e()
}
/// Returns `4 / pi`.
@ -28,13 +28,13 @@ pub fn euler<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn four_over_pi<N: RealField>() -> N {
na::convert::<_, N>(4.0) / N::pi()
pub fn four_over_pi<T: RealField>() -> T {
na::convert::<_, T>(4.0) / T::pi()
}
/// Returns the golden ratio.
pub fn golden_ratio<N: RealField>() -> N {
(N::one() + root_five()) / na::convert(2.0)
pub fn golden_ratio<T: RealField>() -> T {
(T::one() + root_five()) / na::convert(2.0)
}
/// Returns `pi / 2`.
@ -53,8 +53,8 @@ pub fn golden_ratio<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn half_pi<N: RealField>() -> N {
N::frac_pi_2()
pub fn half_pi<T: RealField>() -> T {
T::frac_pi_2()
}
/// Returns `ln(ln(2))`.
@ -63,8 +63,8 @@ pub fn half_pi<N: RealField>() -> N {
///
/// * [`ln_ten`](fn.ln_ten.html)
/// * [`ln_two`](fn.ln_two.html)
pub fn ln_ln_two<N: RealField>() -> N {
N::ln_2().ln()
pub fn ln_ln_two<T: RealField>() -> T {
T::ln_2().ln()
}
/// Returns `ln(10)`.
@ -73,8 +73,8 @@ pub fn ln_ln_two<N: RealField>() -> N {
///
/// * [`ln_ln_two`](fn.ln_ln_two.html)
/// * [`ln_two`](fn.ln_two.html)
pub fn ln_ten<N: RealField>() -> N {
N::ln_10()
pub fn ln_ten<T: RealField>() -> T {
T::ln_10()
}
/// Returns `ln(2)`.
@ -83,8 +83,8 @@ pub fn ln_ten<N: RealField>() -> N {
///
/// * [`ln_ln_two`](fn.ln_ln_two.html)
/// * [`ln_ten`](fn.ln_ten.html)
pub fn ln_two<N: RealField>() -> N {
N::ln_2()
pub fn ln_two<T: RealField>() -> T {
T::ln_2()
}
/// Returns `1`.
@ -106,13 +106,13 @@ pub use na::one;
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn one_over_pi<N: RealField>() -> N {
N::frac_1_pi()
pub fn one_over_pi<T: RealField>() -> T {
T::frac_1_pi()
}
/// Returns `1 / sqrt(2)`.
pub fn one_over_root_two<N: RealField>() -> N {
N::one() / root_two()
pub fn one_over_root_two<T: RealField>() -> T {
T::one() / root_two()
}
/// Returns `1 / (2pi)`.
@ -131,8 +131,8 @@ pub fn one_over_root_two<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn one_over_two_pi<N: RealField>() -> N {
N::frac_1_pi() * na::convert(0.5)
pub fn one_over_two_pi<T: RealField>() -> T {
T::frac_1_pi() * na::convert(0.5)
}
/// Returns `pi / 4`.
@ -151,8 +151,8 @@ pub fn one_over_two_pi<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn quarter_pi<N: RealField>() -> N {
N::frac_pi_4()
pub fn quarter_pi<T: RealField>() -> T {
T::frac_pi_4()
}
/// Returns `sqrt(5)`.
@ -161,8 +161,8 @@ pub fn quarter_pi<N: RealField>() -> N {
///
/// * [`root_three`](fn.root_three.html)
/// * [`root_two`](fn.root_two.html)
pub fn root_five<N: RealField>() -> N {
na::convert::<_, N>(5.0).sqrt()
pub fn root_five<T: RealField>() -> T {
na::convert::<_, T>(5.0).sqrt()
}
/// Returns `sqrt(pi / 2)`.
@ -181,13 +181,13 @@ pub fn root_five<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn root_half_pi<N: RealField>() -> N {
(N::pi() / na::convert(2.0)).sqrt()
pub fn root_half_pi<T: RealField>() -> T {
(T::pi() / na::convert(2.0)).sqrt()
}
/// Returns `sqrt(ln(4))`.
pub fn root_ln_four<N: RealField>() -> N {
na::convert::<_, N>(4.0).ln().sqrt()
pub fn root_ln_four<T: RealField>() -> T {
na::convert::<_, T>(4.0).ln().sqrt()
}
/// Returns the square root of pi.
@ -206,8 +206,8 @@ pub fn root_ln_four<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn root_pi<N: RealField>() -> N {
N::pi().sqrt()
pub fn root_pi<T: RealField>() -> T {
T::pi().sqrt()
}
/// Returns the square root of 3.
@ -216,8 +216,8 @@ pub fn root_pi<N: RealField>() -> N {
///
/// * [`root_five`](fn.root_five.html)
/// * [`root_two`](fn.root_two.html)
pub fn root_three<N: RealField>() -> N {
na::convert::<_, N>(3.0).sqrt()
pub fn root_three<T: RealField>() -> T {
na::convert::<_, T>(3.0).sqrt()
}
/// Returns the square root of 2.
@ -226,9 +226,9 @@ pub fn root_three<N: RealField>() -> N {
///
/// * [`root_five`](fn.root_five.html)
/// * [`root_three`](fn.root_three.html)
pub fn root_two<N: RealField>() -> N {
pub fn root_two<T: RealField>() -> T {
// TODO: there should be a crate::sqrt_2() on the RealField trait.
na::convert::<_, N>(2.0).sqrt()
na::convert::<_, T>(2.0).sqrt()
}
/// Returns the square root of 2pi.
@ -247,8 +247,8 @@ pub fn root_two<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn root_two_pi<N: RealField>() -> N {
N::two_pi().sqrt()
pub fn root_two_pi<T: RealField>() -> T {
T::two_pi().sqrt()
}
/// Returns `1 / 3`.
@ -256,7 +256,7 @@ pub fn root_two_pi<N: RealField>() -> N {
/// # See also:
///
/// * [`two_thirds`](fn.two_thirds.html)
pub fn third<N: RealField>() -> N {
pub fn third<T: RealField>() -> T {
na::convert(1.0 / 3.0)
}
@ -276,8 +276,8 @@ pub fn third<N: RealField>() -> N {
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn three_over_two_pi<N: RealField>() -> N {
na::convert::<_, N>(3.0) / N::two_pi()
pub fn three_over_two_pi<T: RealField>() -> T {
na::convert::<_, T>(3.0) / T::two_pi()
}
/// Returns `2 / pi`.
@ -295,8 +295,8 @@ pub fn three_over_two_pi<N: RealField>() -> N {
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn two_over_pi<N: RealField>() -> N {
N::frac_2_pi()
pub fn two_over_pi<T: RealField>() -> T {
T::frac_2_pi()
}
/// Returns `2 / sqrt(pi)`.
@ -315,8 +315,8 @@ pub fn two_over_pi<N: RealField>() -> N {
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn two_over_root_pi<N: RealField>() -> N {
N::frac_2_sqrt_pi()
pub fn two_over_root_pi<T: RealField>() -> T {
T::frac_2_sqrt_pi()
}
/// Returns `2pi`.
@ -335,8 +335,8 @@ pub fn two_over_root_pi<N: RealField>() -> N {
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
pub fn two_pi<N: RealField>() -> N {
N::two_pi()
pub fn two_pi<T: RealField>() -> T {
T::two_pi()
}
/// Returns `2 / 3`.
@ -344,7 +344,7 @@ pub fn two_pi<N: RealField>() -> N {
/// # See also:
///
/// * [`third`](fn.third.html)
pub fn two_thirds<N: RealField>() -> N {
pub fn two_thirds<T: RealField>() -> T {
na::convert(2.0 / 3.0)
}

View File

@ -8,24 +8,24 @@ use crate::traits::{Alloc, Number, Dimension};
use crate::aliases::TVec;
/// Component-wise approximate equality beween two vectors.
pub fn epsilon_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
where DefaultAllocator: Alloc<N, D> {
pub fn epsilon_equal<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>, epsilon: T) -> TVec<bool, D>
where DefaultAllocator: Alloc<T, D> {
x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon))
}
/// Component-wise approximate equality beween two scalars.
pub fn epsilon_equal2<N: AbsDiffEq<Epsilon = N>>(x: N, y: N, epsilon: N) -> bool {
pub fn epsilon_equal2<T: AbsDiffEq<Epsilon = T>>(x: T, y: T, epsilon: T) -> bool {
abs_diff_eq!(x, y, epsilon = epsilon)
}
/// Component-wise approximate non-equality beween two vectors.
pub fn epsilon_not_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
where DefaultAllocator: Alloc<N, D> {
pub fn epsilon_not_equal<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>, epsilon: T) -> TVec<bool, D>
where DefaultAllocator: Alloc<T, D> {
x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon))
}
/// Component-wise approximate non-equality beween two scalars.
pub fn epsilon_not_equal2<N: AbsDiffEq<Epsilon = N>>(x: N, y: N, epsilon: N) -> bool {
pub fn epsilon_not_equal2<T: AbsDiffEq<Epsilon = T>>(x: T, y: T, epsilon: T) -> bool {
abs_diff_ne!(x, y, epsilon = epsilon)
}
*/

View File

@ -1,10 +1,9 @@
//use na::{Scalar, DefaultAllocator};
//use na::Scalar;
//
//
//use crate::traits::{Alloc, Dimension};
//use crate::aliases::TVec;
//pub fn iround<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<i32, D>
// where DefaultAllocator: Alloc<N, D> {
//pub fn iround<T: Scalar, const D: usize>(x: &TVec<T, D>) -> TVec<i32, D> {
// x.map(|x| x.round())
//}
//
@ -12,7 +11,6 @@
// unimplemented!()
//}
//
//pub fn uround<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<u32, D>
// where DefaultAllocator: Alloc<N, D> {
//pub fn uround<T: Scalar, const D: usize>(x: &TVec<T, D>) -> TVec<u32, D> {
// unimplemented!()
//}

View File

@ -1,7 +1,6 @@
use na::{DefaultAllocator, Scalar};
use na::Scalar;
use crate::aliases::{TMat, TVec};
use crate::traits::{Alloc, Dimension};
/// The `index`-th column of the matrix `m`.
///
@ -10,10 +9,10 @@ use crate::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>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn column<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
index: usize,
) -> TVec<T, R> {
m.column(index).into_owned()
}
@ -24,14 +23,11 @@ where
/// * [`column`](fn.column.html)
/// * [`row`](fn.row.html)
/// * [`set_row`](fn.set_row.html)
pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(
m: &TMat<N, R, C>,
pub fn set_column<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
index: usize,
x: &TVec<N, R>,
) -> TMat<N, R, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
x: &TVec<T, R>,
) -> TMat<T, R, C> {
let mut res = m.clone();
res.set_column(index, x);
res
@ -44,10 +40,10 @@ where
/// * [`column`](fn.column.html)
/// * [`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>,
{
pub fn row<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
index: usize,
) -> TVec<T, C> {
m.row(index).into_owned().transpose()
}
@ -58,14 +54,11 @@ where
/// * [`column`](fn.column.html)
/// * [`row`](fn.row.html)
/// * [`set_column`](fn.set_column.html)
pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(
m: &TMat<N, R, C>,
pub fn set_row<T: Scalar, const R: usize, const C: usize>(
m: &TMat<T, R, C>,
index: usize,
x: &TVec<N, C>,
) -> TMat<N, R, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
x: &TVec<T, C>,
) -> TMat<T, R, C> {
let mut res = m.clone();
res.set_row(index, &x.transpose());
res

View File

@ -1,22 +1,15 @@
use na::{DefaultAllocator, RealField};
use na::RealField;
use crate::aliases::TMat;
use crate::traits::{Alloc, Dimension};
/// Fast matrix inverse for affine matrix.
pub fn affine_inverse<N: RealField, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
where
DefaultAllocator: Alloc<N, D, D>,
{
pub fn affine_inverse<T: RealField, const D: usize>(m: TMat<T, D, D>) -> TMat<T, D, D> {
// TODO: 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: RealField, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
where
DefaultAllocator: Alloc<N, D, D>,
{
pub fn inverse_transpose<T: RealField, const D: usize>(m: TMat<T, D, D>) -> TMat<T, D, D> {
m.try_inverse()
.unwrap_or_else(TMat::<_, D, D>::zeros)
.transpose()

View File

@ -1,9 +1,7 @@
use na::{Scalar, RealField, DefaultAllocator, U3, U4};
use na::{DefaultAllocator, RealField, Scalar, U3, U4};
use crate::traits::{Alloc, Dimension};
use crate::aliases::*;
pub fn packF2x11_1x10(v: &Vec3) -> i32 {
unimplemented!()
}
@ -12,8 +10,10 @@ pub fn packF3x9_E1x5(v: &Vec3) -> i32 {
unimplemented!()
}
pub fn packHalf<D: Dimension>(v: &TVec<f32, D>) -> TVec<u16, D>
where DefaultAllocator: Alloc<u16, D> {
pub fn packHalf<const D: usize>(v: &TVec<f32, D>) -> TVec<u16, D>
where
DefaultAllocator: Alloc<u16, D>,
{
unimplemented!()
}
@ -49,12 +49,14 @@ pub fn packInt4x8(v: &I8Vec4) -> i32 {
unimplemented!()
}
pub fn packRGBM<N: Scalar>(rgb: &TVec3<N>) -> TVec4<N> {
pub fn packRGBM<T: Scalar>(rgb: &TVec3<T>) -> TVec4<T> {
unimplemented!()
}
pub fn packSnorm<I: Scalar, N: RealField, D: Dimension>(v: TVec<N, D>) -> TVec<I, D>
where DefaultAllocator: Alloc<N, D> + Alloc<I, D> {
pub fn packSnorm<I: Scalar, T: RealField, const D: usize>(v: TVec<T, D>) -> TVec<I, D>
where
DefaultAllocator: Alloc<T, D> + Alloc<I, D>,
{
unimplemented!()
}
@ -102,8 +104,10 @@ pub fn packUint4x8(v: &U8Vec4) -> i32 {
unimplemented!()
}
pub fn packUnorm<UI: Scalar, N: RealField, D: Dimension>(v: &TVec<N, D>) -> TVec<UI, D>
where DefaultAllocator: Alloc<N, D> + Alloc<UI, D> {
pub fn packUnorm<UI: Scalar, T: RealField, const D: usize>(v: &TVec<T, D>) -> TVec<UI, D>
where
DefaultAllocator: Alloc<T, D> + Alloc<UI, D>,
{
unimplemented!()
}
@ -155,8 +159,7 @@ pub fn unpackF3x9_E1x5(p: i32) -> Vec3 {
unimplemented!()
}
pub fn unpackHalf<N: Scalar, D: Dimension>(p: TVec<i16, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn unpackHalf<T: Scalar, const D: usize>(p: TVec<i16, D>) -> TVec<T, D> {
unimplemented!()
}
@ -192,12 +195,14 @@ pub fn unpackInt4x8(p: i32) -> I8Vec4 {
unimplemented!()
}
pub fn unpackRGBM<N: Scalar>(rgbm: &TVec4<N>) -> TVec3<N> {
pub fn unpackRGBM<T: Scalar>(rgbm: &TVec4<T>) -> TVec3<T> {
unimplemented!()
}
pub fn unpackSnorm<I: Scalar, N: RealField, D: Dimension>(v: &TVec<I, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> + Alloc<I, D> {
pub fn unpackSnorm<I: Scalar, T: RealField, const D: usize>(v: &TVec<I, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D> + Alloc<I, D>,
{
unimplemented!()
}
@ -245,8 +250,10 @@ pub fn unpackUint4x8(p: i32) -> U8Vec4 {
unimplemented!()
}
pub fn unpackUnorm<UI: Scalar, N: RealField, D: Dimension>(v: &TVec<UI, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> + Alloc<UI, D> {
pub fn unpackUnorm<UI: Scalar, T: RealField, const D: usize>(v: &TVec<UI, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D> + Alloc<UI, D>,
{
unimplemented!()
}

View File

@ -1,36 +1,36 @@
use na::{RealField, UnitQuaternion, U4};
use na::{RealField, UnitQuaternion};
use crate::aliases::{Qua, TMat4, TVec, TVec3};
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
pub fn quat_euler_angles<N: RealField>(x: &Qua<N>) -> TVec3<N> {
pub fn quat_euler_angles<T: RealField>(x: &Qua<T>) -> TVec3<T> {
let q = UnitQuaternion::new_unchecked(*x);
let a = q.euler_angles();
TVec3::new(a.2, a.1, a.0)
}
/// Component-wise `>` comparison between two quaternions.
pub fn quat_greater_than<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
pub fn quat_greater_than<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> TVec<bool, 4> {
crate::greater_than(&x.coords, &y.coords)
}
/// Component-wise `>=` comparison between two quaternions.
pub fn quat_greater_than_equal<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
pub fn quat_greater_than_equal<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> TVec<bool, 4> {
crate::greater_than_equal(&x.coords, &y.coords)
}
/// Component-wise `<` comparison between two quaternions.
pub fn quat_less_than<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
pub fn quat_less_than<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> TVec<bool, 4> {
crate::less_than(&x.coords, &y.coords)
}
/// Component-wise `<=` comparison between two quaternions.
pub fn quat_less_than_equal<N: RealField>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
pub fn quat_less_than_equal<T: RealField>(x: &Qua<T>, y: &Qua<T>) -> TVec<bool, 4> {
crate::less_than_equal(&x.coords, &y.coords)
}
/// Convert a quaternion to a rotation matrix in homogeneous coordinates.
pub fn quat_cast<N: RealField>(x: &Qua<N>) -> TMat4<N> {
pub fn quat_cast<T: RealField>(x: &Qua<T>) -> TMat4<T> {
crate::quat_to_mat4(x)
}
@ -41,34 +41,34 @@ pub fn quat_cast<N: RealField>(x: &Qua<N>) -> TMat4<N> {
/// * `direction` - Direction vector point at where to look
/// * `up` - Object up vector
///
pub fn quat_look_at<N: RealField>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
pub fn quat_look_at<T: RealField>(direction: &TVec3<T>, up: &TVec3<T>) -> Qua<T> {
quat_look_at_rh(direction, up)
}
/// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix).
pub fn quat_look_at_lh<N: RealField>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
pub fn quat_look_at_lh<T: RealField>(direction: &TVec3<T>, up: &TVec3<T>) -> Qua<T> {
UnitQuaternion::look_at_lh(direction, up).into_inner()
}
/// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix).
pub fn quat_look_at_rh<N: RealField>(direction: &TVec3<N>, up: &TVec3<N>) -> Qua<N> {
pub fn quat_look_at_rh<T: RealField>(direction: &TVec3<T>, up: &TVec3<T>) -> Qua<T> {
UnitQuaternion::look_at_rh(direction, up).into_inner()
}
/// The "roll" Euler angle of the quaternion `x` assumed to be normalized.
pub fn quat_roll<N: RealField>(x: &Qua<N>) -> N {
pub fn quat_roll<T: RealField>(x: &Qua<T>) -> T {
// TODO: optimize this.
quat_euler_angles(x).z
}
/// The "yaw" Euler angle of the quaternion `x` assumed to be normalized.
pub fn quat_yaw<N: RealField>(x: &Qua<N>) -> N {
pub fn quat_yaw<T: RealField>(x: &Qua<T>) -> T {
// TODO: optimize this.
quat_euler_angles(x).y
}
/// The "pitch" Euler angle of the quaternion `x` assumed to be normalized.
pub fn quat_pitch<N: RealField>(x: &Qua<N>) -> N {
pub fn quat_pitch<T: RealField>(x: &Qua<T>) -> T {
// TODO: optimize this.
quat_euler_angles(x).x
}

View File

@ -1,15 +1,16 @@
use na::{Scalar, RealField, U3, DefaultAllocator};
use na::{DefaultAllocator, RealField, Scalar, U3};
use crate::traits::{Number, Alloc, Dimension};
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension, Number};
pub fn ceilMultiple<T>(v: T, Multiple: T) -> T {
unimplemented!()
}
pub fn ceilMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn ceilMultiple2<T: Scalar, const D: usize>(v: &TVec<T, D>, Multiple: &TVec<T, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -17,8 +18,10 @@ pub fn ceilPowerOfTwo<IU>(v: IU) -> IU {
unimplemented!()
}
pub fn ceilPowerOfTwo2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn ceilPowerOfTwo2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -26,8 +29,13 @@ pub fn floorMultiple<T>(v: T, Multiple: T) -> T {
unimplemented!()
}
pub fn floorMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn floorMultiple2<T: Scalar, const D: usize>(
v: &TVec<T, D>,
Multiple: &TVec<T, D>,
) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -35,8 +43,10 @@ pub fn floorPowerOfTwo<IU>(v: IU) -> IU {
unimplemented!()
}
pub fn floorPowerOfTwo2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn floorPowerOfTwo2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -44,13 +54,20 @@ pub fn isMultiple<IU>(v: IU, Multiple: IU) -> bool {
unimplemented!()
}
pub fn isMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>,Multiple: N) -> TVec<bool, D>
where DefaultAllocator: Alloc<N, D> {
pub fn isMultiple2<T: Scalar, const D: usize>(v: &TVec<T, D>, Multiple: T) -> TVec<bool, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn isMultiple3<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<bool, D>
where DefaultAllocator: Alloc<N, D> {
pub fn isMultiple3<T: Scalar, const D: usize>(
v: &TVec<T, D>,
Multiple: &TVec<T, D>,
) -> TVec<bool, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -58,8 +75,10 @@ pub fn isPowerOfTwo2<IU>(v: IU) -> bool {
unimplemented!()
}
pub fn isPowerOfTwo<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<bool, D>
where DefaultAllocator: Alloc<N, D> {
pub fn isPowerOfTwo<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<bool, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -67,8 +86,13 @@ pub fn roundMultiple<T>(v: T, Multiple: T) -> T {
unimplemented!()
}
pub fn roundMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn roundMultiple2<T: Scalar, const D: usize>(
v: &TVec<T, D>,
Multiple: &TVec<T, D>,
) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -76,7 +100,9 @@ pub fn roundPowerOfTwo<IU>(v: IU) -> IU {
unimplemented!()
}
pub fn roundPowerOfTwo2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn roundPowerOfTwo2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}

View File

@ -1,81 +1,81 @@
use na::{DefaultAllocator, Quaternion, RealField, Scalar};
use na::{Quaternion, RealField, Scalar};
use crate::aliases::{
Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
TVec2, TVec3, TVec4,
};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// Creates a 2x2 matrix from a slice arranged in column-major order.
pub fn make_mat2<N: Scalar>(ptr: &[N]) -> TMat2<N> {
pub fn make_mat2<T: Scalar>(ptr: &[T]) -> TMat2<T> {
TMat2::from_column_slice(ptr)
}
/// Creates a 2x2 matrix from a slice arranged in column-major order.
pub fn make_mat2x2<N: Scalar>(ptr: &[N]) -> TMat2<N> {
pub fn make_mat2x2<T: Scalar>(ptr: &[T]) -> TMat2<T> {
TMat2::from_column_slice(ptr)
}
/// Creates a 2x3 matrix from a slice arranged in column-major order.
pub fn make_mat2x3<N: Scalar>(ptr: &[N]) -> TMat2x3<N> {
pub fn make_mat2x3<T: Scalar>(ptr: &[T]) -> TMat2x3<T> {
TMat2x3::from_column_slice(ptr)
}
/// Creates a 2x4 matrix from a slice arranged in column-major order.
pub fn make_mat2x4<N: Scalar>(ptr: &[N]) -> TMat2x4<N> {
pub fn make_mat2x4<T: Scalar>(ptr: &[T]) -> TMat2x4<T> {
TMat2x4::from_column_slice(ptr)
}
/// Creates a 3 matrix from a slice arranged in column-major order.
pub fn make_mat3<N: Scalar>(ptr: &[N]) -> TMat3<N> {
pub fn make_mat3<T: Scalar>(ptr: &[T]) -> TMat3<T> {
TMat3::from_column_slice(ptr)
}
/// Creates a 3x2 matrix from a slice arranged in column-major order.
pub fn make_mat3x2<N: Scalar>(ptr: &[N]) -> TMat3x2<N> {
pub fn make_mat3x2<T: Scalar>(ptr: &[T]) -> TMat3x2<T> {
TMat3x2::from_column_slice(ptr)
}
/// Creates a 3x3 matrix from a slice arranged in column-major order.
pub fn make_mat3x3<N: Scalar>(ptr: &[N]) -> TMat3<N> {
pub fn make_mat3x3<T: Scalar>(ptr: &[T]) -> TMat3<T> {
TMat3::from_column_slice(ptr)
}
/// Creates a 3x4 matrix from a slice arranged in column-major order.
pub fn make_mat3x4<N: Scalar>(ptr: &[N]) -> TMat3x4<N> {
pub fn make_mat3x4<T: Scalar>(ptr: &[T]) -> TMat3x4<T> {
TMat3x4::from_column_slice(ptr)
}
/// Creates a 4x4 matrix from a slice arranged in column-major order.
pub fn make_mat4<N: Scalar>(ptr: &[N]) -> TMat4<N> {
pub fn make_mat4<T: Scalar>(ptr: &[T]) -> TMat4<T> {
TMat4::from_column_slice(ptr)
}
/// Creates a 4x2 matrix from a slice arranged in column-major order.
pub fn make_mat4x2<N: Scalar>(ptr: &[N]) -> TMat4x2<N> {
pub fn make_mat4x2<T: Scalar>(ptr: &[T]) -> TMat4x2<T> {
TMat4x2::from_column_slice(ptr)
}
/// Creates a 4x3 matrix from a slice arranged in column-major order.
pub fn make_mat4x3<N: Scalar>(ptr: &[N]) -> TMat4x3<N> {
pub fn make_mat4x3<T: Scalar>(ptr: &[T]) -> TMat4x3<T> {
TMat4x3::from_column_slice(ptr)
}
/// Creates a 4x4 matrix from a slice arranged in column-major order.
pub fn make_mat4x4<N: Scalar>(ptr: &[N]) -> TMat4<N> {
pub fn make_mat4x4<T: Scalar>(ptr: &[T]) -> TMat4<T> {
TMat4::from_column_slice(ptr)
}
/// Converts a 2x2 matrix to a 3x3 matrix.
pub fn mat2_to_mat3<N: Number>(m: &TMat2<N>) -> TMat3<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn mat2_to_mat3<T: Number>(m: &TMat2<T>) -> TMat3<T> {
let _0 = T::zero();
let _1 = T::one();
TMat3::new(m.m11, m.m12, _0, m.m21, m.m22, _0, _0, _0, _1)
}
/// Converts a 3x3 matrix to a 2x2 matrix.
pub fn mat3_to_mat2<N: Scalar>(m: &TMat3<N>) -> TMat2<N> {
pub fn mat3_to_mat2<T: Scalar>(m: &TMat3<T>) -> TMat2<T> {
TMat2::new(
m.m11.inlined_clone(),
m.m12.inlined_clone(),
@ -85,9 +85,9 @@ pub fn mat3_to_mat2<N: Scalar>(m: &TMat3<N>) -> TMat2<N> {
}
/// Converts a 3x3 matrix to a 4x4 matrix.
pub fn mat3_to_mat4<N: Number>(m: &TMat3<N>) -> TMat4<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn mat3_to_mat4<T: Number>(m: &TMat3<T>) -> TMat4<T> {
let _0 = T::zero();
let _1 = T::one();
TMat4::new(
m.m11, m.m12, m.m13, _0, m.m21, m.m22, m.m23, _0, m.m31, m.m32, m.m33, _0, _0, _0, _0, _1,
@ -95,7 +95,7 @@ pub fn mat3_to_mat4<N: Number>(m: &TMat3<N>) -> TMat4<N> {
}
/// Converts a 4x4 matrix to a 3x3 matrix.
pub fn mat4_to_mat3<N: Scalar>(m: &TMat4<N>) -> TMat3<N> {
pub fn mat4_to_mat3<T: Scalar>(m: &TMat4<T>) -> TMat3<T> {
TMat3::new(
m.m11.inlined_clone(),
m.m12.inlined_clone(),
@ -110,9 +110,9 @@ pub fn mat4_to_mat3<N: Scalar>(m: &TMat4<N>) -> TMat3<N> {
}
/// Converts a 2x2 matrix to a 4x4 matrix.
pub fn mat2_to_mat4<N: Number>(m: &TMat2<N>) -> TMat4<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn mat2_to_mat4<T: Number>(m: &TMat2<T>) -> TMat4<T> {
let _0 = T::zero();
let _1 = T::one();
TMat4::new(
m.m11, m.m12, _0, _0, m.m21, m.m22, _0, _0, _0, _0, _1, _0, _0, _0, _0, _1,
@ -120,7 +120,7 @@ pub fn mat2_to_mat4<N: Number>(m: &TMat2<N>) -> TMat4<N> {
}
/// Converts a 4x4 matrix to a 2x2 matrix.
pub fn mat4_to_mat2<N: Scalar>(m: &TMat4<N>) -> TMat2<N> {
pub fn mat4_to_mat2<T: Scalar>(m: &TMat4<T>) -> TMat2<T> {
TMat2::new(
m.m11.inlined_clone(),
m.m12.inlined_clone(),
@ -130,7 +130,7 @@ pub fn mat4_to_mat2<N: Scalar>(m: &TMat4<N>) -> TMat2<N> {
}
/// Creates a quaternion from a slice arranged as `[x, y, z, w]`.
pub fn make_quat<N: RealField>(ptr: &[N]) -> Qua<N> {
pub fn make_quat<T: RealField>(ptr: &[T]) -> Qua<T> {
Quaternion::from(TVec4::from_column_slice(ptr))
}
@ -141,7 +141,7 @@ pub fn make_quat<N: RealField>(ptr: &[N]) -> Qua<N> {
/// * [`make_vec2`](fn.make_vec2.html)
/// * [`make_vec3`](fn.make_vec3.html)
/// * [`make_vec4`](fn.make_vec4.html)
pub fn make_vec1<N: Scalar>(v: &TVec1<N>) -> TVec1<N> {
pub fn make_vec1<T: Scalar>(v: &TVec1<T>) -> TVec1<T> {
v.clone()
}
@ -155,7 +155,7 @@ pub fn make_vec1<N: Scalar>(v: &TVec1<N>) -> TVec1<N> {
/// * [`vec1_to_vec2`](fn.vec1_to_vec2.html)
/// * [`vec1_to_vec3`](fn.vec1_to_vec3.html)
/// * [`vec1_to_vec4`](fn.vec1_to_vec4.html)
pub fn vec2_to_vec1<N: Scalar>(v: &TVec2<N>) -> TVec1<N> {
pub fn vec2_to_vec1<T: Scalar>(v: &TVec2<T>) -> TVec1<T> {
TVec1::new(v.x.inlined_clone())
}
@ -169,7 +169,7 @@ pub fn vec2_to_vec1<N: Scalar>(v: &TVec2<N>) -> TVec1<N> {
/// * [`vec1_to_vec2`](fn.vec1_to_vec2.html)
/// * [`vec1_to_vec3`](fn.vec1_to_vec3.html)
/// * [`vec1_to_vec4`](fn.vec1_to_vec4.html)
pub fn vec3_to_vec1<N: Scalar>(v: &TVec3<N>) -> TVec1<N> {
pub fn vec3_to_vec1<T: Scalar>(v: &TVec3<T>) -> TVec1<T> {
TVec1::new(v.x.inlined_clone())
}
@ -183,7 +183,7 @@ pub fn vec3_to_vec1<N: Scalar>(v: &TVec3<N>) -> TVec1<N> {
/// * [`vec1_to_vec2`](fn.vec1_to_vec2.html)
/// * [`vec1_to_vec3`](fn.vec1_to_vec3.html)
/// * [`vec1_to_vec4`](fn.vec1_to_vec4.html)
pub fn vec4_to_vec1<N: Scalar>(v: &TVec4<N>) -> TVec1<N> {
pub fn vec4_to_vec1<T: Scalar>(v: &TVec4<T>) -> TVec1<T> {
TVec1::new(v.x.inlined_clone())
}
@ -199,8 +199,8 @@ pub fn vec4_to_vec1<N: Scalar>(v: &TVec4<N>) -> TVec1<N> {
/// * [`vec2_to_vec2`](fn.vec2_to_vec2.html)
/// * [`vec2_to_vec3`](fn.vec2_to_vec3.html)
/// * [`vec2_to_vec4`](fn.vec2_to_vec4.html)
pub fn vec1_to_vec2<N: Number>(v: &TVec1<N>) -> TVec2<N> {
TVec2::new(v.x.inlined_clone(), N::zero())
pub fn vec1_to_vec2<T: Number>(v: &TVec1<T>) -> TVec2<T> {
TVec2::new(v.x.inlined_clone(), T::zero())
}
/// Creates a 2D vector from another vector.
@ -214,7 +214,7 @@ pub fn vec1_to_vec2<N: Number>(v: &TVec1<N>) -> TVec2<N> {
/// * [`vec2_to_vec2`](fn.vec2_to_vec2.html)
/// * [`vec2_to_vec3`](fn.vec2_to_vec3.html)
/// * [`vec2_to_vec4`](fn.vec2_to_vec4.html)
pub fn vec2_to_vec2<N: Scalar>(v: &TVec2<N>) -> TVec2<N> {
pub fn vec2_to_vec2<T: Scalar>(v: &TVec2<T>) -> TVec2<T> {
v.clone()
}
@ -228,7 +228,7 @@ pub fn vec2_to_vec2<N: Scalar>(v: &TVec2<N>) -> TVec2<N> {
/// * [`vec2_to_vec2`](fn.vec2_to_vec2.html)
/// * [`vec2_to_vec3`](fn.vec2_to_vec3.html)
/// * [`vec2_to_vec4`](fn.vec2_to_vec4.html)
pub fn vec3_to_vec2<N: Scalar>(v: &TVec3<N>) -> TVec2<N> {
pub fn vec3_to_vec2<T: Scalar>(v: &TVec3<T>) -> TVec2<T> {
TVec2::new(v.x.inlined_clone(), v.y.inlined_clone())
}
@ -242,7 +242,7 @@ pub fn vec3_to_vec2<N: Scalar>(v: &TVec3<N>) -> TVec2<N> {
/// * [`vec2_to_vec2`](fn.vec2_to_vec2.html)
/// * [`vec2_to_vec3`](fn.vec2_to_vec3.html)
/// * [`vec2_to_vec4`](fn.vec2_to_vec4.html)
pub fn vec4_to_vec2<N: Scalar>(v: &TVec4<N>) -> TVec2<N> {
pub fn vec4_to_vec2<T: Scalar>(v: &TVec4<T>) -> TVec2<T> {
TVec2::new(v.x.inlined_clone(), v.y.inlined_clone())
}
@ -253,7 +253,7 @@ pub fn vec4_to_vec2<N: Scalar>(v: &TVec4<N>) -> TVec2<N> {
/// * [`make_vec1`](fn.make_vec1.html)
/// * [`make_vec3`](fn.make_vec3.html)
/// * [`make_vec4`](fn.make_vec4.html)
pub fn make_vec2<N: Scalar>(ptr: &[N]) -> TVec2<N> {
pub fn make_vec2<T: Scalar>(ptr: &[T]) -> TVec2<T> {
TVec2::from_column_slice(ptr)
}
@ -268,8 +268,8 @@ pub fn make_vec2<N: Scalar>(ptr: &[N]) -> TVec2<N> {
/// * [`vec4_to_vec3`](fn.vec4_to_vec3.html)
/// * [`vec1_to_vec2`](fn.vec1_to_vec2.html)
/// * [`vec1_to_vec4`](fn.vec1_to_vec4.html)
pub fn vec1_to_vec3<N: Number>(v: &TVec1<N>) -> TVec3<N> {
TVec3::new(v.x.inlined_clone(), N::zero(), N::zero())
pub fn vec1_to_vec3<T: Number>(v: &TVec1<T>) -> TVec3<T> {
TVec3::new(v.x.inlined_clone(), T::zero(), T::zero())
}
/// Creates a 3D vector from another vector.
@ -284,8 +284,8 @@ pub fn vec1_to_vec3<N: Number>(v: &TVec1<N>) -> TVec3<N> {
/// * [`vec3_to_vec1`](fn.vec3_to_vec1.html)
/// * [`vec3_to_vec2`](fn.vec3_to_vec2.html)
/// * [`vec3_to_vec4`](fn.vec3_to_vec4.html)
pub fn vec2_to_vec3<N: Number>(v: &TVec2<N>) -> TVec3<N> {
TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), N::zero())
pub fn vec2_to_vec3<T: Number>(v: &TVec2<T>) -> TVec3<T> {
TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), T::zero())
}
/// Creates a 3D vector from another vector.
@ -298,7 +298,7 @@ pub fn vec2_to_vec3<N: Number>(v: &TVec2<N>) -> TVec3<N> {
/// * [`vec3_to_vec1`](fn.vec3_to_vec1.html)
/// * [`vec3_to_vec2`](fn.vec3_to_vec2.html)
/// * [`vec3_to_vec4`](fn.vec3_to_vec4.html)
pub fn vec3_to_vec3<N: Scalar>(v: &TVec3<N>) -> TVec3<N> {
pub fn vec3_to_vec3<T: Scalar>(v: &TVec3<T>) -> TVec3<T> {
v.clone()
}
@ -312,7 +312,7 @@ pub fn vec3_to_vec3<N: Scalar>(v: &TVec3<N>) -> TVec3<N> {
/// * [`vec3_to_vec1`](fn.vec3_to_vec1.html)
/// * [`vec3_to_vec2`](fn.vec3_to_vec2.html)
/// * [`vec3_to_vec4`](fn.vec3_to_vec4.html)
pub fn vec4_to_vec3<N: Scalar>(v: &TVec4<N>) -> TVec3<N> {
pub fn vec4_to_vec3<T: Scalar>(v: &TVec4<T>) -> TVec3<T> {
TVec3::new(
v.x.inlined_clone(),
v.y.inlined_clone(),
@ -327,7 +327,7 @@ pub fn vec4_to_vec3<N: Scalar>(v: &TVec4<N>) -> TVec3<N> {
/// * [`make_vec1`](fn.make_vec1.html)
/// * [`make_vec2`](fn.make_vec2.html)
/// * [`make_vec4`](fn.make_vec4.html)
pub fn make_vec3<N: Scalar>(ptr: &[N]) -> TVec3<N> {
pub fn make_vec3<T: Scalar>(ptr: &[T]) -> TVec3<T> {
TVec3::from_column_slice(ptr)
}
@ -343,8 +343,8 @@ pub fn make_vec3<N: Scalar>(ptr: &[N]) -> TVec3<N> {
/// * [`vec1_to_vec2`](fn.vec1_to_vec2.html)
/// * [`vec1_to_vec3`](fn.vec1_to_vec3.html)
/// * [`vec1_to_vec4`](fn.vec1_to_vec4.html)
pub fn vec1_to_vec4<N: Number>(v: &TVec1<N>) -> TVec4<N> {
TVec4::new(v.x, N::zero(), N::zero(), N::zero())
pub fn vec1_to_vec4<T: Number>(v: &TVec1<T>) -> TVec4<T> {
TVec4::new(v.x, T::zero(), T::zero(), T::zero())
}
/// Creates a 4D vector from another vector.
@ -359,8 +359,8 @@ pub fn vec1_to_vec4<N: Number>(v: &TVec1<N>) -> TVec4<N> {
/// * [`vec2_to_vec1`](fn.vec2_to_vec1.html)
/// * [`vec2_to_vec2`](fn.vec2_to_vec2.html)
/// * [`vec2_to_vec3`](fn.vec2_to_vec3.html)
pub fn vec2_to_vec4<N: Number>(v: &TVec2<N>) -> TVec4<N> {
TVec4::new(v.x, v.y, N::zero(), N::zero())
pub fn vec2_to_vec4<T: Number>(v: &TVec2<T>) -> TVec4<T> {
TVec4::new(v.x, v.y, T::zero(), T::zero())
}
/// Creates a 4D vector from another vector.
@ -375,8 +375,8 @@ pub fn vec2_to_vec4<N: Number>(v: &TVec2<N>) -> TVec4<N> {
/// * [`vec3_to_vec1`](fn.vec3_to_vec1.html)
/// * [`vec3_to_vec2`](fn.vec3_to_vec2.html)
/// * [`vec3_to_vec3`](fn.vec3_to_vec3.html)
pub fn vec3_to_vec4<N: Number>(v: &TVec3<N>) -> TVec4<N> {
TVec4::new(v.x, v.y, v.z, N::zero())
pub fn vec3_to_vec4<T: Number>(v: &TVec3<T>) -> TVec4<T> {
TVec4::new(v.x, v.y, v.z, T::zero())
}
/// Creates a 4D vector from another vector.
@ -389,7 +389,7 @@ pub fn vec3_to_vec4<N: Number>(v: &TVec3<N>) -> TVec4<N> {
/// * [`vec4_to_vec1`](fn.vec4_to_vec1.html)
/// * [`vec4_to_vec2`](fn.vec4_to_vec2.html)
/// * [`vec4_to_vec3`](fn.vec4_to_vec3.html)
pub fn vec4_to_vec4<N: Scalar>(v: &TVec4<N>) -> TVec4<N> {
pub fn vec4_to_vec4<T: Scalar>(v: &TVec4<T>) -> TVec4<T> {
v.clone()
}
@ -400,22 +400,16 @@ pub fn vec4_to_vec4<N: Scalar>(v: &TVec4<N>) -> TVec4<N> {
/// * [`make_vec1`](fn.make_vec1.html)
/// * [`make_vec2`](fn.make_vec2.html)
/// * [`make_vec3`](fn.make_vec3.html)
pub fn make_vec4<N: Scalar>(ptr: &[N]) -> TVec4<N> {
pub fn make_vec4<T: Scalar>(ptr: &[T]) -> TVec4<T> {
TVec4::from_column_slice(ptr)
}
/// 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>,
{
pub fn value_ptr<T: Scalar, const R: usize, const C: usize>(x: &TMat<T, R, C>) -> &[T] {
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>,
{
pub fn value_ptr_mut<T: Scalar, const R: usize, const C: usize>(x: &mut TMat<T, R, C>) -> &mut [T] {
x.as_mut_slice()
}

View File

@ -2,12 +2,11 @@ use na::{Scalar, U2};
use crate::aliases::TVec;
pub fn float_distance<T>(x: T, y: T) -> u64 {
unimplemented!()
}
pub fn float_distance2<N: Scalar>(x: &TVec2<N>, y: &TVec2<N>) -> TVec<u64, U2> {
pub fn float_distance2<T: Scalar>(x: &TVec2<T>, y: &TVec2<T>) -> TVec<u64, U2> {
unimplemented!()
}

View File

@ -1,7 +1,5 @@
use na::{self, DefaultAllocator};
use crate::aliases::TMat;
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// The sum of every component of the given matrix or vector.
///
@ -21,11 +19,8 @@ use crate::traits::{Alloc, Dimension, Number};
/// * [`comp_max`](fn.comp_max.html)
/// * [`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>,
{
m.iter().fold(N::zero(), |x, y| x + *y)
pub fn comp_add<T: Number, const R: usize, const C: usize>(m: &TMat<T, R, C>) -> T {
m.iter().fold(T::zero(), |x, y| x + *y)
}
/// The maximum of every component of the given matrix or vector.
@ -50,12 +45,9 @@ where
/// * [`max2`](fn.max2.html)
/// * [`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>,
{
pub fn comp_max<T: Number, const R: usize, const C: usize>(m: &TMat<T, R, C>) -> T {
m.iter()
.fold(N::min_value(), |x, y| crate::max2_scalar(x, *y))
.fold(T::min_value(), |x, y| crate::max2_scalar(x, *y))
}
/// The minimum of every component of the given matrix or vector.
@ -80,12 +72,9 @@ where
/// * [`min2`](fn.min2.html)
/// * [`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>,
{
pub fn comp_min<T: Number, const R: usize, const C: usize>(m: &TMat<T, R, C>) -> T {
m.iter()
.fold(N::max_value(), |x, y| crate::min2_scalar(x, *y))
.fold(T::max_value(), |x, y| crate::min2_scalar(x, *y))
}
/// The product of every component of the given matrix or vector.
@ -106,11 +95,8 @@ where
/// * [`comp_add`](fn.comp_add.html)
/// * [`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>,
{
m.iter().fold(N::one(), |x, y| x * *y)
pub fn comp_mul<T: Number, const R: usize, const C: usize>(m: &TMat<T, R, C>) -> T {
m.iter().fold(T::one(), |x, y| x * *y)
}
//pub fn vec< L, floatType, Q > compNormalize (vec< L, T, Q > const &v)

View File

@ -1,163 +1,163 @@
use na::{RealField, U3, U4};
use crate::aliases::{TVec, TMat};
use crate::aliases::{TMat, TVec};
pub fn derivedEulerAngleX<N: RealField>(angleX: N, angularVelocityX: N) -> TMat4<N> {
pub fn derivedEulerAngleX<T: RealField>(angleX: T, angularVelocityX: T) -> TMat4<T> {
unimplemented!()
}
pub fn derivedEulerAngleY<N: RealField>(angleY: N, angularVelocityY: N) -> TMat4<N> {
pub fn derivedEulerAngleY<T: RealField>(angleY: T, angularVelocityY: T) -> TMat4<T> {
unimplemented!()
}
pub fn derivedEulerAngleZ<N: RealField>(angleZ: N, angularVelocityZ: N) -> TMat4<N> {
pub fn derivedEulerAngleZ<T: RealField>(angleZ: T, angularVelocityZ: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleX<N: RealField>(angleX: N) -> TMat4<N> {
pub fn eulerAngleX<T: RealField>(angleX: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleXY<N: RealField>(angleX: N, angleY: N) -> TMat4<N> {
pub fn eulerAngleXY<T: RealField>(angleX: T, angleY: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleXYX<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleXYX<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleXYZ<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleXYZ<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleXZ<N: RealField>(angleX: N, angleZ: N) -> TMat4<N> {
pub fn eulerAngleXZ<T: RealField>(angleX: T, angleZ: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleXZX<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleXZX<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleXZY<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleXZY<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleY<N: RealField>(angleY: N) -> TMat4<N> {
pub fn eulerAngleY<T: RealField>(angleY: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleYX<N: RealField>(angleY: N, angleX: N) -> TMat4<N> {
pub fn eulerAngleYX<T: RealField>(angleY: T, angleX: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleYXY<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleYXY<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleYXZ<N: RealField>(yaw: N, pitch: N, roll: N) -> TMat4<N> {
pub fn eulerAngleYXZ<T: RealField>(yaw: T, pitch: T, roll: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleYZ<N: RealField>(angleY: N, angleZ: N) -> TMat4<N> {
pub fn eulerAngleYZ<T: RealField>(angleY: T, angleZ: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleYZX<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleYZX<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleYZY<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleYZY<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZ<N: RealField>(angleZ: N) -> TMat4<N> {
pub fn eulerAngleZ<T: RealField>(angleZ: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZX<N: RealField>(angle: N, angleX: N) -> TMat4<N> {
pub fn eulerAngleZX<T: RealField>(angle: T, angleX: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZXY<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleZXY<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZXZ<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleZXZ<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZY<N: RealField>(angleZ: N, angleY: N) -> TMat4<N> {
pub fn eulerAngleZY<T: RealField>(angleZ: T, angleY: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZYX<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleZYX<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn eulerAngleZYZ<N: RealField>(t1: N, t2: N, t3: N) -> TMat4<N> {
pub fn eulerAngleZYZ<T: RealField>(t1: T, t2: T, t3: T) -> TMat4<T> {
unimplemented!()
}
pub fn extractEulerAngleXYX<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleXYX<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleXYZ<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleXYZ<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleXZX<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleXZX<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleXZY<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleXZY<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleYXY<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleYXY<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleYXZ<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleYXZ<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleYZX<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleYZX<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleYZY<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleYZY<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleZXY<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleZXY<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleZXZ<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleZXZ<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleZYX<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleZYX<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn extractEulerAngleZYZ<N: RealField>(M: &TMat4<N>) -> (N, N, N) {
pub fn extractEulerAngleZYZ<T: RealField>(M: &TMat4<T>) -> (T, T, T) {
unimplemented!()
}
pub fn orientate2<N: RealField>(angle: N) -> TMat3x3<N> {
pub fn orientate2<T: RealField>(angle: T) -> TMat3x3<T> {
unimplemented!()
}
pub fn orientate3<N: RealField>(angles: TVec3<N>) -> TMat3x3<N> {
pub fn orientate3<T: RealField>(angles: TVec3<T>) -> TMat3x3<T> {
unimplemented!()
}
pub fn orientate4<N: RealField>(angles: TVec3<N>) -> TMat4<N> {
pub fn orientate4<T: RealField>(angles: TVec3<T>) -> TMat4<T> {
unimplemented!()
}
pub fn yawPitchRoll<N: RealField>(yaw: N, pitch: N, roll: N) -> TMat4<N> {
pub fn yawPitchRoll<T: RealField>(yaw: T, pitch: T, roll: T) -> TMat4<T> {
unimplemented!()
}

View File

@ -2,6 +2,6 @@ use crate::aliases::TVec2;
use crate::traits::Number;
/// The 2D perpendicular product between two vectors.
pub fn cross2d<N: Number>(v: &TVec2<N>, u: &TVec2<N>) -> N {
pub fn cross2d<T: Number>(v: &TVec2<T>, u: &TVec2<T>) -> T {
v.perp(u)
}

View File

@ -6,8 +6,8 @@ use crate::traits::Number;
/// # See also:
///
/// * [`right_handed`](fn.right_handed.html)
pub fn left_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool {
a.cross(b).dot(c) < N::zero()
pub fn left_handed<T: Number>(a: &TVec3<T>, b: &TVec3<T>, c: &TVec3<T>) -> bool {
a.cross(b).dot(c) < T::zero()
}
/// Returns `true` if `{a, b, c}` forms a right-handed trihedron.
@ -15,6 +15,6 @@ pub fn left_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool
/// # See also:
///
/// * [`left_handed`](fn.left_handed.html)
pub fn right_handed<N: Number>(a: &TVec3<N>, b: &TVec3<N>, c: &TVec3<N>) -> bool {
a.cross(b).dot(c) > N::zero()
pub fn right_handed<T: Number>(a: &TVec3<T>, b: &TVec3<T>, c: &TVec3<T>) -> bool {
a.cross(b).dot(c) > T::zero()
}

View File

@ -7,7 +7,7 @@ use crate::aliases::{TMat3, TMat4, TVec3};
/// # See also:
///
/// * [`matrix_cross`](fn.matrix_cross.html)
pub fn matrix_cross3<N: RealField>(x: &TVec3<N>) -> TMat3<N> {
pub fn matrix_cross3<T: RealField>(x: &TVec3<T>) -> TMat3<T> {
x.cross_matrix()
}
@ -16,6 +16,6 @@ pub fn matrix_cross3<N: RealField>(x: &TVec3<N>) -> TMat3<N> {
/// # See also:
///
/// * [`matrix_cross3`](fn.matrix_cross3.html)
pub fn matrix_cross<N: RealField>(x: &TVec3<N>) -> TMat4<N> {
pub fn matrix_cross<T: RealField>(x: &TVec3<T>) -> TMat4<T> {
crate::mat3_to_mat4(&x.cross_matrix())
}

View File

@ -15,7 +15,7 @@ use crate::traits::Number;
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal2x2<N: Number>(v: &TVec2<N>) -> TMat2<N> {
pub fn diagonal2x2<T: Number>(v: &TVec2<T>) -> TMat2<T> {
TMat2::from_diagonal(v)
}
@ -31,7 +31,7 @@ pub fn diagonal2x2<N: Number>(v: &TVec2<N>) -> TMat2<N> {
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal2x3<N: Number>(v: &TVec2<N>) -> TMat2x3<N> {
pub fn diagonal2x3<T: Number>(v: &TVec2<T>) -> TMat2x3<T> {
TMat2x3::from_partial_diagonal(v.as_slice())
}
@ -47,7 +47,7 @@ pub fn diagonal2x3<N: Number>(v: &TVec2<N>) -> TMat2x3<N> {
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal2x4<N: Number>(v: &TVec2<N>) -> TMat2x4<N> {
pub fn diagonal2x4<T: Number>(v: &TVec2<T>) -> TMat2x4<T> {
TMat2x4::from_partial_diagonal(v.as_slice())
}
@ -63,7 +63,7 @@ pub fn diagonal2x4<N: Number>(v: &TVec2<N>) -> TMat2x4<N> {
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal3x2<N: Number>(v: &TVec2<N>) -> TMat3x2<N> {
pub fn diagonal3x2<T: Number>(v: &TVec2<T>) -> TMat3x2<T> {
TMat3x2::from_partial_diagonal(v.as_slice())
}
@ -79,7 +79,7 @@ pub fn diagonal3x2<N: Number>(v: &TVec2<N>) -> TMat3x2<N> {
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal3x3<N: Number>(v: &TVec3<N>) -> TMat3<N> {
pub fn diagonal3x3<T: Number>(v: &TVec3<T>) -> TMat3<T> {
TMat3::from_diagonal(v)
}
@ -95,7 +95,7 @@ pub fn diagonal3x3<N: Number>(v: &TVec3<N>) -> TMat3<N> {
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal3x4<N: Number>(v: &TVec3<N>) -> TMat3x4<N> {
pub fn diagonal3x4<T: Number>(v: &TVec3<T>) -> TMat3x4<T> {
TMat3x4::from_partial_diagonal(v.as_slice())
}
@ -111,7 +111,7 @@ pub fn diagonal3x4<N: Number>(v: &TVec3<N>) -> TMat3x4<N> {
/// * [`diagonal3x4`](fn.diagonal3x4.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal4x2<N: Number>(v: &TVec2<N>) -> TMat4x2<N> {
pub fn diagonal4x2<T: Number>(v: &TVec2<T>) -> TMat4x2<T> {
TMat4x2::from_partial_diagonal(v.as_slice())
}
@ -127,7 +127,7 @@ pub fn diagonal4x2<N: Number>(v: &TVec2<N>) -> TMat4x2<N> {
/// * [`diagonal3x4`](fn.diagonal3x4.html)
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x4`](fn.diagonal4x4.html)
pub fn diagonal4x3<N: Number>(v: &TVec3<N>) -> TMat4x3<N> {
pub fn diagonal4x3<T: Number>(v: &TVec3<T>) -> TMat4x3<T> {
TMat4x3::from_partial_diagonal(v.as_slice())
}
@ -143,6 +143,6 @@ pub fn diagonal4x3<N: Number>(v: &TVec3<N>) -> TMat4x3<N> {
/// * [`diagonal3x4`](fn.diagonal3x4.html)
/// * [`diagonal4x2`](fn.diagonal4x2.html)
/// * [`diagonal4x3`](fn.diagonal4x3.html)
pub fn diagonal4x4<N: Number>(v: &TVec4<N>) -> TMat4<N> {
pub fn diagonal4x4<T: Number>(v: &TVec4<T>) -> TMat4<T> {
TMat4::from_diagonal(v)
}

View File

@ -1,17 +1,13 @@
use na::{DefaultAllocator, RealField};
use na::RealField;
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension};
/// The squared distance between two points.
///
/// # See also:
///
/// * [`distance`](fn.distance.html)
pub fn distance2<N: RealField, D: Dimension>(p0: &TVec<N, D>, p1: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn distance2<T: RealField, const D: usize>(p0: &TVec<T, D>, p1: &TVec<T, D>) -> T {
(p1 - p0).norm_squared()
}
@ -22,10 +18,7 @@ where
/// * [`l1_norm`](fn.l1_norm.html)
/// * [`l2_distance`](fn.l2_distance.html)
/// * [`l2_norm`](fn.l2_norm.html)
pub fn l1_distance<N: RealField, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn l1_distance<T: RealField, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> T {
l1_norm(&(y - x))
}
@ -39,10 +32,7 @@ where
/// * [`l1_distance`](fn.l1_distance.html)
/// * [`l2_distance`](fn.l2_distance.html)
/// * [`l2_norm`](fn.l2_norm.html)
pub fn l1_norm<N: RealField, D: Dimension>(v: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn l1_norm<T: RealField, const D: usize>(v: &TVec<T, D>) -> T {
crate::comp_add(&v.abs())
}
@ -60,10 +50,7 @@ where
/// * [`length2`](fn.length2.html)
/// * [`magnitude`](fn.magnitude.html)
/// * [`magnitude2`](fn.magnitude2.html)
pub fn l2_distance<N: RealField, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn l2_distance<T: RealField, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> T {
l2_norm(&(y - x))
}
@ -83,10 +70,7 @@ where
/// * [`length2`](fn.length2.html)
/// * [`magnitude`](fn.magnitude.html)
/// * [`magnitude2`](fn.magnitude2.html)
pub fn l2_norm<N: RealField, D: Dimension>(x: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn l2_norm<T: RealField, const D: usize>(x: &TVec<T, D>) -> T {
x.norm()
}
@ -101,10 +85,7 @@ where
/// * [`length`](fn.length.html)
/// * [`magnitude`](fn.magnitude.html)
/// * [`magnitude2`](fn.magnitude2.html)
pub fn length2<N: RealField, D: Dimension>(x: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn length2<T: RealField, const D: usize>(x: &TVec<T, D>) -> T {
x.norm_squared()
}
@ -119,19 +100,14 @@ where
/// * [`length2`](fn.length2.html)
/// * [`magnitude`](fn.magnitude.html)
/// * [`nalgebra::norm_squared`](../nalgebra/fn.norm_squared.html)
pub fn magnitude2<N: RealField, D: Dimension>(x: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn magnitude2<T: RealField, const D: usize>(x: &TVec<T, D>) -> T {
x.norm_squared()
}
//pub fn lxNorm<N: RealField, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, unsigned int Depth) -> N
// where DefaultAllocator: Alloc<N, D> {
//pub fn lxNorm<T: RealField, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>, unsigned int Depth) -> T {
// unimplemented!()
//}
//
//pub fn lxNorm<N: RealField, D: Dimension>(x: &TVec<N, D>, unsigned int Depth) -> N
// where DefaultAllocator: Alloc<N, D> {
//pub fn lxNorm<T: RealField, const D: usize>(x: &TVec<T, D>, unsigned int Depth) -> T {
// unimplemented!()
//}

View File

@ -5,6 +5,6 @@ use crate::aliases::TVec3;
/// The normal vector of the given triangle.
///
/// The normal is computed as the normalized vector `cross(p2 - p1, p3 - p1)`.
pub fn triangle_normal<N: RealField>(p1: &TVec3<N>, p2: &TVec3<N>, p3: &TVec3<N>) -> TVec3<N> {
pub fn triangle_normal<T: RealField>(p1: &TVec3<T>, p2: &TVec3<T>, p3: &TVec3<T>) -> TVec3<T> {
(p2 - p1).cross(&(p3 - p1)).normalize()
}

View File

@ -1,7 +1,6 @@
use na::{DefaultAllocator, RealField};
use na::RealField;
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension};
/// The dot product of the normalized version of `x` and `y`.
///
@ -10,10 +9,7 @@ use crate::traits::{Alloc, Dimension};
/// # See also:
///
/// * [`normalize_dot`](fn.normalize_dot.html`)
pub fn fast_normalize_dot<N: RealField, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn fast_normalize_dot<T: RealField, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> T {
// XXX: improve those.
x.normalize().dot(&y.normalize())
}
@ -23,10 +19,7 @@ where
/// # See also:
///
/// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`)
pub fn normalize_dot<N: RealField, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn normalize_dot<T: RealField, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> T {
// XXX: improve those.
x.normalize().dot(&y.normalize())
}

View File

@ -1,97 +1,97 @@
use na::{RealField, Rotation3, Unit, UnitQuaternion, U3};
use na::{RealField, Rotation3, Unit, UnitQuaternion};
use crate::aliases::{Qua, TMat3, TMat4, TVec3, TVec4};
/// Rotate the vector `v` by the quaternion `q` assumed to be normalized.
pub fn quat_cross_vec<N: RealField>(q: &Qua<N>, v: &TVec3<N>) -> TVec3<N> {
pub fn quat_cross_vec<T: RealField>(q: &Qua<T>, v: &TVec3<T>) -> TVec3<T> {
UnitQuaternion::new_unchecked(*q) * v
}
/// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized.
pub fn quat_inv_cross_vec<N: RealField>(v: &TVec3<N>, q: &Qua<N>) -> TVec3<N> {
pub fn quat_inv_cross_vec<T: RealField>(v: &TVec3<T>, q: &Qua<T>) -> TVec3<T> {
UnitQuaternion::new_unchecked(*q).inverse() * v
}
/// The quaternion `w` component.
pub fn quat_extract_real_component<N: RealField>(q: &Qua<N>) -> N {
pub fn quat_extract_real_component<T: RealField>(q: &Qua<T>) -> T {
q.w
}
/// Normalized linear interpolation between two quaternions.
pub fn quat_fast_mix<N: RealField>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
pub fn quat_fast_mix<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
Unit::new_unchecked(*x)
.nlerp(&Unit::new_unchecked(*y), a)
.into_inner()
}
//pub fn quat_intermediate<N: RealField>(prev: &Qua<N>, curr: &Qua<N>, next: &Qua<N>) -> Qua<N> {
//pub fn quat_intermediate<T: RealField>(prev: &Qua<T>, curr: &Qua<T>, next: &Qua<T>) -> Qua<T> {
// unimplemented!()
//}
/// The squared magnitude of a quaternion `q`.
pub fn quat_length2<N: RealField>(q: &Qua<N>) -> N {
pub fn quat_length2<T: RealField>(q: &Qua<T>) -> T {
q.norm_squared()
}
/// The squared magnitude of a quaternion `q`.
pub fn quat_magnitude2<N: RealField>(q: &Qua<N>) -> N {
pub fn quat_magnitude2<T: RealField>(q: &Qua<T>) -> T {
q.norm_squared()
}
/// The quaternion representing the identity rotation.
pub fn quat_identity<N: RealField>() -> Qua<N> {
pub fn quat_identity<T: RealField>() -> Qua<T> {
UnitQuaternion::identity().into_inner()
}
/// Rotates a vector by a quaternion assumed to be normalized.
pub fn quat_rotate_vec3<N: RealField>(q: &Qua<N>, v: &TVec3<N>) -> TVec3<N> {
pub fn quat_rotate_vec3<T: RealField>(q: &Qua<T>, v: &TVec3<T>) -> TVec3<T> {
UnitQuaternion::new_unchecked(*q) * v
}
/// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized.
pub fn quat_rotate_vec<N: RealField>(q: &Qua<N>, v: &TVec4<N>) -> TVec4<N> {
let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<U3>(0);
pub fn quat_rotate_vec<T: RealField>(q: &Qua<T>, v: &TVec4<T>) -> TVec4<T> {
let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<3>(0);
TVec4::new(rotated.x, rotated.y, rotated.z, v.w)
}
/// The rotation required to align `orig` to `dest`.
pub fn quat_rotation<N: RealField>(orig: &TVec3<N>, dest: &TVec3<N>) -> Qua<N> {
pub fn quat_rotation<T: RealField>(orig: &TVec3<T>, dest: &TVec3<T>) -> Qua<T> {
UnitQuaternion::rotation_between(orig, dest)
.unwrap_or_else(UnitQuaternion::identity)
.into_inner()
}
/// The spherical linear interpolation between two quaternions.
pub fn quat_short_mix<N: RealField>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
pub fn quat_short_mix<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
Unit::new_normalize(*x)
.slerp(&Unit::new_normalize(*y), a)
.into_inner()
}
//pub fn quat_squad<N: RealField>(q1: &Qua<N>, q2: &Qua<N>, s1: &Qua<N>, s2: &Qua<N>, h: N) -> Qua<N> {
//pub fn quat_squad<T: RealField>(q1: &Qua<T>, q2: &Qua<T>, s1: &Qua<T>, s2: &Qua<T>, h: T) -> Qua<T> {
// unimplemented!()
//}
/// Converts a quaternion to a rotation matrix.
pub fn quat_to_mat3<N: RealField>(x: &Qua<N>) -> TMat3<N> {
pub fn quat_to_mat3<T: RealField>(x: &Qua<T>) -> TMat3<T> {
UnitQuaternion::new_unchecked(*x)
.to_rotation_matrix()
.into_inner()
}
/// Converts a quaternion to a rotation matrix in homogenous coordinates.
pub fn quat_to_mat4<N: RealField>(x: &Qua<N>) -> TMat4<N> {
pub fn quat_to_mat4<T: RealField>(x: &Qua<T>) -> TMat4<T> {
UnitQuaternion::new_unchecked(*x).to_homogeneous()
}
/// Converts a rotation matrix to a quaternion.
pub fn mat3_to_quat<N: RealField>(x: &TMat3<N>) -> Qua<N> {
pub fn mat3_to_quat<T: RealField>(x: &TMat3<T>) -> Qua<T> {
let r = Rotation3::from_matrix_unchecked(*x);
UnitQuaternion::from_rotation_matrix(&r).into_inner()
}
/// Converts a rotation matrix in homogeneous coordinates to a quaternion.
pub fn to_quat<N: RealField>(x: &TMat4<N>) -> Qua<N> {
let rot = x.fixed_slice::<U3, U3>(0, 0).into_owned();
pub fn to_quat<T: RealField>(x: &TMat4<T>) -> Qua<T> {
let rot = x.fixed_slice::<3, 3>(0, 0).into_owned();
mat3_to_quat(&rot)
}

View File

@ -9,7 +9,7 @@ use crate::aliases::{Qua, TMat4, TVec3};
/// * `m` - Input matrix multiplied by this rotation matrix.
/// * `angle` - Rotation angle expressed in radians.
/// * `axis` - Rotation axis, must be normalized.
pub fn rotate_normalized_axis<N: RealField>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
pub fn rotate_normalized_axis<T: RealField>(m: &TMat4<T>, angle: T, axis: &TVec3<T>) -> TMat4<T> {
m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
}
@ -20,6 +20,6 @@ pub fn rotate_normalized_axis<N: RealField>(m: &TMat4<N>, angle: N, axis: &TVec3
/// * `q` - Source orientation.
/// * `angle` - Angle expressed in radians.
/// * `axis` - Normalized axis of the rotation, must be normalized.
pub fn quat_rotate_normalized_axis<N: RealField>(q: &Qua<N>, angle: N, axis: &TVec3<N>) -> Qua<N> {
pub fn quat_rotate_normalized_axis<T: RealField>(q: &Qua<T>, angle: T, axis: &TVec3<T>) -> Qua<T> {
q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).into_inner()
}

View File

@ -3,7 +3,7 @@ use na::{RealField, Rotation3, Unit, UnitComplex};
use crate::aliases::{TMat4, TVec2, TVec3, TVec4};
/// Build the rotation matrix needed to align `normal` and `up`.
pub fn orientation<N: RealField>(normal: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
pub fn orientation<T: RealField>(normal: &TVec3<T>, up: &TVec3<T>) -> TMat4<T> {
if let Some(r) = Rotation3::rotation_between(normal, up) {
r.to_homogeneous()
} else {
@ -12,52 +12,52 @@ pub fn orientation<N: RealField>(normal: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
}
/// Rotate a two dimensional vector.
pub fn rotate_vec2<N: RealField>(v: &TVec2<N>, angle: N) -> TVec2<N> {
pub fn rotate_vec2<T: RealField>(v: &TVec2<T>, angle: T) -> TVec2<T> {
UnitComplex::new(angle) * v
}
/// Rotate a three dimensional vector around an axis.
pub fn rotate_vec3<N: RealField>(v: &TVec3<N>, angle: N, normal: &TVec3<N>) -> TVec3<N> {
pub fn rotate_vec3<T: RealField>(v: &TVec3<T>, angle: T, normal: &TVec3<T>) -> TVec3<T> {
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v
}
/// Rotate a thee dimensional vector in homogeneous coordinates around an axis.
pub fn rotate_vec4<N: RealField>(v: &TVec4<N>, angle: N, normal: &TVec3<N>) -> TVec4<N> {
pub fn rotate_vec4<T: RealField>(v: &TVec4<T>, angle: T, normal: &TVec3<T>) -> TVec4<T> {
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v
}
/// Rotate a three dimensional vector around the `X` axis.
pub fn rotate_x_vec3<N: RealField>(v: &TVec3<N>, angle: N) -> TVec3<N> {
pub fn rotate_x_vec3<T: RealField>(v: &TVec3<T>, angle: T) -> TVec3<T> {
Rotation3::from_axis_angle(&TVec3::x_axis(), angle) * v
}
/// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis.
pub fn rotate_x_vec4<N: RealField>(v: &TVec4<N>, angle: N) -> TVec4<N> {
pub fn rotate_x_vec4<T: RealField>(v: &TVec4<T>, angle: T) -> TVec4<T> {
Rotation3::from_axis_angle(&TVec3::x_axis(), angle).to_homogeneous() * v
}
/// Rotate a three dimensional vector around the `Y` axis.
pub fn rotate_y_vec3<N: RealField>(v: &TVec3<N>, angle: N) -> TVec3<N> {
pub fn rotate_y_vec3<T: RealField>(v: &TVec3<T>, angle: T) -> TVec3<T> {
Rotation3::from_axis_angle(&TVec3::y_axis(), angle) * v
}
/// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis.
pub fn rotate_y_vec4<N: RealField>(v: &TVec4<N>, angle: N) -> TVec4<N> {
pub fn rotate_y_vec4<T: RealField>(v: &TVec4<T>, angle: T) -> TVec4<T> {
Rotation3::from_axis_angle(&TVec3::y_axis(), angle).to_homogeneous() * v
}
/// Rotate a three dimensional vector around the `Z` axis.
pub fn rotate_z_vec3<N: RealField>(v: &TVec3<N>, angle: N) -> TVec3<N> {
pub fn rotate_z_vec3<T: RealField>(v: &TVec3<T>, angle: T) -> TVec3<T> {
Rotation3::from_axis_angle(&TVec3::z_axis(), angle) * v
}
/// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis.
pub fn rotate_z_vec4<N: RealField>(v: &TVec4<N>, angle: N) -> TVec4<N> {
pub fn rotate_z_vec4<T: RealField>(v: &TVec4<T>, angle: T) -> TVec4<T> {
Rotation3::from_axis_angle(&TVec3::z_axis(), angle).to_homogeneous() * v
}
/// Computes a spherical linear interpolation between the vectors `x` and `y` assumed to be normalized.
pub fn slerp<N: RealField>(x: &TVec3<N>, y: &TVec3<N>, a: N) -> TVec3<N> {
pub fn slerp<T: RealField>(x: &TVec3<T>, y: &TVec3<T>, a: T) -> TVec3<T> {
Unit::new_unchecked(*x)
.slerp(&Unit::new_unchecked(*y), a)
.into_inner()

View File

@ -12,7 +12,7 @@ use crate::traits::Number;
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn rotation<N: RealField>(angle: N, v: &TVec3<N>) -> TMat4<N> {
pub fn rotation<T: RealField>(angle: T, v: &TVec3<T>) -> TMat4<T> {
Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous()
}
@ -25,7 +25,7 @@ pub fn rotation<N: RealField>(angle: N, v: &TVec3<N>) -> TMat4<N> {
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn scaling<N: Number>(v: &TVec3<N>) -> TMat4<N> {
pub fn scaling<T: Number>(v: &TVec3<T>) -> TMat4<T> {
TMat4::new_nonuniform_scaling(v)
}
@ -38,7 +38,7 @@ pub fn scaling<N: Number>(v: &TVec3<N>) -> TMat4<N> {
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn translation<N: Number>(v: &TVec3<N>) -> TMat4<N> {
pub fn translation<T: Number>(v: &TVec3<T>) -> TMat4<T> {
TMat4::new_translation(v)
}
@ -51,7 +51,7 @@ pub fn translation<N: Number>(v: &TVec3<N>) -> TMat4<N> {
/// * [`translation`](fn.translation.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn rotation2d<N: RealField>(angle: N) -> TMat3<N> {
pub fn rotation2d<T: RealField>(angle: T) -> TMat3<T> {
Rotation2::new(angle).to_homogeneous()
}
@ -64,7 +64,7 @@ pub fn rotation2d<N: RealField>(angle: N) -> TMat3<N> {
/// * [`translation`](fn.translation.html)
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn scaling2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
pub fn scaling2d<T: Number>(v: &TVec2<T>) -> TMat3<T> {
TMat3::new_nonuniform_scaling(v)
}
@ -77,6 +77,6 @@ pub fn scaling2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
/// * [`translation`](fn.translation.html)
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
pub fn translation2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
pub fn translation2d<T: Number>(v: &TVec2<T>) -> TMat3<T> {
TMat3::new_translation(v)
}

View File

@ -1,14 +1,12 @@
use na::{U2, U3};
use crate::aliases::{TMat3, TMat4, TVec2, TVec3};
use crate::traits::Number;
/// Build planar projection matrix along normal axis and right-multiply it to `m`.
pub fn proj2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
pub fn proj2d<T: Number>(m: &TMat3<T>, normal: &TVec2<T>) -> TMat3<T> {
let mut res = TMat3::identity();
{
let mut part = res.fixed_slice_mut::<U2, U2>(0, 0);
let mut part = res.fixed_slice_mut::<2, 2>(0, 0);
part -= normal * normal.transpose();
}
@ -16,11 +14,11 @@ pub fn proj2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
}
/// Build planar projection matrix along normal axis, and right-multiply it to `m`.
pub fn proj<N: Number>(m: &TMat4<N>, normal: &TVec3<N>) -> TMat4<N> {
pub fn proj<T: Number>(m: &TMat4<T>, normal: &TVec3<T>) -> TMat4<T> {
let mut res = TMat4::identity();
{
let mut part = res.fixed_slice_mut::<U3, U3>(0, 0);
let mut part = res.fixed_slice_mut::<3, 3>(0, 0);
part -= normal * normal.transpose();
}
@ -28,33 +26,33 @@ pub fn proj<N: Number>(m: &TMat4<N>, normal: &TVec3<N>) -> TMat4<N> {
}
/// Builds a reflection matrix and right-multiply it to `m`.
pub fn reflect2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
pub fn reflect2d<T: Number>(m: &TMat3<T>, normal: &TVec2<T>) -> TMat3<T> {
let mut res = TMat3::identity();
{
let mut part = res.fixed_slice_mut::<U2, U2>(0, 0);
part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose();
let mut part = res.fixed_slice_mut::<2, 2>(0, 0);
part -= (normal * T::from_f64(2.0).unwrap()) * normal.transpose();
}
m * res
}
/// Builds a reflection matrix, and right-multiply it to `m`.
pub fn reflect<N: Number>(m: &TMat4<N>, normal: &TVec3<N>) -> TMat4<N> {
pub fn reflect<T: Number>(m: &TMat4<T>, normal: &TVec3<T>) -> TMat4<T> {
let mut res = TMat4::identity();
{
let mut part = res.fixed_slice_mut::<U3, U3>(0, 0);
part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose();
let mut part = res.fixed_slice_mut::<3, 3>(0, 0);
part -= (normal * T::from_f64(2.0).unwrap()) * normal.transpose();
}
m * res
}
/// Builds a scale-bias matrix.
pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> TMat4<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn scale_bias_matrix<T: Number>(scale: T, bias: T) -> TMat4<T> {
let _0 = T::zero();
let _1 = T::one();
TMat4::new(
scale, _0, _0, bias, _0, scale, _0, bias, _0, _0, scale, bias, _0, _0, _0, _1,
@ -62,50 +60,50 @@ pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> TMat4<N> {
}
/// Builds a scale-bias matrix, and right-multiply it to `m`.
pub fn scale_bias<N: Number>(m: &TMat4<N>, scale: N, bias: N) -> TMat4<N> {
pub fn scale_bias<T: Number>(m: &TMat4<T>, scale: T, bias: T) -> TMat4<T> {
m * scale_bias_matrix(scale, bias)
}
/// Transforms a matrix with a shearing on X axis.
pub fn shear2d_x<N: Number>(m: &TMat3<N>, y: N) -> TMat3<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn shear2d_x<T: Number>(m: &TMat3<T>, y: T) -> TMat3<T> {
let _0 = T::zero();
let _1 = T::one();
let shear = TMat3::new(_1, y, _0, _0, _1, _0, _0, _0, _1);
m * shear
}
/// Transforms a matrix with a shearing on Y axis.
pub fn shear_x<N: Number>(m: &TMat4<N>, y: N, z: N) -> TMat4<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn shear_x<T: Number>(m: &TMat4<T>, y: T, z: T) -> TMat4<T> {
let _0 = T::zero();
let _1 = T::one();
let shear = TMat4::new(_1, _0, _0, _0, y, _1, _0, _0, z, _0, _1, _0, _0, _0, _0, _1);
m * shear
}
/// Transforms a matrix with a shearing on Y axis.
pub fn shear2d_y<N: Number>(m: &TMat3<N>, x: N) -> TMat3<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn shear2d_y<T: Number>(m: &TMat3<T>, x: T) -> TMat3<T> {
let _0 = T::zero();
let _1 = T::one();
let shear = TMat3::new(_1, _0, _0, x, _1, _0, _0, _0, _1);
m * shear
}
/// Transforms a matrix with a shearing on Y axis.
pub fn shear_y<N: Number>(m: &TMat4<N>, x: N, z: N) -> TMat4<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn shear_y<T: Number>(m: &TMat4<T>, x: T, z: T) -> TMat4<T> {
let _0 = T::zero();
let _1 = T::one();
let shear = TMat4::new(_1, x, _0, _0, _0, _1, _0, _0, _0, z, _1, _0, _0, _0, _0, _1);
m * shear
}
/// Transforms a matrix with a shearing on Z axis.
pub fn shear_z<N: Number>(m: &TMat4<N>, x: N, y: N) -> TMat4<N> {
let _0 = N::zero();
let _1 = N::one();
pub fn shear_z<T: Number>(m: &TMat4<T>, x: T, y: T) -> TMat4<T> {
let _0 = T::zero();
let _1 = T::one();
let shear = TMat4::new(_1, _0, x, _0, _0, _1, y, _0, _0, _0, _1, _0, _0, _0, _0, _1);
m * shear

View File

@ -12,7 +12,7 @@ use crate::traits::Number;
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translate2d`](fn.translate2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn rotate2d<N: RealField>(m: &TMat3<N>, angle: N) -> TMat3<N> {
pub fn rotate2d<T: RealField>(m: &TMat3<T>, angle: T) -> TMat3<T> {
m * UnitComplex::new(angle).to_homogeneous()
}
@ -25,7 +25,7 @@ pub fn rotate2d<N: RealField>(m: &TMat3<N>, angle: N) -> TMat3<N> {
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translate2d`](fn.translate2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn scale2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
pub fn scale2d<T: Number>(m: &TMat3<T>, v: &TVec2<T>) -> TMat3<T> {
m.prepend_nonuniform_scaling(v)
}
@ -38,6 +38,6 @@ pub fn scale2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
/// * [`scale2d`](fn.scale2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translation2d`](fn.translation2d.html)
pub fn translate2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
pub fn translate2d<T: Number>(m: &TMat3<T>, v: &TVec2<T>) -> TMat3<T> {
m.prepend_translation(v)
}

View File

@ -1,20 +1,16 @@
use na::{DefaultAllocator, RealField};
use na::RealField;
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension};
/// The angle between two vectors.
pub fn angle<N: RealField, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
where
DefaultAllocator: Alloc<N, D>,
{
pub fn angle<T: RealField, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> T {
x.angle(y)
}
//pub fn oriented_angle<N: RealField>(x: &TVec2<N>, y: &TVec2<N>) -> N {
//pub fn oriented_angle<T: RealField>(x: &TVec2<T>, y: &TVec2<T>) -> T {
// unimplemented!()
//}
//
//pub fn oriented_angle_ref<N: RealField>(x: &TVec3<N>, y: &TVec3<N>, refv: &TVec3<N>) -> N {
//pub fn oriented_angle_ref<T: RealField>(x: &TVec3<T>, y: &TVec3<T>, refv: &TVec3<T>) -> T {
// unimplemented!()
//}

View File

@ -1,14 +1,14 @@
use na::{DefaultAllocator, RealField};
use na::RealField;
use crate::aliases::{TVec, TVec2, TVec3};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// Returns `true` if two vectors are collinear (up to an epsilon).
///
/// # See also:
///
/// * [`are_collinear2d`](fn.are_collinear2d.html)
pub fn are_collinear<N: Number>(v0: &TVec3<N>, v1: &TVec3<N>, epsilon: N) -> bool {
pub fn are_collinear<T: Number>(v0: &TVec3<T>, v1: &TVec3<T>, epsilon: T) -> bool {
is_null(&v0.cross(v1), epsilon)
}
@ -17,43 +17,34 @@ pub fn are_collinear<N: Number>(v0: &TVec3<N>, v1: &TVec3<N>, epsilon: N) -> boo
/// # See also:
///
/// * [`are_collinear`](fn.are_collinear.html)
pub fn are_collinear2d<N: Number>(v0: &TVec2<N>, v1: &TVec2<N>, epsilon: N) -> bool {
abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon)
pub fn are_collinear2d<T: Number>(v0: &TVec2<T>, v1: &TVec2<T>, epsilon: T) -> bool {
abs_diff_eq!(v0.perp(v1), T::zero(), epsilon = epsilon)
}
/// 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
where
DefaultAllocator: Alloc<N, D>,
{
abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon)
pub fn are_orthogonal<T: Number, const D: usize>(
v0: &TVec<T, D>,
v1: &TVec<T, D>,
epsilon: T,
) -> bool {
abs_diff_eq!(v0.dot(v1), T::zero(), epsilon = epsilon)
}
//pub fn are_orthonormal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
// where DefaultAllocator: Alloc<N, D> {
//pub fn are_orthonormal<T: Number, const D: usize>(v0: &TVec<T, D>, v1: &TVec<T, D>, epsilon: T) -> bool {
// unimplemented!()
//}
/// 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>,
{
v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon))
pub fn is_comp_null<T: Number, const D: usize>(v: &TVec<T, D>, epsilon: T) -> TVec<bool, D> {
v.map(|x| abs_diff_eq!(x, T::zero(), epsilon = epsilon))
}
/// Returns `true` if `v` has a magnitude of 1 (up to an epsilon).
pub fn is_normalized<N: RealField, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
where
DefaultAllocator: Alloc<N, D>,
{
abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon)
pub fn is_normalized<T: RealField, const D: usize>(v: &TVec<T, D>, epsilon: T) -> bool {
abs_diff_eq!(v.norm_squared(), T::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>,
{
abs_diff_eq!(*v, TVec::<N, D>::zeros(), epsilon = epsilon)
pub fn is_null<T: Number, const D: usize>(v: &TVec<T, D>, epsilon: T) -> bool {
abs_diff_eq!(*v, TVec::<T, D>::zeros(), epsilon = epsilon)
}

View File

@ -1,29 +1,46 @@
use na::{Scalar, RealField, U3, DefaultAllocator};
use na::{DefaultAllocator, RealField, Scalar, U3};
use crate::traits::{Number, Alloc, Dimension};
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension, Number};
pub fn bitCount<T>(v: T) -> i32 {
unimplemented!()
}
pub fn bitCount2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<i32, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitCount2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<i32, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn bitfieldExtract<N: Scalar, D: Dimension>(Value: &TVec<N, D>, Offset: i32, Bits: i32) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldExtract<T: Scalar, const D: usize>(
Value: &TVec<T, D>,
Offset: i32,
Bits: i32,
) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn bitfieldInsert<N: Scalar, D: Dimension>(Base: &TVec<N, D>, Insert: &TVec<N, D>, Offset: i32, Bits: i32) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldInsert<T: Scalar, const D: usize>(
Base: &TVec<T, D>,
Insert: &TVec<T, D>,
Offset: i32,
Bits: i32,
) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn bitfieldReverse<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> {
pub fn bitfieldReverse<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<T, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -31,8 +48,10 @@ pub fn findLSB<IU>(x: IU) -> u32 {
unimplemented!()
}
pub fn findLSB2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<i32, D>
where DefaultAllocator: Alloc<N, D> {
pub fn findLSB2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<i32, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
@ -40,27 +59,53 @@ pub fn findMSB<IU>(x: IU) -> i32 {
unimplemented!()
}
pub fn findMSB2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<i32, D>
where DefaultAllocator: Alloc<N, D> {
pub fn findMSB2<T: Scalar, const D: usize>(v: &TVec<T, D>) -> TVec<i32, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn imulExtended<N: Scalar, D: Dimension>(x: &TVec<i32, D>, y: &TVec<i32, D>, msb: &TVec<i32, D>, lsb: &TVec<i32, D>)
where DefaultAllocator: Alloc<N, D> {
pub fn imulExtended<T: Scalar, const D: usize>(
x: &TVec<i32, D>,
y: &TVec<i32, D>,
msb: &TVec<i32, D>,
lsb: &TVec<i32, D>,
) where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn uaddCarry<N: Scalar, D: Dimension>(x: &TVec<u32, D>, y: &TVec<u32, D>, carry: &TVec<u32, D>) -> TVec<u32, D>
where DefaultAllocator: Alloc<N, D> {
pub fn uaddCarry<T: Scalar, const D: usize>(
x: &TVec<u32, D>,
y: &TVec<u32, D>,
carry: &TVec<u32, D>,
) -> TVec<u32, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn umulExtended<N: Scalar, D: Dimension>(x: &TVec<u32, D>, y: &TVec<u32, D>, msb: &TVec<u32, D>, lsb: &TVec<u32, D>)
where DefaultAllocator: Alloc<N, D> {
unimplemented!()
}
pub fn usubBorrow<N: Scalar, D: Dimension>(x: &TVec<u32, D>, y: &TVec<u32, D>, borrow: &TVec<u32, D>) -> TVec<u32, D>
where DefaultAllocator: Alloc<N, D> {
pub fn umulExtended<T: Scalar, const D: usize>(
x: &TVec<u32, D>,
y: &TVec<u32, D>,
msb: &TVec<u32, D>,
lsb: &TVec<u32, D>,
) where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}
pub fn usubBorrow<T: Scalar, const D: usize>(
x: &TVec<u32, D>,
y: &TVec<u32, D>,
borrow: &TVec<u32, D>,
) -> TVec<u32, D>
where
DefaultAllocator: Alloc<T, D>,
{
unimplemented!()
}

View File

@ -54,7 +54,7 @@
### Vector and matrix construction
Vectors, matrices, and quaternions can be constructed using several approaches:
* Using functions with the same name as their type in lower-case. For example [`glm::vec3(x, y, z)`](fn.vec3.html) will create a 3D vector.
* Using the `::new` constructor. For example [`Vec3::new(x, y, z)`](../nalgebra/base/type.MatrixMN.html#method.new-27) will create a 3D vector.
* Using the `::new` constructor. For example [`Vec3::new(x, y, z)`](../nalgebra/base/type.OMatrix.html#method.new-27) will create a 3D vector.
* Using the functions prefixed by `make_` to build a vector a matrix from a slice. For example [`glm::make_vec3(&[x, y, z])`](fn.make_vec3.html) will create a 3D vector.
Keep in mind that constructing a matrix using this type of functions require its components to be arranged in column-major order on the slice.
* Using a geometric construction function. For example [`glm::rotation(angle, axis)`](fn.rotation.html) will build a 4x4 homogeneous rotation matrix from an angle (in radians) and an axis.
@ -119,7 +119,7 @@ extern crate approx;
extern crate nalgebra as na;
pub use crate::aliases::*;
pub use crate::traits::{Alloc, Dimension, Number};
pub use crate::traits::Number;
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,

View File

@ -1,52 +1,40 @@
use na::{DefaultAllocator, RealField, Scalar};
use na::{Const, DimMin, RealField, Scalar};
use crate::aliases::{TMat, TVec};
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// The determinant of the matrix `m`.
pub fn determinant<N: RealField, D: Dimension>(m: &TMat<N, D, D>) -> N
pub fn determinant<T: RealField, const D: usize>(m: &TMat<T, D, D>) -> T
where
DefaultAllocator: Alloc<N, D, D>,
Const<D>: DimMin<Const<D>, Output = Const<D>>,
{
m.determinant()
}
/// The inverse of the matrix `m`.
pub fn inverse<N: RealField, D: Dimension>(m: &TMat<N, D, D>) -> TMat<N, D, D>
where
DefaultAllocator: Alloc<N, D, D>,
{
pub fn inverse<T: RealField, const D: usize>(m: &TMat<T, D, D>) -> TMat<T, D, D> {
m.clone()
.try_inverse()
.unwrap_or_else(TMat::<N, D, D>::zeros)
.unwrap_or_else(TMat::<T, D, D>::zeros)
}
/// Component-wise multiplication of two matrices.
pub fn matrix_comp_mult<N: Number, R: Dimension, C: Dimension>(
x: &TMat<N, R, C>,
y: &TMat<N, R, C>,
) -> TMat<N, R, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn matrix_comp_mult<T: Number, const R: usize, const C: usize>(
x: &TMat<T, R, C>,
y: &TMat<T, R, C>,
) -> TMat<T, R, C> {
x.component_mul(y)
}
/// Treats the first parameter `c` as a column vector and the second parameter `r` as a row vector and does a linear algebraic matrix multiply `c * r`.
pub fn outer_product<N: Number, R: Dimension, C: Dimension>(
c: &TVec<N, R>,
r: &TVec<N, C>,
) -> TMat<N, R, C>
where
DefaultAllocator: Alloc<N, R, C>,
{
pub fn outer_product<T: Number, const R: usize, const C: usize>(
c: &TVec<T, R>,
r: &TVec<T, C>,
) -> TMat<T, R, C> {
c * r.transpose()
}
/// 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>,
{
pub fn transpose<T: Scalar, const R: usize, const C: usize>(x: &TMat<T, R, C>) -> TMat<T, C, R> {
x.transpose()
}

View File

@ -1,52 +1,51 @@
use na::Scalar;
use crate::aliases::{Vec2, Vec4, UVec2};
use crate::aliases::{UVec2, Vec2, Vec4};
pub fn packDouble2x32<N: Scalar>(v: &UVec2) -> f64 {
pub fn packDouble2x32<T: Scalar>(v: &UVec2) -> f64 {
unimplemented!()
}
pub fn packHalf2x16<N: Scalar>(v: &Vec2) -> u32 {
pub fn packHalf2x16<T: Scalar>(v: &Vec2) -> u32 {
unimplemented!()
}
pub fn packSnorm2x16<N: Scalar>(v: &Vec2) -> u32 {
pub fn packSnorm2x16<T: Scalar>(v: &Vec2) -> u32 {
unimplemented!()
}
pub fn packSnorm4x8<N: Scalar>(v: &Vec4) -> u32 {
pub fn packSnorm4x8<T: Scalar>(v: &Vec4) -> u32 {
unimplemented!()
}
pub fn packUnorm2x16<N: Scalar>(v: &Vec2) -> u32 {
pub fn packUnorm2x16<T: Scalar>(v: &Vec2) -> u32 {
unimplemented!()
}
pub fn packUnorm4x8<N: Scalar>(v: &Vec4) -> u32 {
pub fn packUnorm4x8<T: Scalar>(v: &Vec4) -> u32 {
unimplemented!()
}
pub fn unpackDouble2x32<N: Scalar>(v: f64) -> UVec2 {
pub fn unpackDouble2x32<T: Scalar>(v: f64) -> UVec2 {
unimplemented!()
}
pub fn unpackHalf2x16<N: Scalar>(v: u32) -> Vec2 {
pub fn unpackHalf2x16<T: Scalar>(v: u32) -> Vec2 {
unimplemented!()
}
pub fn unpackSnorm2x16<N: Scalar>(p: u32) -> Vec2 {
pub fn unpackSnorm2x16<T: Scalar>(p: u32) -> Vec2 {
unimplemented!()
}
pub fn unpackSnorm4x8<N: Scalar>(p: u32) -> Vec4 {
pub fn unpackSnorm4x8<T: Scalar>(p: u32) -> Vec4 {
unimplemented!()
}
pub fn unpackUnorm2x16<N: Scalar>(p: u32) -> Vec2 {
pub fn unpackUnorm2x16<T: Scalar>(p: u32) -> Vec2 {
unimplemented!()
}
pub fn unpackUnorm4x8<N: Scalar>(p: u32) -> Vec4 {
pub fn unpackUnorm4x8<T: Scalar>(p: u32) -> Vec4 {
unimplemented!()
}

View File

@ -1,15 +1,10 @@
use approx::AbsDiffEq;
use num::{Bounded, FromPrimitive, Signed};
use na::allocator::Allocator;
use na::{DimMin, DimName, Scalar, U1};
use na::Scalar;
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub};
use std::cmp::PartialOrd;
/// A type-level number representing a vector, matrix row, or matrix column, dimension.
pub trait Dimension: DimName + DimMin<Self, Output = Self> {}
impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {}
/// A number that can either be an integer or a float.
pub trait Number:
Scalar
@ -39,64 +34,3 @@ impl<
> Number for T
{
}
#[doc(hidden)]
pub trait Alloc<N: Scalar, R: Dimension, C: Dimension = U1>:
Allocator<N, R>
+ Allocator<N, C>
+ Allocator<N, U1, R>
+ Allocator<N, U1, C>
+ Allocator<N, R, C>
+ Allocator<N, C, R>
+ Allocator<N, R, R>
+ Allocator<N, C, C>
+ Allocator<bool, R>
+ Allocator<bool, C>
+ Allocator<f32, R>
+ Allocator<f32, C>
+ Allocator<u32, R>
+ Allocator<u32, C>
+ Allocator<i32, R>
+ Allocator<i32, C>
+ Allocator<f64, R>
+ Allocator<f64, C>
+ Allocator<u64, R>
+ Allocator<u64, C>
+ Allocator<i64, R>
+ Allocator<i64, C>
+ Allocator<i16, R>
+ Allocator<i16, C>
+ Allocator<(usize, usize), R>
+ Allocator<(usize, usize), C>
{
}
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>
+ Allocator<N, R, C>
+ Allocator<N, C, R>
+ Allocator<N, R, R>
+ Allocator<N, C, C>
+ Allocator<bool, R>
+ Allocator<bool, C>
+ Allocator<f32, R>
+ Allocator<f32, C>
+ Allocator<u32, R>
+ Allocator<u32, C>
+ Allocator<i32, R>
+ Allocator<i32, C>
+ Allocator<f64, R>
+ Allocator<f64, C>
+ Allocator<u64, R>
+ Allocator<u64, C>
+ Allocator<i64, R>
+ Allocator<i64, C>
+ Allocator<i16, R>
+ Allocator<i16, C>
+ Allocator<(usize, usize), R>
+ Allocator<(usize, usize), C>
{
}

View File

@ -1,124 +1,78 @@
use na::{self, DefaultAllocator, RealField};
use na::{self, RealField};
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension};
/// Component-wise arc-cosinus.
pub fn acos<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn acos<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.acos())
}
/// Component-wise hyperbolic arc-cosinus.
pub fn acosh<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn acosh<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.acosh())
}
/// Component-wise arc-sinus.
pub fn asin<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn asin<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.asin())
}
/// Component-wise hyperbolic arc-sinus.
pub fn asinh<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn asinh<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.asinh())
}
/// Component-wise arc-tangent of `y / x`.
pub fn atan2<N: RealField, D: Dimension>(y: &TVec<N, D>, x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn atan2<T: RealField, const D: usize>(y: &TVec<T, D>, x: &TVec<T, D>) -> TVec<T, D> {
y.zip_map(x, |y, x| y.atan2(x))
}
/// Component-wise arc-tangent.
pub fn atan<N: RealField, D: Dimension>(y_over_x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn atan<T: RealField, const D: usize>(y_over_x: &TVec<T, D>) -> TVec<T, D> {
y_over_x.map(|e| e.atan())
}
/// Component-wise hyperbolic arc-tangent.
pub fn atanh<N: RealField, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn atanh<T: RealField, const D: usize>(x: &TVec<T, D>) -> TVec<T, D> {
x.map(|e| e.atanh())
}
/// Component-wise cosinus.
pub fn cos<N: RealField, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn cos<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.cos())
}
/// Component-wise hyperbolic cosinus.
pub fn cosh<N: RealField, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn cosh<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.cosh())
}
/// Component-wise conversion from radians to degrees.
pub fn degrees<N: RealField, D: Dimension>(radians: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
radians.map(|e| e * na::convert(180.0) / N::pi())
pub fn degrees<T: RealField, const D: usize>(radians: &TVec<T, D>) -> TVec<T, D> {
radians.map(|e| e * na::convert(180.0) / T::pi())
}
/// Component-wise conversion fro degrees to radians.
pub fn radians<N: RealField, D: Dimension>(degrees: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
degrees.map(|e| e * N::pi() / na::convert(180.0))
pub fn radians<T: RealField, const D: usize>(degrees: &TVec<T, D>) -> TVec<T, D> {
degrees.map(|e| e * T::pi() / na::convert(180.0))
}
/// Component-wise sinus.
pub fn sin<N: RealField, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn sin<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.sin())
}
/// Component-wise hyperbolic sinus.
pub fn sinh<N: RealField, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn sinh<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.sinh())
}
/// Component-wise tangent.
pub fn tan<N: RealField, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn tan<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.tan())
}
/// Component-wise hyperbolic tangent.
pub fn tanh<N: RealField, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn tanh<T: RealField, const D: usize>(angle: &TVec<T, D>) -> TVec<T, D> {
angle.map(|e| e.tanh())
}

View File

@ -1,7 +1,5 @@
use na::DefaultAllocator;
use crate::aliases::TVec;
use crate::traits::{Alloc, Dimension, Number};
use crate::traits::Number;
/// Checks that all the vector components are `true`.
///
@ -20,10 +18,7 @@ use crate::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>,
{
pub fn all<const D: usize>(v: &TVec<bool, D>) -> bool {
v.iter().all(|x| *x)
}
@ -47,10 +42,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>,
{
pub fn any<const D: usize>(v: &TVec<bool, D>) -> bool {
v.iter().any(|x| *x)
}
@ -73,10 +65,7 @@ where
/// * [`less_than_equal`](fn.less_than_equal.html)
/// * [`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>,
{
pub fn equal<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<bool, D> {
x.zip_map(y, |x, y| x == y)
}
@ -99,10 +88,7 @@ where
/// * [`less_than_equal`](fn.less_than_equal.html)
/// * [`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>,
{
pub fn greater_than<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<bool, D> {
x.zip_map(y, |x, y| x > y)
}
@ -125,10 +111,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>
where
DefaultAllocator: Alloc<N, D>,
{
pub fn greater_than_equal<T: Number, const D: usize>(
x: &TVec<T, D>,
y: &TVec<T, D>,
) -> TVec<bool, D> {
x.zip_map(y, |x, y| x >= y)
}
@ -151,10 +137,7 @@ where
/// * [`less_than_equal`](fn.less_than_equal.html)
/// * [`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>,
{
pub fn less_than<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<bool, D> {
x.zip_map(y, |x, y| x < y)
}
@ -177,10 +160,7 @@ where
/// * [`less_than`](fn.less_than.html)
/// * [`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>,
{
pub fn less_than_equal<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<bool, D> {
x.zip_map(y, |x, y| x <= y)
}
@ -204,10 +184,7 @@ where
/// * [`less_than`](fn.less_than.html)
/// * [`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>,
{
pub fn not<const D: usize>(v: &TVec<bool, D>) -> TVec<bool, D> {
v.map(|x| !x)
}
@ -230,9 +207,6 @@ where
/// * [`less_than`](fn.less_than.html)
/// * [`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>,
{
pub fn not_equal<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<bool, D> {
x.zip_map(y, |x, y| x != y)
}

View File

@ -1,6 +1,6 @@
[package]
name = "nalgebra-lapack"
version = "0.16.0"
version = "0.17.0"
authors = [ "Sébastien Crozet <developer@crozet.re>", "Andrew Straw <strawman@astraw.com>" ]
description = "Matrix decompositions using nalgebra matrices and Lapack bindings."
@ -17,9 +17,9 @@ edition = "2018"
maintenance = { status = "actively-developed" }
[features]
serde-serialize = [ "serde", "serde_derive" ]
serde-serialize = [ "serde", "nalgebra/serde-serialize" ]
proptest-support = [ "nalgebra/proptest-support" ]
arbitrary = [ "nalgebra/arbitrary" ]
arbitrary = [ "nalgebra/arbitrary" ]
# For BLAS/LAPACK
default = ["netlib"]
@ -29,19 +29,18 @@ accelerate = ["lapack-src/accelerate"]
intel-mkl = ["lapack-src/intel-mkl"]
[dependencies]
nalgebra = { version = "0.25", path = ".." }
nalgebra = { version = "0.26", path = ".." }
num-traits = "0.2"
num-complex = { version = "0.3", default-features = false }
simba = "0.4"
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
serde = { version = "1.0", features = [ "derive" ], optional = true }
lapack = { version = "0.17", default-features = false }
lapack-src = { version = "0.6", default-features = false }
# clippy = "*"
[dev-dependencies]
nalgebra = { version = "0.25", features = [ "arbitrary" ], path = ".." }
proptest = { version = "1", default-features = false, features = ["std"] }
nalgebra = { version = "0.26", features = [ "arbitrary", "rand" ], path = ".." }
proptest = { version = "1", default-features = false, features = ["std"] }
quickcheck = "1"
approx = "0.4"
rand = "0.8"

View File

@ -5,17 +5,17 @@ use test::{self, Bencher};
#[bench]
fn hessenberg_decompose_100x100(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
}
#[bench]
fn hessenberg_decompose_4x4(bh: &mut Bencher) {
let m = Matrix4::<f64>::new_random();
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
}
#[bench]
fn hessenberg_decompose_500x500(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.iter(|| test::black_box(Hessenberg::new(m.clone())))
bh.iter(|| std::hint::black_box(Hessenberg::new(m.clone())))
}

View File

@ -5,29 +5,29 @@ use test::{self, Bencher};
#[bench]
fn lu_decompose_100x100(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
}
#[bench]
fn lu_decompose_100x500(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(100, 500);
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
}
#[bench]
fn lu_decompose_4x4(bh: &mut Bencher) {
let m = Matrix4::<f64>::new_random();
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
}
#[bench]
fn lu_decompose_500x100(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(500, 100);
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
}
#[bench]
fn lu_decompose_500x500(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.iter(|| test::black_box(LU::new(m.clone())))
bh.iter(|| std::hint::black_box(LU::new(m.clone())))
}

View File

@ -5,29 +5,29 @@ use test::{self, Bencher};
#[bench]
fn qr_decompose_100x100(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(100, 100);
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
}
#[bench]
fn qr_decompose_100x500(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(100, 500);
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
}
#[bench]
fn qr_decompose_4x4(bh: &mut Bencher) {
let m = Matrix4::<f64>::new_random();
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
}
#[bench]
fn qr_decompose_500x100(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(500, 100);
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
}
#[bench]
fn qr_decompose_500x500(bh: &mut Bencher) {
let m = DMatrix::<f64>::new_random(500, 500);
bh.iter(|| test::black_box(QR::new(m.clone())))
bh.iter(|| std::hint::black_box(QR::new(m.clone())))
}

View File

@ -7,7 +7,7 @@ use num_complex::Complex;
use na::allocator::Allocator;
use na::dimension::Dim;
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar};
use na::{DefaultAllocator, Matrix, OMatrix, Scalar};
use lapack;
@ -15,39 +15,39 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(serialize = "DefaultAllocator: Allocator<N, D>,
MatrixN<N, D>: Serialize"))
serde(bound(serialize = "DefaultAllocator: Allocator<T, D>,
OMatrix<T, D, D>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(deserialize = "DefaultAllocator: Allocator<N, D>,
MatrixN<N, D>: Deserialize<'de>"))
serde(bound(deserialize = "DefaultAllocator: Allocator<T, D>,
OMatrix<T, D, D>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct Cholesky<N: Scalar, D: Dim>
pub struct Cholesky<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D, D>,
{
l: MatrixN<N, D>,
l: OMatrix<T, D, D>,
}
impl<N: Scalar + Copy, D: Dim> Copy for Cholesky<N, D>
impl<T: Scalar + Copy, D: Dim> Copy for Cholesky<T, D>
where
DefaultAllocator: Allocator<N, D, D>,
MatrixN<N, D>: Copy,
DefaultAllocator: Allocator<T, D, D>,
OMatrix<T, D, D>: Copy,
{
}
impl<N: CholeskyScalar + Zero, D: Dim> Cholesky<N, D>
impl<T: CholeskyScalar + Zero, D: Dim> Cholesky<T, D>
where
DefaultAllocator: Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D, D>,
{
/// Computes the cholesky decomposition of the given symmetric-definite-positive square
/// matrix.
///
/// Only the lower-triangular part of the input matrix is considered.
#[inline]
pub fn new(mut m: MatrixN<N, D>) -> Option<Self> {
pub fn new(mut m: OMatrix<T, D, D>) -> Option<Self> {
// TODO: check symmetry as well?
assert!(
m.is_square(),
@ -58,14 +58,14 @@ where
let dim = m.nrows() as i32;
let mut info = 0;
N::xpotrf(uplo, dim, m.as_mut_slice(), dim, &mut info);
T::xpotrf(uplo, dim, m.as_mut_slice(), dim, &mut info);
lapack_check!(info);
Some(Self { l: m })
}
/// Retrieves the lower-triangular factor of the cholesky decomposition.
pub fn unpack(mut self) -> MatrixN<N, D> {
pub fn unpack(mut self) -> OMatrix<T, D, D> {
self.l.fill_upper_triangle(Zero::zero(), 1);
self.l
}
@ -75,12 +75,12 @@ where
///
/// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular
/// part are garbage and should be ignored by further computations.
pub fn unpack_dirty(self) -> MatrixN<N, D> {
pub fn unpack_dirty(self) -> OMatrix<T, D, D> {
self.l
}
/// Retrieves the lower-triangular factor of the cholesky decomposition.
pub fn l(&self) -> MatrixN<N, D> {
pub fn l(&self) -> OMatrix<T, D, D> {
let mut res = self.l.clone();
res.fill_upper_triangle(Zero::zero(), 1);
res
@ -91,7 +91,7 @@ where
///
/// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular
/// part are garbage and should be ignored by further computations.
pub fn l_dirty(&self) -> &MatrixN<N, D> {
pub fn l_dirty(&self) -> &OMatrix<T, D, D> {
&self.l
}
@ -99,11 +99,11 @@ where
/// unknown to be determined.
pub fn solve<R2: Dim, C2: Dim, S2>(
&self,
b: &Matrix<N, R2, C2, S2>,
) -> Option<MatrixMN<N, R2, C2>>
b: &Matrix<T, R2, C2, S2>,
) -> Option<OMatrix<T, R2, C2>>
where
S2: Storage<N, R2, C2>,
DefaultAllocator: Allocator<N, R2, C2>,
S2: Storage<T, R2, C2>,
DefaultAllocator: Allocator<T, R2, C2>,
{
let mut res = b.clone_owned();
if self.solve_mut(&mut res) {
@ -115,9 +115,9 @@ 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
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut OMatrix<T, R2, C2>) -> bool
where
DefaultAllocator: Allocator<N, R2, C2>,
DefaultAllocator: Allocator<T, R2, C2>,
{
let dim = self.l.nrows();
@ -131,7 +131,7 @@ where
let ldb = dim as i32;
let mut info = 0;
N::xpotrs(
T::xpotrs(
b'L',
dim as i32,
nrhs,
@ -145,11 +145,11 @@ where
}
/// Computes the inverse of the decomposed matrix.
pub fn inverse(mut self) -> Option<MatrixN<N, D>> {
pub fn inverse(mut self) -> Option<OMatrix<T, D, D>> {
let dim = self.l.nrows();
let mut info = 0;
N::xpotri(
T::xpotri(
b'L',
dim as i32,
self.l.as_mut_slice(),

View File

@ -8,9 +8,9 @@ use simba::scalar::RealField;
use crate::ComplexHelper;
use na::allocator::Allocator;
use na::dimension::{Dim, U1};
use na::dimension::{Const, Dim};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -19,74 +19,74 @@ use lapack;
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
VectorN<N, D>: Serialize,
MatrixN<N, D>: Serialize")
bound(serialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Serialize")
)
)]
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
VectorN<N, D>: Serialize,
MatrixN<N, D>: Deserialize<'de>")
bound(deserialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Deserialize<'de>")
)
)]
#[derive(Clone, Debug)]
pub struct Eigen<N: Scalar, D: Dim>
pub struct Eigen<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
{
/// The eigenvalues of the decomposed matrix.
pub eigenvalues: VectorN<N, D>,
pub eigenvalues: OVector<T, D>,
/// The (right) eigenvectors of the decomposed matrix.
pub eigenvectors: Option<MatrixN<N, D>>,
pub eigenvectors: Option<OMatrix<T, D, D>>,
/// The left eigenvectors of the decomposed matrix.
pub left_eigenvectors: Option<MatrixN<N, D>>,
pub left_eigenvectors: Option<OMatrix<T, D, D>>,
}
impl<N: Scalar + Copy, D: Dim> Copy for Eigen<N, D>
impl<T: Scalar + Copy, D: Dim> Copy for Eigen<T, D>
where
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
VectorN<N, D>: Copy,
MatrixN<N, D>: Copy,
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
OVector<T, D>: Copy,
OMatrix<T, D, D>: Copy,
{
}
impl<N: EigenScalar + RealField, D: Dim> Eigen<N, D>
impl<T: EigenScalar + RealField, D: Dim> Eigen<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
{
/// Computes the eigenvalues and eigenvectors of the square matrix `m`.
///
/// If `eigenvectors` is `false` then, the eigenvectors are not computed explicitly.
pub fn new(
mut m: MatrixN<N, D>,
mut m: OMatrix<T, D, D>,
left_eigenvectors: bool,
eigenvectors: bool,
) -> Option<Eigen<N, D>> {
) -> Option<Eigen<T, D>> {
assert!(
m.is_square(),
"Unable to compute the eigenvalue decomposition of a non-square matrix."
);
let ljob = if left_eigenvectors { b'V' } else { b'N' };
let rjob = if eigenvectors { b'V' } else { b'N' };
let ljob = if left_eigenvectors { b'V' } else { b'T' };
let rjob = if eigenvectors { b'V' } else { b'T' };
let (nrows, ncols) = m.data.shape();
let n = nrows.value();
let lda = n as i32;
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
// TODO: Tap into the workspace.
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
let mut info = 0;
let mut placeholder1 = [N::zero()];
let mut placeholder2 = [N::zero()];
let mut placeholder1 = [T::zero()];
let mut placeholder2 = [T::zero()];
let lwork = N::xgeev_work_size(
let lwork = T::xgeev_work_size(
ljob,
rjob,
n as i32,
@ -112,7 +112,7 @@ where
let mut vr =
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
N::xgeev(
T::xgeev(
ljob,
rjob,
n as i32,
@ -142,7 +142,7 @@ where
let mut vl =
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
N::xgeev(
T::xgeev(
ljob,
rjob,
n as i32,
@ -172,7 +172,7 @@ where
let mut vr =
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
N::xgeev(
T::xgeev(
ljob,
rjob,
n as i32,
@ -199,7 +199,7 @@ where
}
}
(false, false) => {
N::xgeev(
T::xgeev(
ljob,
rjob,
n as i32,
@ -233,9 +233,9 @@ where
/// The complex eigenvalues of the given matrix.
///
/// Panics if the eigenvalue computation does not converge.
pub fn complex_eigenvalues(mut m: MatrixN<N, D>) -> VectorN<Complex<N>, D>
pub fn complex_eigenvalues(mut m: OMatrix<T, D, D>) -> OVector<Complex<T>, D>
where
DefaultAllocator: Allocator<Complex<N>, D>,
DefaultAllocator: Allocator<Complex<T>, D>,
{
assert!(
m.is_square(),
@ -247,16 +247,16 @@ where
let lda = n as i32;
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
let mut info = 0;
let mut placeholder1 = [N::zero()];
let mut placeholder2 = [N::zero()];
let mut placeholder1 = [T::zero()];
let mut placeholder2 = [T::zero()];
let lwork = N::xgeev_work_size(
b'N',
b'N',
let lwork = T::xgeev_work_size(
b'T',
b'T',
n as i32,
m.as_mut_slice(),
lda,
@ -273,9 +273,9 @@ where
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
N::xgeev(
b'N',
b'N',
T::xgeev(
b'T',
b'T',
n as i32,
m.as_mut_slice(),
lda,
@ -291,7 +291,7 @@ where
);
lapack_panic!(info);
let mut res = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut res = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
for i in 0..res.len() {
res[i] = Complex::new(wr[i], wi[i]);
@ -302,8 +302,8 @@ where
/// The determinant of the decomposed matrix.
#[inline]
pub fn determinant(&self) -> N {
let mut det = N::one();
pub fn determinant(&self) -> T {
let mut det = T::one();
for e in self.eigenvalues.iter() {
det *= *e;
}

View File

@ -3,9 +3,9 @@ use num_complex::Complex;
use crate::ComplexHelper;
use na::allocator::Allocator;
use na::dimension::{DimDiff, DimSub, U1};
use na::dimension::{Const, DimDiff, DimSub, U1};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -13,41 +13,41 @@ 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, DimDiff<D, U1>>,
MatrixN<N, D>: Serialize,
VectorN<N, DimDiff<D, U1>>: Serialize"))
serde(bound(serialize = "DefaultAllocator: Allocator<T, D, D> +
Allocator<T, DimDiff<D, U1>>,
OMatrix<T, D, D>: Serialize,
OVector<T, DimDiff<D, U1>>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
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>"))
serde(bound(deserialize = "DefaultAllocator: Allocator<T, D, D> +
Allocator<T, DimDiff<D, U1>>,
OMatrix<T, D, D>: Deserialize<'de>,
OVector<T, DimDiff<D, U1>>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct Hessenberg<N: Scalar, D: DimSub<U1>>
pub struct Hessenberg<T: Scalar, D: DimSub<U1>>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
{
h: MatrixN<N, D>,
tau: VectorN<N, DimDiff<D, U1>>,
h: OMatrix<T, D, D>,
tau: OVector<T, DimDiff<D, U1>>,
}
impl<N: Scalar + Copy, D: DimSub<U1>> Copy for Hessenberg<N, D>
impl<T: Scalar + Copy, D: DimSub<U1>> Copy for Hessenberg<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
MatrixN<N, D>: Copy,
VectorN<N, DimDiff<D, U1>>: Copy,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
OMatrix<T, D, D>: Copy,
OVector<T, DimDiff<D, U1>>: Copy,
{
}
impl<N: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<N, D>
impl<T: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
{
/// Computes the hessenberg decomposition of the matrix `m`.
pub fn new(mut m: MatrixN<N, D>) -> Self {
pub fn new(mut m: OMatrix<T, D, D>) -> Self {
let nrows = m.data.shape().0;
let n = nrows.value() as i32;
@ -60,16 +60,18 @@ where
"Unable to compute the hessenberg decomposition of an empty matrix."
);
let mut tau = unsafe { Matrix::new_uninitialized_generic(nrows.sub(U1), U1).assume_init() };
let mut tau = unsafe {
Matrix::new_uninitialized_generic(nrows.sub(Const::<1>), Const::<1>).assume_init()
};
let mut info = 0;
let lwork =
N::xgehrd_work_size(n, 1, n, m.as_mut_slice(), n, tau.as_mut_slice(), &mut info);
T::xgehrd_work_size(n, 1, n, m.as_mut_slice(), n, tau.as_mut_slice(), &mut info);
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
lapack_panic!(info);
N::xgehrd(
T::xgehrd(
n,
1,
n,
@ -87,36 +89,36 @@ where
/// Computes the hessenberg matrix of this decomposition.
#[inline]
pub fn h(&self) -> MatrixN<N, D> {
pub fn h(&self) -> OMatrix<T, D, D> {
let mut h = self.h.clone_owned();
h.fill_lower_triangle(N::zero(), 2);
h.fill_lower_triangle(T::zero(), 2);
h
}
}
impl<N: HessenbergReal + Zero, D: DimSub<U1>> Hessenberg<N, D>
impl<T: HessenbergReal + Zero, D: DimSub<U1>> Hessenberg<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimDiff<D, U1>>,
{
/// Computes the matrices `(Q, H)` of this decomposition.
#[inline]
pub fn unpack(self) -> (MatrixN<N, D>, MatrixN<N, D>) {
pub fn unpack(self) -> (OMatrix<T, D, D>, OMatrix<T, D, D>) {
(self.q(), self.h())
}
/// Computes the unitary matrix `Q` of this decomposition.
#[inline]
pub fn q(&self) -> MatrixN<N, D> {
pub fn q(&self) -> OMatrix<T, D, D> {
let n = self.h.nrows() as i32;
let mut q = self.h.clone_owned();
let mut info = 0;
let lwork =
N::xorghr_work_size(n, 1, n, q.as_mut_slice(), n, self.tau.as_slice(), &mut info);
let mut work = vec![N::zero(); lwork as usize];
T::xorghr_work_size(n, 1, n, q.as_mut_slice(), n, self.tau.as_slice(), &mut info);
let mut work = vec![T::zero(); lwork as usize];
N::xorghr(
T::xorghr(
n,
1,
n,

View File

@ -3,9 +3,9 @@ use num_complex::Complex;
use crate::ComplexHelper;
use na::allocator::Allocator;
use na::dimension::{Dim, DimMin, DimMinimum, U1};
use na::dimension::{Const, Dim, DimMin, DimMinimum};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -20,57 +20,57 @@ 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<T, R, C> +
Allocator<i32, DimMinimum<R, C>>,
MatrixMN<N, R, C>: Serialize,
OMatrix<T, 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<T, R, C> +
Allocator<i32, DimMinimum<R, C>>,
MatrixMN<N, R, C>: Deserialize<'de>,
OMatrix<T, R, C>: Deserialize<'de>,
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct LU<N: Scalar, R: DimMin<C>, C: Dim>
pub struct LU<T: Scalar, R: DimMin<C>, C: Dim>
where
DefaultAllocator: Allocator<i32, DimMinimum<R, C>> + Allocator<N, R, C>,
DefaultAllocator: Allocator<i32, DimMinimum<R, C>> + Allocator<T, R, C>,
{
lu: MatrixMN<N, R, C>,
p: VectorN<i32, DimMinimum<R, C>>,
lu: OMatrix<T, R, C>,
p: OVector<i32, DimMinimum<R, C>>,
}
impl<N: Scalar + Copy, R: DimMin<C>, C: Dim> Copy for LU<N, R, C>
impl<T: Scalar + Copy, R: DimMin<C>, C: Dim> Copy for LU<T, R, C>
where
DefaultAllocator: Allocator<N, R, C> + Allocator<i32, DimMinimum<R, C>>,
MatrixMN<N, R, C>: Copy,
VectorN<i32, DimMinimum<R, C>>: Copy,
DefaultAllocator: Allocator<T, R, C> + Allocator<i32, DimMinimum<R, C>>,
OMatrix<T, R, C>: Copy,
OVector<i32, DimMinimum<R, C>>: Copy,
{
}
impl<N: LUScalar, R: Dim, C: Dim> LU<N, R, C>
impl<T: LUScalar, R: Dim, C: Dim> LU<T, R, C>
where
N: Zero + One,
T: Zero + One,
R: DimMin<C>,
DefaultAllocator: Allocator<N, R, C>
+ Allocator<N, R, R>
+ Allocator<N, R, DimMinimum<R, C>>
+ Allocator<N, DimMinimum<R, C>, C>
DefaultAllocator: Allocator<T, R, C>
+ Allocator<T, R, R>
+ Allocator<T, R, DimMinimum<R, C>>
+ Allocator<T, DimMinimum<R, C>, C>
+ Allocator<i32, DimMinimum<R, C>>,
{
/// Computes the LU decomposition with partial (row) pivoting of `matrix`.
pub fn new(mut m: MatrixMN<N, R, C>) -> Self {
pub fn new(mut m: OMatrix<T, R, C>) -> Self {
let (nrows, ncols) = m.data.shape();
let min_nrows_ncols = nrows.min(ncols);
let nrows = nrows.value() as i32;
let ncols = ncols.value() as i32;
let mut ipiv: VectorN<i32, _> = Matrix::zeros_generic(min_nrows_ncols, U1);
let mut ipiv: OVector<i32, _> = Matrix::zeros_generic(min_nrows_ncols, Const::<1>);
let mut info = 0;
N::xgetrf(
T::xgetrf(
nrows,
ncols,
m.as_mut_slice(),
@ -85,7 +85,7 @@ where
/// Gets the lower-triangular matrix part of the decomposition.
#[inline]
pub fn l(&self) -> MatrixMN<N, R, DimMinimum<R, C>> {
pub fn l(&self) -> OMatrix<T, R, DimMinimum<R, C>> {
let (nrows, ncols) = self.lu.data.shape();
let mut res = self.lu.columns_generic(0, nrows.min(ncols)).into_owned();
@ -97,7 +97,7 @@ where
/// Gets the upper-triangular matrix part of the decomposition.
#[inline]
pub fn u(&self) -> MatrixMN<N, DimMinimum<R, C>, C> {
pub fn u(&self) -> OMatrix<T, DimMinimum<R, C>, C> {
let (nrows, ncols) = self.lu.data.shape();
let mut res = self.lu.rows_generic(0, nrows.min(ncols)).into_owned();
@ -111,7 +111,7 @@ where
/// Computing the permutation matrix explicitly is costly and usually not necessary.
/// To permute rows of a matrix or vector, use the method `self.permute(...)` instead.
#[inline]
pub fn p(&self) -> MatrixN<N, R> {
pub fn p(&self) -> OMatrix<T, R, R> {
let (dim, _) = self.lu.data.shape();
let mut id = Matrix::identity_generic(dim, dim);
self.permute(&mut id);
@ -124,19 +124,19 @@ where
/// Gets the LAPACK permutation indices.
#[inline]
pub fn permutation_indices(&self) -> &VectorN<i32, DimMinimum<R, C>> {
pub fn permutation_indices(&self) -> &OVector<i32, DimMinimum<R, C>> {
&self.p
}
/// 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>)
pub fn permute<C2: Dim>(&self, rhs: &mut OMatrix<T, R, C2>)
where
DefaultAllocator: Allocator<N, R, C2>,
DefaultAllocator: Allocator<T, R, C2>,
{
let (nrows, ncols) = rhs.shape();
N::xlaswp(
T::xlaswp(
ncols as i32,
rhs.as_mut_slice(),
nrows as i32,
@ -147,9 +147,9 @@ where
);
}
fn generic_solve_mut<R2: Dim, C2: Dim>(&self, trans: u8, b: &mut MatrixMN<N, R2, C2>) -> bool
fn generic_solve_mut<R2: Dim, C2: Dim>(&self, trans: u8, b: &mut OMatrix<T, R2, C2>) -> bool
where
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
let dim = self.lu.nrows();
@ -167,7 +167,7 @@ where
let ldb = dim as i32;
let mut info = 0;
N::xgetrs(
T::xgetrs(
trans,
dim as i32,
nrhs,
@ -184,14 +184,14 @@ where
/// Solves the linear system `self * x = b`, where `x` is the unknown to be determined.
pub fn solve<R2: Dim, C2: Dim, S2>(
&self,
b: &Matrix<N, R2, C2, S2>,
) -> Option<MatrixMN<N, R2, C2>>
b: &Matrix<T, R2, C2, S2>,
) -> Option<OMatrix<T, R2, C2>>
where
S2: Storage<N, R2, C2>,
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
S2: Storage<T, R2, C2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
let mut res = b.clone_owned();
if self.generic_solve_mut(b'N', &mut res) {
if self.generic_solve_mut(b'T', &mut res) {
Some(res)
} else {
None
@ -202,11 +202,11 @@ where
/// determined.
pub fn solve_transpose<R2: Dim, C2: Dim, S2>(
&self,
b: &Matrix<N, R2, C2, S2>,
) -> Option<MatrixMN<N, R2, C2>>
b: &Matrix<T, R2, C2, S2>,
) -> Option<OMatrix<T, R2, C2>>
where
S2: Storage<N, R2, C2>,
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
S2: Storage<T, R2, C2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
let mut res = b.clone_owned();
if self.generic_solve_mut(b'T', &mut res) {
@ -220,11 +220,11 @@ where
/// be determined.
pub fn solve_conjugate_transpose<R2: Dim, C2: Dim, S2>(
&self,
b: &Matrix<N, R2, C2, S2>,
) -> Option<MatrixMN<N, R2, C2>>
b: &Matrix<T, R2, C2, S2>,
) -> Option<OMatrix<T, R2, C2>>
where
S2: Storage<N, R2, C2>,
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
S2: Storage<T, R2, C2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
let mut res = b.clone_owned();
if self.generic_solve_mut(b'T', &mut res) {
@ -237,20 +237,20 @@ where
/// Solves in-place the linear system `self * x = b`, where `x` is the unknown to be determined.
///
/// 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
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut OMatrix<T, R2, C2>) -> bool
where
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
self.generic_solve_mut(b'N', b)
self.generic_solve_mut(b'T', b)
}
/// Solves in-place the linear system `self.transpose() * x = b`, where `x` is the unknown to be
/// determined.
///
/// 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
pub fn solve_transpose_mut<R2: Dim, C2: Dim>(&self, b: &mut OMatrix<T, R2, C2>) -> bool
where
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
self.generic_solve_mut(b'T', b)
}
@ -259,25 +259,25 @@ where
/// be determined.
///
/// Returns `false` if no solution was found (the decomposed matrix is singular).
pub fn solve_adjoint_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
pub fn solve_adjoint_mut<R2: Dim, C2: Dim>(&self, b: &mut OMatrix<T, R2, C2>) -> bool
where
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
DefaultAllocator: Allocator<T, R2, C2> + Allocator<i32, R2>,
{
self.generic_solve_mut(b'T', b)
}
}
impl<N: LUScalar, D: Dim> LU<N, D, D>
impl<T: LUScalar, D: Dim> LU<T, D, D>
where
N: Zero + One,
T: Zero + One,
D: DimMin<D, Output = D>,
DefaultAllocator: Allocator<N, D, D> + Allocator<i32, D>,
DefaultAllocator: Allocator<T, D, D> + Allocator<i32, D>,
{
/// Computes the inverse of the decomposed matrix.
pub fn inverse(mut self) -> Option<MatrixN<N, D>> {
pub fn inverse(mut self) -> Option<OMatrix<T, D, D>> {
let dim = self.lu.nrows() as i32;
let mut info = 0;
let lwork = N::xgetri_work_size(
let lwork = T::xgetri_work_size(
dim,
self.lu.as_mut_slice(),
dim,
@ -288,7 +288,7 @@ where
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
N::xgetri(
T::xgetri(
dim,
self.lu.as_mut_slice(),
dim,

View File

@ -6,9 +6,9 @@ use num_complex::Complex;
use crate::ComplexHelper;
use na::allocator::Allocator;
use na::dimension::{Dim, DimMin, DimMinimum, U1};
use na::dimension::{Const, Dim, DimMin, DimMinimum};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixMN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -16,55 +16,56 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(serialize = "DefaultAllocator: Allocator<N, R, C> +
Allocator<N, DimMinimum<R, C>>,
MatrixMN<N, R, C>: Serialize,
VectorN<N, DimMinimum<R, C>>: Serialize"))
serde(bound(serialize = "DefaultAllocator: Allocator<T, R, C> +
Allocator<T, DimMinimum<R, C>>,
OMatrix<T, R, C>: Serialize,
OVector<T, DimMinimum<R, C>>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(deserialize = "DefaultAllocator: Allocator<N, R, C> +
Allocator<N, DimMinimum<R, C>>,
MatrixMN<N, R, C>: Deserialize<'de>,
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"))
serde(bound(deserialize = "DefaultAllocator: Allocator<T, R, C> +
Allocator<T, DimMinimum<R, C>>,
OMatrix<T, R, C>: Deserialize<'de>,
OVector<T, DimMinimum<R, C>>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct QR<N: Scalar, R: DimMin<C>, C: Dim>
pub struct QR<T: Scalar, R: DimMin<C>, C: Dim>
where
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
DefaultAllocator: Allocator<T, R, C> + Allocator<T, DimMinimum<R, C>>,
{
qr: MatrixMN<N, R, C>,
tau: VectorN<N, DimMinimum<R, C>>,
qr: OMatrix<T, R, C>,
tau: OVector<T, DimMinimum<R, C>>,
}
impl<N: Scalar + Copy, R: DimMin<C>, C: Dim> Copy for QR<N, R, C>
impl<T: Scalar + Copy, R: DimMin<C>, C: Dim> Copy for QR<T, R, C>
where
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
MatrixMN<N, R, C>: Copy,
VectorN<N, DimMinimum<R, C>>: Copy,
DefaultAllocator: Allocator<T, R, C> + Allocator<T, DimMinimum<R, C>>,
OMatrix<T, R, C>: Copy,
OVector<T, DimMinimum<R, C>>: Copy,
{
}
impl<N: QRScalar + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
impl<T: QRScalar + Zero, R: DimMin<C>, C: Dim> QR<T, 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>>,
DefaultAllocator: Allocator<T, R, C>
+ Allocator<T, R, DimMinimum<R, C>>
+ Allocator<T, DimMinimum<R, C>, C>
+ Allocator<T, DimMinimum<R, C>>,
{
/// Computes the QR decomposition of the matrix `m`.
pub fn new(mut m: MatrixMN<N, R, C>) -> Self {
pub fn new(mut m: OMatrix<T, R, C>) -> Self {
let (nrows, ncols) = m.data.shape();
let mut info = 0;
let mut tau =
unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), U1).assume_init() };
let mut tau = unsafe {
Matrix::new_uninitialized_generic(nrows.min(ncols), Const::<1>).assume_init()
};
if nrows.value() == 0 || ncols.value() == 0 {
return Self { qr: m, tau: tau };
}
let lwork = N::xgeqrf_work_size(
let lwork = T::xgeqrf_work_size(
nrows.value() as i32,
ncols.value() as i32,
m.as_mut_slice(),
@ -75,7 +76,7 @@ where
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
N::xgeqrf(
T::xgeqrf(
nrows.value() as i32,
ncols.value() as i32,
m.as_mut_slice(),
@ -91,37 +92,37 @@ where
/// Retrieves the upper trapezoidal submatrix `R` of this decomposition.
#[inline]
pub fn r(&self) -> MatrixMN<N, DimMinimum<R, C>, C> {
pub fn r(&self) -> OMatrix<T, DimMinimum<R, C>, C> {
let (nrows, ncols) = self.qr.data.shape();
self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle()
}
}
impl<N: QRReal + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
impl<T: QRReal + Zero, R: DimMin<C>, C: Dim> QR<T, 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>>,
DefaultAllocator: Allocator<T, R, C>
+ Allocator<T, R, DimMinimum<R, C>>
+ Allocator<T, DimMinimum<R, C>, C>
+ Allocator<T, DimMinimum<R, C>>,
{
/// Retrieves the matrices `(Q, R)` of this decompositions.
pub fn unpack(
self,
) -> (
MatrixMN<N, R, DimMinimum<R, C>>,
MatrixMN<N, DimMinimum<R, C>, C>,
OMatrix<T, R, DimMinimum<R, C>>,
OMatrix<T, DimMinimum<R, C>, C>,
) {
(self.q(), self.r())
}
/// Computes the orthogonal matrix `Q` of this decomposition.
#[inline]
pub fn q(&self) -> MatrixMN<N, R, DimMinimum<R, C>> {
pub fn q(&self) -> OMatrix<T, R, DimMinimum<R, C>> {
let (nrows, ncols) = self.qr.data.shape();
let min_nrows_ncols = nrows.min(ncols);
if min_nrows_ncols.value() == 0 {
return MatrixMN::from_element_generic(nrows, min_nrows_ncols, N::zero());
return OMatrix::from_element_generic(nrows, min_nrows_ncols, T::zero());
}
let mut q = self
@ -132,7 +133,7 @@ where
let mut info = 0;
let nrows = nrows.value() as i32;
let lwork = N::xorgqr_work_size(
let lwork = T::xorgqr_work_size(
nrows,
min_nrows_ncols.value() as i32,
self.tau.len() as i32,
@ -142,9 +143,9 @@ where
&mut info,
);
let mut work = vec![N::zero(); lwork as usize];
let mut work = vec![T::zero(); lwork as usize];
N::xorgqr(
T::xorgqr(
nrows,
min_nrows_ncols.value() as i32,
self.tau.len() as i32,

View File

@ -8,9 +8,9 @@ use simba::scalar::RealField;
use crate::ComplexHelper;
use na::allocator::Allocator;
use na::dimension::{Dim, U1};
use na::dimension::{Const, Dim};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -19,53 +19,53 @@ use lapack;
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
VectorN<N, D>: Serialize,
MatrixN<N, D>: Serialize")
bound(serialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Serialize")
)
)]
#[cfg_attr(
feature = "serde-serialize",
serde(
bound(deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
VectorN<N, D>: Serialize,
MatrixN<N, D>: Deserialize<'de>")
bound(deserialize = "DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Deserialize<'de>")
)
)]
#[derive(Clone, Debug)]
pub struct Schur<N: Scalar, D: Dim>
pub struct Schur<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
{
re: VectorN<N, D>,
im: VectorN<N, D>,
t: MatrixN<N, D>,
q: MatrixN<N, D>,
re: OVector<T, D>,
im: OVector<T, D>,
t: OMatrix<T, D, D>,
q: OMatrix<T, D, D>,
}
impl<N: Scalar + Copy, D: Dim> Copy for Schur<N, D>
impl<T: Scalar + Copy, D: Dim> Copy for Schur<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
MatrixN<N, D>: Copy,
VectorN<N, D>: Copy,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
OMatrix<T, D, D>: Copy,
OVector<T, D>: Copy,
{
}
impl<N: SchurScalar + RealField, D: Dim> Schur<N, D>
impl<T: SchurScalar + RealField, D: Dim> Schur<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
{
/// Computes the eigenvalues and real Schur form of the matrix `m`.
///
/// Panics if the method did not converge.
pub fn new(m: MatrixN<N, D>) -> Self {
pub fn new(m: OMatrix<T, D, D>) -> Self {
Self::try_new(m).expect("Schur decomposition: convergence failed.")
}
/// Computes the eigenvalues and real Schur form of the matrix `m`.
///
/// Returns `None` if the method did not converge.
pub fn try_new(mut m: MatrixN<N, D>) -> Option<Self> {
pub fn try_new(mut m: OMatrix<T, D, D>) -> Option<Self> {
assert!(
m.is_square(),
"Unable to compute the eigenvalue decomposition of a non-square matrix."
@ -78,16 +78,16 @@ where
let mut info = 0;
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
let mut q = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
// Placeholders:
let mut bwork = [0i32];
let mut unused = 0;
let lwork = N::xgees_work_size(
let lwork = T::xgees_work_size(
b'V',
b'N',
b'T',
n as i32,
m.as_mut_slice(),
lda,
@ -103,9 +103,9 @@ where
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
N::xgees(
T::xgees(
b'V',
b'N',
b'T',
n as i32,
m.as_mut_slice(),
lda,
@ -131,14 +131,14 @@ where
/// Retrieves the unitary matrix `Q` and the upper-quasitriangular matrix `T` such that the
/// decomposed matrix equals `Q * T * Q.transpose()`.
pub fn unpack(self) -> (MatrixN<N, D>, MatrixN<N, D>) {
pub fn unpack(self) -> (OMatrix<T, D, D>, OMatrix<T, D, D>) {
(self.q, self.t)
}
/// Computes the real eigenvalues of the decomposed matrix.
///
/// Return `None` if some eigenvalues are complex.
pub fn eigenvalues(&self) -> Option<VectorN<N, D>> {
pub fn eigenvalues(&self) -> Option<OVector<T, D>> {
if self.im.iter().all(|e| e.is_zero()) {
Some(self.re.clone())
} else {
@ -147,12 +147,13 @@ where
}
/// Computes the complex eigenvalues of the decomposed matrix.
pub fn complex_eigenvalues(&self) -> VectorN<Complex<N>, D>
pub fn complex_eigenvalues(&self) -> OVector<Complex<T>, D>
where
DefaultAllocator: Allocator<Complex<N>, D>,
DefaultAllocator: Allocator<Complex<T>, D>,
{
let mut out =
unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1).assume_init() };
let mut out = unsafe {
OVector::new_uninitialized_generic(self.t.data.shape().0, Const::<1>).assume_init()
};
for i in 0..out.len() {
out[i] = Complex::new(self.re[i], self.im[i])

View File

@ -5,9 +5,9 @@ use num::Signed;
use std::cmp;
use na::allocator::Allocator;
use na::dimension::{Dim, DimMin, DimMinimum, U1};
use na::dimension::{Const, Dim, DimMin, DimMinimum, U1};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -15,41 +15,41 @@ use lapack;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde-serialize",
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"))
serde(bound(serialize = "DefaultAllocator: Allocator<T, DimMinimum<R, C>> +
Allocator<T, R, R> +
Allocator<T, C, C>,
OMatrix<T, R>: Serialize,
OMatrix<T, C>: Serialize,
OVector<T, DimMinimum<R, C>>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
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>"))
serde(bound(serialize = "DefaultAllocator: Allocator<T, DimMinimum<R, C>> +
Allocator<T, R, R> +
Allocator<T, C, C>,
OMatrix<T, R>: Deserialize<'de>,
OMatrix<T, C>: Deserialize<'de>,
OVector<T, DimMinimum<R, C>>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct SVD<N: Scalar, R: DimMin<C>, C: Dim>
pub struct SVD<T: Scalar, R: DimMin<C>, C: Dim>
where
DefaultAllocator: Allocator<N, R, R> + Allocator<N, DimMinimum<R, C>> + Allocator<N, C, C>,
DefaultAllocator: Allocator<T, R, R> + Allocator<T, DimMinimum<R, C>> + Allocator<T, C, C>,
{
/// The left-singular vectors `U` of this SVD.
pub u: MatrixN<N, R>, // TODO: should be MatrixMN<N, R, DimMinimum<R, C>>
pub u: OMatrix<T, R, R>, // TODO: should be OMatrix<T, R, DimMinimum<R, C>>
/// The right-singular vectors `V^t` of this SVD.
pub vt: MatrixN<N, C>, // TODO: should be MatrixMN<N, DimMinimum<R, C>, C>
pub vt: OMatrix<T, C, C>, // TODO: should be OMatrix<T, DimMinimum<R, C>, C>
/// The singular values of this SVD.
pub singular_values: VectorN<N, DimMinimum<R, C>>,
pub singular_values: OVector<T, DimMinimum<R, C>>,
}
impl<N: Scalar + Copy, R: DimMin<C>, C: Dim> Copy for SVD<N, R, C>
impl<T: Scalar + Copy, R: DimMin<C>, C: Dim> Copy for SVD<T, R, C>
where
DefaultAllocator: Allocator<N, C, C> + Allocator<N, R, R> + Allocator<N, DimMinimum<R, C>>,
MatrixMN<N, R, R>: Copy,
MatrixMN<N, C, C>: Copy,
VectorN<N, DimMinimum<R, C>>: Copy,
DefaultAllocator: Allocator<T, C, C> + Allocator<T, R, R> + Allocator<T, DimMinimum<R, C>>,
OMatrix<T, R, R>: Copy,
OMatrix<T, C, C>: Copy,
OVector<T, DimMinimum<R, C>>: Copy,
{
}
@ -63,19 +63,19 @@ where
+ Allocator<Self, C, C>,
{
/// Computes the SVD decomposition of `m`.
fn compute(m: MatrixMN<Self, R, C>) -> Option<SVD<Self, R, C>>;
fn compute(m: OMatrix<Self, R, C>) -> Option<SVD<Self, R, C>>;
}
impl<N: SVDScalar<R, C>, R: DimMin<C>, C: Dim> SVD<N, R, C>
impl<T: SVDScalar<R, C>, R: DimMin<C>, C: Dim> SVD<T, R, C>
where
DefaultAllocator: Allocator<N, R, R>
+ Allocator<N, R, C>
+ Allocator<N, DimMinimum<R, C>>
+ Allocator<N, C, C>,
DefaultAllocator: Allocator<T, R, R>
+ Allocator<T, R, C>
+ Allocator<T, DimMinimum<R, C>>
+ Allocator<T, C, C>,
{
/// Computes the Singular Value Decomposition of `matrix`.
pub fn new(m: MatrixMN<N, R, C>) -> Option<Self> {
N::compute(m)
pub fn new(m: OMatrix<T, R, C>) -> Option<Self> {
T::compute(m)
}
}
@ -88,7 +88,7 @@ macro_rules! svd_impl(
Allocator<$t, C, C> +
Allocator<$t, DimMinimum<R, C>> {
fn compute(mut m: MatrixMN<$t, R, C>) -> Option<SVD<$t, R, C>> {
fn compute(mut m: OMatrix<$t, R, C>) -> Option<SVD<$t, R, C>> {
let (nrows, ncols) = m.data.shape();
if nrows.value() == 0 || ncols.value() == 0 {
@ -100,7 +100,7 @@ macro_rules! svd_impl(
let lda = nrows.value() as i32;
let mut u = unsafe { Matrix::new_uninitialized_generic(nrows, nrows).assume_init() };
let mut s = unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), U1).assume_init() };
let mut s = unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), Const::<1>).assume_init() };
let mut vt = unsafe { Matrix::new_uninitialized_generic(ncols, ncols).assume_init() };
let ldu = nrows.value();
@ -150,12 +150,12 @@ macro_rules! svd_impl(
/// Useful if some components (e.g. some singular values) of this decomposition have
/// been manually changed by the user.
#[inline]
pub fn recompose(self) -> MatrixMN<$t, R, C> {
pub fn recompose(self) -> OMatrix<$t, R, C> {
let nrows = self.u.data.shape().0;
let ncols = self.vt.data.shape().1;
let min_nrows_ncols = nrows.min(ncols);
let mut res: MatrixMN<_, R, C> = Matrix::zeros_generic(nrows, ncols);
let mut res: OMatrix<_, R, C> = Matrix::zeros_generic(nrows, ncols);
{
let mut sres = res.generic_slice_mut((0, 0), (min_nrows_ncols, ncols));
@ -175,12 +175,12 @@ macro_rules! svd_impl(
///
/// All singular value below epsilon will be set to zero instead of being inverted.
#[inline]
pub fn pseudo_inverse(&self, epsilon: $t) -> MatrixMN<$t, C, R> {
pub fn pseudo_inverse(&self, epsilon: $t) -> OMatrix<$t, C, R> {
let nrows = self.u.data.shape().0;
let ncols = self.vt.data.shape().1;
let min_nrows_ncols = nrows.min(ncols);
let mut res: MatrixMN<_, C, R> = Matrix::zeros_generic(ncols, nrows);
let mut res: OMatrix<_, C, R> = Matrix::zeros_generic(ncols, nrows);
{
let mut sres = res.generic_slice_mut((0, 0), (min_nrows_ncols, nrows));
@ -230,9 +230,9 @@ macro_rules! svd_complex_impl(
($name: ident, $t: ty, $lapack_func: path) => (
impl SVDScalar for Complex<$t> {
fn compute<R: Dim, C: Dim, S>(mut m: Matrix<$t, R, C, S>) -> Option<SVD<$t, R, C, S::Alloc>>
Option<(MatrixN<Complex<$t>, R, S::Alloc>,
VectorN<$t, DimMinimum<R, C>, S::Alloc>,
MatrixN<Complex<$t>, C, S::Alloc>)>
Option<(OMatrix<Complex<$t>, R, S::Alloc>,
OVector<$t, DimMinimum<R, C>, S::Alloc>,
OMatrix<Complex<$t>, C, S::Alloc>)>
where R: DimMin<C>,
S: ContiguousStorage<Complex<$t>, R, C>,
S::Alloc: OwnedAllocator<Complex<$t>, R, C, S> +

View File

@ -8,9 +8,9 @@ use simba::scalar::RealField;
use crate::ComplexHelper;
use na::allocator::Allocator;
use na::dimension::{Dim, U1};
use na::dimension::{Const, Dim};
use na::storage::Storage;
use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN};
use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar};
use lapack;
@ -18,47 +18,47 @@ 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>,
VectorN<N, D>: Serialize,
MatrixN<N, D>: Serialize"))
serde(bound(serialize = "DefaultAllocator: Allocator<T, D, D> +
Allocator<T, D>,
OVector<T, D>: Serialize,
OMatrix<T, D, D>: Serialize"))
)]
#[cfg_attr(
feature = "serde-serialize",
serde(bound(deserialize = "DefaultAllocator: Allocator<N, D, D> +
Allocator<N, D>,
VectorN<N, D>: Deserialize<'de>,
MatrixN<N, D>: Deserialize<'de>"))
serde(bound(deserialize = "DefaultAllocator: Allocator<T, D, D> +
Allocator<T, D>,
OVector<T, D>: Deserialize<'de>,
OMatrix<T, D, D>: Deserialize<'de>"))
)]
#[derive(Clone, Debug)]
pub struct SymmetricEigen<N: Scalar, D: Dim>
pub struct SymmetricEigen<T: Scalar, D: Dim>
where
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D> + Allocator<T, D, D>,
{
/// The eigenvectors of the decomposed matrix.
pub eigenvectors: MatrixN<N, D>,
pub eigenvectors: OMatrix<T, D, D>,
/// The unsorted eigenvalues of the decomposed matrix.
pub eigenvalues: VectorN<N, D>,
pub eigenvalues: OVector<T, D>,
}
impl<N: Scalar + Copy, D: Dim> Copy for SymmetricEigen<N, D>
impl<T: Scalar + Copy, D: Dim> Copy for SymmetricEigen<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
MatrixN<N, D>: Copy,
VectorN<N, D>: Copy,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
OMatrix<T, D, D>: Copy,
OVector<T, D>: Copy,
{
}
impl<N: SymmetricEigenScalar + RealField, D: Dim> SymmetricEigen<N, D>
impl<T: SymmetricEigenScalar + RealField, D: Dim> SymmetricEigen<T, D>
where
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
{
/// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`.
///
/// Only the lower-triangular part of `m` is read. If `eigenvectors` is `false` then, the
/// eigenvectors are not computed explicitly. Panics if the method did not converge.
pub fn new(m: MatrixN<N, D>) -> Self {
pub fn new(m: OMatrix<T, D, D>) -> Self {
let (vals, vecs) =
Self::do_decompose(m, true).expect("SymmetricEigen: convergence failure.");
Self {
@ -71,7 +71,7 @@ where
///
/// Only the lower-triangular part of `m` is read. If `eigenvectors` is `false` then, the
/// eigenvectors are not computed explicitly. Returns `None` if the method did not converge.
pub fn try_new(m: MatrixN<N, D>) -> Option<Self> {
pub fn try_new(m: OMatrix<T, D, D>) -> Option<Self> {
Self::do_decompose(m, true).map(|(vals, vecs)| SymmetricEigen {
eigenvalues: vals,
eigenvectors: vecs.unwrap(),
@ -79,30 +79,31 @@ where
}
fn do_decompose(
mut m: MatrixN<N, D>,
mut m: OMatrix<T, D, D>,
eigenvectors: bool,
) -> Option<(VectorN<N, D>, Option<MatrixN<N, D>>)> {
) -> Option<(OVector<T, D>, Option<OMatrix<T, D, D>>)> {
assert!(
m.is_square(),
"Unable to compute the eigenvalue decomposition of a non-square matrix."
);
let jobz = if eigenvectors { b'V' } else { b'N' };
let jobz = if eigenvectors { b'V' } else { b'T' };
let nrows = m.data.shape().0;
let n = nrows.value();
let lda = n as i32;
let mut values = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() };
let mut values =
unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
let mut info = 0;
let lwork = N::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info);
let lwork = T::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info);
lapack_check!(info);
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
N::xsyev(
T::xsyev(
jobz,
b'L',
n as i32,
@ -122,7 +123,7 @@ where
/// Computes only the eigenvalues of the input matrix.
///
/// Panics if the method does not converge.
pub fn eigenvalues(m: MatrixN<N, D>) -> VectorN<N, D> {
pub fn eigenvalues(m: OMatrix<T, D, D>) -> OVector<T, D> {
Self::do_decompose(m, false)
.expect("SymmetricEigen eigenvalues: convergence failure.")
.0
@ -131,14 +132,14 @@ where
/// Computes only the eigenvalues of the input matrix.
///
/// Returns `None` if the method does not converge.
pub fn try_eigenvalues(m: MatrixN<N, D>) -> Option<VectorN<N, D>> {
pub fn try_eigenvalues(m: OMatrix<T, D, D>) -> Option<OVector<T, D>> {
Self::do_decompose(m, false).map(|res| res.0)
}
/// The determinant of the decomposed matrix.
#[inline]
pub fn determinant(&self) -> N {
let mut det = N::one();
pub fn determinant(&self) -> T {
let mut det = T::one();
for e in self.eigenvalues.iter() {
det *= *e;
}
@ -149,7 +150,7 @@ where
/// Rebuild the original matrix.
///
/// This is useful if some of the eigenvalues have been manually modified.
pub fn recompose(&self) -> MatrixN<N, D> {
pub fn recompose(&self) -> OMatrix<T, D, D> {
let mut u_t = self.eigenvectors.clone();
for i in 0..self.eigenvalues.len() {
let val = self.eigenvalues[i];

View File

@ -1,6 +1,6 @@
[package]
name = "nalgebra-sparse"
version = "0.1.0"
version = "0.2.0"
authors = [ "Andreas Longva", "Sébastien Crozet <developer@crozet.re>" ]
edition = "2018"
description = "Sparse matrix computation based on nalgebra."
@ -20,7 +20,7 @@ compare = [ "matrixcompare-core" ]
slow-tests = []
[dependencies]
nalgebra = { version="0.25", path = "../" }
nalgebra = { version="0.26", path = "../" }
num-traits = { version = "0.2", default-features = false }
proptest = { version = "1.0", optional = true }
matrixcompare-core = { version = "0.1.0", optional = true }
@ -28,7 +28,7 @@ matrixcompare-core = { version = "0.1.0", optional = true }
[dev-dependencies]
itertools = "0.10"
matrixcompare = { version = "0.2.0", features = [ "proptest-support" ] }
nalgebra = { version="0.25", path = "../", features = ["compare"] }
nalgebra = { version="0.26", path = "../", features = ["compare"] }
[package.metadata.docs.rs]
# Enable certain features when building docs for docs.rs

View File

@ -10,7 +10,7 @@ use nalgebra::allocator::Allocator;
use nalgebra::base::storage::Storage;
use nalgebra::constraint::{DimEq, ShapeConstraint};
use nalgebra::{
ClosedAdd, ClosedDiv, ClosedMul, ClosedSub, DefaultAllocator, Dim, Dynamic, Matrix, MatrixMN,
ClosedAdd, ClosedDiv, ClosedMul, ClosedSub, DefaultAllocator, Dim, Dynamic, Matrix, OMatrix,
Scalar, U1,
};
use num_traits::{One, Zero};
@ -274,7 +274,7 @@ macro_rules! impl_spmm_cs_dense {
impl_spmm_cs_dense!(&'a $matrix_type_name<T>, &'a Matrix<T, R, C, S>, $spmm_fn, |lhs, rhs| {
let (_, ncols) = rhs.data.shape();
let nrows = Dynamic::new(lhs.nrows());
let mut result = MatrixMN::<T, Dynamic, C>::zeros_generic(nrows, ncols);
let mut result = OMatrix::<T, Dynamic, C>::zeros_generic(nrows, ncols);
$spmm_fn(T::zero(), &mut result, T::one(), Op::NoOp(lhs), Op::NoOp(rhs));
result
});
@ -305,7 +305,7 @@ macro_rules! impl_spmm_cs_dense {
DefaultAllocator: Allocator<T, Dynamic, C>,
// TODO: Is it possible to simplify these bounds?
ShapeConstraint:
// Bounds so that we can turn MatrixMN<T, Dynamic, C> into a DMatrixSliceMut
// Bounds so that we can turn OMatrix<T, Dynamic, C> into a DMatrixSliceMut
DimEq<U1, <<DefaultAllocator as Allocator<T, Dynamic, C>>::Buffer as Storage<T, Dynamic, C>>::RStride>
+ DimEq<C, Dynamic>
+ DimEq<Dynamic, <<DefaultAllocator as Allocator<T, Dynamic, C>>::Buffer as Storage<T, Dynamic, C>>::CStride>
@ -316,7 +316,7 @@ macro_rules! impl_spmm_cs_dense {
{
// We need the column dimension to be generic, so that if RHS is a vector, then
// we also get a vector (and not a matrix)
type Output = MatrixMN<T, Dynamic, C>;
type Output = OMatrix<T, Dynamic, C>;
fn mul(self, rhs: $dense_matrix_type) -> Self::Output {
let $lhs = self;

View File

@ -4,7 +4,7 @@ use crate::base::dimension::{U1, U2, U3, U4, U5, U6};
use crate::base::storage::Owned;
#[cfg(any(feature = "std", feature = "alloc"))]
use crate::base::vec_storage::VecStorage;
use crate::base::Matrix;
use crate::base::{ArrayStorage, Const, Matrix, Unit};
/*
*
@ -13,244 +13,254 @@ use crate::base::Matrix;
*
*
*/
/// A statically sized column-major matrix with `R` rows and `C` columns.
/// An owned matrix column-major matrix with `R` rows and `C` columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[deprecated(note = "This matrix name contains a typo. Use MatrixMN instead.")]
pub type MatrixNM<N, R, C> = Matrix<N, R, C, Owned<N, R, C>>;
pub type OMatrix<T, R, C> = Matrix<T, R, C, Owned<T, R, C>>;
/// An owned matrix column-major matrix with `R` rows and `C` columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[deprecated(
note = "use SMatrix for a statically-sized matrix using integer dimensions, or OMatrix for an owned matrix using types as dimensions."
)]
pub type MatrixMN<T, R, C> = Matrix<T, R, C, Owned<T, R, C>>;
/// An owned matrix column-major matrix with `D` columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[deprecated(note = "use OMatrix<T, D, D> or SMatrix<T, D, D> instead.")]
pub type MatrixN<T, D> = Matrix<T, D, D, Owned<T, D, D>>;
/// A statically sized column-major matrix with `R` rows and `C` columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixMN<N, R, C> = Matrix<N, R, C, Owned<N, R, C>>;
/// A statically sized column-major square matrix with `D` rows and columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixN<N, D> = Matrix<N, D, D, Owned<N, D, D>>;
pub type SMatrix<T, const R: usize, const C: usize> =
Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>>;
/// A dynamically sized column-major matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type DMatrix<N> = Matrix<N, Dynamic, Dynamic, Owned<N, Dynamic, Dynamic>>;
pub type DMatrix<T> = Matrix<T, Dynamic, Dynamic, VecStorage<T, Dynamic, Dynamic>>;
/// A heap-allocated, column-major, matrix with a dynamic number of rows and 1 columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type MatrixXx1<N> = Matrix<N, Dynamic, U1, Owned<N, Dynamic, U1>>;
pub type MatrixXx1<T> = Matrix<T, Dynamic, U1, VecStorage<T, Dynamic, U1>>;
/// A heap-allocated, column-major, matrix with a dynamic number of rows and 2 columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type MatrixXx2<N> = Matrix<N, Dynamic, U2, Owned<N, Dynamic, U2>>;
pub type MatrixXx2<T> = Matrix<T, Dynamic, U2, VecStorage<T, Dynamic, U2>>;
/// A heap-allocated, column-major, matrix with a dynamic number of rows and 3 columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type MatrixXx3<N> = Matrix<N, Dynamic, U3, Owned<N, Dynamic, U3>>;
pub type MatrixXx3<T> = Matrix<T, Dynamic, U3, VecStorage<T, Dynamic, U3>>;
/// A heap-allocated, column-major, matrix with a dynamic number of rows and 4 columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type MatrixXx4<N> = Matrix<N, Dynamic, U4, Owned<N, Dynamic, U4>>;
pub type MatrixXx4<T> = Matrix<T, Dynamic, U4, VecStorage<T, Dynamic, U4>>;
/// A heap-allocated, column-major, matrix with a dynamic number of rows and 5 columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type MatrixXx5<N> = Matrix<N, Dynamic, U5, Owned<N, Dynamic, U5>>;
pub type MatrixXx5<T> = Matrix<T, Dynamic, U5, VecStorage<T, Dynamic, U5>>;
/// A heap-allocated, column-major, matrix with a dynamic number of rows and 6 columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type MatrixXx6<N> = Matrix<N, Dynamic, U6, Owned<N, Dynamic, U6>>;
pub type MatrixXx6<T> = Matrix<T, Dynamic, U6, VecStorage<T, Dynamic, U6>>;
/// A heap-allocated, row-major, matrix with 1 rows and a dynamic number of columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type Matrix1xX<N> = Matrix<N, U1, Dynamic, Owned<N, U1, Dynamic>>;
pub type Matrix1xX<T> = Matrix<T, U1, Dynamic, VecStorage<T, U1, Dynamic>>;
/// A heap-allocated, row-major, matrix with 2 rows and a dynamic number of columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type Matrix2xX<N> = Matrix<N, U2, Dynamic, Owned<N, U2, Dynamic>>;
pub type Matrix2xX<T> = Matrix<T, U2, Dynamic, VecStorage<T, U2, Dynamic>>;
/// A heap-allocated, row-major, matrix with 3 rows and a dynamic number of columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type Matrix3xX<N> = Matrix<N, U3, Dynamic, Owned<N, U3, Dynamic>>;
pub type Matrix3xX<T> = Matrix<T, U3, Dynamic, VecStorage<T, U3, Dynamic>>;
/// A heap-allocated, row-major, matrix with 4 rows and a dynamic number of columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type Matrix4xX<N> = Matrix<N, U4, Dynamic, Owned<N, U4, Dynamic>>;
pub type Matrix4xX<T> = Matrix<T, U4, Dynamic, VecStorage<T, U4, Dynamic>>;
/// A heap-allocated, row-major, matrix with 5 rows and a dynamic number of columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type Matrix5xX<N> = Matrix<N, U5, Dynamic, Owned<N, U5, Dynamic>>;
pub type Matrix5xX<T> = Matrix<T, U5, Dynamic, VecStorage<T, U5, Dynamic>>;
/// A heap-allocated, row-major, matrix with 6 rows and a dynamic number of columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[cfg(any(feature = "std", feature = "alloc"))]
pub type Matrix6xX<N> = Matrix<N, U6, Dynamic, Owned<N, U6, Dynamic>>;
pub type Matrix6xX<T> = Matrix<T, U6, Dynamic, VecStorage<T, U6, Dynamic>>;
/// A stack-allocated, column-major, 1x1 square matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix1<N> = Matrix<N, U1, U1, Owned<N, U1, U1>>;
pub type Matrix1<T> = Matrix<T, U1, U1, ArrayStorage<T, 1, 1>>;
/// A stack-allocated, column-major, 2x2 square matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix2<N> = Matrix<N, U2, U2, Owned<N, U2, U2>>;
pub type Matrix2<T> = Matrix<T, U2, U2, ArrayStorage<T, 2, 2>>;
/// A stack-allocated, column-major, 3x3 square matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix3<N> = Matrix<N, U3, U3, Owned<N, U3, U3>>;
pub type Matrix3<T> = Matrix<T, U3, U3, ArrayStorage<T, 3, 3>>;
/// A stack-allocated, column-major, 4x4 square matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix4<N> = Matrix<N, U4, U4, Owned<N, U4, U4>>;
pub type Matrix4<T> = Matrix<T, U4, U4, ArrayStorage<T, 4, 4>>;
/// A stack-allocated, column-major, 5x5 square matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix5<N> = Matrix<N, U5, U5, Owned<N, U5, U5>>;
pub type Matrix5<T> = Matrix<T, U5, U5, ArrayStorage<T, 5, 5>>;
/// A stack-allocated, column-major, 6x6 square matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix6<N> = Matrix<N, U6, U6, Owned<N, U6, U6>>;
pub type Matrix6<T> = Matrix<T, U6, U6, ArrayStorage<T, 6, 6>>;
/// A stack-allocated, column-major, 1x2 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix1x2<N> = Matrix<N, U1, U2, Owned<N, U1, U2>>;
pub type Matrix1x2<T> = Matrix<T, U1, U2, ArrayStorage<T, 1, 2>>;
/// A stack-allocated, column-major, 1x3 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix1x3<N> = Matrix<N, U1, U3, Owned<N, U1, U3>>;
pub type Matrix1x3<T> = Matrix<T, U1, U3, ArrayStorage<T, 1, 3>>;
/// A stack-allocated, column-major, 1x4 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix1x4<N> = Matrix<N, U1, U4, Owned<N, U1, U4>>;
pub type Matrix1x4<T> = Matrix<T, U1, U4, ArrayStorage<T, 1, 4>>;
/// A stack-allocated, column-major, 1x5 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix1x5<N> = Matrix<N, U1, U5, Owned<N, U1, U5>>;
pub type Matrix1x5<T> = Matrix<T, U1, U5, ArrayStorage<T, 1, 5>>;
/// A stack-allocated, column-major, 1x6 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix1x6<N> = Matrix<N, U1, U6, Owned<N, U1, U6>>;
pub type Matrix1x6<T> = Matrix<T, U1, U6, ArrayStorage<T, 1, 6>>;
/// A stack-allocated, column-major, 2x3 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix2x3<N> = Matrix<N, U2, U3, Owned<N, U2, U3>>;
pub type Matrix2x3<T> = Matrix<T, U2, U3, ArrayStorage<T, 2, 3>>;
/// A stack-allocated, column-major, 2x4 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix2x4<N> = Matrix<N, U2, U4, Owned<N, U2, U4>>;
pub type Matrix2x4<T> = Matrix<T, U2, U4, ArrayStorage<T, 2, 4>>;
/// A stack-allocated, column-major, 2x5 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix2x5<N> = Matrix<N, U2, U5, Owned<N, U2, U5>>;
pub type Matrix2x5<T> = Matrix<T, U2, U5, ArrayStorage<T, 2, 5>>;
/// A stack-allocated, column-major, 2x6 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix2x6<N> = Matrix<N, U2, U6, Owned<N, U2, U6>>;
pub type Matrix2x6<T> = Matrix<T, U2, U6, ArrayStorage<T, 2, 6>>;
/// A stack-allocated, column-major, 3x4 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix3x4<N> = Matrix<N, U3, U4, Owned<N, U3, U4>>;
pub type Matrix3x4<T> = Matrix<T, U3, U4, ArrayStorage<T, 3, 4>>;
/// A stack-allocated, column-major, 3x5 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix3x5<N> = Matrix<N, U3, U5, Owned<N, U3, U5>>;
pub type Matrix3x5<T> = Matrix<T, U3, U5, ArrayStorage<T, 3, 5>>;
/// A stack-allocated, column-major, 3x6 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix3x6<N> = Matrix<N, U3, U6, Owned<N, U3, U6>>;
pub type Matrix3x6<T> = Matrix<T, U3, U6, ArrayStorage<T, 3, 6>>;
/// A stack-allocated, column-major, 4x5 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix4x5<N> = Matrix<N, U4, U5, Owned<N, U4, U5>>;
pub type Matrix4x5<T> = Matrix<T, U4, U5, ArrayStorage<T, 4, 5>>;
/// A stack-allocated, column-major, 4x6 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix4x6<N> = Matrix<N, U4, U6, Owned<N, U4, U6>>;
pub type Matrix4x6<T> = Matrix<T, U4, U6, ArrayStorage<T, 4, 6>>;
/// A stack-allocated, column-major, 5x6 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix5x6<N> = Matrix<N, U5, U6, Owned<N, U5, U6>>;
pub type Matrix5x6<T> = Matrix<T, U5, U6, ArrayStorage<T, 5, 6>>;
/// A stack-allocated, column-major, 2x1 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix2x1<N> = Matrix<N, U2, U1, Owned<N, U2, U1>>;
pub type Matrix2x1<T> = Matrix<T, U2, U1, ArrayStorage<T, 2, 1>>;
/// A stack-allocated, column-major, 3x1 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix3x1<N> = Matrix<N, U3, U1, Owned<N, U3, U1>>;
pub type Matrix3x1<T> = Matrix<T, U3, U1, ArrayStorage<T, 3, 1>>;
/// A stack-allocated, column-major, 4x1 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix4x1<N> = Matrix<N, U4, U1, Owned<N, U4, U1>>;
pub type Matrix4x1<T> = Matrix<T, U4, U1, ArrayStorage<T, 4, 1>>;
/// A stack-allocated, column-major, 5x1 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix5x1<N> = Matrix<N, U5, U1, Owned<N, U5, U1>>;
pub type Matrix5x1<T> = Matrix<T, U5, U1, ArrayStorage<T, 5, 1>>;
/// A stack-allocated, column-major, 6x1 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix6x1<N> = Matrix<N, U6, U1, Owned<N, U6, U1>>;
pub type Matrix6x1<T> = Matrix<T, U6, U1, ArrayStorage<T, 6, 1>>;
/// A stack-allocated, column-major, 3x2 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix3x2<N> = Matrix<N, U3, U2, Owned<N, U3, U2>>;
pub type Matrix3x2<T> = Matrix<T, U3, U2, ArrayStorage<T, 3, 2>>;
/// A stack-allocated, column-major, 4x2 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix4x2<N> = Matrix<N, U4, U2, Owned<N, U4, U2>>;
pub type Matrix4x2<T> = Matrix<T, U4, U2, ArrayStorage<T, 4, 2>>;
/// A stack-allocated, column-major, 5x2 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix5x2<N> = Matrix<N, U5, U2, Owned<N, U5, U2>>;
pub type Matrix5x2<T> = Matrix<T, U5, U2, ArrayStorage<T, 5, 2>>;
/// A stack-allocated, column-major, 6x2 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix6x2<N> = Matrix<N, U6, U2, Owned<N, U6, U2>>;
pub type Matrix6x2<T> = Matrix<T, U6, U2, ArrayStorage<T, 6, 2>>;
/// A stack-allocated, column-major, 4x3 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix4x3<N> = Matrix<N, U4, U3, Owned<N, U4, U3>>;
pub type Matrix4x3<T> = Matrix<T, U4, U3, ArrayStorage<T, 4, 3>>;
/// A stack-allocated, column-major, 5x3 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix5x3<N> = Matrix<N, U5, U3, Owned<N, U5, U3>>;
pub type Matrix5x3<T> = Matrix<T, U5, U3, ArrayStorage<T, 5, 3>>;
/// A stack-allocated, column-major, 6x3 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix6x3<N> = Matrix<N, U6, U3, Owned<N, U6, U3>>;
pub type Matrix6x3<T> = Matrix<T, U6, U3, ArrayStorage<T, 6, 3>>;
/// A stack-allocated, column-major, 5x4 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix5x4<N> = Matrix<N, U5, U4, Owned<N, U5, U4>>;
pub type Matrix5x4<T> = Matrix<T, U5, U4, ArrayStorage<T, 5, 4>>;
/// A stack-allocated, column-major, 6x4 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix6x4<N> = Matrix<N, U6, U4, Owned<N, U6, U4>>;
pub type Matrix6x4<T> = Matrix<T, U6, U4, ArrayStorage<T, 6, 4>>;
/// A stack-allocated, column-major, 6x5 matrix.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type Matrix6x5<N> = Matrix<N, U6, U5, Owned<N, U6, U5>>;
pub type Matrix6x5<T> = Matrix<T, U6, U5, ArrayStorage<T, 6, 5>>;
/*
*
@ -261,23 +271,33 @@ pub type Matrix6x5<N> = Matrix<N, U6, U5, Owned<N, U6, U5>>;
*/
/// A dynamically sized column vector.
#[cfg(any(feature = "std", feature = "alloc"))]
pub type DVector<N> = Matrix<N, Dynamic, U1, VecStorage<N, Dynamic, U1>>;
pub type DVector<T> = Matrix<T, Dynamic, U1, VecStorage<T, Dynamic, U1>>;
/// An owned D-dimensional column vector.
pub type OVector<T, D> = Matrix<T, D, U1, Owned<T, D, U1>>;
/// A statically sized D-dimensional column vector.
pub type VectorN<N, D> = Matrix<N, D, U1, Owned<N, D, U1>>;
pub type SVector<T, const D: usize> = Matrix<T, Const<D>, U1, ArrayStorage<T, D, 1>>; // Owned<T, Const<D>, U1>>;
/// An owned matrix column-major matrix with `R` rows and `C` columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
#[deprecated(
note = "use SVector for a statically-sized matrix using integer dimensions, or OVector for an owned matrix using types as dimensions."
)]
pub type VectorN<T, D> = Matrix<T, D, U1, Owned<T, D, U1>>;
/// A stack-allocated, 1-dimensional column vector.
pub type Vector1<N> = Matrix<N, U1, U1, Owned<N, U1, U1>>;
pub type Vector1<T> = Matrix<T, U1, U1, ArrayStorage<T, 1, 1>>;
/// A stack-allocated, 2-dimensional column vector.
pub type Vector2<N> = Matrix<N, U2, U1, Owned<N, U2, U1>>;
pub type Vector2<T> = Matrix<T, U2, U1, ArrayStorage<T, 2, 1>>;
/// A stack-allocated, 3-dimensional column vector.
pub type Vector3<N> = Matrix<N, U3, U1, Owned<N, U3, U1>>;
pub type Vector3<T> = Matrix<T, U3, U1, ArrayStorage<T, 3, 1>>;
/// A stack-allocated, 4-dimensional column vector.
pub type Vector4<N> = Matrix<N, U4, U1, Owned<N, U4, U1>>;
pub type Vector4<T> = Matrix<T, U4, U1, ArrayStorage<T, 4, 1>>;
/// A stack-allocated, 5-dimensional column vector.
pub type Vector5<N> = Matrix<N, U5, U1, Owned<N, U5, U1>>;
pub type Vector5<T> = Matrix<T, U5, U1, ArrayStorage<T, 5, 1>>;
/// A stack-allocated, 6-dimensional column vector.
pub type Vector6<N> = Matrix<N, U6, U1, Owned<N, U6, U1>>;
pub type Vector6<T> = Matrix<T, U6, U1, ArrayStorage<T, 6, 1>>;
/*
*
@ -288,20 +308,43 @@ pub type Vector6<N> = Matrix<N, U6, U1, Owned<N, U6, U1>>;
*/
/// A dynamically sized row vector.
#[cfg(any(feature = "std", feature = "alloc"))]
pub type RowDVector<N> = Matrix<N, U1, Dynamic, VecStorage<N, U1, Dynamic>>;
pub type RowDVector<T> = Matrix<T, U1, Dynamic, VecStorage<T, U1, Dynamic>>;
/// An owned D-dimensional row vector.
pub type RowOVector<T, D> = Matrix<T, U1, D, Owned<T, U1, D>>;
/// A statically sized D-dimensional row vector.
pub type RowVectorN<N, D> = Matrix<N, U1, D, Owned<N, U1, D>>;
pub type RowSVector<T, const D: usize> = Matrix<T, U1, Const<D>, ArrayStorage<T, 1, D>>;
/// A stack-allocated, 1-dimensional row vector.
pub type RowVector1<N> = Matrix<N, U1, U1, Owned<N, U1, U1>>;
pub type RowVector1<T> = Matrix<T, U1, U1, ArrayStorage<T, 1, 1>>;
/// A stack-allocated, 2-dimensional row vector.
pub type RowVector2<N> = Matrix<N, U1, U2, Owned<N, U1, U2>>;
pub type RowVector2<T> = Matrix<T, U1, U2, ArrayStorage<T, 1, 2>>;
/// A stack-allocated, 3-dimensional row vector.
pub type RowVector3<N> = Matrix<N, U1, U3, Owned<N, U1, U3>>;
pub type RowVector3<T> = Matrix<T, U1, U3, ArrayStorage<T, 1, 3>>;
/// A stack-allocated, 4-dimensional row vector.
pub type RowVector4<N> = Matrix<N, U1, U4, Owned<N, U1, U4>>;
pub type RowVector4<T> = Matrix<T, U1, U4, ArrayStorage<T, 1, 4>>;
/// A stack-allocated, 5-dimensional row vector.
pub type RowVector5<N> = Matrix<N, U1, U5, Owned<N, U1, U5>>;
pub type RowVector5<T> = Matrix<T, U1, U5, ArrayStorage<T, 1, 5>>;
/// A stack-allocated, 6-dimensional row vector.
pub type RowVector6<N> = Matrix<N, U1, U6, Owned<N, U1, U6>>;
pub type RowVector6<T> = Matrix<T, U1, U6, ArrayStorage<T, 1, 6>>;
/*
*
*
* Unit Vector.
*
*
*/
/// A stack-allocated, 1-dimensional unit vector.
pub type UnitVector1<T> = Unit<Matrix<T, U1, U1, ArrayStorage<T, 1, 1>>>;
/// A stack-allocated, 2-dimensional unit vector.
pub type UnitVector2<T> = Unit<Matrix<T, U2, U1, ArrayStorage<T, 2, 1>>>;
/// A stack-allocated, 3-dimensional unit vector.
pub type UnitVector3<T> = Unit<Matrix<T, U3, U1, ArrayStorage<T, 3, 1>>>;
/// A stack-allocated, 4-dimensional unit vector.
pub type UnitVector4<T> = Unit<Matrix<T, U4, U1, ArrayStorage<T, 4, 1>>>;
/// A stack-allocated, 5-dimensional unit vector.
pub type UnitVector5<T> = Unit<Matrix<T, U5, U1, ArrayStorage<T, 5, 1>>>;
/// A stack-allocated, 6-dimensional unit vector.
pub type UnitVector6<T> = Unit<Matrix<T, U6, U1, ArrayStorage<T, 6, 1>>>;

View File

@ -1,6 +1,6 @@
use crate::base::dimension::{Dynamic, U1, U2, U3, U4, U5, U6};
use crate::base::matrix_slice::{SliceStorage, SliceStorageMut};
use crate::base::Matrix;
use crate::base::{Const, Matrix};
/*
*
@ -9,287 +9,290 @@ use crate::base::Matrix;
*
*
*/
/// A column-major matrix slice with `R` rows and `C` columns.
// NOTE: we can't provide defaults for the strides because it's not supported yet by min_const_generics.
/// A column-major matrix slice with dimensions known at compile-time.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMN<'a, N, R, C, RStride = U1, CStride = R> =
Matrix<N, R, C, SliceStorage<'a, N, R, C, RStride, CStride>>;
/// A column-major matrix slice with `D` rows and columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceN<'a, N, D, RStride = U1, CStride = D> =
Matrix<N, D, D, SliceStorage<'a, N, D, D, RStride, CStride>>;
pub type SMatrixSlice<'a, T, const R: usize, const C: usize> =
Matrix<T, Const<R>, Const<C>, SliceStorage<'a, T, Const<R>, Const<C>, Const<1>, Const<R>>>;
/// A column-major matrix slice dynamic numbers of rows and columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type DMatrixSlice<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, Dynamic, SliceStorage<'a, N, Dynamic, Dynamic, RStride, CStride>>;
pub type DMatrixSlice<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, Dynamic, SliceStorage<'a, T, Dynamic, Dynamic, RStride, CStride>>;
/// A column-major 1x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice1<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U1, SliceStorage<'a, N, U1, U1, RStride, CStride>>;
pub type MatrixSlice1<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U1, SliceStorage<'a, T, U1, U1, RStride, CStride>>;
/// A column-major 2x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice2<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U2, SliceStorage<'a, N, U2, U2, RStride, CStride>>;
pub type MatrixSlice2<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U2, SliceStorage<'a, T, U2, U2, RStride, CStride>>;
/// A column-major 3x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice3<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U3, SliceStorage<'a, N, U3, U3, RStride, CStride>>;
pub type MatrixSlice3<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U3, SliceStorage<'a, T, U3, U3, RStride, CStride>>;
/// A column-major 4x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice4<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U4, SliceStorage<'a, N, U4, U4, RStride, CStride>>;
pub type MatrixSlice4<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U4, SliceStorage<'a, T, U4, U4, RStride, CStride>>;
/// A column-major 5x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice5<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U5, SliceStorage<'a, N, U5, U5, RStride, CStride>>;
pub type MatrixSlice5<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U5, SliceStorage<'a, T, U5, U5, RStride, CStride>>;
/// A column-major 6x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice6<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U6, SliceStorage<'a, N, U6, U6, RStride, CStride>>;
pub type MatrixSlice6<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U6, SliceStorage<'a, T, U6, U6, RStride, CStride>>;
/// A column-major 1x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice1x2<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U2, SliceStorage<'a, N, U1, U2, RStride, CStride>>;
pub type MatrixSlice1x2<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U2, SliceStorage<'a, T, U1, U2, RStride, CStride>>;
/// A column-major 1x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice1x3<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U3, SliceStorage<'a, N, U1, U3, RStride, CStride>>;
pub type MatrixSlice1x3<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U3, SliceStorage<'a, T, U1, U3, RStride, CStride>>;
/// A column-major 1x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice1x4<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U4, SliceStorage<'a, N, U1, U4, RStride, CStride>>;
pub type MatrixSlice1x4<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U4, SliceStorage<'a, T, U1, U4, RStride, CStride>>;
/// A column-major 1x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice1x5<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U5, SliceStorage<'a, N, U1, U5, RStride, CStride>>;
pub type MatrixSlice1x5<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U5, SliceStorage<'a, T, U1, U5, RStride, CStride>>;
/// A column-major 1x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice1x6<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U6, SliceStorage<'a, N, U1, U6, RStride, CStride>>;
pub type MatrixSlice1x6<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U6, SliceStorage<'a, T, U1, U6, RStride, CStride>>;
/// A column-major 2x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice2x1<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U1, SliceStorage<'a, N, U2, U1, RStride, CStride>>;
pub type MatrixSlice2x1<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U1, SliceStorage<'a, T, U2, U1, RStride, CStride>>;
/// A column-major 2x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice2x3<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U3, SliceStorage<'a, N, U2, U3, RStride, CStride>>;
pub type MatrixSlice2x3<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U3, SliceStorage<'a, T, U2, U3, RStride, CStride>>;
/// A column-major 2x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice2x4<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U4, SliceStorage<'a, N, U2, U4, RStride, CStride>>;
pub type MatrixSlice2x4<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U4, SliceStorage<'a, T, U2, U4, RStride, CStride>>;
/// A column-major 2x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice2x5<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U5, SliceStorage<'a, N, U2, U5, RStride, CStride>>;
pub type MatrixSlice2x5<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U5, SliceStorage<'a, T, U2, U5, RStride, CStride>>;
/// A column-major 2x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice2x6<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U6, SliceStorage<'a, N, U2, U6, RStride, CStride>>;
pub type MatrixSlice2x6<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U6, SliceStorage<'a, T, U2, U6, RStride, CStride>>;
/// A column-major 3x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice3x1<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U1, SliceStorage<'a, N, U3, U1, RStride, CStride>>;
pub type MatrixSlice3x1<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U1, SliceStorage<'a, T, U3, U1, RStride, CStride>>;
/// A column-major 3x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice3x2<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U2, SliceStorage<'a, N, U3, U2, RStride, CStride>>;
pub type MatrixSlice3x2<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U2, SliceStorage<'a, T, U3, U2, RStride, CStride>>;
/// A column-major 3x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice3x4<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U4, SliceStorage<'a, N, U3, U4, RStride, CStride>>;
pub type MatrixSlice3x4<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U4, SliceStorage<'a, T, U3, U4, RStride, CStride>>;
/// A column-major 3x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice3x5<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U5, SliceStorage<'a, N, U3, U5, RStride, CStride>>;
pub type MatrixSlice3x5<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U5, SliceStorage<'a, T, U3, U5, RStride, CStride>>;
/// A column-major 3x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice3x6<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U6, SliceStorage<'a, N, U3, U6, RStride, CStride>>;
pub type MatrixSlice3x6<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U6, SliceStorage<'a, T, U3, U6, RStride, CStride>>;
/// A column-major 4x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice4x1<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U1, SliceStorage<'a, N, U4, U1, RStride, CStride>>;
pub type MatrixSlice4x1<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U1, SliceStorage<'a, T, U4, U1, RStride, CStride>>;
/// A column-major 4x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice4x2<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U2, SliceStorage<'a, N, U4, U2, RStride, CStride>>;
pub type MatrixSlice4x2<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U2, SliceStorage<'a, T, U4, U2, RStride, CStride>>;
/// A column-major 4x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice4x3<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U3, SliceStorage<'a, N, U4, U3, RStride, CStride>>;
pub type MatrixSlice4x3<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U3, SliceStorage<'a, T, U4, U3, RStride, CStride>>;
/// A column-major 4x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice4x5<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U5, SliceStorage<'a, N, U4, U5, RStride, CStride>>;
pub type MatrixSlice4x5<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U5, SliceStorage<'a, T, U4, U5, RStride, CStride>>;
/// A column-major 4x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice4x6<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U6, SliceStorage<'a, N, U4, U6, RStride, CStride>>;
pub type MatrixSlice4x6<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U6, SliceStorage<'a, T, U4, U6, RStride, CStride>>;
/// A column-major 5x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice5x1<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U1, SliceStorage<'a, N, U5, U1, RStride, CStride>>;
pub type MatrixSlice5x1<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U1, SliceStorage<'a, T, U5, U1, RStride, CStride>>;
/// A column-major 5x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice5x2<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U2, SliceStorage<'a, N, U5, U2, RStride, CStride>>;
pub type MatrixSlice5x2<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U2, SliceStorage<'a, T, U5, U2, RStride, CStride>>;
/// A column-major 5x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice5x3<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U3, SliceStorage<'a, N, U5, U3, RStride, CStride>>;
pub type MatrixSlice5x3<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U3, SliceStorage<'a, T, U5, U3, RStride, CStride>>;
/// A column-major 5x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice5x4<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U4, SliceStorage<'a, N, U5, U4, RStride, CStride>>;
pub type MatrixSlice5x4<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U4, SliceStorage<'a, T, U5, U4, RStride, CStride>>;
/// A column-major 5x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice5x6<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U6, SliceStorage<'a, N, U5, U6, RStride, CStride>>;
pub type MatrixSlice5x6<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U6, SliceStorage<'a, T, U5, U6, RStride, CStride>>;
/// A column-major 6x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice6x1<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U1, SliceStorage<'a, N, U6, U1, RStride, CStride>>;
pub type MatrixSlice6x1<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U1, SliceStorage<'a, T, U6, U1, RStride, CStride>>;
/// A column-major 6x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice6x2<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U2, SliceStorage<'a, N, U6, U2, RStride, CStride>>;
pub type MatrixSlice6x2<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U2, SliceStorage<'a, T, U6, U2, RStride, CStride>>;
/// A column-major 6x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice6x3<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U3, SliceStorage<'a, N, U6, U3, RStride, CStride>>;
pub type MatrixSlice6x3<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U3, SliceStorage<'a, T, U6, U3, RStride, CStride>>;
/// A column-major 6x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice6x4<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U4, SliceStorage<'a, N, U6, U4, RStride, CStride>>;
pub type MatrixSlice6x4<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U4, SliceStorage<'a, T, U6, U4, RStride, CStride>>;
/// A column-major 6x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSlice6x5<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U5, SliceStorage<'a, N, U6, U5, RStride, CStride>>;
pub type MatrixSlice6x5<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U5, SliceStorage<'a, T, U6, U5, RStride, CStride>>;
/// A column-major matrix slice with 1 row and a number of columns chosen at runtime.
pub type MatrixSlice1xX<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, Dynamic, SliceStorage<'a, N, U1, Dynamic, RStride, CStride>>;
pub type MatrixSlice1xX<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, Dynamic, SliceStorage<'a, T, U1, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 2 rows and a number of columns chosen at runtime.
pub type MatrixSlice2xX<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, Dynamic, SliceStorage<'a, N, U2, Dynamic, RStride, CStride>>;
pub type MatrixSlice2xX<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, Dynamic, SliceStorage<'a, T, U2, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 3 rows and a number of columns chosen at runtime.
pub type MatrixSlice3xX<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, Dynamic, SliceStorage<'a, N, U3, Dynamic, RStride, CStride>>;
pub type MatrixSlice3xX<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, Dynamic, SliceStorage<'a, T, U3, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 4 rows and a number of columns chosen at runtime.
pub type MatrixSlice4xX<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, Dynamic, SliceStorage<'a, N, U4, Dynamic, RStride, CStride>>;
pub type MatrixSlice4xX<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, Dynamic, SliceStorage<'a, T, U4, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 5 rows and a number of columns chosen at runtime.
pub type MatrixSlice5xX<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, Dynamic, SliceStorage<'a, N, U5, Dynamic, RStride, CStride>>;
pub type MatrixSlice5xX<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, Dynamic, SliceStorage<'a, T, U5, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 6 rows and a number of columns chosen at runtime.
pub type MatrixSlice6xX<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, Dynamic, SliceStorage<'a, N, U6, Dynamic, RStride, CStride>>;
pub type MatrixSlice6xX<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, Dynamic, SliceStorage<'a, T, U6, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 1 column.
pub type MatrixSliceXx1<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U1, SliceStorage<'a, N, Dynamic, U1, RStride, CStride>>;
pub type MatrixSliceXx1<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U1, SliceStorage<'a, T, Dynamic, U1, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 2 columns.
pub type MatrixSliceXx2<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U2, SliceStorage<'a, N, Dynamic, U2, RStride, CStride>>;
pub type MatrixSliceXx2<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U2, SliceStorage<'a, T, Dynamic, U2, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 3 columns.
pub type MatrixSliceXx3<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U3, SliceStorage<'a, N, Dynamic, U3, RStride, CStride>>;
pub type MatrixSliceXx3<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U3, SliceStorage<'a, T, Dynamic, U3, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 4 columns.
pub type MatrixSliceXx4<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U4, SliceStorage<'a, N, Dynamic, U4, RStride, CStride>>;
pub type MatrixSliceXx4<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U4, SliceStorage<'a, T, Dynamic, U4, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 5 columns.
pub type MatrixSliceXx5<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U5, SliceStorage<'a, N, Dynamic, U5, RStride, CStride>>;
pub type MatrixSliceXx5<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U5, SliceStorage<'a, T, Dynamic, U5, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 6 columns.
pub type MatrixSliceXx6<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U6, SliceStorage<'a, N, Dynamic, U6, RStride, CStride>>;
pub type MatrixSliceXx6<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U6, SliceStorage<'a, T, Dynamic, U6, RStride, CStride>>;
/// A column vector slice with `D` rows.
pub type VectorSliceN<'a, N, D, RStride = U1, CStride = D> =
Matrix<N, D, U1, SliceStorage<'a, N, D, U1, RStride, CStride>>;
/// A column vector slice with dimensions known at compile-time.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice<'a, T, D, RStride = U1, CStride = D> =
Matrix<T, D, U1, SliceStorage<'a, T, D, U1, RStride, CStride>>;
/// A column vector slice with dimensions known at compile-time.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type SVectorSlice<'a, T, const D: usize> =
Matrix<T, Const<D>, Const<1>, SliceStorage<'a, T, Const<D>, Const<1>, Const<1>, Const<D>>>;
/// A column vector slice dynamic numbers of rows and columns.
pub type DVectorSlice<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U1, SliceStorage<'a, N, Dynamic, U1, RStride, CStride>>;
pub type DVectorSlice<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U1, SliceStorage<'a, T, Dynamic, U1, RStride, CStride>>;
/// A 1D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice1<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U1, SliceStorage<'a, N, U1, U1, RStride, CStride>>;
pub type VectorSlice1<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U1, SliceStorage<'a, T, U1, U1, RStride, CStride>>;
/// A 2D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice2<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U1, SliceStorage<'a, N, U2, U1, RStride, CStride>>;
pub type VectorSlice2<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U1, SliceStorage<'a, T, U2, U1, RStride, CStride>>;
/// A 3D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice3<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U1, SliceStorage<'a, N, U3, U1, RStride, CStride>>;
pub type VectorSlice3<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U1, SliceStorage<'a, T, U3, U1, RStride, CStride>>;
/// A 4D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice4<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U1, SliceStorage<'a, N, U4, U1, RStride, CStride>>;
pub type VectorSlice4<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U1, SliceStorage<'a, T, U4, U1, RStride, CStride>>;
/// A 5D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice5<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U1, SliceStorage<'a, N, U5, U1, RStride, CStride>>;
pub type VectorSlice5<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U1, SliceStorage<'a, T, U5, U1, RStride, CStride>>;
/// A 6D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSlice6<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U1, SliceStorage<'a, N, U6, U1, RStride, CStride>>;
pub type VectorSlice6<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U1, SliceStorage<'a, T, U6, U1, RStride, CStride>>;
/*
*
@ -301,281 +304,297 @@ pub type VectorSlice6<'a, N, RStride = U1, CStride = U6> =
/// A column-major matrix slice with `R` rows and `C` columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMutMN<'a, N, R, C, RStride = U1, CStride = R> =
Matrix<N, R, C, SliceStorageMut<'a, N, R, C, RStride, CStride>>;
pub type MatrixSliceMutMN<'a, T, R, C, RStride = U1, CStride = R> =
Matrix<T, R, C, SliceStorageMut<'a, T, R, C, RStride, CStride>>;
/// A column-major matrix slice with `D` rows and columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMutN<'a, N, D, RStride = U1, CStride = D> =
Matrix<N, D, D, SliceStorageMut<'a, N, D, D, RStride, CStride>>;
pub type MatrixSliceMutN<'a, T, D, RStride = U1, CStride = D> =
Matrix<T, D, D, SliceStorageMut<'a, T, D, D, RStride, CStride>>;
/// A column-major matrix slice with dimensions known at compile-time.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type SMatrixSliceMut<'a, T, const R: usize, const C: usize> =
Matrix<T, Const<R>, Const<C>, SliceStorageMut<'a, T, Const<R>, Const<C>, Const<1>, Const<R>>>;
/// A column-major matrix slice dynamic numbers of rows and columns.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type DMatrixSliceMut<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, Dynamic, SliceStorageMut<'a, N, Dynamic, Dynamic, RStride, CStride>>;
pub type DMatrixSliceMut<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, Dynamic, SliceStorageMut<'a, T, Dynamic, Dynamic, RStride, CStride>>;
/// A column-major 1x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut1<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U1, SliceStorageMut<'a, N, U1, U1, RStride, CStride>>;
pub type MatrixSliceMut1<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U1, SliceStorageMut<'a, T, U1, U1, RStride, CStride>>;
/// A column-major 2x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut2<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U2, SliceStorageMut<'a, N, U2, U2, RStride, CStride>>;
pub type MatrixSliceMut2<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U2, SliceStorageMut<'a, T, U2, U2, RStride, CStride>>;
/// A column-major 3x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut3<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U3, SliceStorageMut<'a, N, U3, U3, RStride, CStride>>;
pub type MatrixSliceMut3<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U3, SliceStorageMut<'a, T, U3, U3, RStride, CStride>>;
/// A column-major 4x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut4<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U4, SliceStorageMut<'a, N, U4, U4, RStride, CStride>>;
pub type MatrixSliceMut4<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U4, SliceStorageMut<'a, T, U4, U4, RStride, CStride>>;
/// A column-major 5x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut5<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U5, SliceStorageMut<'a, N, U5, U5, RStride, CStride>>;
pub type MatrixSliceMut5<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U5, SliceStorageMut<'a, T, U5, U5, RStride, CStride>>;
/// A column-major 6x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut6<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U6, SliceStorageMut<'a, N, U6, U6, RStride, CStride>>;
pub type MatrixSliceMut6<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U6, SliceStorageMut<'a, T, U6, U6, RStride, CStride>>;
/// A column-major 1x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut1x2<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U2, SliceStorageMut<'a, N, U1, U2, RStride, CStride>>;
pub type MatrixSliceMut1x2<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U2, SliceStorageMut<'a, T, U1, U2, RStride, CStride>>;
/// A column-major 1x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut1x3<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U3, SliceStorageMut<'a, N, U1, U3, RStride, CStride>>;
pub type MatrixSliceMut1x3<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U3, SliceStorageMut<'a, T, U1, U3, RStride, CStride>>;
/// A column-major 1x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut1x4<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U4, SliceStorageMut<'a, N, U1, U4, RStride, CStride>>;
pub type MatrixSliceMut1x4<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U4, SliceStorageMut<'a, T, U1, U4, RStride, CStride>>;
/// A column-major 1x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut1x5<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U5, SliceStorageMut<'a, N, U1, U5, RStride, CStride>>;
pub type MatrixSliceMut1x5<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U5, SliceStorageMut<'a, T, U1, U5, RStride, CStride>>;
/// A column-major 1x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut1x6<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U6, SliceStorageMut<'a, N, U1, U6, RStride, CStride>>;
pub type MatrixSliceMut1x6<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U6, SliceStorageMut<'a, T, U1, U6, RStride, CStride>>;
/// A column-major 2x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut2x1<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U1, SliceStorageMut<'a, N, U2, U1, RStride, CStride>>;
pub type MatrixSliceMut2x1<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U1, SliceStorageMut<'a, T, U2, U1, RStride, CStride>>;
/// A column-major 2x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut2x3<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U3, SliceStorageMut<'a, N, U2, U3, RStride, CStride>>;
pub type MatrixSliceMut2x3<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U3, SliceStorageMut<'a, T, U2, U3, RStride, CStride>>;
/// A column-major 2x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut2x4<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U4, SliceStorageMut<'a, N, U2, U4, RStride, CStride>>;
pub type MatrixSliceMut2x4<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U4, SliceStorageMut<'a, T, U2, U4, RStride, CStride>>;
/// A column-major 2x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut2x5<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U5, SliceStorageMut<'a, N, U2, U5, RStride, CStride>>;
pub type MatrixSliceMut2x5<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U5, SliceStorageMut<'a, T, U2, U5, RStride, CStride>>;
/// A column-major 2x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut2x6<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U6, SliceStorageMut<'a, N, U2, U6, RStride, CStride>>;
pub type MatrixSliceMut2x6<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U6, SliceStorageMut<'a, T, U2, U6, RStride, CStride>>;
/// A column-major 3x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut3x1<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U1, SliceStorageMut<'a, N, U3, U1, RStride, CStride>>;
pub type MatrixSliceMut3x1<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U1, SliceStorageMut<'a, T, U3, U1, RStride, CStride>>;
/// A column-major 3x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut3x2<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U2, SliceStorageMut<'a, N, U3, U2, RStride, CStride>>;
pub type MatrixSliceMut3x2<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U2, SliceStorageMut<'a, T, U3, U2, RStride, CStride>>;
/// A column-major 3x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut3x4<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U4, SliceStorageMut<'a, N, U3, U4, RStride, CStride>>;
pub type MatrixSliceMut3x4<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U4, SliceStorageMut<'a, T, U3, U4, RStride, CStride>>;
/// A column-major 3x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut3x5<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U5, SliceStorageMut<'a, N, U3, U5, RStride, CStride>>;
pub type MatrixSliceMut3x5<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U5, SliceStorageMut<'a, T, U3, U5, RStride, CStride>>;
/// A column-major 3x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut3x6<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U6, SliceStorageMut<'a, N, U3, U6, RStride, CStride>>;
pub type MatrixSliceMut3x6<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U6, SliceStorageMut<'a, T, U3, U6, RStride, CStride>>;
/// A column-major 4x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut4x1<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U1, SliceStorageMut<'a, N, U4, U1, RStride, CStride>>;
pub type MatrixSliceMut4x1<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U1, SliceStorageMut<'a, T, U4, U1, RStride, CStride>>;
/// A column-major 4x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut4x2<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U2, SliceStorageMut<'a, N, U4, U2, RStride, CStride>>;
pub type MatrixSliceMut4x2<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U2, SliceStorageMut<'a, T, U4, U2, RStride, CStride>>;
/// A column-major 4x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut4x3<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U3, SliceStorageMut<'a, N, U4, U3, RStride, CStride>>;
pub type MatrixSliceMut4x3<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U3, SliceStorageMut<'a, T, U4, U3, RStride, CStride>>;
/// A column-major 4x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut4x5<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U5, SliceStorageMut<'a, N, U4, U5, RStride, CStride>>;
pub type MatrixSliceMut4x5<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U5, SliceStorageMut<'a, T, U4, U5, RStride, CStride>>;
/// A column-major 4x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut4x6<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U6, SliceStorageMut<'a, N, U4, U6, RStride, CStride>>;
pub type MatrixSliceMut4x6<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U6, SliceStorageMut<'a, T, U4, U6, RStride, CStride>>;
/// A column-major 5x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut5x1<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U1, SliceStorageMut<'a, N, U5, U1, RStride, CStride>>;
pub type MatrixSliceMut5x1<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U1, SliceStorageMut<'a, T, U5, U1, RStride, CStride>>;
/// A column-major 5x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut5x2<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U2, SliceStorageMut<'a, N, U5, U2, RStride, CStride>>;
pub type MatrixSliceMut5x2<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U2, SliceStorageMut<'a, T, U5, U2, RStride, CStride>>;
/// A column-major 5x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut5x3<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U3, SliceStorageMut<'a, N, U5, U3, RStride, CStride>>;
pub type MatrixSliceMut5x3<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U3, SliceStorageMut<'a, T, U5, U3, RStride, CStride>>;
/// A column-major 5x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut5x4<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U4, SliceStorageMut<'a, N, U5, U4, RStride, CStride>>;
pub type MatrixSliceMut5x4<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U4, SliceStorageMut<'a, T, U5, U4, RStride, CStride>>;
/// A column-major 5x6 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut5x6<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U6, SliceStorageMut<'a, N, U5, U6, RStride, CStride>>;
pub type MatrixSliceMut5x6<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U6, SliceStorageMut<'a, T, U5, U6, RStride, CStride>>;
/// A column-major 6x1 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut6x1<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U1, SliceStorageMut<'a, N, U6, U1, RStride, CStride>>;
pub type MatrixSliceMut6x1<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U1, SliceStorageMut<'a, T, U6, U1, RStride, CStride>>;
/// A column-major 6x2 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut6x2<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U2, SliceStorageMut<'a, N, U6, U2, RStride, CStride>>;
pub type MatrixSliceMut6x2<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U2, SliceStorageMut<'a, T, U6, U2, RStride, CStride>>;
/// A column-major 6x3 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut6x3<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U3, SliceStorageMut<'a, N, U6, U3, RStride, CStride>>;
pub type MatrixSliceMut6x3<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U3, SliceStorageMut<'a, T, U6, U3, RStride, CStride>>;
/// A column-major 6x4 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut6x4<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U4, SliceStorageMut<'a, N, U6, U4, RStride, CStride>>;
pub type MatrixSliceMut6x4<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U4, SliceStorageMut<'a, T, U6, U4, RStride, CStride>>;
/// A column-major 6x5 matrix slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type MatrixSliceMut6x5<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U5, SliceStorageMut<'a, N, U6, U5, RStride, CStride>>;
pub type MatrixSliceMut6x5<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U5, SliceStorageMut<'a, T, U6, U5, RStride, CStride>>;
/// A column-major matrix slice with 1 row and a number of columns chosen at runtime.
pub type MatrixSliceMut1xX<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, Dynamic, SliceStorageMut<'a, N, U1, Dynamic, RStride, CStride>>;
pub type MatrixSliceMut1xX<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, Dynamic, SliceStorageMut<'a, T, U1, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 2 rows and a number of columns chosen at runtime.
pub type MatrixSliceMut2xX<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, Dynamic, SliceStorageMut<'a, N, U2, Dynamic, RStride, CStride>>;
pub type MatrixSliceMut2xX<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, Dynamic, SliceStorageMut<'a, T, U2, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 3 rows and a number of columns chosen at runtime.
pub type MatrixSliceMut3xX<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, Dynamic, SliceStorageMut<'a, N, U3, Dynamic, RStride, CStride>>;
pub type MatrixSliceMut3xX<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, Dynamic, SliceStorageMut<'a, T, U3, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 4 rows and a number of columns chosen at runtime.
pub type MatrixSliceMut4xX<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, Dynamic, SliceStorageMut<'a, N, U4, Dynamic, RStride, CStride>>;
pub type MatrixSliceMut4xX<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, Dynamic, SliceStorageMut<'a, T, U4, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 5 rows and a number of columns chosen at runtime.
pub type MatrixSliceMut5xX<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, Dynamic, SliceStorageMut<'a, N, U5, Dynamic, RStride, CStride>>;
pub type MatrixSliceMut5xX<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, Dynamic, SliceStorageMut<'a, T, U5, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with 6 rows and a number of columns chosen at runtime.
pub type MatrixSliceMut6xX<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, Dynamic, SliceStorageMut<'a, N, U6, Dynamic, RStride, CStride>>;
pub type MatrixSliceMut6xX<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, Dynamic, SliceStorageMut<'a, T, U6, Dynamic, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 1 column.
pub type MatrixSliceMutXx1<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U1, SliceStorageMut<'a, N, Dynamic, U1, RStride, CStride>>;
pub type MatrixSliceMutXx1<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U1, SliceStorageMut<'a, T, Dynamic, U1, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 2 columns.
pub type MatrixSliceMutXx2<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U2, SliceStorageMut<'a, N, Dynamic, U2, RStride, CStride>>;
pub type MatrixSliceMutXx2<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U2, SliceStorageMut<'a, T, Dynamic, U2, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 3 columns.
pub type MatrixSliceMutXx3<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U3, SliceStorageMut<'a, N, Dynamic, U3, RStride, CStride>>;
pub type MatrixSliceMutXx3<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U3, SliceStorageMut<'a, T, Dynamic, U3, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 4 columns.
pub type MatrixSliceMutXx4<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U4, SliceStorageMut<'a, N, Dynamic, U4, RStride, CStride>>;
pub type MatrixSliceMutXx4<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U4, SliceStorageMut<'a, T, Dynamic, U4, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 5 columns.
pub type MatrixSliceMutXx5<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U5, SliceStorageMut<'a, N, Dynamic, U5, RStride, CStride>>;
pub type MatrixSliceMutXx5<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U5, SliceStorageMut<'a, T, Dynamic, U5, RStride, CStride>>;
/// A column-major matrix slice with a number of rows chosen at runtime and 6 columns.
pub type MatrixSliceMutXx6<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U6, SliceStorageMut<'a, N, Dynamic, U6, RStride, CStride>>;
pub type MatrixSliceMutXx6<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U6, SliceStorageMut<'a, T, Dynamic, U6, RStride, CStride>>;
/// A column vector slice with `D` rows.
pub type VectorSliceMutN<'a, N, D, RStride = U1, CStride = D> =
Matrix<N, D, U1, SliceStorageMut<'a, N, D, U1, RStride, CStride>>;
/// A column vector slice with dimensions known at compile-time.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut<'a, T, D, RStride = U1, CStride = D> =
Matrix<T, D, U1, SliceStorageMut<'a, T, D, U1, RStride, CStride>>;
/// A column vector slice with dimensions known at compile-time.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type SVectorSliceMut<'a, T, const D: usize> =
Matrix<T, Const<D>, Const<1>, SliceStorageMut<'a, T, Const<D>, Const<1>, Const<1>, Const<D>>>;
/// A column vector slice dynamic numbers of rows and columns.
pub type DVectorSliceMut<'a, N, RStride = U1, CStride = Dynamic> =
Matrix<N, Dynamic, U1, SliceStorageMut<'a, N, Dynamic, U1, RStride, CStride>>;
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type DVectorSliceMut<'a, T, RStride = U1, CStride = Dynamic> =
Matrix<T, Dynamic, U1, SliceStorageMut<'a, T, Dynamic, U1, RStride, CStride>>;
/// A 1D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut1<'a, N, RStride = U1, CStride = U1> =
Matrix<N, U1, U1, SliceStorageMut<'a, N, U1, U1, RStride, CStride>>;
pub type VectorSliceMut1<'a, T, RStride = U1, CStride = U1> =
Matrix<T, U1, U1, SliceStorageMut<'a, T, U1, U1, RStride, CStride>>;
/// A 2D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut2<'a, N, RStride = U1, CStride = U2> =
Matrix<N, U2, U1, SliceStorageMut<'a, N, U2, U1, RStride, CStride>>;
pub type VectorSliceMut2<'a, T, RStride = U1, CStride = U2> =
Matrix<T, U2, U1, SliceStorageMut<'a, T, U2, U1, RStride, CStride>>;
/// A 3D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut3<'a, N, RStride = U1, CStride = U3> =
Matrix<N, U3, U1, SliceStorageMut<'a, N, U3, U1, RStride, CStride>>;
pub type VectorSliceMut3<'a, T, RStride = U1, CStride = U3> =
Matrix<T, U3, U1, SliceStorageMut<'a, T, U3, U1, RStride, CStride>>;
/// A 4D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut4<'a, N, RStride = U1, CStride = U4> =
Matrix<N, U4, U1, SliceStorageMut<'a, N, U4, U1, RStride, CStride>>;
pub type VectorSliceMut4<'a, T, RStride = U1, CStride = U4> =
Matrix<T, U4, U1, SliceStorageMut<'a, T, U4, U1, RStride, CStride>>;
/// A 5D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut5<'a, N, RStride = U1, CStride = U5> =
Matrix<N, U5, U1, SliceStorageMut<'a, N, U5, U1, RStride, CStride>>;
pub type VectorSliceMut5<'a, T, RStride = U1, CStride = U5> =
Matrix<T, U5, U1, SliceStorageMut<'a, T, U5, U1, RStride, CStride>>;
/// A 6D column vector slice.
///
/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.**
pub type VectorSliceMut6<'a, N, RStride = U1, CStride = U6> =
Matrix<N, U6, U1, SliceStorageMut<'a, N, U6, U1, RStride, CStride>>;
pub type VectorSliceMut6<'a, T, RStride = U1, CStride = U6> =
Matrix<T, U6, U1, SliceStorageMut<'a, T, U6, U1, RStride, CStride>>;

View File

@ -9,7 +9,7 @@ use crate::base::storage::ContiguousStorageMut;
use crate::base::{DefaultAllocator, Scalar};
/// A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()`
/// elements of type `N`.
/// elements of type `T`.
///
/// An allocator is said to be:
/// static: if `R` and `C` both implement `DimName`.
@ -17,15 +17,15 @@ use crate::base::{DefaultAllocator, Scalar};
///
/// Every allocator must be both static and dynamic. Though not all implementations may share the
/// same `Buffer` type.
pub trait Allocator<N: Scalar, R: Dim, C: Dim = U1>: Any + Sized {
pub trait Allocator<T: Scalar, R: Dim, C: Dim = U1>: Any + Sized {
/// The type of buffer this allocator can instanciate.
type Buffer: ContiguousStorageMut<N, R, C> + Clone;
type Buffer: ContiguousStorageMut<T, R, C> + Clone;
/// Allocates a buffer with the given number of rows and columns without initializing its content.
unsafe fn allocate_uninitialized(nrows: R, ncols: C) -> mem::MaybeUninit<Self::Buffer>;
/// Allocates a buffer initialized with the content of the given iterator.
fn allocate_from_iterator<I: IntoIterator<Item = N>>(
fn allocate_from_iterator<I: IntoIterator<Item = T>>(
nrows: R,
ncols: C,
iter: I,
@ -34,8 +34,8 @@ 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<T: Scalar, RFrom: Dim, CFrom: Dim, RTo: Dim, CTo: Dim>:
Allocator<T, RFrom, CFrom> + Allocator<T, 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:
@ -47,8 +47,8 @@ pub trait Reallocator<N: Scalar, RFrom: Dim, CFrom: Dim, RTo: Dim, CTo: Dim>:
unsafe fn reallocate_copy(
nrows: RTo,
ncols: CTo,
buf: <Self as Allocator<N, RFrom, CFrom>>::Buffer,
) -> <Self as Allocator<N, RTo, CTo>>::Buffer;
buf: <Self as Allocator<T, RFrom, CFrom>>::Buffer,
) -> <Self as Allocator<T, RTo, CTo>>::Buffer;
}
/// The number of rows of the result of a componentwise operation on two matrices.
@ -59,48 +59,48 @@ pub type SameShapeC<C1, C2> = <ShapeConstraint as SameNumberOfColumns<C1, C2>>::
// TODO: 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<T, R1, C1, R2, C2>:
Allocator<T, R1, C1> + Allocator<T, SameShapeR<R1, R2>, SameShapeC<C1, C2>>
where
R1: Dim,
R2: Dim,
C1: Dim,
C2: Dim,
N: Scalar,
T: Scalar,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
{
}
impl<N, R1, R2, C1, C2> SameShapeAllocator<N, R1, C1, R2, C2> for DefaultAllocator
impl<T, R1, R2, C1, C2> SameShapeAllocator<T, R1, C1, R2, C2> for DefaultAllocator
where
R1: Dim,
R2: Dim,
C1: Dim,
C2: Dim,
N: Scalar,
DefaultAllocator: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>,
T: Scalar,
DefaultAllocator: Allocator<T, R1, C1> + Allocator<T, 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<T, R1, R2>:
Allocator<T, R1> + Allocator<T, SameShapeR<R1, R2>> + SameShapeAllocator<T, R1, U1, R2, U1>
where
R1: Dim,
R2: Dim,
N: Scalar,
T: Scalar,
ShapeConstraint: SameNumberOfRows<R1, R2>,
{
}
impl<N, R1, R2> SameShapeVectorAllocator<N, R1, R2> for DefaultAllocator
impl<T, R1, R2> SameShapeVectorAllocator<T, R1, R2> for DefaultAllocator
where
R1: Dim,
R2: Dim,
N: Scalar,
DefaultAllocator: Allocator<N, R1, U1> + Allocator<N, SameShapeR<R1, R2>>,
T: Scalar,
DefaultAllocator: Allocator<T, R1, U1> + Allocator<T, SameShapeR<R1, R2>>,
ShapeConstraint: SameNumberOfRows<R1, R2>,
{
}

View File

@ -1,29 +1,26 @@
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
// use std::hash::{Hash, Hasher};
#[cfg(feature = "abomonation-serialize")]
use std::io::{Result as IOResult, Write};
use std::ops::{Deref, DerefMut, Mul};
use std::ops::Mul;
#[cfg(feature = "serde-serialize")]
#[cfg(feature = "serde-serialize-no-std")]
use serde::de::{Error, SeqAccess, Visitor};
#[cfg(feature = "serde-serialize")]
#[cfg(feature = "serde-serialize-no-std")]
use serde::ser::SerializeSeq;
#[cfg(feature = "serde-serialize")]
#[cfg(feature = "serde-serialize-no-std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "serde-serialize")]
#[cfg(feature = "serde-serialize-no-std")]
use std::marker::PhantomData;
#[cfg(feature = "serde-serialize")]
#[cfg(feature = "serde-serialize-no-std")]
use std::mem;
#[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation;
use generic_array::{ArrayLength, GenericArray};
use typenum::Prod;
use crate::base::allocator::Allocator;
use crate::base::default_allocator::DefaultAllocator;
use crate::base::dimension::{DimName, U1};
use crate::base::dimension::{Const, ToTypenum};
use crate::base::storage::{
ContiguousStorage, ContiguousStorageMut, Owned, ReshapableStorage, Storage, StorageMut,
};
@ -36,166 +33,49 @@ use crate::base::Scalar;
*/
/// A array-based statically sized matrix data storage.
#[repr(C)]
pub struct ArrayStorage<N, R, C>
where
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
data: GenericArray<N, Prod<R::Value, C::Value>>,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct ArrayStorage<T, const R: usize, const C: usize>(pub [[T; R]; C]);
#[deprecated(note = "renamed to `ArrayStorage`")]
/// Renamed to [ArrayStorage].
pub type MatrixArray<N, R, C> = ArrayStorage<N, R, C>;
impl<N, R, C> Default for ArrayStorage<N, R, C>
// TODO: remove this once the stdlib implements Default for arrays.
impl<T: Default, const R: usize, const C: usize> Default for ArrayStorage<T, R, C>
where
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
N: Default,
[[T; R]; C]: Default,
{
#[inline]
fn default() -> Self {
ArrayStorage {
data: Default::default(),
}
Self(Default::default())
}
}
impl<N, R, C> Hash for ArrayStorage<N, R, C>
where
N: Hash,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
fn hash<H: Hasher>(&self, state: &mut H) {
self.data[..].hash(state)
}
}
impl<N, R, C> Deref for ArrayStorage<N, R, C>
where
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
type Target = GenericArray<N, Prod<R::Value, C::Value>>;
#[inline]
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl<N, R, C> DerefMut for ArrayStorage<N, R, C>
where
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.data
}
}
impl<N, R, C> Debug for ArrayStorage<N, R, C>
where
N: Debug,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
impl<T: Debug, const R: usize, const C: usize> Debug for ArrayStorage<T, R, C> {
#[inline]
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
self.data.fmt(fmt)
self.0.fmt(fmt)
}
}
impl<N, R, C> Copy for ArrayStorage<N, R, C>
unsafe impl<T, const R: usize, const C: usize> Storage<T, Const<R>, Const<C>>
for ArrayStorage<T, R, C>
where
N: Copy,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
GenericArray<N, Prod<R::Value, C::Value>>: Copy,
T: Scalar,
DefaultAllocator: Allocator<T, Const<R>, Const<C>, Buffer = Self>,
{
}
impl<N, R, C> Clone for ArrayStorage<N, R, C>
where
N: Clone,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
#[inline]
fn clone(&self) -> Self {
ArrayStorage {
data: self.data.clone(),
}
}
}
impl<N, R, C> Eq for ArrayStorage<N, R, C>
where
N: Eq,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
}
impl<N, R, C> PartialEq for ArrayStorage<N, R, C>
where
N: PartialEq,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
#[inline]
fn eq(&self, right: &Self) -> bool {
self.data == right.data
}
}
unsafe impl<N, R, C> Storage<N, R, C> for ArrayStorage<N, R, C>
where
N: Scalar,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
{
type RStride = U1;
type CStride = R;
type RStride = Const<1>;
type CStride = Const<R>;
#[inline]
fn ptr(&self) -> *const N {
self[..].as_ptr()
fn ptr(&self) -> *const T {
self.0.as_ptr() as *const T
}
#[inline]
fn shape(&self) -> (R, C) {
(R::name(), C::name())
fn shape(&self) -> (Const<R>, Const<C>) {
(Const, Const)
}
#[inline]
fn strides(&self) -> (Self::RStride, Self::CStride) {
(Self::RStride::name(), Self::CStride::name())
(Const, Const)
}
#[inline]
@ -204,112 +84,107 @@ where
}
#[inline]
fn into_owned(self) -> Owned<N, R, C>
fn into_owned(self) -> Owned<T, Const<R>, Const<C>>
where
DefaultAllocator: Allocator<N, R, C>,
DefaultAllocator: Allocator<T, Const<R>, Const<C>>,
{
self
}
#[inline]
fn clone_owned(&self) -> Owned<N, R, C>
fn clone_owned(&self) -> Owned<T, Const<R>, Const<C>>
where
DefaultAllocator: Allocator<N, R, C>,
DefaultAllocator: Allocator<T, Const<R>, Const<C>>,
{
let it = self.iter().cloned();
let it = self.as_slice().iter().cloned();
DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it)
}
#[inline]
fn as_slice(&self) -> &[N] {
&self[..]
fn as_slice(&self) -> &[T] {
unsafe { std::slice::from_raw_parts(self.ptr(), R * C) }
}
}
unsafe impl<N, R, C> StorageMut<N, R, C> for ArrayStorage<N, R, C>
unsafe impl<T, const R: usize, const C: usize> StorageMut<T, Const<R>, Const<C>>
for ArrayStorage<T, R, C>
where
N: Scalar,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
T: Scalar,
DefaultAllocator: Allocator<T, Const<R>, Const<C>, Buffer = Self>,
{
#[inline]
fn ptr_mut(&mut self) -> *mut N {
self[..].as_mut_ptr()
fn ptr_mut(&mut self) -> *mut T {
self.0.as_mut_ptr() as *mut T
}
#[inline]
fn as_mut_slice(&mut self) -> &mut [N] {
&mut self[..]
fn as_mut_slice(&mut self) -> &mut [T] {
unsafe { std::slice::from_raw_parts_mut(self.ptr_mut(), R * C) }
}
}
unsafe impl<N, R, C> ContiguousStorage<N, R, C> for ArrayStorage<N, R, C>
unsafe impl<T, const R: usize, const C: usize> ContiguousStorage<T, Const<R>, Const<C>>
for ArrayStorage<T, R, C>
where
N: Scalar,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
T: Scalar,
DefaultAllocator: Allocator<T, Const<R>, Const<C>, Buffer = Self>,
{
}
unsafe impl<N, R, C> ContiguousStorageMut<N, R, C> for ArrayStorage<N, R, C>
unsafe impl<T, const R: usize, const C: usize> ContiguousStorageMut<T, Const<R>, Const<C>>
for ArrayStorage<T, R, C>
where
N: Scalar,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
T: Scalar,
DefaultAllocator: Allocator<T, Const<R>, Const<C>, Buffer = Self>,
{
}
impl<N, R1, C1, R2, C2> ReshapableStorage<N, R1, C1, R2, C2> for ArrayStorage<N, R1, C1>
impl<T, const R1: usize, const C1: usize, const R2: usize, const C2: usize>
ReshapableStorage<T, Const<R1>, Const<C1>, Const<R2>, Const<C2>> for ArrayStorage<T, R1, C1>
where
N: Scalar,
R1: DimName,
C1: DimName,
R1::Value: Mul<C1::Value>,
Prod<R1::Value, C1::Value>: ArrayLength<N>,
R2: DimName,
C2: DimName,
R2::Value: Mul<C2::Value, Output = Prod<R1::Value, C1::Value>>,
Prod<R2::Value, C2::Value>: ArrayLength<N>,
T: Scalar,
Const<R1>: ToTypenum,
Const<C1>: ToTypenum,
Const<R2>: ToTypenum,
Const<C2>: ToTypenum,
<Const<R1> as ToTypenum>::Typenum: Mul<<Const<C1> as ToTypenum>::Typenum>,
<Const<R2> as ToTypenum>::Typenum: Mul<
<Const<C2> as ToTypenum>::Typenum,
Output = typenum::Prod<
<Const<R1> as ToTypenum>::Typenum,
<Const<C1> as ToTypenum>::Typenum,
>,
>,
{
type Output = ArrayStorage<N, R2, C2>;
type Output = ArrayStorage<T, R2, C2>;
fn reshape_generic(self, _: R2, _: C2) -> Self::Output {
ArrayStorage { data: self.data }
fn reshape_generic(self, _: Const<R2>, _: Const<C2>) -> Self::Output {
unsafe {
let data: [[T; R2]; C2] = std::mem::transmute_copy(&self.0);
std::mem::forget(self.0);
ArrayStorage(data)
}
}
}
/*
*
* Allocation-less serde impls.
* Serialization.
*
*/
// XXX: open an issue for GenericArray so that it implements serde traits?
#[cfg(feature = "serde-serialize")]
impl<N, R, C> Serialize for ArrayStorage<N, R, C>
// XXX: open an issue for serde so that it allows the serialization/deserialization of all arrays?
#[cfg(feature = "serde-serialize-no-std")]
impl<T, const R: usize, const C: usize> Serialize for ArrayStorage<T, R, C>
where
N: Scalar + Serialize,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
T: Scalar + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?;
let mut serializer = serializer.serialize_seq(Some(R * C))?;
for e in self.iter() {
for e in self.as_slice().iter() {
serializer.serialize_element(e)?;
}
@ -317,14 +192,10 @@ where
}
}
#[cfg(feature = "serde-serialize")]
impl<'a, N, R, C> Deserialize<'a> for ArrayStorage<N, R, C>
#[cfg(feature = "serde-serialize-no-std")]
impl<'a, T, const R: usize, const C: usize> Deserialize<'a> for ArrayStorage<T, R, C>
where
N: Scalar + Deserialize<'a>,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
T: Scalar + Deserialize<'a>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@ -334,20 +205,16 @@ where
}
}
#[cfg(feature = "serde-serialize")]
#[cfg(feature = "serde-serialize-no-std")]
/// A visitor that produces a matrix array.
struct ArrayStorageVisitor<N, R, C> {
marker: PhantomData<(N, R, C)>,
struct ArrayStorageVisitor<T, const R: usize, const C: usize> {
marker: PhantomData<T>,
}
#[cfg(feature = "serde-serialize")]
impl<N, R, C> ArrayStorageVisitor<N, R, C>
#[cfg(feature = "serde-serialize-no-std")]
impl<T, const R: usize, const C: usize> ArrayStorageVisitor<T, R, C>
where
N: Scalar,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
T: Scalar,
{
/// Construct a new sequence visitor.
pub fn new() -> Self {
@ -357,23 +224,19 @@ where
}
}
#[cfg(feature = "serde-serialize")]
impl<'a, N, R, C> Visitor<'a> for ArrayStorageVisitor<N, R, C>
#[cfg(feature = "serde-serialize-no-std")]
impl<'a, T, const R: usize, const C: usize> Visitor<'a> for ArrayStorageVisitor<T, R, C>
where
N: Scalar + Deserialize<'a>,
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
T: Scalar + Deserialize<'a>,
{
type Value = ArrayStorage<N, R, C>;
type Value = ArrayStorage<T, R, C>;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("a matrix array")
}
#[inline]
fn visit_seq<V>(self, mut visitor: V) -> Result<ArrayStorage<N, R, C>, V::Error>
fn visit_seq<V>(self, mut visitor: V) -> Result<ArrayStorage<T, R, C>, V::Error>
where
V: SeqAccess<'a>,
{
@ -381,12 +244,13 @@ where
let mut curr = 0;
while let Some(value) = visitor.next_element()? {
*out.get_mut(curr)
*out.as_mut_slice()
.get_mut(curr)
.ok_or_else(|| V::Error::invalid_length(curr, &self))? = value;
curr += 1;
}
if curr == R::dim() * C::dim() {
if curr == R * C {
Ok(out)
} else {
Err(V::Error::invalid_length(curr, &self))
@ -395,36 +259,24 @@ where
}
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar + bytemuck::Zeroable, R: DimName, C: DimName> bytemuck::Zeroable
for ArrayStorage<N, R, C>
where
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
Self: Copy,
unsafe impl<T: Scalar + Copy + bytemuck::Zeroable, const R: usize, const C: usize>
bytemuck::Zeroable for ArrayStorage<T, R, C>
{
}
#[cfg(feature = "bytemuck")]
unsafe impl<N: Scalar + bytemuck::Pod, R: DimName, C: DimName> bytemuck::Pod
for ArrayStorage<N, R, C>
where
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
Self: Copy,
unsafe impl<T: Scalar + Copy + bytemuck::Pod, const R: usize, const C: usize> bytemuck::Pod
for ArrayStorage<T, R, C>
{
}
#[cfg(feature = "abomonation-serialize")]
impl<N, R, C> Abomonation for ArrayStorage<N, R, C>
impl<T, const R: usize, const C: usize> Abomonation for ArrayStorage<T, R, C>
where
R: DimName,
C: DimName,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
N: Abomonation,
T: Scalar + Abomonation,
{
unsafe fn entomb<W: Write>(&self, writer: &mut W) -> IOResult<()> {
for element in self.data.as_slice() {
for element in self.as_slice() {
element.entomb(writer)?;
}
@ -432,7 +284,7 @@ where
}
unsafe fn exhume<'a, 'b>(&'a mut self, mut bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
for element in self.data.as_mut_slice() {
for element in self.as_mut_slice() {
let temp = bytes;
bytes = if let Some(remainder) = element.exhume(temp) {
remainder
@ -444,9 +296,6 @@ where
}
fn extent(&self) -> usize {
self.data
.as_slice()
.iter()
.fold(0, |acc, e| acc + e.extent())
self.as_slice().iter().fold(0, |acc, e| acc + e.extent())
}
}

View File

@ -10,25 +10,25 @@ use crate::base::allocator::Allocator;
use crate::base::constraint::{
AreMultipliable, DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint,
};
use crate::base::dimension::{Dim, Dynamic, U1, U2, U3, U4};
use crate::base::dimension::{Const, Dim, Dynamic, U1, U2, U3, U4};
use crate::base::storage::{Storage, StorageMut};
use crate::base::{
DVectorSlice, DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector, VectorSliceN,
DVectorSlice, DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector, VectorSlice,
};
/// # Dot/scalar product
impl<N, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S>
impl<T, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S>
where
N: Scalar + Zero + ClosedAdd + ClosedMul,
T: Scalar + Zero + ClosedAdd + ClosedMul,
{
#[inline(always)]
fn dotx<R2: Dim, C2: Dim, SB>(
&self,
rhs: &Matrix<N, R2, C2, SB>,
conjugate: impl Fn(N) -> N,
) -> N
rhs: &Matrix<T, R2, C2, SB>,
conjugate: impl Fn(T) -> T,
) -> T
where
SB: Storage<N, R2, C2>,
SB: Storage<T, R2, C2>,
ShapeConstraint: DimEq<R, R2> + DimEq<C, C2>,
{
assert!(
@ -92,7 +92,7 @@ where
//
// And this comment from bluss:
// https://users.rust-lang.org/t/how-to-zip-two-slices-efficiently/2048/12
let mut res = N::zero();
let mut res = T::zero();
// We have to define them outside of the loop (and not inside at first assignment)
// otherwise vectorization won't kick in for some reason.
@ -108,14 +108,14 @@ where
for j in 0..self.ncols() {
let mut i = 0;
acc0 = N::zero();
acc1 = N::zero();
acc2 = N::zero();
acc3 = N::zero();
acc4 = N::zero();
acc5 = N::zero();
acc6 = N::zero();
acc7 = N::zero();
acc0 = T::zero();
acc1 = T::zero();
acc2 = T::zero();
acc3 = T::zero();
acc4 = T::zero();
acc5 = T::zero();
acc6 = T::zero();
acc7 = T::zero();
while self.nrows() - i >= 8 {
acc0 += unsafe {
@ -193,9 +193,9 @@ where
/// ```
///
#[inline]
pub fn dot<R2: Dim, C2: Dim, SB>(&self, rhs: &Matrix<N, R2, C2, SB>) -> N
pub fn dot<R2: Dim, C2: Dim, SB>(&self, rhs: &Matrix<T, R2, C2, SB>) -> T
where
SB: Storage<N, R2, C2>,
SB: Storage<T, R2, C2>,
ShapeConstraint: DimEq<R, R2> + DimEq<C, C2>,
{
self.dotx(rhs, |e| e)
@ -221,13 +221,13 @@ where
/// assert_ne!(vec1.dotc(&vec2), vec1.dot(&vec2));
/// ```
#[inline]
pub fn dotc<R2: Dim, C2: Dim, SB>(&self, rhs: &Matrix<N, R2, C2, SB>) -> N
pub fn dotc<R2: Dim, C2: Dim, SB>(&self, rhs: &Matrix<T, R2, C2, SB>) -> T
where
N: SimdComplexField,
SB: Storage<N, R2, C2>,
T: SimdComplexField,
SB: Storage<T, R2, C2>,
ShapeConstraint: DimEq<R, R2> + DimEq<C, C2>,
{
self.dotx(rhs, N::simd_conjugate)
self.dotx(rhs, T::simd_conjugate)
}
/// The dot product between the transpose of `self` and `rhs`.
@ -248,9 +248,9 @@ where
/// assert_eq!(mat1.tr_dot(&mat2), 9.1);
/// ```
#[inline]
pub fn tr_dot<R2: Dim, C2: Dim, SB>(&self, rhs: &Matrix<N, R2, C2, SB>) -> N
pub fn tr_dot<R2: Dim, C2: Dim, SB>(&self, rhs: &Matrix<T, R2, C2, SB>) -> T
where
SB: Storage<N, R2, C2>,
SB: Storage<T, R2, C2>,
ShapeConstraint: DimEq<C, R2> + DimEq<R, C2>,
{
let (nrows, ncols) = self.shape();
@ -260,7 +260,7 @@ where
"Transposed dot product dimension mismatch."
);
let mut res = N::zero();
let mut res = T::zero();
for j in 0..self.nrows() {
for i in 0..self.ncols() {
@ -275,17 +275,17 @@ where
}
}
fn array_axcpy<N>(
y: &mut [N],
a: N,
x: &[N],
c: N,
beta: N,
fn array_axcpy<T>(
y: &mut [T],
a: T,
x: &[T],
c: T,
beta: T,
stride1: usize,
stride2: usize,
len: usize,
) where
N: Scalar + Zero + ClosedAdd + ClosedMul,
T: Scalar + Zero + ClosedAdd + ClosedMul,
{
for i in 0..len {
unsafe {
@ -298,9 +298,9 @@ fn array_axcpy<N>(
}
}
fn array_axc<N>(y: &mut [N], a: N, x: &[N], c: N, stride1: usize, stride2: usize, len: usize)
fn array_axc<T>(y: &mut [T], a: T, x: &[T], c: T, stride1: usize, stride2: usize, len: usize)
where
N: Scalar + Zero + ClosedAdd + ClosedMul,
T: Scalar + Zero + ClosedAdd + ClosedMul,
{
for i in 0..len {
unsafe {
@ -312,10 +312,10 @@ where
}
/// # BLAS functions
impl<N, D: Dim, S> Vector<N, D, S>
impl<T, D: Dim, S> Vector<T, D, S>
where
N: Scalar + Zero + ClosedAdd + ClosedMul,
S: StorageMut<N, D>,
T: Scalar + Zero + ClosedAdd + ClosedMul,
S: StorageMut<T, D>,
{
/// Computes `self = a * x * c + b * self`.
///
@ -331,9 +331,9 @@ where
/// assert_eq!(vec1, Vector3::new(6.0, 12.0, 18.0));
/// ```
#[inline]
pub fn axcpy<D2: Dim, SB>(&mut self, a: N, x: &Vector<N, D2, SB>, c: N, b: N)
pub fn axcpy<D2: Dim, SB>(&mut self, a: T, x: &Vector<T, D2, SB>, c: T, b: T)
where
SB: Storage<N, D2>,
SB: Storage<T, D2>,
ShapeConstraint: DimEq<D, D2>,
{
assert_eq!(self.nrows(), x.nrows(), "Axcpy: mismatched vector shapes.");
@ -365,14 +365,14 @@ where
/// assert_eq!(vec1, Vector3::new(6.0, 12.0, 18.0));
/// ```
#[inline]
pub fn axpy<D2: Dim, SB>(&mut self, a: N, x: &Vector<N, D2, SB>, b: N)
pub fn axpy<D2: Dim, SB>(&mut self, a: T, x: &Vector<T, D2, SB>, b: T)
where
N: One,
SB: Storage<N, D2>,
T: One,
SB: Storage<T, D2>,
ShapeConstraint: DimEq<D, D2>,
{
assert_eq!(self.nrows(), x.nrows(), "Axpy: mismatched vector shapes.");
self.axcpy(a, x, N::one(), b)
self.axcpy(a, x, T::one(), b)
}
/// Computes `self = alpha * a * x + beta * self`, where `a` is a matrix, `x` a vector, and
@ -394,14 +394,14 @@ where
#[inline]
pub fn gemv<R2: Dim, C2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, R2, C2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, R2, C2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, R2> + AreMultipliable<R2, C2, D3, U1>,
{
let dim1 = self.nrows();
@ -418,7 +418,7 @@ where
// because we documented the guaranty that `self` is
// never read if `beta` is zero.
if beta.is_zero() {
self.fill(N::zero());
self.fill(T::zero());
} else {
*self *= beta;
}
@ -434,25 +434,25 @@ where
let col2 = a.column(j);
let val = unsafe { x.vget_unchecked(j).inlined_clone() };
self.axcpy(alpha.inlined_clone(), &col2, val, N::one());
self.axcpy(alpha.inlined_clone(), &col2, val, T::one());
}
}
#[inline(always)]
fn xxgemv<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &SquareMatrix<N, D2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &SquareMatrix<T, D2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
dot: impl Fn(
&DVectorSlice<N, SB::RStride, SB::CStride>,
&DVectorSlice<N, SC::RStride, SC::CStride>,
) -> N,
&DVectorSlice<T, SB::RStride, SB::CStride>,
&DVectorSlice<T, SC::RStride, SC::CStride>,
) -> T,
) where
N: One,
SB: Storage<N, D2, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, D2> + AreMultipliable<D2, D2, D3, U1>,
{
let dim1 = self.nrows();
@ -490,7 +490,7 @@ where
self.rows_range_mut(j + 1..).axpy(
alpha.inlined_clone() * val,
&col2.rows_range(j + 1..),
N::one(),
T::one(),
);
}
}
@ -501,14 +501,14 @@ where
#[deprecated(note = "This is renamed `sygemv` to match the original BLAS terminology.")]
pub fn gemv_symm<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &SquareMatrix<N, D2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &SquareMatrix<T, D2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, D2, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, D2> + AreMultipliable<D2, D2, D3, U1>,
{
self.sygemv(alpha, a, x, beta)
@ -545,14 +545,14 @@ where
#[inline]
pub fn sygemv<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &SquareMatrix<N, D2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &SquareMatrix<T, D2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, D2, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, D2> + AreMultipliable<D2, D2, D3, U1>,
{
self.xxgemv(alpha, a, x, beta, |a, b| a.dot(b))
@ -590,14 +590,14 @@ where
#[inline]
pub fn hegemv<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &SquareMatrix<N, D2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &SquareMatrix<T, D2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
) where
N: SimdComplexField,
SB: Storage<N, D2, D2>,
SC: Storage<N, D3>,
T: SimdComplexField,
SB: Storage<T, D2, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, D2> + AreMultipliable<D2, D2, D3, U1>,
{
self.xxgemv(alpha, a, x, beta, |a, b| a.dotc(b))
@ -606,15 +606,15 @@ where
#[inline(always)]
fn gemv_xx<R2: Dim, C2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
dot: impl Fn(&VectorSliceN<N, R2, SB::RStride, SB::CStride>, &Vector<N, D3, SC>) -> N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
dot: impl Fn(&VectorSlice<T, R2, SB::RStride, SB::CStride>, &Vector<T, D3, SC>) -> T,
) where
N: One,
SB: Storage<N, R2, C2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, R2, C2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, C2> + AreMultipliable<C2, R2, D3, U1>,
{
let dim1 = self.nrows();
@ -665,14 +665,14 @@ where
#[inline]
pub fn gemv_tr<R2: Dim, C2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, R2, C2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, R2, C2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, C2> + AreMultipliable<C2, R2, D3, U1>,
{
self.gemv_xx(alpha, a, x, beta, |a, b| a.dot(b))
@ -700,36 +700,36 @@ where
#[inline]
pub fn gemv_ad<R2: Dim, C2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
x: &Vector<N, D3, SC>,
beta: N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
x: &Vector<T, D3, SC>,
beta: T,
) where
N: SimdComplexField,
SB: Storage<N, R2, C2>,
SC: Storage<N, D3>,
T: SimdComplexField,
SB: Storage<T, R2, C2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<D, C2> + AreMultipliable<C2, R2, D3, U1>,
{
self.gemv_xx(alpha, a, x, beta, |a, b| a.dotc(b))
}
}
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
impl<T, R1: Dim, C1: Dim, S: StorageMut<T, R1, C1>> Matrix<T, R1, C1, S>
where
N: Scalar + Zero + ClosedAdd + ClosedMul,
T: Scalar + Zero + ClosedAdd + ClosedMul,
{
#[inline(always)]
fn gerx<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
conjugate: impl Fn(N) -> N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
conjugate: impl Fn(T) -> T,
) where
N: One,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
let (nrows1, ncols1) = self.shape();
@ -768,14 +768,14 @@ where
#[inline]
pub fn ger<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
self.gerx(alpha, x, y, beta, |e| e)
@ -801,14 +801,14 @@ where
#[inline]
pub fn gerc<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
) where
N: SimdComplexField,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: SimdComplexField,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
self.gerx(alpha, x, y, beta, SimdComplexField::simd_conjugate)
@ -838,14 +838,14 @@ where
#[inline]
pub fn gemm<R2: Dim, C2: Dim, R3: Dim, C3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
b: &Matrix<N, R3, C3, SC>,
beta: N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
b: &Matrix<T, R3, C3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, R2, C2>,
SC: Storage<N, R3, C3>,
T: One,
SB: Storage<T, R2, C2>,
SC: Storage<T, R3, C3>,
ShapeConstraint: SameNumberOfRows<R1, R2>
+ SameNumberOfColumns<C1, C3>
+ AreMultipliable<R2, C2, R3, C3>,
@ -897,14 +897,14 @@ where
// because we documented the guaranty that `self` is
// never read if `beta` is zero.
if beta.is_zero() {
self.fill(N::zero());
self.fill(T::zero());
} else {
*self *= beta;
}
return;
}
if N::is::<f32>() {
if T::is::<f32>() {
let (rsa, csa) = a.strides();
let (rsb, csb) = b.strides();
let (rsc, csc) = self.strides();
@ -928,7 +928,7 @@ where
);
}
return;
} else if N::is::<f64>() {
} else if T::is::<f64>() {
let (rsa, csa) = a.strides();
let (rsb, csb) = b.strides();
let (rsc, csc) = self.strides();
@ -993,14 +993,14 @@ where
#[inline]
pub fn gemm_tr<R2: Dim, C2: Dim, R3: Dim, C3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
b: &Matrix<N, R3, C3, SC>,
beta: N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
b: &Matrix<T, R3, C3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, R2, C2>,
SC: Storage<N, R3, C3>,
T: One,
SB: Storage<T, R2, C2>,
SC: Storage<T, R3, C3>,
ShapeConstraint: SameNumberOfRows<R1, C2>
+ SameNumberOfColumns<C1, C3>
+ AreMultipliable<C2, R2, R3, C3>,
@ -1055,14 +1055,14 @@ where
#[inline]
pub fn gemm_ad<R2: Dim, C2: Dim, R3: Dim, C3: Dim, SB, SC>(
&mut self,
alpha: N,
a: &Matrix<N, R2, C2, SB>,
b: &Matrix<N, R3, C3, SC>,
beta: N,
alpha: T,
a: &Matrix<T, R2, C2, SB>,
b: &Matrix<T, R3, C3, SC>,
beta: T,
) where
N: SimdComplexField,
SB: Storage<N, R2, C2>,
SC: Storage<N, R3, C3>,
T: SimdComplexField,
SB: Storage<T, R2, C2>,
SC: Storage<T, R3, C3>,
ShapeConstraint: SameNumberOfRows<R1, C2>
+ SameNumberOfColumns<C1, C3>
+ AreMultipliable<C2, R2, R3, C3>,
@ -1088,22 +1088,22 @@ where
}
}
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
impl<T, R1: Dim, C1: Dim, S: StorageMut<T, R1, C1>> Matrix<T, R1, C1, S>
where
N: Scalar + Zero + ClosedAdd + ClosedMul,
T: Scalar + Zero + ClosedAdd + ClosedMul,
{
#[inline(always)]
fn xxgerx<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
conjugate: impl Fn(N) -> N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
conjugate: impl Fn(T) -> T,
) where
N: One,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
let dim1 = self.nrows();
@ -1120,7 +1120,7 @@ where
let val = unsafe { conjugate(y.vget_unchecked(j).inlined_clone()) };
let subdim = Dynamic::new(dim1 - j);
// TODO: avoid bound checks.
self.generic_slice_mut((j, j), (subdim, U1)).axpy(
self.generic_slice_mut((j, j), (subdim, Const::<1>)).axpy(
alpha.inlined_clone() * val,
&x.rows_range(j..),
beta.inlined_clone(),
@ -1151,14 +1151,14 @@ where
#[deprecated(note = "This is renamed `syger` to match the original BLAS terminology.")]
pub fn ger_symm<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
self.syger(alpha, x, y, beta)
@ -1187,14 +1187,14 @@ where
#[inline]
pub fn syger<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
) where
N: One,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: One,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
self.xxgerx(alpha, x, y, beta, |e| e)
@ -1222,23 +1222,23 @@ where
#[inline]
pub fn hegerc<D2: Dim, D3: Dim, SB, SC>(
&mut self,
alpha: N,
x: &Vector<N, D2, SB>,
y: &Vector<N, D3, SC>,
beta: N,
alpha: T,
x: &Vector<T, D2, SB>,
y: &Vector<T, D3, SC>,
beta: T,
) where
N: SimdComplexField,
SB: Storage<N, D2>,
SC: Storage<N, D3>,
T: SimdComplexField,
SB: Storage<T, D2>,
SC: Storage<T, D3>,
ShapeConstraint: DimEq<R1, D2> + DimEq<C1, D3>,
{
self.xxgerx(alpha, x, y, beta, SimdComplexField::simd_conjugate)
}
}
impl<N, D1: Dim, S: StorageMut<N, D1, D1>> SquareMatrix<N, D1, S>
impl<T, D1: Dim, S: StorageMut<T, D1, D1>> SquareMatrix<T, D1, S>
where
N: Scalar + Zero + One + ClosedAdd + ClosedMul,
T: Scalar + Zero + One + ClosedAdd + ClosedMul,
{
/// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`.
///
@ -1268,27 +1268,27 @@ where
/// assert_relative_eq!(mat, expected);
pub fn quadform_tr_with_workspace<D2, S2, R3, C3, S3, D4, S4>(
&mut self,
work: &mut Vector<N, D2, S2>,
alpha: N,
lhs: &Matrix<N, R3, C3, S3>,
mid: &SquareMatrix<N, D4, S4>,
beta: N,
work: &mut Vector<T, D2, S2>,
alpha: T,
lhs: &Matrix<T, R3, C3, S3>,
mid: &SquareMatrix<T, D4, S4>,
beta: T,
) where
D2: Dim,
R3: Dim,
C3: Dim,
D4: Dim,
S2: StorageMut<N, D2>,
S3: Storage<N, R3, C3>,
S4: Storage<N, D4, D4>,
S2: StorageMut<T, D2>,
S3: Storage<T, R3, C3>,
S4: Storage<T, D4, D4>,
ShapeConstraint: DimEq<D1, D2> + DimEq<D1, R3> + DimEq<D2, R3> + DimEq<C3, D4>,
{
work.gemv(N::one(), lhs, &mid.column(0), N::zero());
work.gemv(T::one(), lhs, &mid.column(0), T::zero());
self.ger(alpha.inlined_clone(), work, &lhs.column(0), beta);
for j in 1..mid.ncols() {
work.gemv(N::one(), lhs, &mid.column(j), N::zero());
self.ger(alpha.inlined_clone(), work, &lhs.column(j), N::one());
work.gemv(T::one(), lhs, &mid.column(j), T::zero());
self.ger(alpha.inlined_clone(), work, &lhs.column(j), T::one());
}
}
@ -1315,21 +1315,22 @@ where
/// assert_relative_eq!(mat, expected);
pub fn quadform_tr<R3, C3, S3, D4, S4>(
&mut self,
alpha: N,
lhs: &Matrix<N, R3, C3, S3>,
mid: &SquareMatrix<N, D4, S4>,
beta: N,
alpha: T,
lhs: &Matrix<T, R3, C3, S3>,
mid: &SquareMatrix<T, D4, S4>,
beta: T,
) where
R3: Dim,
C3: Dim,
D4: Dim,
S3: Storage<N, R3, C3>,
S4: Storage<N, D4, D4>,
S3: Storage<T, R3, C3>,
S4: Storage<T, D4, D4>,
ShapeConstraint: DimEq<D1, D1> + DimEq<D1, R3> + DimEq<C3, D4>,
DefaultAllocator: Allocator<N, D1>,
DefaultAllocator: Allocator<T, D1>,
{
let mut work =
unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, U1) };
let mut work = unsafe {
crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Const::<1>)
};
self.quadform_tr_with_workspace(&mut work, alpha, lhs, mid, beta)
}
@ -1360,28 +1361,28 @@ where
/// assert_relative_eq!(mat, expected);
pub fn quadform_with_workspace<D2, S2, D3, S3, R4, C4, S4>(
&mut self,
work: &mut Vector<N, D2, S2>,
alpha: N,
mid: &SquareMatrix<N, D3, S3>,
rhs: &Matrix<N, R4, C4, S4>,
beta: N,
work: &mut Vector<T, D2, S2>,
alpha: T,
mid: &SquareMatrix<T, D3, S3>,
rhs: &Matrix<T, R4, C4, S4>,
beta: T,
) where
D2: Dim,
D3: Dim,
R4: Dim,
C4: Dim,
S2: StorageMut<N, D2>,
S3: Storage<N, D3, D3>,
S4: Storage<N, R4, C4>,
S2: StorageMut<T, D2>,
S3: Storage<T, D3, D3>,
S4: Storage<T, R4, C4>,
ShapeConstraint:
DimEq<D3, R4> + DimEq<D1, C4> + DimEq<D2, D3> + AreMultipliable<C4, R4, D2, U1>,
{
work.gemv(N::one(), mid, &rhs.column(0), N::zero());
work.gemv(T::one(), mid, &rhs.column(0), T::zero());
self.column_mut(0)
.gemv_tr(alpha.inlined_clone(), &rhs, work, beta.inlined_clone());
for j in 1..rhs.ncols() {
work.gemv(N::one(), mid, &rhs.column(j), N::zero());
work.gemv(T::one(), mid, &rhs.column(j), T::zero());
self.column_mut(j)
.gemv_tr(alpha.inlined_clone(), &rhs, work, beta.inlined_clone());
}
@ -1409,21 +1410,22 @@ where
/// assert_relative_eq!(mat, expected);
pub fn quadform<D2, S2, R3, C3, S3>(
&mut self,
alpha: N,
mid: &SquareMatrix<N, D2, S2>,
rhs: &Matrix<N, R3, C3, S3>,
beta: N,
alpha: T,
mid: &SquareMatrix<T, D2, S2>,
rhs: &Matrix<T, R3, C3, S3>,
beta: T,
) where
D2: Dim,
R3: Dim,
C3: Dim,
S2: Storage<N, D2, D2>,
S3: Storage<N, R3, C3>,
S2: Storage<T, D2, D2>,
S3: Storage<T, R3, C3>,
ShapeConstraint: DimEq<D2, R3> + DimEq<D1, C3> + AreMultipliable<C3, R3, D2, U1>,
DefaultAllocator: Allocator<N, D2>,
DefaultAllocator: Allocator<T, D2>,
{
let mut work =
unsafe { crate::unimplemented_or_uninitialized_generic!(mid.data.shape().0, U1) };
let mut work = unsafe {
crate::unimplemented_or_uninitialized_generic!(mid.data.shape().0, Const::<1>)
};
self.quadform_with_workspace(&mut work, alpha, mid, rhs, beta)
}
}

View File

@ -11,8 +11,8 @@ use crate::base::allocator::Allocator;
use crate::base::dimension::{DimName, DimNameDiff, DimNameSub, U1};
use crate::base::storage::{Storage, StorageMut};
use crate::base::{
DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, Vector2,
Vector3, VectorN,
Const, DefaultAllocator, Matrix3, Matrix4, OMatrix, OVector, Scalar, SquareMatrix, Unit,
Vector, Vector2, Vector3,
};
use crate::geometry::{
Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point2, Point3, Rotation2,
@ -22,26 +22,26 @@ use crate::geometry::{
use simba::scalar::{ClosedAdd, ClosedMul, RealField};
/// # Translation and scaling in any dimension
impl<N, D: DimName> MatrixN<N, D>
impl<T, D: DimName> OMatrix<T, D, D>
where
N: Scalar + Zero + One,
DefaultAllocator: Allocator<N, D, D>,
T: Scalar + Zero + One,
DefaultAllocator: Allocator<T, D, D>,
{
/// Creates a new homogeneous matrix that applies the same scaling factor on each dimension.
#[inline]
pub fn new_scaling(scaling: N) -> Self {
pub fn new_scaling(scaling: T) -> Self {
let mut res = Self::from_diagonal_element(scaling);
res[(D::dim() - 1, D::dim() - 1)] = N::one();
res[(D::dim() - 1, D::dim() - 1)] = T::one();
res
}
/// Creates a new homogeneous matrix that applies a distinct scaling factor for each dimension.
#[inline]
pub fn new_nonuniform_scaling<SB>(scaling: &Vector<N, DimNameDiff<D, U1>, SB>) -> Self
pub fn new_nonuniform_scaling<SB>(scaling: &Vector<T, DimNameDiff<D, U1>, SB>) -> Self
where
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
SB: Storage<T, DimNameDiff<D, U1>>,
{
let mut res = Self::identity();
for i in 0..scaling.len() {
@ -53,24 +53,27 @@ where
/// Creates a new homogeneous matrix that applies a pure translation.
#[inline]
pub fn new_translation<SB>(translation: &Vector<N, DimNameDiff<D, U1>, SB>) -> Self
pub fn new_translation<SB>(translation: &Vector<T, DimNameDiff<D, U1>, SB>) -> Self
where
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
SB: Storage<T, DimNameDiff<D, U1>>,
{
let mut res = Self::identity();
res.fixed_slice_mut::<DimNameDiff<D, U1>, U1>(0, D::dim() - 1)
.copy_from(translation);
res.generic_slice_mut(
(0, D::dim() - 1),
(DimNameDiff::<D, U1>::name(), Const::<1>),
)
.copy_from(translation);
res
}
}
/// # 2D transformations as a Matrix3
impl<N: RealField> Matrix3<N> {
impl<T: RealField> Matrix3<T> {
/// Builds a 2 dimensional homogeneous rotation matrix from an angle in radian.
#[inline]
pub fn new_rotation(angle: N) -> Self {
pub fn new_rotation(angle: T) -> Self {
Rotation2::new(angle).to_homogeneous()
}
@ -78,9 +81,9 @@ impl<N: RealField> Matrix3<N> {
///
/// Can be used to implement "zoom_to" functionality.
#[inline]
pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector2<N>, pt: &Point2<N>) -> Self {
let zero = N::zero();
let one = N::one();
pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector2<T>, pt: &Point2<T>) -> Self {
let zero = T::zero();
let one = T::one();
Matrix3::new(
scaling.x,
zero,
@ -96,12 +99,12 @@ impl<N: RealField> Matrix3<N> {
}
/// # 3D transformations as a Matrix4
impl<N: RealField> Matrix4<N> {
impl<T: RealField> Matrix4<T> {
/// Builds a 3D homogeneous rotation matrix from an axis and an angle (multiplied together).
///
/// Returns the identity matrix if the given argument is zero.
#[inline]
pub fn new_rotation(axisangle: Vector3<N>) -> Self {
pub fn new_rotation(axisangle: Vector3<T>) -> Self {
Rotation3::new(axisangle).to_homogeneous()
}
@ -109,7 +112,7 @@ impl<N: RealField> Matrix4<N> {
///
/// Returns the identity matrix if the given argument is zero.
#[inline]
pub fn new_rotation_wrt_point(axisangle: Vector3<N>, pt: Point3<N>) -> Self {
pub fn new_rotation_wrt_point(axisangle: Vector3<T>, pt: Point3<T>) -> Self {
let rot = Rotation3::from_scaled_axis(axisangle);
Isometry::rotation_wrt_point(rot, pt).to_homogeneous()
}
@ -118,9 +121,9 @@ impl<N: RealField> Matrix4<N> {
///
/// Can be used to implement "zoom_to" functionality.
#[inline]
pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector3<N>, pt: &Point3<N>) -> Self {
let zero = N::zero();
let one = N::one();
pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector3<T>, pt: &Point3<T>) -> Self {
let zero = T::zero();
let one = T::one();
Matrix4::new(
scaling.x,
zero,
@ -146,31 +149,31 @@ impl<N: RealField> Matrix4<N> {
/// Returns the identity matrix if the given argument is zero.
/// This is identical to `Self::new_rotation`.
#[inline]
pub fn from_scaled_axis(axisangle: Vector3<N>) -> Self {
pub fn from_scaled_axis(axisangle: Vector3<T>) -> Self {
Rotation3::from_scaled_axis(axisangle).to_homogeneous()
}
/// Creates a new rotation from Euler angles.
///
/// The primitive rotations are applied in order: 1 roll 2 pitch 3 yaw.
pub fn from_euler_angles(roll: N, pitch: N, yaw: N) -> Self {
pub fn from_euler_angles(roll: T, pitch: T, yaw: T) -> Self {
Rotation3::from_euler_angles(roll, pitch, yaw).to_homogeneous()
}
/// Builds a 3D homogeneous rotation matrix from an axis and a rotation angle.
pub fn from_axis_angle(axis: &Unit<Vector3<N>>, angle: N) -> Self {
pub fn from_axis_angle(axis: &Unit<Vector3<T>>, angle: T) -> Self {
Rotation3::from_axis_angle(axis, angle).to_homogeneous()
}
/// Creates a new homogeneous matrix for an orthographic projection.
#[inline]
pub fn new_orthographic(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Self {
pub fn new_orthographic(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> Self {
Orthographic3::new(left, right, bottom, top, znear, zfar).into_inner()
}
/// Creates a new homogeneous matrix for a perspective projection.
#[inline]
pub fn new_perspective(aspect: N, fovy: N, znear: N, zfar: N) -> Self {
pub fn new_perspective(aspect: T, fovy: T, znear: T, zfar: T) -> Self {
Perspective3::new(aspect, fovy, znear, zfar).into_inner()
}
@ -180,40 +183,40 @@ impl<N: RealField> Matrix4<N> {
/// It maps the view direction `target - eye` to the positive `z` axis and the origin to the
/// `eye`.
#[inline]
pub fn face_towards(eye: &Point3<N>, target: &Point3<N>, up: &Vector3<N>) -> Self {
pub fn face_towards(eye: &Point3<T>, target: &Point3<T>, up: &Vector3<T>) -> Self {
IsometryMatrix3::face_towards(eye, target, up).to_homogeneous()
}
/// Deprecated: Use [Matrix4::face_towards] instead.
#[deprecated(note = "renamed to `face_towards`")]
pub fn new_observer_frame(eye: &Point3<N>, target: &Point3<N>, up: &Vector3<N>) -> Self {
pub fn new_observer_frame(eye: &Point3<T>, target: &Point3<T>, up: &Vector3<T>) -> Self {
Matrix4::face_towards(eye, target, up)
}
/// Builds a right-handed look-at view matrix.
#[inline]
pub fn look_at_rh(eye: &Point3<N>, target: &Point3<N>, up: &Vector3<N>) -> Self {
pub fn look_at_rh(eye: &Point3<T>, target: &Point3<T>, up: &Vector3<T>) -> Self {
IsometryMatrix3::look_at_rh(eye, target, up).to_homogeneous()
}
/// Builds a left-handed look-at view matrix.
#[inline]
pub fn look_at_lh(eye: &Point3<N>, target: &Point3<N>, up: &Vector3<N>) -> Self {
pub fn look_at_lh(eye: &Point3<T>, target: &Point3<T>, up: &Vector3<T>) -> Self {
IsometryMatrix3::look_at_lh(eye, target, up).to_homogeneous()
}
}
/// # Append/prepend translation and scaling
impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D, D>>
SquareMatrix<N, D, S>
impl<T: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<T, D, D>>
SquareMatrix<T, D, S>
{
/// Computes the transformation equal to `self` followed by an uniform scaling factor.
#[inline]
#[must_use = "Did you mean to use append_scaling_mut()?"]
pub fn append_scaling(&self, scaling: N) -> MatrixN<N, D>
pub fn append_scaling(&self, scaling: T) -> OMatrix<T, D, D>
where
D: DimNameSub<U1>,
DefaultAllocator: Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D, D>,
{
let mut res = self.clone_owned();
res.append_scaling_mut(scaling);
@ -223,10 +226,10 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
/// Computes the transformation equal to an uniform scaling factor followed by `self`.
#[inline]
#[must_use = "Did you mean to use prepend_scaling_mut()?"]
pub fn prepend_scaling(&self, scaling: N) -> MatrixN<N, D>
pub fn prepend_scaling(&self, scaling: T) -> OMatrix<T, D, D>
where
D: DimNameSub<U1>,
DefaultAllocator: Allocator<N, D, D>,
DefaultAllocator: Allocator<T, D, D>,
{
let mut res = self.clone_owned();
res.prepend_scaling_mut(scaling);
@ -238,12 +241,12 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
#[must_use = "Did you mean to use append_nonuniform_scaling_mut()?"]
pub fn append_nonuniform_scaling<SB>(
&self,
scaling: &Vector<N, DimNameDiff<D, U1>, SB>,
) -> MatrixN<N, D>
scaling: &Vector<T, DimNameDiff<D, U1>, SB>,
) -> OMatrix<T, D, D>
where
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<N, D, D>,
SB: Storage<T, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D>,
{
let mut res = self.clone_owned();
res.append_nonuniform_scaling_mut(scaling);
@ -255,12 +258,12 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
#[must_use = "Did you mean to use prepend_nonuniform_scaling_mut()?"]
pub fn prepend_nonuniform_scaling<SB>(
&self,
scaling: &Vector<N, DimNameDiff<D, U1>, SB>,
) -> MatrixN<N, D>
scaling: &Vector<T, DimNameDiff<D, U1>, SB>,
) -> OMatrix<T, D, D>
where
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<N, D, D>,
SB: Storage<T, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D>,
{
let mut res = self.clone_owned();
res.prepend_nonuniform_scaling_mut(scaling);
@ -270,11 +273,14 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
/// Computes the transformation equal to `self` followed by a translation.
#[inline]
#[must_use = "Did you mean to use append_translation_mut()?"]
pub fn append_translation<SB>(&self, shift: &Vector<N, DimNameDiff<D, U1>, SB>) -> MatrixN<N, D>
pub fn append_translation<SB>(
&self,
shift: &Vector<T, DimNameDiff<D, U1>, SB>,
) -> OMatrix<T, D, D>
where
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<N, D, D>,
SB: Storage<T, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D>,
{
let mut res = self.clone_owned();
res.append_translation_mut(shift);
@ -286,12 +292,12 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
#[must_use = "Did you mean to use prepend_translation_mut()?"]
pub fn prepend_translation<SB>(
&self,
shift: &Vector<N, DimNameDiff<D, U1>, SB>,
) -> MatrixN<N, D>
shift: &Vector<T, DimNameDiff<D, U1>, SB>,
) -> OMatrix<T, D, D>
where
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimNameDiff<D, U1>>,
SB: Storage<T, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D> + Allocator<T, DimNameDiff<D, U1>>,
{
let mut res = self.clone_owned();
res.prepend_translation_mut(shift);
@ -300,36 +306,36 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
/// Computes in-place the transformation equal to `self` followed by an uniform scaling factor.
#[inline]
pub fn append_scaling_mut(&mut self, scaling: N)
pub fn append_scaling_mut(&mut self, scaling: T)
where
S: StorageMut<N, D, D>,
S: StorageMut<T, D, D>,
D: DimNameSub<U1>,
{
let mut to_scale = self.fixed_rows_mut::<DimNameDiff<D, U1>>(0);
let mut to_scale = self.rows_generic_mut(0, DimNameDiff::<D, U1>::name());
to_scale *= scaling;
}
/// Computes in-place the transformation equal to an uniform scaling factor followed by `self`.
#[inline]
pub fn prepend_scaling_mut(&mut self, scaling: N)
pub fn prepend_scaling_mut(&mut self, scaling: T)
where
S: StorageMut<N, D, D>,
S: StorageMut<T, D, D>,
D: DimNameSub<U1>,
{
let mut to_scale = self.fixed_columns_mut::<DimNameDiff<D, U1>>(0);
let mut to_scale = self.columns_generic_mut(0, DimNameDiff::<D, U1>::name());
to_scale *= scaling;
}
/// Computes in-place the transformation equal to `self` followed by a non-uniform scaling factor.
#[inline]
pub fn append_nonuniform_scaling_mut<SB>(&mut self, scaling: &Vector<N, DimNameDiff<D, U1>, SB>)
pub fn append_nonuniform_scaling_mut<SB>(&mut self, scaling: &Vector<T, DimNameDiff<D, U1>, SB>)
where
S: StorageMut<N, D, D>,
S: StorageMut<T, D, D>,
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
SB: Storage<T, DimNameDiff<D, U1>>,
{
for i in 0..scaling.len() {
let mut to_scale = self.fixed_rows_mut::<U1>(i);
let mut to_scale = self.fixed_rows_mut::<1>(i);
to_scale *= scaling[i].inlined_clone();
}
}
@ -338,25 +344,25 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
#[inline]
pub fn prepend_nonuniform_scaling_mut<SB>(
&mut self,
scaling: &Vector<N, DimNameDiff<D, U1>, SB>,
scaling: &Vector<T, DimNameDiff<D, U1>, SB>,
) where
S: StorageMut<N, D, D>,
S: StorageMut<T, D, D>,
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
SB: Storage<T, DimNameDiff<D, U1>>,
{
for i in 0..scaling.len() {
let mut to_scale = self.fixed_columns_mut::<U1>(i);
let mut to_scale = self.fixed_columns_mut::<1>(i);
to_scale *= scaling[i].inlined_clone();
}
}
/// Computes the transformation equal to `self` followed by a translation.
#[inline]
pub fn append_translation_mut<SB>(&mut self, shift: &Vector<N, DimNameDiff<D, U1>, SB>)
pub fn append_translation_mut<SB>(&mut self, shift: &Vector<T, DimNameDiff<D, U1>, SB>)
where
S: StorageMut<N, D, D>,
S: StorageMut<T, D, D>,
D: DimNameSub<U1>,
SB: Storage<N, DimNameDiff<D, U1>>,
SB: Storage<T, DimNameDiff<D, U1>>,
{
for i in 0..D::dim() {
for j in 0..D::dim() - 1 {
@ -368,41 +374,55 @@ impl<N: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<N, D
/// Computes the transformation equal to a translation followed by `self`.
#[inline]
pub fn prepend_translation_mut<SB>(&mut self, shift: &Vector<N, DimNameDiff<D, U1>, SB>)
pub fn prepend_translation_mut<SB>(&mut self, shift: &Vector<T, DimNameDiff<D, U1>, SB>)
where
D: DimNameSub<U1>,
S: StorageMut<N, D, D>,
SB: Storage<N, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<N, DimNameDiff<D, U1>>,
S: StorageMut<T, D, D>,
SB: Storage<T, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<T, DimNameDiff<D, U1>>,
{
let scale = self
.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0)
.generic_slice(
(D::dim() - 1, 0),
(Const::<1>, DimNameDiff::<D, U1>::name()),
)
.tr_dot(&shift);
let post_translation =
self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0) * shift;
let post_translation = self.generic_slice(
(0, 0),
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
) * shift;
self[(D::dim() - 1, D::dim() - 1)] += scale;
let mut translation = self.fixed_slice_mut::<DimNameDiff<D, U1>, U1>(0, D::dim() - 1);
let mut translation = self.generic_slice_mut(
(0, D::dim() - 1),
(DimNameDiff::<D, U1>::name(), Const::<1>),
);
translation += post_translation;
}
}
/// # Transformation of vectors and points
impl<N: RealField, D: DimNameSub<U1>, S: Storage<N, D, D>> SquareMatrix<N, D, S>
impl<T: RealField, D: DimNameSub<U1>, S: Storage<T, D, D>> SquareMatrix<T, D, S>
where
DefaultAllocator: Allocator<N, D, D>
+ Allocator<N, DimNameDiff<D, U1>>
+ Allocator<N, DimNameDiff<D, U1>, DimNameDiff<D, U1>>,
DefaultAllocator: Allocator<T, D, D>
+ Allocator<T, DimNameDiff<D, U1>>
+ Allocator<T, DimNameDiff<D, U1>, DimNameDiff<D, U1>>,
{
/// Transforms the given vector, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_vector(
&self,
v: &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);
v: &OVector<T, DimNameDiff<D, U1>>,
) -> OVector<T, DimNameDiff<D, U1>> {
let transform = self.generic_slice(
(0, 0),
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
);
let normalizer = self.generic_slice(
(D::dim() - 1, 0),
(Const::<1>, DimNameDiff::<D, U1>::name()),
);
let n = normalizer.tr_dot(&v);
if !n.is_zero() {
@ -411,18 +431,33 @@ where
transform * v
}
}
impl<T: RealField, S: Storage<T, Const<3>, Const<3>>> SquareMatrix<T, Const<3>, S> {
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_point(
&self,
pt: &Point<N, DimNameDiff<D, U1>>,
) -> Point<N, DimNameDiff<D, U1>> {
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)) };
pub fn transform_point(&self, pt: &Point<T, 2>) -> Point<T, 2> {
let transform = self.fixed_slice::<2, 2>(0, 0);
let translation = self.fixed_slice::<2, 1>(0, 2);
let normalizer = self.fixed_slice::<1, 2>(2, 0);
let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((2, 2)) };
if !n.is_zero() {
(transform * pt + translation) / n
} else {
transform * pt + translation
}
}
}
impl<T: RealField, S: Storage<T, Const<4>, Const<4>>> SquareMatrix<T, Const<4>, S> {
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_point(&self, pt: &Point<T, 3>) -> Point<T, 3> {
let transform = self.fixed_slice::<3, 3>(0, 0);
let translation = self.fixed_slice::<3, 1>(0, 3);
let normalizer = self.fixed_slice::<1, 3>(3, 0);
let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((3, 3)) };
if !n.is_zero() {
(transform * pt + translation) / n

View File

@ -10,13 +10,13 @@ use crate::base::allocator::{Allocator, SameShapeAllocator};
use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
use crate::base::dimension::Dim;
use crate::base::storage::{Storage, StorageMut};
use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixSum, Scalar};
use crate::base::{DefaultAllocator, Matrix, MatrixSum, OMatrix, Scalar};
use crate::ClosedAdd;
/// The type of the result of a matrix component-wise operation.
pub type MatrixComponentOp<N, R1, C1, R2, C2> = MatrixSum<N, R1, C1, R2, C2>;
pub type MatrixComponentOp<T, R1, C1, R2, C2> = MatrixSum<T, R1, C1, R2, C2>;
impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
impl<T: Scalar, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {
/// Computes the component-wise absolute value.
///
/// # Example
@ -28,10 +28,10 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// assert_eq!(a.abs(), Matrix2::new(0.0, 1.0, 2.0, 3.0))
/// ```
#[inline]
pub fn abs(&self) -> MatrixMN<N, R, C>
pub fn abs(&self) -> OMatrix<T, R, C>
where
N: Signed,
DefaultAllocator: Allocator<N, R, C>,
T: Signed,
DefaultAllocator: Allocator<T, R, C>,
{
let mut res = self.clone_owned();
@ -49,11 +49,11 @@ macro_rules! component_binop_impl(
($($binop: ident, $binop_mut: ident, $binop_assign: ident, $cmpy: ident, $Trait: ident . $op: ident . $op_assign: ident, $desc:expr, $desc_cmpy:expr, $desc_mut:expr);* $(;)*) => {$(
#[doc = $desc]
#[inline]
pub fn $binop<R2, C2, SB>(&self, rhs: &Matrix<N, R2, C2, SB>) -> MatrixComponentOp<N, R1, C1, R2, C2>
where N: $Trait,
pub fn $binop<R2, C2, SB>(&self, rhs: &Matrix<T, R2, C2, SB>) -> MatrixComponentOp<T, R1, C1, R2, C2>
where T: $Trait,
R2: Dim, C2: Dim,
SB: Storage<N, R2, C2>,
DefaultAllocator: SameShapeAllocator<N, R1, C1, R2, C2>,
SB: Storage<T, R2, C2>,
DefaultAllocator: SameShapeAllocator<T, R1, C1, R2, C2>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2> {
assert_eq!(self.shape(), rhs.shape(), "Componentwise mul/div: mismatched matrix dimensions.");
@ -73,13 +73,13 @@ macro_rules! component_binop_impl(
// componentwise binop plus Y.
#[doc = $desc_cmpy]
#[inline]
pub fn $cmpy<R2, C2, SB, R3, C3, SC>(&mut self, alpha: N, a: &Matrix<N, R2, C2, SB>, b: &Matrix<N, R3, C3, SC>, beta: N)
where N: $Trait + Zero + Mul<N, Output = N> + Add<N, Output = N>,
pub fn $cmpy<R2, C2, SB, R3, C3, SC>(&mut self, alpha: T, a: &Matrix<T, R2, C2, SB>, b: &Matrix<T, R3, C3, SC>, beta: T)
where T: $Trait + Zero + Mul<T, Output = T> + Add<T, Output = T>,
R2: Dim, C2: Dim,
R3: Dim, C3: Dim,
SA: StorageMut<N, R1, C1>,
SB: Storage<N, R2, C2>,
SC: Storage<N, R3, C3>,
SA: StorageMut<T, R1, C1>,
SB: Storage<T, R2, C2>,
SC: Storage<T, R3, C3>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2> +
SameNumberOfRows<R1, R3> + SameNumberOfColumns<C1, C3> {
assert_eq!(self.shape(), a.shape(), "Componentwise mul/div: mismatched matrix dimensions.");
@ -109,12 +109,12 @@ macro_rules! component_binop_impl(
#[doc = $desc_mut]
#[inline]
pub fn $binop_assign<R2, C2, SB>(&mut self, rhs: &Matrix<N, R2, C2, SB>)
where N: $Trait,
pub fn $binop_assign<R2, C2, SB>(&mut self, rhs: &Matrix<T, R2, C2, SB>)
where T: $Trait,
R2: Dim,
C2: Dim,
SA: StorageMut<N, R1, C1>,
SB: Storage<N, R2, C2>,
SA: StorageMut<T, R1, C1>,
SB: Storage<T, R2, C2>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2> {
assert_eq!(self.shape(), rhs.shape(), "Componentwise mul/div: mismatched matrix dimensions.");
@ -131,12 +131,12 @@ macro_rules! component_binop_impl(
#[doc = $desc_mut]
#[inline]
#[deprecated(note = "This is renamed using the `_assign` suffix instead of the `_mut` suffix.")]
pub fn $binop_mut<R2, C2, SB>(&mut self, rhs: &Matrix<N, R2, C2, SB>)
where N: $Trait,
pub fn $binop_mut<R2, C2, SB>(&mut self, rhs: &Matrix<T, R2, C2, SB>)
where T: $Trait,
R2: Dim,
C2: Dim,
SA: StorageMut<N, R1, C1>,
SB: Storage<N, R2, C2>,
SA: StorageMut<T, R1, C1>,
SB: Storage<T, R2, C2>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2> {
self.$binop_assign(rhs)
}
@ -144,7 +144,7 @@ macro_rules! component_binop_impl(
);
/// # Componentwise operations
impl<N: Scalar, R1: Dim, C1: Dim, SA: Storage<N, R1, C1>> Matrix<N, R1, C1, SA> {
impl<T: Scalar, R1: Dim, C1: Dim, SA: Storage<T, R1, C1>> Matrix<T, R1, C1, SA> {
component_binop_impl!(
component_mul, component_mul_mut, component_mul_assign, cmpy, ClosedMul.mul.mul_assign,
r"
@ -241,30 +241,30 @@ impl<N: Scalar, R1: Dim, C1: Dim, SA: Storage<N, R1, C1>> Matrix<N, R1, C1, SA>
/// Computes the infimum (aka. componentwise min) of two matrices/vectors.
#[inline]
pub fn inf(&self, other: &Self) -> MatrixMN<N, R1, C1>
pub fn inf(&self, other: &Self) -> OMatrix<T, R1, C1>
where
N: SimdPartialOrd,
DefaultAllocator: Allocator<N, R1, C1>,
T: SimdPartialOrd,
DefaultAllocator: Allocator<T, R1, C1>,
{
self.zip_map(other, |a, b| a.simd_min(b))
}
/// Computes the supremum (aka. componentwise max) of two matrices/vectors.
#[inline]
pub fn sup(&self, other: &Self) -> MatrixMN<N, R1, C1>
pub fn sup(&self, other: &Self) -> OMatrix<T, R1, C1>
where
N: SimdPartialOrd,
DefaultAllocator: Allocator<N, R1, C1>,
T: SimdPartialOrd,
DefaultAllocator: Allocator<T, R1, C1>,
{
self.zip_map(other, |a, b| a.simd_max(b))
}
/// Computes the (infimum, supremum) of two matrices/vectors.
#[inline]
pub fn inf_sup(&self, other: &Self) -> (MatrixMN<N, R1, C1>, MatrixMN<N, R1, C1>)
pub fn inf_sup(&self, other: &Self) -> (OMatrix<T, R1, C1>, OMatrix<T, R1, C1>)
where
N: SimdPartialOrd,
DefaultAllocator: Allocator<N, R1, C1>,
T: SimdPartialOrd,
DefaultAllocator: Allocator<T, R1, C1>,
{
// TODO: can this be optimized?
(self.inf(other), self.sup(other))
@ -273,10 +273,10 @@ impl<N: Scalar, R1: Dim, C1: Dim, SA: Storage<N, R1, C1>> Matrix<N, R1, C1, SA>
/// Adds a scalar to `self`.
#[inline]
#[must_use = "Did you mean to use add_scalar_mut()?"]
pub fn add_scalar(&self, rhs: N) -> MatrixMN<N, R1, C1>
pub fn add_scalar(&self, rhs: T) -> OMatrix<T, R1, C1>
where
N: ClosedAdd,
DefaultAllocator: Allocator<N, R1, C1>,
T: ClosedAdd,
DefaultAllocator: Allocator<T, R1, C1>,
{
let mut res = self.clone_owned();
res.add_scalar_mut(rhs);
@ -285,10 +285,10 @@ impl<N: Scalar, R1: Dim, C1: Dim, SA: Storage<N, R1, C1>> Matrix<N, R1, C1, SA>
/// Adds a scalar to `self` in-place.
#[inline]
pub fn add_scalar_mut(&mut self, rhs: N)
pub fn add_scalar_mut(&mut self, rhs: T)
where
N: ClosedAdd,
SA: StorageMut<N, R1, C1>,
T: ClosedAdd,
SA: StorageMut<T, R1, C1>,
{
for e in self.iter_mut() {
*e += rhs.inlined_clone()

View File

@ -20,9 +20,11 @@ use typenum::{self, Cmp, Greater};
use simba::scalar::{ClosedAdd, ClosedMul};
use crate::base::allocator::Allocator;
use crate::base::dimension::{Dim, DimName, Dynamic, U1, U2, U3, U4, U5, U6};
use crate::base::dimension::{Dim, DimName, Dynamic, ToTypenum};
use crate::base::storage::Storage;
use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vector, VectorN};
use crate::base::{
ArrayStorage, Const, DefaultAllocator, Matrix, OMatrix, OVector, Scalar, Unit, Vector,
};
/// When "no_unsound_assume_init" is enabled, expands to `unimplemented!()` instead of `new_uninitialized_generic().assume_init()`.
/// Intended as a placeholder, each callsite should be refactored to use uninitialized memory soundly
@ -31,7 +33,7 @@ macro_rules! unimplemented_or_uninitialized_generic {
($nrows:expr, $ncols:expr) => {{
#[cfg(feature="no_unsound_assume_init")] {
// Some of the call sites need the number of rows and columns from this to infer a type, so
// uninitialized memory is used to infer the type, as `N: Zero` isn't available at all callsites.
// uninitialized memory is used to infer the type, as `T: Zero` isn't available at all callsites.
// This may technically still be UB even though the assume_init is dead code, but all callsites should be fixed before #556 is closed.
let typeinference_helper = crate::base::Matrix::new_uninitialized_generic($nrows, $ncols);
unimplemented!();
@ -47,9 +49,9 @@ macro_rules! unimplemented_or_uninitialized_generic {
/// the dimension as inputs.
///
/// These functions should only be used when working on dimension-generic code.
impl<N: Scalar, R: Dim, C: Dim> MatrixMN<N, R, C>
impl<T: Scalar, R: Dim, C: Dim> OMatrix<T, R, C>
where
DefaultAllocator: Allocator<N, R, C>,
DefaultAllocator: Allocator<T, 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()`.
@ -60,7 +62,7 @@ where
/// Creates a matrix with all its elements set to `elem`.
#[inline]
pub fn from_element_generic(nrows: R, ncols: C, elem: N) -> Self {
pub fn from_element_generic(nrows: R, ncols: C, elem: T) -> Self {
let len = nrows.value() * ncols.value();
Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len))
}
@ -69,7 +71,7 @@ where
///
/// Same as `from_element_generic`.
#[inline]
pub fn repeat_generic(nrows: R, ncols: C, elem: N) -> Self {
pub fn repeat_generic(nrows: R, ncols: C, elem: T) -> Self {
let len = nrows.value() * ncols.value();
Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len))
}
@ -78,16 +80,16 @@ where
#[inline]
pub fn zeros_generic(nrows: R, ncols: C) -> Self
where
N: Zero,
T: Zero,
{
Self::from_element_generic(nrows, ncols, N::zero())
Self::from_element_generic(nrows, ncols, T::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>,
I: IntoIterator<Item = T>,
{
Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter))
}
@ -98,7 +100,7 @@ where
/// The order of elements in the slice must follow the usual mathematic writing, i.e.,
/// row-by-row.
#[inline]
pub fn from_row_slice_generic(nrows: R, ncols: C, slice: &[N]) -> Self {
pub fn from_row_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self {
assert!(
slice.len() == nrows.value() * ncols.value(),
"Matrix init. error: the slice did not contain the right number of elements."
@ -119,7 +121,7 @@ where
/// Creates a matrix with its elements filled with the components provided by a slice. The
/// components must have the same layout as the matrix data storage (i.e. column-major).
#[inline]
pub fn from_column_slice_generic(nrows: R, ncols: C, slice: &[N]) -> Self {
pub fn from_column_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self {
Self::from_iterator_generic(nrows, ncols, slice.iter().cloned())
}
@ -128,7 +130,7 @@ where
#[inline]
pub fn from_fn_generic<F>(nrows: R, ncols: C, mut f: F) -> Self
where
F: FnMut(usize, usize) -> N,
F: FnMut(usize, usize) -> T,
{
let mut res: Self = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) };
@ -148,9 +150,9 @@ where
#[inline]
pub fn identity_generic(nrows: R, ncols: C) -> Self
where
N: Zero + One,
T: Zero + One,
{
Self::from_diagonal_element_generic(nrows, ncols, N::one())
Self::from_diagonal_element_generic(nrows, ncols, T::one())
}
/// Creates a new matrix with its diagonal filled with copies of `elt`.
@ -158,9 +160,9 @@ where
/// If the matrix is not square, the largest square submatrix starting at index `(0, 0)` is set
/// 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
pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: T) -> Self
where
N: Zero + One,
T: Zero + One,
{
let mut res = Self::zeros_generic(nrows, ncols);
@ -176,9 +178,9 @@ 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
pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[T]) -> Self
where
N: Zero,
T: Zero,
{
let mut res = Self::zeros_generic(nrows, ncols);
assert!(
@ -210,9 +212,9 @@ where
/// m.m31 == 7.0 && m.m32 == 8.0 && m.m33 == 9.0);
/// ```
#[inline]
pub fn from_rows<SB>(rows: &[Matrix<N, U1, C, SB>]) -> Self
pub fn from_rows<SB>(rows: &[Matrix<T, Const<1>, C, SB>]) -> Self
where
SB: Storage<N, U1, C>,
SB: Storage<T, Const<1>, C>,
{
assert!(!rows.is_empty(), "At least one row must be given.");
let nrows = R::try_to_usize().unwrap_or_else(|| rows.len());
@ -252,9 +254,9 @@ where
/// m.m31 == 3.0 && m.m32 == 6.0 && m.m33 == 9.0);
/// ```
#[inline]
pub fn from_columns<SB>(columns: &[Vector<N, R, SB>]) -> Self
pub fn from_columns<SB>(columns: &[Vector<T, R, SB>]) -> Self
where
SB: Storage<N, R>,
SB: Storage<T, R>,
{
assert!(!columns.is_empty(), "At least one column must be given.");
let ncols = C::try_to_usize().unwrap_or_else(|| columns.len());
@ -282,15 +284,16 @@ where
#[cfg(feature = "rand")]
pub fn new_random_generic(nrows: R, ncols: C) -> Self
where
Standard: Distribution<N>,
Standard: Distribution<T>,
{
Self::from_fn_generic(nrows, ncols, |_, _| rand::random())
let mut rng = rand::thread_rng();
Self::from_fn_generic(nrows, ncols, |_, _| rng.gen())
}
/// Creates a matrix filled with random values from the given distribution.
#[inline]
#[cfg(feature = "rand-no-std")]
pub fn from_distribution_generic<Distr: Distribution<N> + ?Sized, G: Rng + ?Sized>(
pub fn from_distribution_generic<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
nrows: R,
ncols: C,
distribution: &Distr,
@ -305,12 +308,12 @@ where
///
/// # Example
/// ```
/// # use nalgebra::{Dynamic, DMatrix, Matrix, U1};
/// # use nalgebra::{Dynamic, DMatrix, Matrix, Const};
///
/// let vec = vec![0, 1, 2, 3, 4, 5];
/// let vec_ptr = vec.as_ptr();
///
/// let matrix = Matrix::from_vec_generic(Dynamic::new(vec.len()), U1, vec);
/// let matrix = Matrix::from_vec_generic(Dynamic::new(vec.len()), Const::<1>, vec);
/// let matrix_storage_ptr = matrix.data.as_vec().as_ptr();
///
/// // `matrix` is backed by exactly the same `Vec` as it was constructed from.
@ -318,15 +321,15 @@ where
/// ```
#[inline]
#[cfg(any(feature = "std", feature = "alloc"))]
pub fn from_vec_generic(nrows: R, ncols: C, data: Vec<N>) -> Self {
pub fn from_vec_generic(nrows: R, ncols: C, data: Vec<T>) -> Self {
Self::from_iterator_generic(nrows, ncols, data)
}
}
impl<N, D: Dim> MatrixN<N, D>
impl<T, D: Dim> OMatrix<T, D, D>
where
N: Scalar,
DefaultAllocator: Allocator<N, D, D>,
T: Scalar,
DefaultAllocator: Allocator<T, D, D>,
{
/// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0.
///
@ -347,9 +350,9 @@ where
/// dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 3.0);
/// ```
#[inline]
pub fn from_diagonal<SB: Storage<N, D>>(diag: &Vector<N, D, SB>) -> Self
pub fn from_diagonal<SB: Storage<T, D>>(diag: &Vector<T, D, SB>) -> Self
where
N: Zero,
T: Zero,
{
let (dim, _) = diag.data.shape();
let mut res = Self::zeros_generic(dim, dim);
@ -398,7 +401,7 @@ macro_rules! impl_constructors(
/// dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
/// ```
#[inline]
pub fn from_element($($args: usize,)* elem: N) -> Self {
pub fn from_element($($args: usize,)* elem: T) -> Self {
Self::from_element_generic($($gargs, )* elem)
}
@ -425,7 +428,7 @@ macro_rules! impl_constructors(
/// dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0);
/// ```
#[inline]
pub fn repeat($($args: usize,)* elem: N) -> Self {
pub fn repeat($($args: usize,)* elem: T) -> Self {
Self::repeat_generic($($gargs, )* elem)
}
@ -451,7 +454,7 @@ macro_rules! impl_constructors(
/// ```
#[inline]
pub fn zeros($($args: usize),*) -> Self
where N: Zero {
where T: Zero {
Self::zeros_generic($($gargs),*)
}
@ -480,7 +483,7 @@ macro_rules! impl_constructors(
/// ```
#[inline]
pub fn from_iterator<I>($($args: usize,)* iter: I) -> Self
where I: IntoIterator<Item = N> {
where I: IntoIterator<Item = T> {
Self::from_iterator_generic($($gargs, )* iter)
}
@ -508,7 +511,7 @@ macro_rules! impl_constructors(
/// ```
#[inline]
pub fn from_fn<F>($($args: usize,)* f: F) -> Self
where F: FnMut(usize, usize) -> N {
where F: FnMut(usize, usize) -> T {
Self::from_fn_generic($($gargs, )* f)
}
@ -532,7 +535,7 @@ macro_rules! impl_constructors(
/// ```
#[inline]
pub fn identity($($args: usize,)*) -> Self
where N: Zero + One {
where T: Zero + One {
Self::identity_generic($($gargs),* )
}
@ -554,8 +557,8 @@ macro_rules! impl_constructors(
/// dm[(1, 0)] == 0.0 && dm[(1, 1)] == 5.0 && dm[(1, 2)] == 0.0);
/// ```
#[inline]
pub fn from_diagonal_element($($args: usize,)* elt: N) -> Self
where N: Zero + One {
pub fn from_diagonal_element($($args: usize,)* elt: T) -> Self
where T: Zero + One {
Self::from_diagonal_element_generic($($gargs, )* elt)
}
@ -581,15 +584,15 @@ macro_rules! impl_constructors(
/// dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 0.0);
/// ```
#[inline]
pub fn from_partial_diagonal($($args: usize,)* elts: &[N]) -> Self
where N: Zero {
pub fn from_partial_diagonal($($args: usize,)* elts: &[T]) -> Self
where T: Zero {
Self::from_partial_diagonal_generic($($gargs, )* elts)
}
/// Creates a matrix or vector filled with random values from the given distribution.
#[inline]
#[cfg(feature = "rand-no-std")]
pub fn from_distribution<Distr: Distribution<N> + ?Sized, G: Rng + ?Sized>(
pub fn from_distribution<Distr: Distribution<T> + ?Sized, G: Rng + ?Sized>(
$($args: usize,)*
distribution: &Distr,
rng: &mut G,
@ -601,28 +604,28 @@ macro_rules! impl_constructors(
#[inline]
#[cfg(feature = "rand")]
pub fn new_random($($args: usize),*) -> Self
where Standard: Distribution<N> {
where Standard: Distribution<T> {
Self::new_random_generic($($gargs),*)
}
}
);
/// # Constructors of statically-sized vectors or statically-sized matrices
impl<N: Scalar, R: DimName, C: DimName> MatrixMN<N, R, C>
impl<T: Scalar, R: DimName, C: DimName> OMatrix<T, R, C>
where
DefaultAllocator: Allocator<N, R, C>,
DefaultAllocator: Allocator<T, R, C>,
{
// TODO: this is not very pretty. We could find a better call syntax.
impl_constructors!(R, C; // Arguments for Matrix<N, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<N, ..., S>
// TODO: this is not very pretty. We could find a better call syntax.
impl_constructors!(R, C; // Arguments for Matrix<T, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<T, ..., S>
R::name(), C::name(); // Arguments for `_generic` constructors.
); // Arguments for non-generic constructors.
}
/// # Constructors of matrices with a dynamic number of columns
impl<N: Scalar, R: DimName> MatrixMN<N, R, Dynamic>
impl<T: Scalar, R: DimName> OMatrix<T, R, Dynamic>
where
DefaultAllocator: Allocator<N, R, Dynamic>,
DefaultAllocator: Allocator<T, R, Dynamic>,
{
impl_constructors!(R, Dynamic;
=> R: DimName;
@ -631,9 +634,9 @@ where
}
/// # Constructors of dynamic vectors and matrices with a dynamic number of rows
impl<N: Scalar, C: DimName> MatrixMN<N, Dynamic, C>
impl<T: Scalar, C: DimName> OMatrix<T, Dynamic, C>
where
DefaultAllocator: Allocator<N, Dynamic, C>,
DefaultAllocator: Allocator<T, Dynamic, C>,
{
impl_constructors!(Dynamic, C;
=> C: DimName;
@ -642,9 +645,9 @@ where
}
/// # Constructors of fully dynamic matrices
impl<N: Scalar> MatrixMN<N, Dynamic, Dynamic>
impl<T: Scalar> OMatrix<T, Dynamic, Dynamic>
where
DefaultAllocator: Allocator<N, Dynamic, Dynamic>,
DefaultAllocator: Allocator<T, Dynamic, Dynamic>,
{
impl_constructors!(Dynamic, Dynamic;
;
@ -660,8 +663,8 @@ where
*/
macro_rules! impl_constructors_from_data(
($data: ident; $($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => {
impl<N: Scalar, $($DimIdent: $DimBound, )*> MatrixMN<N $(, $Dims)*>
where DefaultAllocator: Allocator<N $(, $Dims)*> {
impl<T: Scalar, $($DimIdent: $DimBound, )*> OMatrix<T $(, $Dims)*>
where DefaultAllocator: Allocator<T $(, $Dims)*> {
/// Creates a matrix with its elements filled with the components provided by a slice
/// in row-major order.
///
@ -688,7 +691,7 @@ macro_rules! impl_constructors_from_data(
/// dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5);
/// ```
#[inline]
pub fn from_row_slice($($args: usize,)* $data: &[N]) -> Self {
pub fn from_row_slice($($args: usize,)* $data: &[T]) -> Self {
Self::from_row_slice_generic($($gargs, )* $data)
}
@ -715,7 +718,7 @@ macro_rules! impl_constructors_from_data(
/// dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
/// ```
#[inline]
pub fn from_column_slice($($args: usize,)* $data: &[N]) -> Self {
pub fn from_column_slice($($args: usize,)* $data: &[T]) -> Self {
Self::from_column_slice_generic($($gargs, )* $data)
}
@ -741,7 +744,7 @@ macro_rules! impl_constructors_from_data(
/// ```
#[inline]
#[cfg(any(feature = "std", feature = "alloc"))]
pub fn from_vec($($args: usize,)* $data: Vec<N>) -> Self {
pub fn from_vec($($args: usize,)* $data: Vec<T>) -> Self {
Self::from_vec_generic($($gargs, )* $data)
}
}
@ -749,8 +752,8 @@ macro_rules! impl_constructors_from_data(
);
// TODO: this is not very pretty. We could find a better call syntax.
impl_constructors_from_data!(data; R, C; // Arguments for Matrix<N, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<N, ..., S>
impl_constructors_from_data!(data; R, C; // Arguments for Matrix<T, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<T, ..., S>
R::name(), C::name(); // Arguments for `_generic` constructors.
); // Arguments for non-generic constructors.
@ -774,14 +777,14 @@ impl_constructors_from_data!(data; Dynamic, Dynamic;
* Zero, One, Rand traits.
*
*/
impl<N, R: DimName, C: DimName> Zero for MatrixMN<N, R, C>
impl<T, R: DimName, C: DimName> Zero for OMatrix<T, R, C>
where
N: Scalar + Zero + ClosedAdd,
DefaultAllocator: Allocator<N, R, C>,
T: Scalar + Zero + ClosedAdd,
DefaultAllocator: Allocator<T, R, C>,
{
#[inline]
fn zero() -> Self {
Self::from_element(N::zero())
Self::from_element(T::zero())
}
#[inline]
@ -790,10 +793,10 @@ where
}
}
impl<N, D: DimName> One for MatrixN<N, D>
impl<T, D: DimName> One for OMatrix<T, D, D>
where
N: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<N, D, D>,
T: Scalar + Zero + One + ClosedMul + ClosedAdd,
DefaultAllocator: Allocator<T, D, D>,
{
#[inline]
fn one() -> Self {
@ -801,45 +804,45 @@ where
}
}
impl<N, R: DimName, C: DimName> Bounded for MatrixMN<N, R, C>
impl<T, R: DimName, C: DimName> Bounded for OMatrix<T, R, C>
where
N: Scalar + Bounded,
DefaultAllocator: Allocator<N, R, C>,
T: Scalar + Bounded,
DefaultAllocator: Allocator<T, R, C>,
{
#[inline]
fn max_value() -> Self {
Self::from_element(N::max_value())
Self::from_element(T::max_value())
}
#[inline]
fn min_value() -> Self {
Self::from_element(N::min_value())
Self::from_element(T::min_value())
}
}
#[cfg(feature = "rand-no-std")]
impl<N: Scalar, R: Dim, C: Dim> Distribution<MatrixMN<N, R, C>> for Standard
impl<T: Scalar, R: Dim, C: Dim> Distribution<OMatrix<T, R, C>> for Standard
where
DefaultAllocator: Allocator<N, R, C>,
Standard: Distribution<N>,
DefaultAllocator: Allocator<T, R, C>,
Standard: Distribution<T>,
{
#[inline]
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> MatrixMN<N, R, C> {
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> OMatrix<T, R, C> {
let nrows = R::try_to_usize().unwrap_or_else(|| rng.gen_range(0..10));
let ncols = C::try_to_usize().unwrap_or_else(|| rng.gen_range(0..10));
MatrixMN::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| rng.gen())
OMatrix::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| rng.gen())
}
}
#[cfg(feature = "arbitrary")]
impl<N, R, C> Arbitrary for MatrixMN<N, R, C>
impl<T, R, C> Arbitrary for OMatrix<T, R, C>
where
R: Dim,
C: Dim,
N: Scalar + Arbitrary + Send,
DefaultAllocator: Allocator<N, R, C>,
Owned<N, R, C>: Clone + Send,
T: Scalar + Arbitrary + Send,
DefaultAllocator: Allocator<T, R, C>,
Owned<T, R, C>: Clone + Send,
{
#[inline]
fn arbitrary(g: &mut Gen) -> Self {
@ -847,23 +850,24 @@ where
let ncols = C::try_to_usize().unwrap_or(usize::arbitrary(g) % 10);
Self::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| {
N::arbitrary(g)
T::arbitrary(g)
})
}
}
// TODO(specialization): faster impls possible for D≤4 (see rand_distr::{UnitCircle, UnitSphere})
#[cfg(feature = "rand")]
impl<N: crate::RealField, D: DimName> Distribution<Unit<VectorN<N, D>>> for Standard
impl<T: crate::RealField, D: DimName> Distribution<Unit<OVector<T, D>>> for Standard
where
DefaultAllocator: Allocator<N, D>,
rand_distr::StandardNormal: Distribution<N>,
DefaultAllocator: Allocator<T, D>,
rand_distr::StandardNormal: Distribution<T>,
{
/// Generate a uniformly distributed random unit vector.
#[inline]
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit<VectorN<N, D>> {
Unit::new_normalize(VectorN::from_distribution_generic(
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit<OVector<T, D>> {
Unit::new_normalize(OVector::from_distribution_generic(
D::name(),
U1,
Const::<1>,
&rand_distr::StandardNormal,
rng,
))
@ -875,22 +879,44 @@ where
* Constructors for small matrices and vectors.
*
*/
macro_rules! transpose_array(
[$($a: ident),*;] => {
[$([$a]),*]
};
[$($a: ident),*; $($b: ident),*;] => {
[$([$a, $b]),*];
};
[$($a: ident),*; $($b: ident),*; $($c: ident),*;] => {
[$([$a, $b, $c]),*];
};
[$($a: ident),*; $($b: ident),*; $($c: ident),*; $($d: ident),*;] => {
[$([$a, $b, $c, $d]),*];
};
[$($a: ident),*; $($b: ident),*; $($c: ident),*; $($d: ident),*; $($e: ident),*;] => {
[$([$a, $b, $c, $d, $e]),*];
};
[$($a: ident),*; $($b: ident),*; $($c: ident),*; $($d: ident),*; $($e: ident),*; $($f: ident),*;] => {
[$([$a, $b, $c, $d, $e, $f]),*];
};
);
macro_rules! componentwise_constructors_impl(
($($R: ty, $C: ty, $($args: ident:($irow: expr,$icol: expr)),*);* $(;)*) => {$(
impl<N> MatrixMN<N, $R, $C>
where N: Scalar,
DefaultAllocator: Allocator<N, $R, $C> {
($($R: expr, $C: expr, [$($($args: ident),*);*] $(;)*)*) => {$(
impl<T> Matrix<T, Const<$R>, Const<$C>, ArrayStorage<T, $R, $C>> {
/// Initializes this matrix from its components.
#[inline]
pub fn new($($args: N),*) -> Self {
pub const fn new($($($args: T),*),*) -> Self {
unsafe {
#[cfg(feature="no_unsound_assume_init")]
let mut res: Self = unimplemented!();
#[cfg(not(feature="no_unsound_assume_init"))]
let mut res = Self::new_uninitialized().assume_init();
$( *res.get_unchecked_mut(($irow, $icol)) = $args; )*
res
Self::from_data_statically_unchecked(
ArrayStorage(
transpose_array![
$(
$($args),*
;)*
]
)
)
}
}
}
@ -901,145 +927,145 @@ componentwise_constructors_impl!(
/*
* Square matrices 1 .. 6.
*/
U2, U2, m11:(0,0), m12:(0,1),
m21:(1,0), m22:(1,1);
U3, U3, m11:(0,0), m12:(0,1), m13:(0,2),
m21:(1,0), m22:(1,1), m23:(1,2),
m31:(2,0), m32:(2,1), m33:(2,2);
U4, U4, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3);
U5, U5, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3), m45:(3,4),
m51:(4,0), m52:(4,1), m53:(4,2), m54:(4,3), m55:(4,4);
U6, U6, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4), m16:(0,5),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4), m26:(1,5),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4), m36:(2,5),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3), m45:(3,4), m46:(3,5),
m51:(4,0), m52:(4,1), m53:(4,2), m54:(4,3), m55:(4,4), m56:(4,5),
m61:(5,0), m62:(5,1), m63:(5,2), m64:(5,3), m65:(5,4), m66:(5,5);
2, 2, [m11, m12;
m21, m22];
3, 3, [m11, m12, m13;
m21, m22, m23;
m31, m32, m33];
4, 4, [m11, m12, m13, m14;
m21, m22, m23, m24;
m31, m32, m33, m34;
m41, m42, m43, m44];
5, 5, [m11, m12, m13, m14, m15;
m21, m22, m23, m24, m25;
m31, m32, m33, m34, m35;
m41, m42, m43, m44, m45;
m51, m52, m53, m54, m55];
6, 6, [m11, m12, m13, m14, m15, m16;
m21, m22, m23, m24, m25, m26;
m31, m32, m33, m34, m35, m36;
m41, m42, m43, m44, m45, m46;
m51, m52, m53, m54, m55, m56;
m61, m62, m63, m64, m65, m66];
/*
* Rectangular matrices with 2 rows.
*/
U2, U3, m11:(0,0), m12:(0,1), m13:(0,2),
m21:(1,0), m22:(1,1), m23:(1,2);
U2, U4, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3);
U2, U5, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4);
U2, U6, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4), m16:(0,5),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4), m26:(1,5);
2, 3, [m11, m12, m13;
m21, m22, m23];
2, 4, [m11, m12, m13, m14;
m21, m22, m23, m24];
2, 5, [m11, m12, m13, m14, m15;
m21, m22, m23, m24, m25];
2, 6, [m11, m12, m13, m14, m15, m16;
m21, m22, m23, m24, m25, m26];
/*
* Rectangular matrices with 3 rows.
*/
U3, U2, m11:(0,0), m12:(0,1),
m21:(1,0), m22:(1,1),
m31:(2,0), m32:(2,1);
U3, U4, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3);
U3, U5, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4);
U3, U6, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4), m16:(0,5),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4), m26:(1,5),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4), m36:(2,5);
3, 2, [m11, m12;
m21, m22;
m31, m32];
3, 4, [m11, m12, m13, m14;
m21, m22, m23, m24;
m31, m32, m33, m34];
3, 5, [m11, m12, m13, m14, m15;
m21, m22, m23, m24, m25;
m31, m32, m33, m34, m35];
3, 6, [m11, m12, m13, m14, m15, m16;
m21, m22, m23, m24, m25, m26;
m31, m32, m33, m34, m35, m36];
/*
* Rectangular matrices with 4 rows.
*/
U4, U2, m11:(0,0), m12:(0,1),
m21:(1,0), m22:(1,1),
m31:(2,0), m32:(2,1),
m41:(3,0), m42:(3,1);
U4, U3, m11:(0,0), m12:(0,1), m13:(0,2),
m21:(1,0), m22:(1,1), m23:(1,2),
m31:(2,0), m32:(2,1), m33:(2,2),
m41:(3,0), m42:(3,1), m43:(3,2);
U4, U5, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3), m45:(3,4);
U4, U6, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4), m16:(0,5),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4), m26:(1,5),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4), m36:(2,5),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3), m45:(3,4), m46:(3,5);
4, 2, [m11, m12;
m21, m22;
m31, m32;
m41, m42];
4, 3, [m11, m12, m13;
m21, m22, m23;
m31, m32, m33;
m41, m42, m43];
4, 5, [m11, m12, m13, m14, m15;
m21, m22, m23, m24, m25;
m31, m32, m33, m34, m35;
m41, m42, m43, m44, m45];
4, 6, [m11, m12, m13, m14, m15, m16;
m21, m22, m23, m24, m25, m26;
m31, m32, m33, m34, m35, m36;
m41, m42, m43, m44, m45, m46];
/*
* Rectangular matrices with 5 rows.
*/
U5, U2, m11:(0,0), m12:(0,1),
m21:(1,0), m22:(1,1),
m31:(2,0), m32:(2,1),
m41:(3,0), m42:(3,1),
m51:(4,0), m52:(4,1);
U5, U3, m11:(0,0), m12:(0,1), m13:(0,2),
m21:(1,0), m22:(1,1), m23:(1,2),
m31:(2,0), m32:(2,1), m33:(2,2),
m41:(3,0), m42:(3,1), m43:(3,2),
m51:(4,0), m52:(4,1), m53:(4,2);
U5, U4, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3),
m51:(4,0), m52:(4,1), m53:(4,2), m54:(4,3);
U5, U6, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4), m16:(0,5),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4), m26:(1,5),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4), m36:(2,5),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3), m45:(3,4), m46:(3,5),
m51:(4,0), m52:(4,1), m53:(4,2), m54:(4,3), m55:(4,4), m56:(4,5);
5, 2, [m11, m12;
m21, m22;
m31, m32;
m41, m42;
m51, m52];
5, 3, [m11, m12, m13;
m21, m22, m23;
m31, m32, m33;
m41, m42, m43;
m51, m52, m53];
5, 4, [m11, m12, m13, m14;
m21, m22, m23, m24;
m31, m32, m33, m34;
m41, m42, m43, m44;
m51, m52, m53, m54];
5, 6, [m11, m12, m13, m14, m15, m16;
m21, m22, m23, m24, m25, m26;
m31, m32, m33, m34, m35, m36;
m41, m42, m43, m44, m45, m46;
m51, m52, m53, m54, m55, m56];
/*
* Rectangular matrices with 6 rows.
*/
U6, U2, m11:(0,0), m12:(0,1),
m21:(1,0), m22:(1,1),
m31:(2,0), m32:(2,1),
m41:(3,0), m42:(3,1),
m51:(4,0), m52:(4,1),
m61:(5,0), m62:(5,1);
U6, U3, m11:(0,0), m12:(0,1), m13:(0,2),
m21:(1,0), m22:(1,1), m23:(1,2),
m31:(2,0), m32:(2,1), m33:(2,2),
m41:(3,0), m42:(3,1), m43:(3,2),
m51:(4,0), m52:(4,1), m53:(4,2),
m61:(5,0), m62:(5,1), m63:(5,2);
U6, U4, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3),
m51:(4,0), m52:(4,1), m53:(4,2), m54:(4,3),
m61:(5,0), m62:(5,1), m63:(5,2), m64:(5,3);
U6, U5, m11:(0,0), m12:(0,1), m13:(0,2), m14:(0,3), m15:(0,4),
m21:(1,0), m22:(1,1), m23:(1,2), m24:(1,3), m25:(1,4),
m31:(2,0), m32:(2,1), m33:(2,2), m34:(2,3), m35:(2,4),
m41:(3,0), m42:(3,1), m43:(3,2), m44:(3,3), m45:(3,4),
m51:(4,0), m52:(4,1), m53:(4,2), m54:(4,3), m55:(4,4),
m61:(5,0), m62:(5,1), m63:(5,2), m64:(5,3), m65:(5,4);
6, 2, [m11, m12;
m21, m22;
m31, m32;
m41, m42;
m51, m52;
m61, m62];
6, 3, [m11, m12, m13;
m21, m22, m23;
m31, m32, m33;
m41, m42, m43;
m51, m52, m53;
m61, m62, m63];
6, 4, [m11, m12, m13, m14;
m21, m22, m23, m24;
m31, m32, m33, m34;
m41, m42, m43, m44;
m51, m52, m53, m54;
m61, m62, m63, m64];
6, 5, [m11, m12, m13, m14, m15;
m21, m22, m23, m24, m25;
m31, m32, m33, m34, m35;
m41, m42, m43, m44, m45;
m51, m52, m53, m54, m55;
m61, m62, m63, m64, m65];
/*
* Row vectors 1 .. 6.
*/
U1, U1, x:(0,0);
U1, U2, x:(0,0), y:(0,1);
U1, U3, x:(0,0), y:(0,1), z:(0,2);
U1, U4, x:(0,0), y:(0,1), z:(0,2), w:(0,3);
U1, U5, x:(0,0), y:(0,1), z:(0,2), w:(0,3), a:(0,4);
U1, U6, x:(0,0), y:(0,1), z:(0,2), w:(0,3), a:(0,4), b:(0,5);
1, 1, [x];
1, 2, [x, y];
1, 3, [x, y, z];
1, 4, [x, y, z, w];
1, 5, [x, y, z, w, a];
1, 6, [x, y, z, w, a, b];
/*
* Column vectors 1 .. 6.
*/
U2, U1, x:(0,0), y:(1,0);
U3, U1, x:(0,0), y:(1,0), z:(2,0);
U4, U1, x:(0,0), y:(1,0), z:(2,0), w:(3,0);
U5, U1, x:(0,0), y:(1,0), z:(2,0), w:(3,0), a:(4,0);
U6, U1, x:(0,0), y:(1,0), z:(2,0), w:(3,0), a:(4,0), b:(5,0);
2, 1, [x; y];
3, 1, [x; y; z];
4, 1, [x; y; z; w];
5, 1, [x; y; z; w; a];
6, 1, [x; y; z; w; a; b];
);
/*
@ -1047,34 +1073,35 @@ componentwise_constructors_impl!(
* Axis constructors.
*
*/
impl<N, R: DimName> VectorN<N, R>
impl<T, R: DimName> OVector<T, R>
where
N: Scalar + Zero + One,
DefaultAllocator: Allocator<N, R>,
R: ToTypenum,
T: Scalar + Zero + One,
DefaultAllocator: Allocator<T, R>,
{
/// The column vector with `val` as its i-th component.
#[inline]
pub fn ith(i: usize, val: N) -> Self {
pub fn ith(i: usize, val: T) -> Self {
let mut res = Self::zeros();
res[i] = val;
res
}
/// The column unit vector with `N::one()` as its i-th component.
/// The column unit vector with `T::one()` as its i-th component.
#[inline]
pub fn ith_axis(i: usize) -> Unit<Self> {
Unit::new_unchecked(Self::ith(i, N::one()))
Unit::new_unchecked(Self::ith(i, T::one()))
}
/// 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>,
R::Typenum: Cmp<typenum::U0, Output = Greater>,
{
let mut res = Self::zeros();
unsafe {
*res.vget_unchecked_mut(0) = N::one();
*res.vget_unchecked_mut(0) = T::one();
}
res
@ -1084,11 +1111,11 @@ where
#[inline]
pub fn y() -> Self
where
R::Value: Cmp<typenum::U1, Output = Greater>,
R::Typenum: Cmp<typenum::U1, Output = Greater>,
{
let mut res = Self::zeros();
unsafe {
*res.vget_unchecked_mut(1) = N::one();
*res.vget_unchecked_mut(1) = T::one();
}
res
@ -1098,11 +1125,11 @@ where
#[inline]
pub fn z() -> Self
where
R::Value: Cmp<typenum::U2, Output = Greater>,
R::Typenum: Cmp<typenum::U2, Output = Greater>,
{
let mut res = Self::zeros();
unsafe {
*res.vget_unchecked_mut(2) = N::one();
*res.vget_unchecked_mut(2) = T::one();
}
res
@ -1112,11 +1139,11 @@ where
#[inline]
pub fn w() -> Self
where
R::Value: Cmp<typenum::U3, Output = Greater>,
R::Typenum: Cmp<typenum::U3, Output = Greater>,
{
let mut res = Self::zeros();
unsafe {
*res.vget_unchecked_mut(3) = N::one();
*res.vget_unchecked_mut(3) = T::one();
}
res
@ -1126,11 +1153,11 @@ where
#[inline]
pub fn a() -> Self
where
R::Value: Cmp<typenum::U4, Output = Greater>,
R::Typenum: Cmp<typenum::U4, Output = Greater>,
{
let mut res = Self::zeros();
unsafe {
*res.vget_unchecked_mut(4) = N::one();
*res.vget_unchecked_mut(4) = T::one();
}
res
@ -1140,11 +1167,11 @@ where
#[inline]
pub fn b() -> Self
where
R::Value: Cmp<typenum::U5, Output = Greater>,
R::Typenum: Cmp<typenum::U5, Output = Greater>,
{
let mut res = Self::zeros();
unsafe {
*res.vget_unchecked_mut(5) = N::one();
*res.vget_unchecked_mut(5) = T::one();
}
res
@ -1154,7 +1181,7 @@ where
#[inline]
pub fn x_axis() -> Unit<Self>
where
R::Value: Cmp<typenum::U0, Output = Greater>,
R::Typenum: Cmp<typenum::U0, Output = Greater>,
{
Unit::new_unchecked(Self::x())
}
@ -1163,7 +1190,7 @@ where
#[inline]
pub fn y_axis() -> Unit<Self>
where
R::Value: Cmp<typenum::U1, Output = Greater>,
R::Typenum: Cmp<typenum::U1, Output = Greater>,
{
Unit::new_unchecked(Self::y())
}
@ -1172,7 +1199,7 @@ where
#[inline]
pub fn z_axis() -> Unit<Self>
where
R::Value: Cmp<typenum::U2, Output = Greater>,
R::Typenum: Cmp<typenum::U2, Output = Greater>,
{
Unit::new_unchecked(Self::z())
}
@ -1181,7 +1208,7 @@ where
#[inline]
pub fn w_axis() -> Unit<Self>
where
R::Value: Cmp<typenum::U3, Output = Greater>,
R::Typenum: Cmp<typenum::U3, Output = Greater>,
{
Unit::new_unchecked(Self::w())
}
@ -1190,7 +1217,7 @@ where
#[inline]
pub fn a_axis() -> Unit<Self>
where
R::Value: Cmp<typenum::U4, Output = Greater>,
R::Typenum: Cmp<typenum::U4, Output = Greater>,
{
Unit::new_unchecked(Self::a())
}
@ -1199,7 +1226,7 @@ where
#[inline]
pub fn b_axis() -> Unit<Self>
where
R::Value: Cmp<typenum::U5, Output = Greater>,
R::Typenum: Cmp<typenum::U5, Output = Greater>,
{
Unit::new_unchecked(Self::b())
}

View File

@ -1,12 +1,12 @@
use crate::base::dimension::{Dim, DimName, Dynamic, U1};
use crate::base::dimension::{Const, Dim, DimName, Dynamic};
use crate::base::matrix_slice::{SliceStorage, SliceStorageMut};
use crate::base::{MatrixSliceMN, MatrixSliceMutMN, Scalar};
use crate::base::{MatrixSlice, MatrixSliceMutMN, Scalar};
use num_rational::Ratio;
/// # Creating matrix slices from `&[T]`
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSliceMN<'a, N, R, C, RStride, CStride>
impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSlice<'a, T, R, C, RStride, CStride>
{
/// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances.
///
@ -14,7 +14,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn from_slice_with_strides_generic_unchecked(
data: &'a [N],
data: &'a [T],
start: usize,
nrows: R,
ncols: C,
@ -35,7 +35,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn from_slice_with_strides_generic(
data: &'a [N],
data: &'a [T],
nrows: R,
ncols: C,
rstride: RStride,
@ -56,19 +56,21 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
}
}
impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> {
impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSlice<'a, T, R, C> {
/// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances.
///
/// This method is unsafe because the input data array is not checked to contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn from_slice_generic_unchecked(
data: &'a [N],
data: &'a [T],
start: usize,
nrows: R,
ncols: C,
) -> Self {
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
Self::from_slice_with_strides_generic_unchecked(
data, start, nrows, ncols, Const::<1>, nrows,
)
}
/// Creates a matrix slice from an array and with dimensions and strides specified by generic types instances.
@ -76,41 +78,41 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> {
/// Panics if the input data array dose not contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn from_slice_generic(data: &'a [N], nrows: R, ncols: C) -> Self {
Self::from_slice_with_strides_generic(data, nrows, ncols, U1, nrows)
pub fn from_slice_generic(data: &'a [T], nrows: R, ncols: C) -> Self {
Self::from_slice_with_strides_generic(data, nrows, ncols, Const::<1>, nrows)
}
}
macro_rules! impl_constructors(
($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => {
impl<'a, N: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMN<'a, N, $($Dims),*> {
impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixSlice<'a, T, $($Dims),*> {
/// Creates a new matrix slice from the given data array.
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn from_slice(data: &'a [N], $($args: usize),*) -> Self {
pub fn from_slice(data: &'a [T], $($args: usize),*) -> Self {
Self::from_slice_generic(data, $($gargs),*)
}
/// Creates, without bound checking, a new matrix slice from the given data array.
#[inline]
pub unsafe fn from_slice_unchecked(data: &'a [N], start: usize, $($args: usize),*) -> Self {
pub unsafe fn from_slice_unchecked(data: &'a [T], start: usize, $($args: usize),*) -> Self {
Self::from_slice_generic_unchecked(data, start, $($gargs),*)
}
}
impl<'a, N: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMN<'a, N, $($Dims,)* Dynamic, Dynamic> {
impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixSlice<'a, T, $($Dims,)* Dynamic, Dynamic> {
/// Creates a new matrix slice with the specified strides from the given data array.
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn from_slice_with_strides(data: &'a [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
pub fn from_slice_with_strides(data: &'a [T], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic(data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
/// Creates, without bound checking, a new matrix slice with the specified strides from the given data array.
#[inline]
pub unsafe fn from_slice_with_strides_unchecked(data: &'a [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
pub unsafe fn from_slice_with_strides_unchecked(data: &'a [T], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic_unchecked(data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
}
@ -118,8 +120,8 @@ macro_rules! impl_constructors(
);
// TODO: this is not very pretty. We could find a better call syntax.
impl_constructors!(R, C; // Arguments for Matrix<N, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<N, ..., S>
impl_constructors!(R, C; // Arguments for Matrix<T, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<T, ..., S>
R::name(), C::name(); // Arguments for `_generic` constructors.
); // Arguments for non-generic constructors.
@ -139,8 +141,8 @@ impl_constructors!(Dynamic, Dynamic;
nrows, ncols);
/// # Creating mutable matrix slices from `&mut [T]`
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSliceMutMN<'a, N, R, C, RStride, CStride>
impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSliceMutMN<'a, T, R, C, RStride, CStride>
{
/// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions and strides specified by generic types instances.
///
@ -148,7 +150,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn from_slice_with_strides_generic_unchecked(
data: &'a mut [N],
data: &'a mut [T],
start: usize,
nrows: R,
ncols: C,
@ -169,7 +171,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
/// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn from_slice_with_strides_generic(
data: &'a mut [N],
data: &'a mut [T],
nrows: R,
ncols: C,
rstride: RStride,
@ -212,19 +214,21 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
}
}
impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> {
impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, T, R, C> {
/// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions specified by generic types instances.
///
/// This method is unsafe because the input data array is not checked to contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub unsafe fn from_slice_generic_unchecked(
data: &'a mut [N],
data: &'a mut [T],
start: usize,
nrows: R,
ncols: C,
) -> Self {
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
Self::from_slice_with_strides_generic_unchecked(
data, start, nrows, ncols, Const::<1>, nrows,
)
}
/// Creates a mutable matrix slice from an array and with dimensions and strides specified by generic types instances.
@ -232,42 +236,42 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> {
/// Panics if the input data array dose not contain enough elements.
/// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`.
#[inline]
pub fn from_slice_generic(data: &'a mut [N], nrows: R, ncols: C) -> Self {
Self::from_slice_with_strides_generic(data, nrows, ncols, U1, nrows)
pub fn from_slice_generic(data: &'a mut [T], nrows: R, ncols: C) -> Self {
Self::from_slice_with_strides_generic(data, nrows, ncols, Const::<1>, nrows)
}
}
macro_rules! impl_constructors_mut(
($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => {
impl<'a, N: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, N, $($Dims),*> {
impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, T, $($Dims),*> {
/// Creates a new mutable matrix slice from the given data array.
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn from_slice(data: &'a mut [N], $($args: usize),*) -> Self {
pub fn from_slice(data: &'a mut [T], $($args: usize),*) -> Self {
Self::from_slice_generic(data, $($gargs),*)
}
/// Creates, without bound checking, a new mutable matrix slice from the given data array.
#[inline]
pub unsafe fn from_slice_unchecked(data: &'a mut [N], start: usize, $($args: usize),*) -> Self {
pub unsafe fn from_slice_unchecked(data: &'a mut [T], start: usize, $($args: usize),*) -> Self {
Self::from_slice_generic_unchecked(data, start, $($gargs),*)
}
}
impl<'a, N: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, N, $($Dims,)* Dynamic, Dynamic> {
impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, T, $($Dims,)* Dynamic, Dynamic> {
/// Creates a new mutable matrix slice with the specified strides from the given data array.
///
/// Panics if `data` does not contain enough elements.
#[inline]
pub fn from_slice_with_strides_mut(data: &'a mut [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
pub fn from_slice_with_strides_mut(data: &'a mut [T], $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic(
data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
/// Creates, without bound checking, a new mutable matrix slice with the specified strides from the given data array.
#[inline]
pub unsafe fn from_slice_with_strides_unchecked(data: &'a mut [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
pub unsafe fn from_slice_with_strides_unchecked(data: &'a mut [T], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self {
Self::from_slice_with_strides_generic_unchecked(
data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride))
}
@ -276,8 +280,8 @@ macro_rules! impl_constructors_mut(
);
// TODO: this is not very pretty. We could find a better call syntax.
impl_constructors_mut!(R, C; // Arguments for Matrix<N, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<N, ..., S>
impl_constructors_mut!(R, C; // Arguments for Matrix<T, ..., S>
=> R: DimName, => C: DimName; // Type parameters for impl<T, ..., S>
R::name(), C::name(); // Arguments for `_generic` constructors.
); // Arguments for non-generic constructors.

View File

@ -5,10 +5,6 @@ use std::convert::{AsMut, AsRef, From, Into};
use std::mem;
use std::ptr;
use generic_array::ArrayLength;
use std::ops::Mul;
use typenum::Prod;
use simba::simd::{PrimitiveSimdValue, SimdValue};
use crate::base::allocator::{Allocator, SameShapeAllocator};
@ -16,13 +12,13 @@ use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstr
#[cfg(any(feature = "std", feature = "alloc"))]
use crate::base::dimension::Dynamic;
use crate::base::dimension::{
Dim, DimName, U1, U10, U11, U12, U13, U14, U15, U16, U2, U3, U4, U5, U6, U7, U8, U9,
Const, Dim, DimName, U1, U10, U11, U12, U13, U14, U15, U16, U2, U3, U4, U5, U6, U7, U8, U9,
};
use crate::base::iter::{MatrixIter, MatrixIterMut};
use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut};
use crate::base::{
ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixMN, MatrixSlice,
MatrixSliceMut, Scalar,
ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixSlice,
MatrixSliceMut, OMatrix, Scalar,
};
#[cfg(any(feature = "std", feature = "alloc"))]
use crate::base::{DVector, VecStorage};
@ -30,30 +26,30 @@ use crate::base::{SliceStorage, SliceStorageMut};
use crate::constraint::DimEq;
// TODO: too bad this won't work allo slice conversions.
impl<N1, N2, R1, C1, R2, C2> SubsetOf<MatrixMN<N2, R2, C2>> for MatrixMN<N1, R1, C1>
impl<T1, T2, R1, C1, R2, C2> SubsetOf<OMatrix<T2, R2, C2>> for OMatrix<T1, R1, C1>
where
R1: Dim,
C1: Dim,
R2: Dim,
C2: Dim,
N1: Scalar,
N2: Scalar + SupersetOf<N1>,
T1: Scalar,
T2: Scalar + SupersetOf<T1>,
DefaultAllocator:
Allocator<N2, R2, C2> + Allocator<N1, R1, C1> + SameShapeAllocator<N1, R1, C1, R2, C2>,
Allocator<T2, R2, C2> + Allocator<T1, R1, C1> + SameShapeAllocator<T1, R1, C1, R2, C2>,
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
{
#[inline]
fn to_superset(&self) -> MatrixMN<N2, R2, C2> {
fn to_superset(&self) -> OMatrix<T2, R2, C2> {
let (nrows, ncols) = self.shape();
let nrows2 = R2::from_usize(nrows);
let ncols2 = C2::from_usize(ncols);
let mut res: MatrixMN<N2, R2, C2> =
let mut res: OMatrix<T2, R2, C2> =
unsafe { crate::unimplemented_or_uninitialized_generic!(nrows2, ncols2) };
for i in 0..nrows {
for j in 0..ncols {
unsafe {
*res.get_unchecked_mut((i, j)) = N2::from_subset(self.get_unchecked((i, j)))
*res.get_unchecked_mut((i, j)) = T2::from_subset(self.get_unchecked((i, j)))
}
}
}
@ -62,12 +58,12 @@ where
}
#[inline]
fn is_in_subset(m: &MatrixMN<N2, R2, C2>) -> bool {
fn is_in_subset(m: &OMatrix<T2, R2, C2>) -> bool {
m.iter().all(|e| e.is_in_subset())
}
#[inline]
fn from_superset_unchecked(m: &MatrixMN<N2, R2, C2>) -> Self {
fn from_superset_unchecked(m: &OMatrix<T2, R2, C2>) -> Self {
let (nrows2, ncols2) = m.shape();
let nrows = R1::from_usize(nrows2);
let ncols = C1::from_usize(ncols2);
@ -85,9 +81,9 @@ where
}
}
impl<'a, N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> IntoIterator for &'a Matrix<N, R, C, S> {
type Item = &'a N;
type IntoIter = MatrixIter<'a, N, R, C, S>;
impl<'a, T: Scalar, R: Dim, C: Dim, S: Storage<T, R, C>> IntoIterator for &'a Matrix<T, R, C, S> {
type Item = &'a T;
type IntoIter = MatrixIter<'a, T, R, C, S>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
@ -95,11 +91,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> IntoIterator for &'a Ma
}
}
impl<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> IntoIterator
for &'a mut Matrix<N, R, C, S>
impl<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut<T, R, C>> IntoIterator
for &'a mut Matrix<T, R, C, S>
{
type Item = &'a mut N;
type IntoIter = MatrixIterMut<'a, N, R, C, S>;
type Item = &'a mut T;
type IntoIter = MatrixIterMut<'a, T, R, C, S>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
@ -109,11 +105,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> IntoIterator
macro_rules! impl_from_into_asref_1D(
($(($NRows: ident, $NCols: ident) => $SZ: expr);* $(;)*) => {$(
impl<N> From<[N; $SZ]> for MatrixMN<N, $NRows, $NCols>
where N: Scalar,
DefaultAllocator: Allocator<N, $NRows, $NCols> {
impl<T> From<[T; $SZ]> for OMatrix<T, $NRows, $NCols>
where T: Scalar,
DefaultAllocator: Allocator<T, $NRows, $NCols> {
#[inline]
fn from(arr: [N; $SZ]) -> Self {
fn from(arr: [T; $SZ]) -> Self {
unsafe {
let mut res = Self::new_uninitialized();
ptr::copy_nonoverlapping(&arr[0], (*res.as_mut_ptr()).data.ptr_mut(), $SZ);
@ -123,35 +119,35 @@ macro_rules! impl_from_into_asref_1D(
}
}
impl<N, S> Into<[N; $SZ]> for Matrix<N, $NRows, $NCols, S>
where N: Scalar,
S: ContiguousStorage<N, $NRows, $NCols> {
impl<T, S> Into<[T; $SZ]> for Matrix<T, $NRows, $NCols, S>
where T: Scalar,
S: ContiguousStorage<T, $NRows, $NCols> {
#[inline]
fn into(self) -> [N; $SZ] {
let mut res = mem::MaybeUninit::<[N; $SZ]>::uninit();
fn into(self) -> [T; $SZ] {
let mut res = mem::MaybeUninit::<[T; $SZ]>::uninit();
unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZ) };
unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut T, $SZ) };
unsafe { res.assume_init() }
}
}
impl<N, S> AsRef<[N; $SZ]> for Matrix<N, $NRows, $NCols, S>
where N: Scalar,
S: ContiguousStorage<N, $NRows, $NCols> {
impl<T, S> AsRef<[T; $SZ]> for Matrix<T, $NRows, $NCols, S>
where T: Scalar,
S: ContiguousStorage<T, $NRows, $NCols> {
#[inline]
fn as_ref(&self) -> &[N; $SZ] {
fn as_ref(&self) -> &[T; $SZ] {
unsafe {
mem::transmute(self.data.ptr())
}
}
}
impl<N, S> AsMut<[N; $SZ]> for Matrix<N, $NRows, $NCols, S>
where N: Scalar,
S: ContiguousStorageMut<N, $NRows, $NCols> {
impl<T, S> AsMut<[T; $SZ]> for Matrix<T, $NRows, $NCols, S>
where T: Scalar,
S: ContiguousStorageMut<T, $NRows, $NCols> {
#[inline]
fn as_mut(&mut self) -> &mut [N; $SZ] {
fn as_mut(&mut self) -> &mut [T; $SZ] {
unsafe {
mem::transmute(self.data.ptr_mut())
}
@ -177,10 +173,10 @@ impl_from_into_asref_1D!(
macro_rules! impl_from_into_asref_2D(
($(($NRows: ty, $NCols: ty) => ($SZRows: expr, $SZCols: expr));* $(;)*) => {$(
impl<N: Scalar> From<[[N; $SZRows]; $SZCols]> for MatrixMN<N, $NRows, $NCols>
where DefaultAllocator: Allocator<N, $NRows, $NCols> {
impl<T: Scalar> From<[[T; $SZRows]; $SZCols]> for OMatrix<T, $NRows, $NCols>
where DefaultAllocator: Allocator<T, $NRows, $NCols> {
#[inline]
fn from(arr: [[N; $SZRows]; $SZCols]) -> Self {
fn from(arr: [[T; $SZRows]; $SZCols]) -> Self {
unsafe {
let mut res = Self::new_uninitialized();
ptr::copy_nonoverlapping(&arr[0][0], (*res.as_mut_ptr()).data.ptr_mut(), $SZRows * $SZCols);
@ -190,32 +186,32 @@ macro_rules! impl_from_into_asref_2D(
}
}
impl<N: Scalar, S> Into<[[N; $SZRows]; $SZCols]> for Matrix<N, $NRows, $NCols, S>
where S: ContiguousStorage<N, $NRows, $NCols> {
impl<T: Scalar, S> Into<[[T; $SZRows]; $SZCols]> for Matrix<T, $NRows, $NCols, S>
where S: ContiguousStorage<T, $NRows, $NCols> {
#[inline]
fn into(self) -> [[N; $SZRows]; $SZCols] {
let mut res = mem::MaybeUninit::<[[N; $SZRows]; $SZCols]>::uninit();
fn into(self) -> [[T; $SZRows]; $SZCols] {
let mut res = mem::MaybeUninit::<[[T; $SZRows]; $SZCols]>::uninit();
unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZRows * $SZCols) };
unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut T, $SZRows * $SZCols) };
unsafe { res.assume_init() }
}
}
impl<N: Scalar, S> AsRef<[[N; $SZRows]; $SZCols]> for Matrix<N, $NRows, $NCols, S>
where S: ContiguousStorage<N, $NRows, $NCols> {
impl<T: Scalar, S> AsRef<[[T; $SZRows]; $SZCols]> for Matrix<T, $NRows, $NCols, S>
where S: ContiguousStorage<T, $NRows, $NCols> {
#[inline]
fn as_ref(&self) -> &[[N; $SZRows]; $SZCols] {
fn as_ref(&self) -> &[[T; $SZRows]; $SZCols] {
unsafe {
mem::transmute(self.data.ptr())
}
}
}
impl<N: Scalar, S> AsMut<[[N; $SZRows]; $SZCols]> for Matrix<N, $NRows, $NCols, S>
where S: ContiguousStorageMut<N, $NRows, $NCols> {
impl<T: Scalar, S> AsMut<[[T; $SZRows]; $SZCols]> for Matrix<T, $NRows, $NCols, S>
where S: ContiguousStorageMut<T, $NRows, $NCols> {
#[inline]
fn as_mut(&mut self) -> &mut [[N; $SZRows]; $SZCols] {
fn as_mut(&mut self) -> &mut [[T; $SZRows]; $SZCols] {
unsafe {
mem::transmute(self.data.ptr_mut())
}
@ -233,111 +229,105 @@ impl_from_into_asref_2D!(
(U6, U2) => (6, 2); (U6, U3) => (6, 3); (U6, U4) => (6, 4); (U6, U5) => (6, 5); (U6, U6) => (6, 6);
);
impl<'a, N, R, C, RStride, CStride> From<MatrixSlice<'a, N, R, C, RStride, CStride>>
for Matrix<N, R, C, ArrayStorage<N, R, C>>
impl<'a, T, RStride, CStride, const R: usize, const C: usize>
From<MatrixSlice<'a, T, Const<R>, Const<C>, RStride, CStride>>
for Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>>
where
N: Scalar,
R: DimName,
C: DimName,
T: Scalar,
RStride: Dim,
CStride: Dim,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
fn from(matrix_slice: MatrixSlice<'a, N, R, C, RStride, CStride>) -> Self {
fn from(matrix_slice: MatrixSlice<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
matrix_slice.into_owned()
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, N, C, RStride, CStride> From<MatrixSlice<'a, N, Dynamic, C, RStride, CStride>>
for Matrix<N, Dynamic, C, VecStorage<N, Dynamic, C>>
impl<'a, T, C, RStride, CStride> From<MatrixSlice<'a, T, Dynamic, C, RStride, CStride>>
for Matrix<T, Dynamic, C, VecStorage<T, Dynamic, C>>
where
N: Scalar,
T: Scalar,
C: Dim,
RStride: Dim,
CStride: Dim,
{
fn from(matrix_slice: MatrixSlice<'a, N, Dynamic, C, RStride, CStride>) -> Self {
fn from(matrix_slice: MatrixSlice<'a, T, Dynamic, C, RStride, CStride>) -> Self {
matrix_slice.into_owned()
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, N, R, RStride, CStride> From<MatrixSlice<'a, N, R, Dynamic, RStride, CStride>>
for Matrix<N, R, Dynamic, VecStorage<N, R, Dynamic>>
impl<'a, T, R, RStride, CStride> From<MatrixSlice<'a, T, R, Dynamic, RStride, CStride>>
for Matrix<T, R, Dynamic, VecStorage<T, R, Dynamic>>
where
N: Scalar,
T: Scalar,
R: DimName,
RStride: Dim,
CStride: Dim,
{
fn from(matrix_slice: MatrixSlice<'a, N, R, Dynamic, RStride, CStride>) -> Self {
fn from(matrix_slice: MatrixSlice<'a, T, R, Dynamic, RStride, CStride>) -> Self {
matrix_slice.into_owned()
}
}
impl<'a, N, R, C, RStride, CStride> From<MatrixSliceMut<'a, N, R, C, RStride, CStride>>
for Matrix<N, R, C, ArrayStorage<N, R, C>>
impl<'a, T, RStride, CStride, const R: usize, const C: usize>
From<MatrixSliceMut<'a, T, Const<R>, Const<C>, RStride, CStride>>
for Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>>
where
N: Scalar,
R: DimName,
C: DimName,
T: Scalar,
RStride: Dim,
CStride: Dim,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
{
fn from(matrix_slice: MatrixSliceMut<'a, N, R, C, RStride, CStride>) -> Self {
fn from(matrix_slice: MatrixSliceMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
matrix_slice.into_owned()
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, N, C, RStride, CStride> From<MatrixSliceMut<'a, N, Dynamic, C, RStride, CStride>>
for Matrix<N, Dynamic, C, VecStorage<N, Dynamic, C>>
impl<'a, T, C, RStride, CStride> From<MatrixSliceMut<'a, T, Dynamic, C, RStride, CStride>>
for Matrix<T, Dynamic, C, VecStorage<T, Dynamic, C>>
where
N: Scalar,
T: Scalar,
C: Dim,
RStride: Dim,
CStride: Dim,
{
fn from(matrix_slice: MatrixSliceMut<'a, N, Dynamic, C, RStride, CStride>) -> Self {
fn from(matrix_slice: MatrixSliceMut<'a, T, Dynamic, C, RStride, CStride>) -> Self {
matrix_slice.into_owned()
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, N, R, RStride, CStride> From<MatrixSliceMut<'a, N, R, Dynamic, RStride, CStride>>
for Matrix<N, R, Dynamic, VecStorage<N, R, Dynamic>>
impl<'a, T, R, RStride, CStride> From<MatrixSliceMut<'a, T, R, Dynamic, RStride, CStride>>
for Matrix<T, R, Dynamic, VecStorage<T, R, Dynamic>>
where
N: Scalar,
T: Scalar,
R: DimName,
RStride: Dim,
CStride: Dim,
{
fn from(matrix_slice: MatrixSliceMut<'a, N, R, Dynamic, RStride, CStride>) -> Self {
fn from(matrix_slice: MatrixSliceMut<'a, T, R, Dynamic, RStride, CStride>) -> Self {
matrix_slice.into_owned()
}
}
impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix<N, R, C, S>>
for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride>
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix<T, R, C, S>>
for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride>
where
N: Scalar,
T: Scalar,
R: Dim,
C: Dim,
RSlice: Dim,
CSlice: Dim,
RStride: Dim,
CStride: Dim,
S: Storage<N, R, C>,
S: Storage<T, R, C>,
ShapeConstraint: DimEq<R, RSlice>
+ DimEq<C, CSlice>
+ DimEq<RStride, S::RStride>
+ DimEq<CStride, S::CStride>,
{
fn from(m: &'a Matrix<N, R, C, S>) -> Self {
fn from(m: &'a Matrix<T, R, C, S>) -> Self {
let (row, col) = m.data.shape();
let row_slice = RSlice::from_usize(row.value());
let col_slice = CSlice::from_usize(col.value());
@ -358,23 +348,23 @@ where
}
}
impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<N, R, C, S>>
for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride>
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride>
where
N: Scalar,
T: Scalar,
R: Dim,
C: Dim,
RSlice: Dim,
CSlice: Dim,
RStride: Dim,
CStride: Dim,
S: Storage<N, R, C>,
S: Storage<T, R, C>,
ShapeConstraint: DimEq<R, RSlice>
+ DimEq<C, CSlice>
+ DimEq<RStride, S::RStride>
+ DimEq<CStride, S::CStride>,
{
fn from(m: &'a mut Matrix<N, R, C, S>) -> Self {
fn from(m: &'a mut Matrix<T, R, C, S>) -> Self {
let (row, col) = m.data.shape();
let row_slice = RSlice::from_usize(row.value());
let col_slice = CSlice::from_usize(col.value());
@ -395,23 +385,23 @@ where
}
}
impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<N, R, C, S>>
for MatrixSliceMut<'a, N, RSlice, CSlice, RStride, CStride>
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
for MatrixSliceMut<'a, T, RSlice, CSlice, RStride, CStride>
where
N: Scalar,
T: Scalar,
R: Dim,
C: Dim,
RSlice: Dim,
CSlice: Dim,
RStride: Dim,
CStride: Dim,
S: StorageMut<N, R, C>,
S: StorageMut<T, R, C>,
ShapeConstraint: DimEq<R, RSlice>
+ DimEq<C, CSlice>
+ DimEq<RStride, S::RStride>
+ DimEq<CStride, S::CStride>,
{
fn from(m: &'a mut Matrix<N, R, C, S>) -> Self {
fn from(m: &'a mut Matrix<T, R, C, S>) -> Self {
let (row, col) = m.data.shape();
let row_slice = RSlice::from_usize(row.value());
let col_slice = CSlice::from_usize(col.value());
@ -433,54 +423,54 @@ where
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, N: Scalar> From<Vec<N>> for DVector<N> {
impl<'a, T: Scalar> From<Vec<T>> for DVector<T> {
#[inline]
fn from(vec: Vec<N>) -> Self {
fn from(vec: Vec<T>) -> Self {
Self::from_vec(vec)
}
}
impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage<N, R, C>> Into<&'a [N]>
for &'a Matrix<N, R, C, S>
impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage<T, R, C>> Into<&'a [T]>
for &'a Matrix<T, R, C, S>
{
#[inline]
fn into(self) -> &'a [N] {
fn into(self) -> &'a [T] {
self.as_slice()
}
}
impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut<N, R, C>> Into<&'a mut [N]>
for &'a mut Matrix<N, R, C, S>
impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut<T, R, C>> Into<&'a mut [T]>
for &'a mut Matrix<T, R, C, S>
{
#[inline]
fn into(self) -> &'a mut [N] {
fn into(self) -> &'a mut [T] {
self.as_mut_slice()
}
}
impl<'a, N: Scalar + Copy> From<&'a [N]> for DVectorSlice<'a, N> {
impl<'a, T: Scalar + Copy> From<&'a [T]> for DVectorSlice<'a, T> {
#[inline]
fn from(slice: &'a [N]) -> Self {
fn from(slice: &'a [T]) -> Self {
Self::from_slice(slice, slice.len())
}
}
impl<'a, N: Scalar + Copy> From<&'a mut [N]> for DVectorSliceMut<'a, N> {
impl<'a, T: Scalar + Copy> From<&'a mut [T]> for DVectorSliceMut<'a, T> {
#[inline]
fn from(slice: &'a mut [N]) -> Self {
fn from(slice: &'a mut [T]) -> Self {
Self::from_slice(slice, slice.len())
}
}
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 2]>
for MatrixMN<N, R, C>
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[OMatrix<T::Element, R, C>; 2]>
for OMatrix<T, R, C>
where
N: From<[<N as SimdValue>::Element; 2]>,
N::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
T: From<[<T as SimdValue>::Element; 2]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
{
#[inline]
fn from(arr: [MatrixMN<N::Element, R, C>; 2]) -> Self {
fn from(arr: [OMatrix<T::Element, R, C>; 2]) -> Self {
let (nrows, ncols) = arr[0].data.shape();
Self::from_fn_generic(nrows, ncols, |i, j| {
@ -493,15 +483,15 @@ where
}
}
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 4]>
for MatrixMN<N, R, C>
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[OMatrix<T::Element, R, C>; 4]>
for OMatrix<T, R, C>
where
N: From<[<N as SimdValue>::Element; 4]>,
N::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
T: From<[<T as SimdValue>::Element; 4]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
{
#[inline]
fn from(arr: [MatrixMN<N::Element, R, C>; 4]) -> Self {
fn from(arr: [OMatrix<T::Element, R, C>; 4]) -> Self {
let (nrows, ncols) = arr[0].data.shape();
Self::from_fn_generic(nrows, ncols, |i, j| {
@ -516,15 +506,15 @@ where
}
}
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 8]>
for MatrixMN<N, R, C>
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[OMatrix<T::Element, R, C>; 8]>
for OMatrix<T, R, C>
where
N: From<[<N as SimdValue>::Element; 8]>,
N::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
T: From<[<T as SimdValue>::Element; 8]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
{
#[inline]
fn from(arr: [MatrixMN<N::Element, R, C>; 8]) -> Self {
fn from(arr: [OMatrix<T::Element, R, C>; 8]) -> Self {
let (nrows, ncols) = arr[0].data.shape();
Self::from_fn_generic(nrows, ncols, |i, j| {
@ -543,14 +533,14 @@ where
}
}
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 16]>
for MatrixMN<N, R, C>
impl<T: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[OMatrix<T::Element, R, C>; 16]>
for OMatrix<T, R, C>
where
N: From<[<N as SimdValue>::Element; 16]>,
N::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
T: From<[<T as SimdValue>::Element; 16]>,
T::Element: Scalar + SimdValue,
DefaultAllocator: Allocator<T, R, C> + Allocator<T::Element, R, C>,
{
fn from(arr: [MatrixMN<N::Element, R, C>; 16]) -> Self {
fn from(arr: [OMatrix<T::Element, R, C>; 16]) -> Self {
let (nrows, ncols) = arr[0].data.shape();
Self::from_fn_generic(nrows, ncols, |i, j| {

Some files were not shown because too many files have changed in this diff Show More