From 5d514f99b608eda79d72c69f20777b0028557d33 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Mon, 16 Sep 2019 12:23:04 +0100 Subject: [PATCH] Make std feature imply alloc --- Cargo.toml | 2 +- src/base/alias.rs | 10 +++---- src/base/construction.rs | 2 +- src/base/conversion.rs | 12 ++++---- src/base/default_allocator.rs | 20 ++++++------- src/base/edition.rs | 46 +++++++++++++++--------------- src/base/matrix_alga.rs | 4 +-- src/base/mod.rs | 4 +-- src/lib.rs | 1 - src/linalg/permutation_sequence.rs | 4 +-- 10 files changed, 52 insertions(+), 53 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47d4cf13..f239c4d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ path = "src/lib.rs" [features] default = [ "std", "rand_with_std" ] -std = [ "matrixmultiply", "alga/std" ] +std = [ "matrixmultiply", "alga/std", "alloc" ] # Since Cargo doesn't support multiplicitave features, use this to enable rand+std: rand_with_std = [ "rand/std", "std", "rand_distr" ] stdweb = [ "rand", "rand/stdweb" ] diff --git a/src/base/alias.rs b/src/base/alias.rs index a8925cf3..d28af20b 100644 --- a/src/base/alias.rs +++ b/src/base/alias.rs @@ -1,7 +1,7 @@ -#[cfg(any(feature = "alloc", feature = "std"))] +#[cfg(feature = "alloc")] use crate::base::dimension::Dynamic; use crate::base::dimension::{U1, U2, U3, U4, U5, U6}; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::base::vec_storage::VecStorage; use crate::base::storage::Owned; use crate::base::Matrix; @@ -24,7 +24,7 @@ pub type MatrixMN = Matrix>; pub type MatrixN = MatrixMN; /// A dynamically sized column-major matrix. -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] pub type DMatrix = MatrixN; /// A stack-allocated, column-major, 1x1 square matrix. @@ -118,7 +118,7 @@ pub type Matrix6x5 = MatrixMN; * */ /// A dynamically sized column vector. -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] pub type DVector = Matrix>; /// A statically sized D-dimensional column vector. @@ -145,7 +145,7 @@ pub type Vector6 = VectorN; * */ /// A dynamically sized row vector. -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] pub type RowDVector = Matrix>; /// A statically sized D-dimensional row vector. diff --git a/src/base/construction.rs b/src/base/construction.rs index 04fda0d6..7ed3bef0 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -777,7 +777,7 @@ where } } -#[cfg(feature = "arbitrary")] +#[cfg(all(feature = "arbitrary", feature = "rand"))] impl Arbitrary for MatrixMN where R: Dim, diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 4c5bb017..93a49fbb 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -14,11 +14,11 @@ use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstr use crate::base::dimension::{ Dim, DimName, U1, U10, U11, U12, U13, U14, U15, U16, U2, U3, U4, U5, U6, U7, U8, U9, }; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::base::dimension::Dynamic; use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut}; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::base::VecStorage; use crate::base::{DefaultAllocator, Matrix, ArrayStorage, MatrixMN, MatrixSlice, MatrixSliceMut, Scalar}; @@ -353,7 +353,7 @@ where } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl<'a, N, C, RStride, CStride> From> for Matrix> where @@ -367,7 +367,7 @@ where } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl<'a, N, R, RStride, CStride> From> for Matrix> where @@ -397,7 +397,7 @@ where } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl<'a, N, C, RStride, CStride> From> for Matrix> where @@ -411,7 +411,7 @@ where } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl<'a, N, R, RStride, CStride> From> for Matrix> where diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index c07c8708..a04651aa 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -15,11 +15,11 @@ use generic_array::ArrayLength; use typenum::Prod; use crate::base::allocator::{Allocator, Reallocator}; -#[cfg(any(feature = "alloc", feature = "std"))] +#[cfg(feature = "alloc")] use crate::base::dimension::Dynamic; use crate::base::dimension::{Dim, DimName}; use crate::base::array_storage::ArrayStorage; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::base::vec_storage::VecStorage; use crate::base::storage::{Storage, StorageMut}; use crate::base::Scalar; @@ -75,7 +75,7 @@ where // Dynamic - Static // Dynamic - Dynamic -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Allocator for DefaultAllocator { type Buffer = VecStorage; @@ -106,7 +106,7 @@ impl Allocator for DefaultAllocator { } // Static - Dynamic -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Allocator for DefaultAllocator { type Buffer = VecStorage; @@ -172,7 +172,7 @@ where } // Static × Static -> Dynamic × Any -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Reallocator for DefaultAllocator where RFrom: DimName, @@ -201,7 +201,7 @@ where } // Static × Static -> Static × Dynamic -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Reallocator for DefaultAllocator where RFrom: DimName, @@ -230,7 +230,7 @@ where } // All conversion from a dynamic buffer to a dynamic buffer. -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Reallocator for DefaultAllocator { @@ -246,7 +246,7 @@ impl Reallocator Reallocator for DefaultAllocator { @@ -262,7 +262,7 @@ impl Reallocator Reallocator for DefaultAllocator { @@ -278,7 +278,7 @@ impl Reallocator Reallocator for DefaultAllocator { diff --git a/src/base/edition.rs b/src/base/edition.rs index e473246f..6db83490 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -1,20 +1,20 @@ use num::{One, Zero}; use std::cmp; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use std::iter::ExactSizeIterator; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use std::mem; use std::ptr; use crate::base::allocator::{Allocator, Reallocator}; use crate::base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::base::dimension::Dynamic; use crate::base::dimension::{ Dim, DimAdd, DimDiff, DimMin, DimMinimum, DimName, DimSub, DimSum, U1, }; use crate::base::storage::{Storage, StorageMut}; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::base::DMatrix; use crate::base::{DefaultAllocator, Matrix, MatrixMN, RowVector, Scalar, Vector}; @@ -40,7 +40,7 @@ impl> Matrix { } /// Creates a new matrix by extracting the given set of rows from `self`. - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn select_rows<'a, I>(&self, irows: I) -> MatrixMN where I: IntoIterator, @@ -72,7 +72,7 @@ impl> Matrix { } /// Creates a new matrix by extracting the given set of columns from `self`. - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn select_columns<'a, I>(&self, icols: I) -> MatrixMN where I: IntoIterator, @@ -308,7 +308,7 @@ impl> Matrix { } /// Removes all columns in `indices` - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn remove_columns_at(self, indices: &[usize]) -> MatrixMN where C: DimSub, @@ -345,7 +345,7 @@ impl> Matrix { } /// Removes all rows in `indices` - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn remove_rows_at(self, indices: &[usize]) -> MatrixMN where R: DimSub, @@ -392,7 +392,7 @@ impl> Matrix { /// Removes `n` consecutive columns from this matrix, starting with the `i`-th (included). #[inline] - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn remove_columns(self, i: usize, n: usize) -> MatrixMN where C: DimSub, @@ -475,7 +475,7 @@ impl> Matrix { /// Removes `n` consecutive rows from this matrix, starting with the `i`-th (included). #[inline] - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn remove_rows(self, i: usize, n: usize) -> MatrixMN where R: DimSub, @@ -553,7 +553,7 @@ impl> Matrix { /// Inserts `n` columns filled with `val` starting at the `i-th` position. #[inline] - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn insert_columns(self, i: usize, n: usize, val: N) -> MatrixMN where C: DimAdd, @@ -631,7 +631,7 @@ impl> Matrix { /// Inserts `n` rows filled with `val` starting at the `i-th` position. #[inline] - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn insert_rows(self, i: usize, n: usize, val: N) -> MatrixMN where R: DimAdd, @@ -691,7 +691,7 @@ impl> Matrix { /// /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// rows and/or columns than `self`, then the extra rows or columns are filled with `val`. - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix where DefaultAllocator: Reallocator { self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val) @@ -701,7 +701,7 @@ impl> Matrix { /// /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// rows than `self`, then the extra rows are filled with `val`. - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn resize_vertically(self, new_nrows: usize, val: N) -> MatrixMN where DefaultAllocator: Reallocator { let ncols = self.data.shape().1; @@ -712,7 +712,7 @@ impl> Matrix { /// /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// columns than `self`, then the extra columns are filled with `val`. - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn resize_horizontally(self, new_ncols: usize, val: N) -> MatrixMN where DefaultAllocator: Reallocator { let nrows = self.data.shape().0; @@ -796,7 +796,7 @@ impl> Matrix { } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl DMatrix { /// Resizes this matrix in-place. /// @@ -813,7 +813,7 @@ impl DMatrix { } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl MatrixMN where DefaultAllocator: Allocator { @@ -823,7 +823,7 @@ where DefaultAllocator: Allocator /// rows than `self`, then the extra rows are filled with `val`. /// /// Defined only for owned matrices with a dynamic number of rows (for example, `DVector`). - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn resize_vertically_mut(&mut self, new_nrows: usize, val: N) where DefaultAllocator: Reallocator { let placeholder = @@ -834,7 +834,7 @@ where DefaultAllocator: Allocator } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl MatrixMN where DefaultAllocator: Allocator { @@ -844,7 +844,7 @@ where DefaultAllocator: Allocator /// columns than `self`, then the extra columns are filled with `val`. /// /// Defined only for owned matrices with a dynamic number of columns (for example, `DVector`). - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] pub fn resize_horizontally_mut(&mut self, new_ncols: usize, val: N) where DefaultAllocator: Reallocator { let placeholder = @@ -935,7 +935,7 @@ unsafe fn extend_rows( /// Extend the number of columns of the `Matrix` with elements from /// a given iterator. -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Extend for Matrix where N: Scalar, @@ -983,7 +983,7 @@ where /// Extend the number of rows of the `Vector` with elements from /// a given iterator. -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Extend for Matrix where N: Scalar, @@ -1004,7 +1004,7 @@ where } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl Extend> for Matrix where N: Scalar, diff --git a/src/base/matrix_alga.rs b/src/base/matrix_alga.rs index ac6aced7..5419f02d 100644 --- a/src/base/matrix_alga.rs +++ b/src/base/matrix_alga.rs @@ -285,7 +285,7 @@ where DefaultAllocator: Allocator } } _ => { - #[cfg(any(feature = "std", feature = "alloc"))] + #[cfg(feature = "alloc")] { // XXX: use a GenericArray instead. let mut known_basis = Vec::new(); @@ -310,7 +310,7 @@ where DefaultAllocator: Allocator } } } - #[cfg(all(not(feature = "std"), not(feature = "alloc")))] + #[cfg(not(feature = "alloc"))] { panic!("Cannot compute the orthogonal subspace basis of a vector with a dimension greater than 3 \ if #![no_std] is enabled and the 'alloc' feature is not enabled.") diff --git a/src/base/mod.rs b/src/base/mod.rs index 0ec6311c..139e560b 100644 --- a/src/base/mod.rs +++ b/src/base/mod.rs @@ -23,7 +23,7 @@ mod matrix; mod matrix_alga; mod array_storage; mod matrix_slice; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] mod vec_storage; mod properties; mod scalar; @@ -47,5 +47,5 @@ pub use self::alias::*; pub use self::alias_slice::*; pub use self::array_storage::*; pub use self::matrix_slice::*; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] pub use self::vec_storage::*; diff --git a/src/lib.rs b/src/lib.rs index 08dfcbe2..139b53d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,6 @@ an optimized set of tools for computer graphics and physics. Those features incl html_root_url = "https://nalgebra.org/rustdoc" )] #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))] #[macro_use] extern crate approx; diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index ce493905..3202e0b2 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -6,7 +6,7 @@ use num::One; use crate::allocator::Allocator; use crate::base::{DefaultAllocator, Matrix, Scalar, VectorN}; -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] use crate::dimension::Dynamic; use crate::dimension::{Dim, DimName, U1}; use crate::storage::StorageMut; @@ -51,7 +51,7 @@ where DefaultAllocator: Allocator<(usize, usize), D> } } -#[cfg(any(feature = "std", feature = "alloc"))] +#[cfg(feature = "alloc")] impl PermutationSequence where DefaultAllocator: Allocator<(usize, usize), Dynamic> {