From 857ce13b6365e41ce0a88875b96d98a59dc8f5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Thu, 19 Nov 2020 16:18:42 +0100 Subject: [PATCH] Add DVector::from(Vec). --- src/base/construction.rs | 7 +++++-- src/base/conversion.rs | 14 ++++++++++++-- src/base/matrix_simba.rs | 3 --- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/base/construction.rs b/src/base/construction.rs index c740ce88..8c34bf3c 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -1,3 +1,6 @@ +#[cfg(all(feature = "alloc", not(feature = "std")))] +use alloc::vec::Vec; + #[cfg(feature = "arbitrary")] use crate::base::storage::Owned; #[cfg(feature = "arbitrary")] @@ -297,7 +300,7 @@ where /// assert_eq!(matrix_storage_ptr, vec_ptr); /// ``` #[inline] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn from_vec_generic(nrows: R, ncols: C, data: Vec) -> Self { Self::from_iterator_generic(nrows, ncols, data) } @@ -719,7 +722,7 @@ macro_rules! impl_constructors_from_data( /// dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5); /// ``` #[inline] - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "alloc"))] pub fn from_vec($($args: usize,)* $data: Vec) -> Self { Self::from_vec_generic($($gargs, )* $data) } diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 88d6ddf3..583632a8 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -1,3 +1,5 @@ +#[cfg(all(feature = "alloc", not(feature = "std")))] +use alloc::vec::Vec; #[cfg(feature = "mint")] use mint; use simba::scalar::{SubsetOf, SupersetOf}; @@ -20,12 +22,12 @@ use crate::base::dimension::{ }; use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut}; -#[cfg(any(feature = "std", feature = "alloc"))] -use crate::base::VecStorage; use crate::base::{ ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixMN, MatrixSlice, MatrixSliceMut, Scalar, }; +#[cfg(any(feature = "std", feature = "alloc"))] +use crate::base::{DVector, VecStorage}; use crate::base::{SliceStorage, SliceStorageMut}; use crate::constraint::DimEq; @@ -545,6 +547,14 @@ where } } +#[cfg(any(feature = "std", feature = "alloc"))] +impl<'a, N: Scalar> From> for DVector { + #[inline] + fn from(vec: Vec) -> Self { + Self::from_vec(vec) + } +} + impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage> Into<&'a [N]> for &'a Matrix { diff --git a/src/base/matrix_simba.rs b/src/base/matrix_simba.rs index a23ff3fb..09bc937f 100644 --- a/src/base/matrix_simba.rs +++ b/src/base/matrix_simba.rs @@ -1,6 +1,3 @@ -#[cfg(all(feature = "alloc", not(feature = "std")))] -use alloc::vec::Vec; - use simba::simd::SimdValue; use crate::base::allocator::Allocator;