2020-11-19 23:18:42 +08:00
|
|
|
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
|
|
|
|
use alloc::vec::Vec;
|
2020-03-21 19:16:46 +08:00
|
|
|
|
use simba::scalar::{SubsetOf, SupersetOf};
|
2018-05-19 23:15:15 +08:00
|
|
|
|
use std::convert::{AsMut, AsRef, From, Into};
|
|
|
|
|
use std::mem;
|
|
|
|
|
use std::ptr;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2018-10-13 16:25:34 +08:00
|
|
|
|
use generic_array::ArrayLength;
|
2018-09-29 04:54:41 +08:00
|
|
|
|
use std::ops::Mul;
|
|
|
|
|
use typenum::Prod;
|
|
|
|
|
|
2020-03-23 16:16:01 +08:00
|
|
|
|
use simba::simd::{PrimitiveSimdValue, SimdValue};
|
|
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
|
use crate::base::allocator::{Allocator, SameShapeAllocator};
|
|
|
|
|
use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
|
2020-03-21 19:16:46 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
|
|
|
use crate::base::dimension::Dynamic;
|
2019-03-23 21:29:07 +08:00
|
|
|
|
use crate::base::dimension::{
|
2019-02-03 22:16:50 +08:00
|
|
|
|
Dim, DimName, U1, U10, U11, U12, U13, U14, U15, U16, U2, U3, U4, U5, U6, U7, U8, U9,
|
2018-10-13 16:25:34 +08:00
|
|
|
|
};
|
2019-03-23 21:29:07 +08:00
|
|
|
|
use crate::base::iter::{MatrixIter, MatrixIterMut};
|
|
|
|
|
use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut};
|
2020-03-21 19:16:46 +08:00
|
|
|
|
use crate::base::{
|
|
|
|
|
ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixMN, MatrixSlice,
|
|
|
|
|
MatrixSliceMut, Scalar,
|
|
|
|
|
};
|
2020-11-19 23:18:42 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
|
|
|
use crate::base::{DVector, VecStorage};
|
2019-11-06 00:11:39 +08:00
|
|
|
|
use crate::base::{SliceStorage, SliceStorageMut};
|
2019-11-05 00:53:21 +08:00
|
|
|
|
use crate::constraint::DimEq;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
2020-11-15 23:57:49 +08:00
|
|
|
|
// TODO: too bad this won't work allo slice conversions.
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<N1, N2, R1, C1, R2, C2> SubsetOf<MatrixMN<N2, R2, C2>> for MatrixMN<N1, R1, C1>
|
2018-02-02 19:26:35 +08:00
|
|
|
|
where
|
|
|
|
|
R1: Dim,
|
|
|
|
|
C1: Dim,
|
|
|
|
|
R2: Dim,
|
|
|
|
|
C2: Dim,
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N1: Scalar,
|
|
|
|
|
N2: Scalar + SupersetOf<N1>,
|
2018-05-19 23:15:15 +08:00
|
|
|
|
DefaultAllocator:
|
|
|
|
|
Allocator<N2, R2, C2> + Allocator<N1, R1, C1> + SameShapeAllocator<N1, R1, C1, R2, C2>,
|
2018-02-02 19:26:35 +08:00
|
|
|
|
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
|
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
fn to_superset(&self) -> MatrixMN<N2, R2, C2> {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
let (nrows, ncols) = self.shape();
|
|
|
|
|
let nrows2 = R2::from_usize(nrows);
|
|
|
|
|
let ncols2 = C2::from_usize(ncols);
|
|
|
|
|
|
2020-11-28 05:00:48 +08:00
|
|
|
|
let mut res: MatrixMN<N2, R2, C2> =
|
|
|
|
|
unsafe { crate::unimplemented_or_uninitialized_generic!(nrows2, ncols2) };
|
2018-02-02 19:26:35 +08:00
|
|
|
|
for i in 0..nrows {
|
|
|
|
|
for j in 0..ncols {
|
2020-03-21 19:16:46 +08:00
|
|
|
|
unsafe {
|
|
|
|
|
*res.get_unchecked_mut((i, j)) = N2::from_subset(self.get_unchecked((i, j)))
|
|
|
|
|
}
|
2016-12-05 05:44:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
fn is_in_subset(m: &MatrixMN<N2, R2, C2>) -> bool {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
m.iter().all(|e| e.is_in_subset())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2020-03-21 19:16:46 +08:00
|
|
|
|
fn from_superset_unchecked(m: &MatrixMN<N2, R2, C2>) -> Self {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
let (nrows2, ncols2) = m.shape();
|
|
|
|
|
let nrows = R1::from_usize(nrows2);
|
|
|
|
|
let ncols = C1::from_usize(ncols2);
|
|
|
|
|
|
2020-11-28 04:58:48 +08:00
|
|
|
|
let mut res: Self = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) };
|
2018-02-02 19:26:35 +08:00
|
|
|
|
for i in 0..nrows2 {
|
|
|
|
|
for j in 0..ncols2 {
|
2020-03-21 19:16:46 +08:00
|
|
|
|
unsafe {
|
|
|
|
|
*res.get_unchecked_mut((i, j)) = m.get_unchecked((i, j)).to_subset_unchecked()
|
|
|
|
|
}
|
2016-12-05 05:44:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-18 20:28:22 +08:00
|
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
|
impl<'a, N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> IntoIterator for &'a Matrix<N, R, C, S> {
|
2018-02-02 19:26:35 +08:00
|
|
|
|
type Item = &'a N;
|
2017-04-11 06:13:28 +08:00
|
|
|
|
type IntoIter = MatrixIter<'a, N, R, C, S>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
|
self.iter()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
|
impl<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> IntoIterator
|
2018-05-19 23:15:15 +08:00
|
|
|
|
for &'a mut Matrix<N, R, C, S>
|
|
|
|
|
{
|
2018-02-02 19:26:35 +08:00
|
|
|
|
type Item = &'a mut N;
|
2017-04-11 06:13:28 +08:00
|
|
|
|
type IntoIter = MatrixIterMut<'a, N, R, C, S>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn into_iter(self) -> Self::IntoIter {
|
|
|
|
|
self.iter_mut()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 20:28:22 +08:00
|
|
|
|
macro_rules! impl_from_into_asref_1D(
|
2017-02-27 05:15:11 +08:00
|
|
|
|
($(($NRows: ident, $NCols: ident) => $SZ: expr);* $(;)*) => {$(
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<N> From<[N; $SZ]> for MatrixMN<N, $NRows, $NCols>
|
2019-12-17 07:09:14 +08:00
|
|
|
|
where N: Scalar,
|
2017-08-03 01:37:44 +08:00
|
|
|
|
DefaultAllocator: Allocator<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn from(arr: [N; $SZ]) -> Self {
|
|
|
|
|
unsafe {
|
|
|
|
|
let mut res = Self::new_uninitialized();
|
2020-11-27 12:25:36 +08:00
|
|
|
|
ptr::copy_nonoverlapping(&arr[0], (*res.as_mut_ptr()).data.ptr_mut(), $SZ);
|
2017-02-18 20:28:22 +08:00
|
|
|
|
|
2020-11-27 12:25:36 +08:00
|
|
|
|
res.assume_init()
|
2017-02-18 20:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 05:15:11 +08:00
|
|
|
|
impl<N, S> Into<[N; $SZ]> for Matrix<N, $NRows, $NCols, S>
|
2019-12-17 07:09:14 +08:00
|
|
|
|
where N: Scalar,
|
2017-08-03 01:37:44 +08:00
|
|
|
|
S: ContiguousStorage<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn into(self) -> [N; $SZ] {
|
2020-04-01 04:50:26 +08:00
|
|
|
|
let mut res = mem::MaybeUninit::<[N; $SZ]>::uninit();
|
2017-02-18 20:28:22 +08:00
|
|
|
|
|
2020-04-01 13:14:32 +08:00
|
|
|
|
unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZ) };
|
2020-04-01 04:50:26 +08:00
|
|
|
|
|
2020-04-01 13:14:32 +08:00
|
|
|
|
unsafe { res.assume_init() }
|
2017-02-18 20:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 05:15:11 +08:00
|
|
|
|
impl<N, S> AsRef<[N; $SZ]> for Matrix<N, $NRows, $NCols, S>
|
2019-12-17 07:09:14 +08:00
|
|
|
|
where N: Scalar,
|
2017-08-03 01:37:44 +08:00
|
|
|
|
S: ContiguousStorage<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn as_ref(&self) -> &[N; $SZ] {
|
|
|
|
|
unsafe {
|
|
|
|
|
mem::transmute(self.data.ptr())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 05:15:11 +08:00
|
|
|
|
impl<N, S> AsMut<[N; $SZ]> for Matrix<N, $NRows, $NCols, S>
|
2019-12-17 07:09:14 +08:00
|
|
|
|
where N: Scalar,
|
2017-08-03 01:37:44 +08:00
|
|
|
|
S: ContiguousStorageMut<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn as_mut(&mut self) -> &mut [N; $SZ] {
|
|
|
|
|
unsafe {
|
|
|
|
|
mem::transmute(self.data.ptr_mut())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)*}
|
|
|
|
|
);
|
|
|
|
|
|
2017-02-27 05:15:11 +08:00
|
|
|
|
// Implement for vectors of dimension 1 .. 16.
|
2017-02-18 20:28:22 +08:00
|
|
|
|
impl_from_into_asref_1D!(
|
2017-02-27 05:15:11 +08:00
|
|
|
|
// Row vectors.
|
|
|
|
|
(U1, U1 ) => 1; (U1, U2 ) => 2; (U1, U3 ) => 3; (U1, U4 ) => 4;
|
|
|
|
|
(U1, U5 ) => 5; (U1, U6 ) => 6; (U1, U7 ) => 7; (U1, U8 ) => 8;
|
|
|
|
|
(U1, U9 ) => 9; (U1, U10) => 10; (U1, U11) => 11; (U1, U12) => 12;
|
|
|
|
|
(U1, U13) => 13; (U1, U14) => 14; (U1, U15) => 15; (U1, U16) => 16;
|
|
|
|
|
|
|
|
|
|
// Column vectors.
|
|
|
|
|
(U2 , U1) => 2; (U3 , U1) => 3; (U4 , U1) => 4;
|
|
|
|
|
(U5 , U1) => 5; (U6 , U1) => 6; (U7 , U1) => 7; (U8 , U1) => 8;
|
|
|
|
|
(U9 , U1) => 9; (U10, U1) => 10; (U11, U1) => 11; (U12, U1) => 12;
|
|
|
|
|
(U13, U1) => 13; (U14, U1) => 14; (U15, U1) => 15; (U16, U1) => 16;
|
2017-02-18 20:28:22 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
macro_rules! impl_from_into_asref_2D(
|
|
|
|
|
($(($NRows: ty, $NCols: ty) => ($SZRows: expr, $SZCols: expr));* $(;)*) => {$(
|
2019-12-17 07:09:14 +08:00
|
|
|
|
impl<N: Scalar> From<[[N; $SZRows]; $SZCols]> for MatrixMN<N, $NRows, $NCols>
|
2017-08-03 01:37:44 +08:00
|
|
|
|
where DefaultAllocator: Allocator<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn from(arr: [[N; $SZRows]; $SZCols]) -> Self {
|
|
|
|
|
unsafe {
|
|
|
|
|
let mut res = Self::new_uninitialized();
|
2020-11-27 12:25:36 +08:00
|
|
|
|
ptr::copy_nonoverlapping(&arr[0][0], (*res.as_mut_ptr()).data.ptr_mut(), $SZRows * $SZCols);
|
2017-02-18 20:28:22 +08:00
|
|
|
|
|
2020-11-27 12:25:36 +08:00
|
|
|
|
res.assume_init()
|
2017-02-18 20:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
|
impl<N: Scalar, S> Into<[[N; $SZRows]; $SZCols]> for Matrix<N, $NRows, $NCols, S>
|
2017-08-03 01:37:44 +08:00
|
|
|
|
where S: ContiguousStorage<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn into(self) -> [[N; $SZRows]; $SZCols] {
|
2020-04-01 04:50:26 +08:00
|
|
|
|
let mut res = mem::MaybeUninit::<[[N; $SZRows]; $SZCols]>::uninit();
|
2017-02-18 20:28:22 +08:00
|
|
|
|
|
2020-04-01 13:14:32 +08:00
|
|
|
|
unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZRows * $SZCols) };
|
2020-04-06 04:49:33 +08:00
|
|
|
|
|
2020-04-01 13:14:32 +08:00
|
|
|
|
unsafe { res.assume_init() }
|
2017-02-18 20:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
|
impl<N: Scalar, S> AsRef<[[N; $SZRows]; $SZCols]> for Matrix<N, $NRows, $NCols, S>
|
2017-08-03 01:37:44 +08:00
|
|
|
|
where S: ContiguousStorage<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn as_ref(&self) -> &[[N; $SZRows]; $SZCols] {
|
|
|
|
|
unsafe {
|
|
|
|
|
mem::transmute(self.data.ptr())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 07:09:14 +08:00
|
|
|
|
impl<N: Scalar, S> AsMut<[[N; $SZRows]; $SZCols]> for Matrix<N, $NRows, $NCols, S>
|
2017-08-03 01:37:44 +08:00
|
|
|
|
where S: ContiguousStorageMut<N, $NRows, $NCols> {
|
2017-02-18 20:28:22 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn as_mut(&mut self) -> &mut [[N; $SZRows]; $SZCols] {
|
|
|
|
|
unsafe {
|
|
|
|
|
mem::transmute(self.data.ptr_mut())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)*}
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Implement for matrices with shape 2x2 .. 6x6.
|
2017-02-18 20:28:22 +08:00
|
|
|
|
impl_from_into_asref_2D!(
|
2017-02-27 05:15:11 +08:00
|
|
|
|
(U2, U2) => (2, 2); (U2, U3) => (2, 3); (U2, U4) => (2, 4); (U2, U5) => (2, 5); (U2, U6) => (2, 6);
|
|
|
|
|
(U3, U2) => (3, 2); (U3, U3) => (3, 3); (U3, U4) => (3, 4); (U3, U5) => (3, 5); (U3, U6) => (3, 6);
|
|
|
|
|
(U4, U2) => (4, 2); (U4, U3) => (4, 3); (U4, U4) => (4, 4); (U4, U5) => (4, 5); (U4, U6) => (4, 6);
|
|
|
|
|
(U5, U2) => (5, 2); (U5, U3) => (5, 3); (U5, U4) => (5, 4); (U5, U5) => (5, 5); (U5, U6) => (5, 6);
|
|
|
|
|
(U6, U2) => (6, 2); (U6, U3) => (6, 3); (U6, U4) => (6, 4); (U6, U5) => (6, 5); (U6, U6) => (6, 6);
|
2017-02-18 20:28:22 +08:00
|
|
|
|
);
|
2017-07-25 23:04:12 +08:00
|
|
|
|
|
2018-09-29 04:54:41 +08:00
|
|
|
|
impl<'a, N, R, C, RStride, CStride> From<MatrixSlice<'a, N, R, C, RStride, CStride>>
|
2018-12-06 05:40:03 +08:00
|
|
|
|
for Matrix<N, R, C, ArrayStorage<N, R, C>>
|
2018-09-29 04:54:41 +08:00
|
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N: Scalar,
|
2018-09-29 04:54:41 +08:00
|
|
|
|
R: DimName,
|
|
|
|
|
C: DimName,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
R::Value: Mul<C::Value>,
|
|
|
|
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
|
|
|
|
{
|
2018-10-01 11:30:28 +08:00
|
|
|
|
fn from(matrix_slice: MatrixSlice<'a, N, R, C, RStride, CStride>) -> Self {
|
2018-09-29 04:54:41 +08:00
|
|
|
|
matrix_slice.into_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 11:30:28 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
2018-09-29 04:54:41 +08:00
|
|
|
|
impl<'a, N, C, RStride, CStride> From<MatrixSlice<'a, N, Dynamic, C, RStride, CStride>>
|
2018-12-06 05:46:17 +08:00
|
|
|
|
for Matrix<N, Dynamic, C, VecStorage<N, Dynamic, C>>
|
2018-09-29 04:54:41 +08:00
|
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N: Scalar,
|
2018-09-29 04:54:41 +08:00
|
|
|
|
C: Dim,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
{
|
2018-10-01 11:30:28 +08:00
|
|
|
|
fn from(matrix_slice: MatrixSlice<'a, N, Dynamic, C, RStride, CStride>) -> Self {
|
2018-09-29 04:54:41 +08:00
|
|
|
|
matrix_slice.into_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 11:30:28 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
2018-09-29 04:54:41 +08:00
|
|
|
|
impl<'a, N, R, RStride, CStride> From<MatrixSlice<'a, N, R, Dynamic, RStride, CStride>>
|
2018-12-06 05:46:17 +08:00
|
|
|
|
for Matrix<N, R, Dynamic, VecStorage<N, R, Dynamic>>
|
2018-09-29 04:54:41 +08:00
|
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N: Scalar,
|
2018-09-29 04:54:41 +08:00
|
|
|
|
R: DimName,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
{
|
2018-10-01 11:30:28 +08:00
|
|
|
|
fn from(matrix_slice: MatrixSlice<'a, N, R, Dynamic, RStride, CStride>) -> Self {
|
2018-09-29 04:54:41 +08:00
|
|
|
|
matrix_slice.into_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, N, R, C, RStride, CStride> From<MatrixSliceMut<'a, N, R, C, RStride, CStride>>
|
2018-12-06 05:40:03 +08:00
|
|
|
|
for Matrix<N, R, C, ArrayStorage<N, R, C>>
|
2018-09-29 04:54:41 +08:00
|
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N: Scalar,
|
2018-09-29 04:54:41 +08:00
|
|
|
|
R: DimName,
|
|
|
|
|
C: DimName,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
R::Value: Mul<C::Value>,
|
|
|
|
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
|
|
|
|
{
|
2018-10-01 11:30:28 +08:00
|
|
|
|
fn from(matrix_slice: MatrixSliceMut<'a, N, R, C, RStride, CStride>) -> Self {
|
2018-09-29 04:54:41 +08:00
|
|
|
|
matrix_slice.into_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 11:30:28 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
2018-09-29 04:54:41 +08:00
|
|
|
|
impl<'a, N, C, RStride, CStride> From<MatrixSliceMut<'a, N, Dynamic, C, RStride, CStride>>
|
2018-12-06 05:46:17 +08:00
|
|
|
|
for Matrix<N, Dynamic, C, VecStorage<N, Dynamic, C>>
|
2018-09-29 04:54:41 +08:00
|
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N: Scalar,
|
2018-09-29 04:54:41 +08:00
|
|
|
|
C: Dim,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
{
|
2018-10-13 16:25:34 +08:00
|
|
|
|
fn from(matrix_slice: MatrixSliceMut<'a, N, Dynamic, C, RStride, CStride>) -> Self {
|
2018-09-29 04:54:41 +08:00
|
|
|
|
matrix_slice.into_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 11:30:28 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
2018-09-29 04:54:41 +08:00
|
|
|
|
impl<'a, N, R, RStride, CStride> From<MatrixSliceMut<'a, N, R, Dynamic, RStride, CStride>>
|
2018-12-06 05:46:17 +08:00
|
|
|
|
for Matrix<N, R, Dynamic, VecStorage<N, R, Dynamic>>
|
2018-09-29 04:54:41 +08:00
|
|
|
|
where
|
2019-12-17 07:09:14 +08:00
|
|
|
|
N: Scalar,
|
2018-09-29 04:54:41 +08:00
|
|
|
|
R: DimName,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
{
|
2018-10-01 11:30:28 +08:00
|
|
|
|
fn from(matrix_slice: MatrixSliceMut<'a, N, R, Dynamic, RStride, CStride>) -> Self {
|
2018-09-29 04:54:41 +08:00
|
|
|
|
matrix_slice.into_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-05 00:53:21 +08:00
|
|
|
|
|
2019-11-06 00:11:39 +08:00
|
|
|
|
impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix<N, R, C, S>>
|
2020-03-21 19:16:46 +08:00
|
|
|
|
for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride>
|
|
|
|
|
where
|
|
|
|
|
N: Scalar,
|
|
|
|
|
R: Dim,
|
|
|
|
|
C: Dim,
|
|
|
|
|
RSlice: Dim,
|
|
|
|
|
CSlice: Dim,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
S: Storage<N, R, C>,
|
|
|
|
|
ShapeConstraint: DimEq<R, RSlice>
|
|
|
|
|
+ DimEq<C, CSlice>
|
|
|
|
|
+ DimEq<RStride, S::RStride>
|
|
|
|
|
+ DimEq<CStride, S::CStride>,
|
2019-11-05 00:53:21 +08:00
|
|
|
|
{
|
|
|
|
|
fn from(m: &'a Matrix<N, 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());
|
2019-11-06 00:11:39 +08:00
|
|
|
|
|
|
|
|
|
let (rstride, cstride) = m.strides();
|
|
|
|
|
|
|
|
|
|
let rstride_slice = RStride::from_usize(rstride);
|
|
|
|
|
let cstride_slice = CStride::from_usize(cstride);
|
|
|
|
|
|
|
|
|
|
unsafe {
|
2020-03-21 19:16:46 +08:00
|
|
|
|
let data = SliceStorage::from_raw_parts(
|
|
|
|
|
m.data.ptr(),
|
|
|
|
|
(row_slice, col_slice),
|
|
|
|
|
(rstride_slice, cstride_slice),
|
|
|
|
|
);
|
2019-11-06 00:11:39 +08:00
|
|
|
|
Matrix::from_data_statically_unchecked(data)
|
|
|
|
|
}
|
2019-11-05 00:53:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 00:11:39 +08:00
|
|
|
|
impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<N, R, C, S>>
|
2020-03-21 19:16:46 +08:00
|
|
|
|
for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride>
|
|
|
|
|
where
|
|
|
|
|
N: Scalar,
|
|
|
|
|
R: Dim,
|
|
|
|
|
C: Dim,
|
|
|
|
|
RSlice: Dim,
|
|
|
|
|
CSlice: Dim,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
S: Storage<N, R, C>,
|
|
|
|
|
ShapeConstraint: DimEq<R, RSlice>
|
|
|
|
|
+ DimEq<C, CSlice>
|
|
|
|
|
+ DimEq<RStride, S::RStride>
|
|
|
|
|
+ DimEq<CStride, S::CStride>,
|
2019-11-05 00:53:21 +08:00
|
|
|
|
{
|
|
|
|
|
fn from(m: &'a mut Matrix<N, 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());
|
2019-11-06 00:11:39 +08:00
|
|
|
|
|
|
|
|
|
let (rstride, cstride) = m.strides();
|
|
|
|
|
|
|
|
|
|
let rstride_slice = RStride::from_usize(rstride);
|
|
|
|
|
let cstride_slice = CStride::from_usize(cstride);
|
|
|
|
|
|
|
|
|
|
unsafe {
|
2020-03-21 19:16:46 +08:00
|
|
|
|
let data = SliceStorage::from_raw_parts(
|
|
|
|
|
m.data.ptr(),
|
|
|
|
|
(row_slice, col_slice),
|
|
|
|
|
(rstride_slice, cstride_slice),
|
|
|
|
|
);
|
2019-11-06 00:11:39 +08:00
|
|
|
|
Matrix::from_data_statically_unchecked(data)
|
|
|
|
|
}
|
2019-11-05 00:53:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 00:11:39 +08:00
|
|
|
|
impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<N, R, C, S>>
|
2020-03-21 19:16:46 +08:00
|
|
|
|
for MatrixSliceMut<'a, N, RSlice, CSlice, RStride, CStride>
|
|
|
|
|
where
|
|
|
|
|
N: Scalar,
|
|
|
|
|
R: Dim,
|
|
|
|
|
C: Dim,
|
|
|
|
|
RSlice: Dim,
|
|
|
|
|
CSlice: Dim,
|
|
|
|
|
RStride: Dim,
|
|
|
|
|
CStride: Dim,
|
|
|
|
|
S: StorageMut<N, R, C>,
|
|
|
|
|
ShapeConstraint: DimEq<R, RSlice>
|
|
|
|
|
+ DimEq<C, CSlice>
|
|
|
|
|
+ DimEq<RStride, S::RStride>
|
|
|
|
|
+ DimEq<CStride, S::CStride>,
|
2019-11-05 00:53:21 +08:00
|
|
|
|
{
|
|
|
|
|
fn from(m: &'a mut Matrix<N, 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());
|
2019-11-06 00:11:39 +08:00
|
|
|
|
|
|
|
|
|
let (rstride, cstride) = m.strides();
|
|
|
|
|
|
|
|
|
|
let rstride_slice = RStride::from_usize(rstride);
|
|
|
|
|
let cstride_slice = CStride::from_usize(cstride);
|
|
|
|
|
|
|
|
|
|
unsafe {
|
2020-03-21 19:16:46 +08:00
|
|
|
|
let data = SliceStorageMut::from_raw_parts(
|
|
|
|
|
m.data.ptr_mut(),
|
|
|
|
|
(row_slice, col_slice),
|
|
|
|
|
(rstride_slice, cstride_slice),
|
|
|
|
|
);
|
2019-11-06 00:11:39 +08:00
|
|
|
|
Matrix::from_data_statically_unchecked(data)
|
|
|
|
|
}
|
2019-11-05 00:53:21 +08:00
|
|
|
|
}
|
2019-12-25 00:37:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-19 23:18:42 +08:00
|
|
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
|
|
|
impl<'a, N: Scalar> From<Vec<N>> for DVector<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(vec: Vec<N>) -> Self {
|
|
|
|
|
Self::from_vec(vec)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 19:16:46 +08:00
|
|
|
|
impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage<N, R, C>> Into<&'a [N]>
|
|
|
|
|
for &'a Matrix<N, R, C, S>
|
|
|
|
|
{
|
2019-12-25 00:37:27 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn into(self) -> &'a [N] {
|
|
|
|
|
self.as_slice()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 19:16:46 +08:00
|
|
|
|
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>
|
|
|
|
|
{
|
2019-12-25 00:37:27 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn into(self) -> &'a mut [N] {
|
|
|
|
|
self.as_mut_slice()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, N: Scalar + Copy> From<&'a [N]> for DVectorSlice<'a, N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(slice: &'a [N]) -> Self {
|
|
|
|
|
Self::from_slice(slice, slice.len())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, N: Scalar + Copy> From<&'a mut [N]> for DVectorSliceMut<'a, N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(slice: &'a mut [N]) -> Self {
|
|
|
|
|
Self::from_slice(slice, slice.len())
|
|
|
|
|
}
|
2020-03-21 19:16:46 +08:00
|
|
|
|
}
|
2020-03-23 16:16:01 +08:00
|
|
|
|
|
|
|
|
|
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 2]>
|
|
|
|
|
for MatrixMN<N, R, C>
|
|
|
|
|
where
|
|
|
|
|
N: From<[<N as SimdValue>::Element; 2]>,
|
|
|
|
|
N::Element: Scalar + SimdValue,
|
|
|
|
|
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
|
|
|
|
|
{
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(arr: [MatrixMN<N::Element, R, C>; 2]) -> Self {
|
|
|
|
|
let (nrows, ncols) = arr[0].data.shape();
|
|
|
|
|
|
|
|
|
|
Self::from_fn_generic(nrows, ncols, |i, j| {
|
|
|
|
|
[
|
|
|
|
|
arr[0][(i, j)].inlined_clone(),
|
|
|
|
|
arr[1][(i, j)].inlined_clone(),
|
|
|
|
|
]
|
|
|
|
|
.into()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 4]>
|
|
|
|
|
for MatrixMN<N, R, C>
|
|
|
|
|
where
|
|
|
|
|
N: From<[<N as SimdValue>::Element; 4]>,
|
|
|
|
|
N::Element: Scalar + SimdValue,
|
|
|
|
|
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
|
|
|
|
|
{
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(arr: [MatrixMN<N::Element, R, C>; 4]) -> Self {
|
|
|
|
|
let (nrows, ncols) = arr[0].data.shape();
|
|
|
|
|
|
|
|
|
|
Self::from_fn_generic(nrows, ncols, |i, j| {
|
|
|
|
|
[
|
|
|
|
|
arr[0][(i, j)].inlined_clone(),
|
|
|
|
|
arr[1][(i, j)].inlined_clone(),
|
|
|
|
|
arr[2][(i, j)].inlined_clone(),
|
|
|
|
|
arr[3][(i, j)].inlined_clone(),
|
|
|
|
|
]
|
|
|
|
|
.into()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 8]>
|
|
|
|
|
for MatrixMN<N, R, C>
|
|
|
|
|
where
|
|
|
|
|
N: From<[<N as SimdValue>::Element; 8]>,
|
|
|
|
|
N::Element: Scalar + SimdValue,
|
|
|
|
|
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
|
|
|
|
|
{
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(arr: [MatrixMN<N::Element, R, C>; 8]) -> Self {
|
|
|
|
|
let (nrows, ncols) = arr[0].data.shape();
|
|
|
|
|
|
|
|
|
|
Self::from_fn_generic(nrows, ncols, |i, j| {
|
|
|
|
|
[
|
|
|
|
|
arr[0][(i, j)].inlined_clone(),
|
|
|
|
|
arr[1][(i, j)].inlined_clone(),
|
|
|
|
|
arr[2][(i, j)].inlined_clone(),
|
|
|
|
|
arr[3][(i, j)].inlined_clone(),
|
|
|
|
|
arr[4][(i, j)].inlined_clone(),
|
|
|
|
|
arr[5][(i, j)].inlined_clone(),
|
|
|
|
|
arr[6][(i, j)].inlined_clone(),
|
|
|
|
|
arr[7][(i, j)].inlined_clone(),
|
|
|
|
|
]
|
|
|
|
|
.into()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<N: Scalar + PrimitiveSimdValue, R: Dim, C: Dim> From<[MatrixMN<N::Element, R, C>; 16]>
|
|
|
|
|
for MatrixMN<N, R, C>
|
|
|
|
|
where
|
|
|
|
|
N: From<[<N as SimdValue>::Element; 16]>,
|
|
|
|
|
N::Element: Scalar + SimdValue,
|
|
|
|
|
DefaultAllocator: Allocator<N, R, C> + Allocator<N::Element, R, C>,
|
|
|
|
|
{
|
|
|
|
|
fn from(arr: [MatrixMN<N::Element, R, C>; 16]) -> Self {
|
|
|
|
|
let (nrows, ncols) = arr[0].data.shape();
|
|
|
|
|
|
|
|
|
|
Self::from_fn_generic(nrows, ncols, |i, j| {
|
|
|
|
|
[
|
|
|
|
|
arr[0][(i, j)].inlined_clone(),
|
|
|
|
|
arr[1][(i, j)].inlined_clone(),
|
|
|
|
|
arr[2][(i, j)].inlined_clone(),
|
|
|
|
|
arr[3][(i, j)].inlined_clone(),
|
|
|
|
|
arr[4][(i, j)].inlined_clone(),
|
|
|
|
|
arr[5][(i, j)].inlined_clone(),
|
|
|
|
|
arr[6][(i, j)].inlined_clone(),
|
|
|
|
|
arr[7][(i, j)].inlined_clone(),
|
|
|
|
|
arr[8][(i, j)].inlined_clone(),
|
|
|
|
|
arr[9][(i, j)].inlined_clone(),
|
|
|
|
|
arr[10][(i, j)].inlined_clone(),
|
|
|
|
|
arr[11][(i, j)].inlined_clone(),
|
|
|
|
|
arr[12][(i, j)].inlined_clone(),
|
|
|
|
|
arr[13][(i, j)].inlined_clone(),
|
|
|
|
|
arr[14][(i, j)].inlined_clone(),
|
|
|
|
|
arr[15][(i, j)].inlined_clone(),
|
|
|
|
|
]
|
|
|
|
|
.into()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|