Make std feature imply alloc

This commit is contained in:
Diggory Hardy 2019-09-16 12:23:04 +01:00
parent 32d922f0c7
commit 5d514f99b6
10 changed files with 52 additions and 53 deletions

View File

@ -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" ]

View File

@ -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<N, R, C> = Matrix<N, R, C, Owned<N, R, C>>;
pub type MatrixN<N, D> = MatrixMN<N, D, D>;
/// A dynamically sized column-major matrix.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
pub type DMatrix<N> = MatrixN<N, Dynamic>;
/// A stack-allocated, column-major, 1x1 square matrix.
@ -118,7 +118,7 @@ pub type Matrix6x5<N> = MatrixMN<N, U6, U5>;
*
*/
/// A dynamically sized column vector.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
pub type DVector<N> = Matrix<N, Dynamic, U1, VecStorage<N, Dynamic, U1>>;
/// A statically sized D-dimensional column vector.
@ -145,7 +145,7 @@ pub type Vector6<N> = VectorN<N, U6>;
*
*/
/// A dynamically sized row vector.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
pub type RowDVector<N> = Matrix<N, U1, Dynamic, VecStorage<N, U1, Dynamic>>;
/// A statically sized D-dimensional row vector.

View File

@ -777,7 +777,7 @@ where
}
}
#[cfg(feature = "arbitrary")]
#[cfg(all(feature = "arbitrary", feature = "rand"))]
impl<N, R, C> Arbitrary for MatrixMN<N, R, C>
where
R: Dim,

View File

@ -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<MatrixSlice<'a, N, Dynamic, C, RStride, CStride>>
for Matrix<N, Dynamic, C, VecStorage<N, Dynamic, C>>
where
@ -367,7 +367,7 @@ where
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(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>>
where
@ -397,7 +397,7 @@ where
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(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>>
where
@ -411,7 +411,7 @@ where
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(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>>
where

View File

@ -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<N: Scalar, C: Dim> Allocator<N, Dynamic, C> for DefaultAllocator {
type Buffer = VecStorage<N, Dynamic, C>;
@ -106,7 +106,7 @@ impl<N: Scalar, C: Dim> Allocator<N, Dynamic, C> for DefaultAllocator {
}
// Static - Dynamic
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, R: DimName> Allocator<N, R, Dynamic> for DefaultAllocator {
type Buffer = VecStorage<N, R, Dynamic>;
@ -172,7 +172,7 @@ where
}
// Static × Static -> Dynamic × Any
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, RFrom, CFrom, CTo> Reallocator<N, RFrom, CFrom, Dynamic, CTo> for DefaultAllocator
where
RFrom: DimName,
@ -201,7 +201,7 @@ where
}
// Static × Static -> Static × Dynamic
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, RFrom, CFrom, RTo> Reallocator<N, RFrom, CFrom, RTo, Dynamic> 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<N: Scalar, CFrom: Dim, CTo: Dim> Reallocator<N, Dynamic, CFrom, Dynamic, CTo>
for DefaultAllocator
{
@ -246,7 +246,7 @@ impl<N: Scalar, CFrom: Dim, CTo: Dim> Reallocator<N, Dynamic, CFrom, Dynamic, CT
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, CFrom: Dim, RTo: DimName> Reallocator<N, Dynamic, CFrom, RTo, Dynamic>
for DefaultAllocator
{
@ -262,7 +262,7 @@ impl<N: Scalar, CFrom: Dim, RTo: DimName> Reallocator<N, Dynamic, CFrom, RTo, Dy
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, RFrom: DimName, CTo: Dim> Reallocator<N, RFrom, Dynamic, Dynamic, CTo>
for DefaultAllocator
{
@ -278,7 +278,7 @@ impl<N: Scalar, RFrom: DimName, CTo: Dim> Reallocator<N, RFrom, Dynamic, Dynamic
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, RFrom: DimName, RTo: DimName> Reallocator<N, RFrom, Dynamic, RTo, Dynamic>
for DefaultAllocator
{

View File

@ -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<N: Scalar + Zero, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
}
/// 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<N, Dynamic, C>
where
I: IntoIterator<Item = &'a usize>,
@ -72,7 +72,7 @@ impl<N: Scalar + Zero, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
}
/// 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<N, R, Dynamic>
where
I: IntoIterator<Item = &'a usize>,
@ -308,7 +308,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
}
/// Removes all columns in `indices`
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
pub fn remove_columns_at(self, indices: &[usize]) -> MatrixMN<N, R, Dynamic>
where
C: DimSub<Dynamic, Output = Dynamic>,
@ -345,7 +345,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
}
/// Removes all rows in `indices`
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
pub fn remove_rows_at(self, indices: &[usize]) -> MatrixMN<N, Dynamic, C>
where
R: DimSub<Dynamic, Output = Dynamic>,
@ -392,7 +392,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// 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<N, R, Dynamic>
where
C: DimSub<Dynamic, Output = Dynamic>,
@ -475,7 +475,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// 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<N, Dynamic, C>
where
R: DimSub<Dynamic, Output = Dynamic>,
@ -553,7 +553,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// 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<N, R, Dynamic>
where
C: DimAdd<Dynamic, Output = Dynamic>,
@ -631,7 +631,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// 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<N, Dynamic, C>
where
R: DimAdd<Dynamic, Output = Dynamic>,
@ -691,7 +691,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
///
/// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix<N>
where DefaultAllocator: Reallocator<N, R, C, Dynamic, Dynamic> {
self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val)
@ -701,7 +701,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
///
/// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more
/// rows 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<N, Dynamic, C>
where DefaultAllocator: Reallocator<N, R, C, Dynamic, C> {
let ncols = self.data.shape().1;
@ -712,7 +712,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
///
/// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more
/// 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<N, R, Dynamic>
where DefaultAllocator: Reallocator<N, R, C, R, Dynamic> {
let nrows = self.data.shape().0;
@ -796,7 +796,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar> DMatrix<N> {
/// Resizes this matrix in-place.
///
@ -813,7 +813,7 @@ impl<N: Scalar> DMatrix<N> {
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, C: Dim> MatrixMN<N, Dynamic, C>
where DefaultAllocator: Allocator<N, Dynamic, C>
{
@ -823,7 +823,7 @@ where DefaultAllocator: Allocator<N, Dynamic, C>
/// 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<N, Dynamic, C, Dynamic, C> {
let placeholder =
@ -834,7 +834,7 @@ where DefaultAllocator: Allocator<N, Dynamic, C>
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N: Scalar, R: Dim> MatrixMN<N, R, Dynamic>
where DefaultAllocator: Allocator<N, R, Dynamic>
{
@ -844,7 +844,7 @@ where DefaultAllocator: Allocator<N, R, Dynamic>
/// 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<N, R, Dynamic, R, Dynamic> {
let placeholder =
@ -935,7 +935,7 @@ unsafe fn extend_rows<N: Scalar>(
/// Extend the number of columns of the `Matrix` with elements from
/// a given iterator.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N, R, S> Extend<N> for Matrix<N, R, Dynamic, S>
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<N, S> Extend<N> for Matrix<N, Dynamic, U1, S>
where
N: Scalar,
@ -1004,7 +1004,7 @@ where
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg(feature = "alloc")]
impl<N, R, S, RV, SV> Extend<Vector<N, RV, SV>> for Matrix<N, R, Dynamic, S>
where
N: Scalar,

View File

@ -285,7 +285,7 @@ where DefaultAllocator: Allocator<N, R, C>
}
}
_ => {
#[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<N, R, C>
}
}
}
#[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.")

View File

@ -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::*;

View File

@ -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;

View File

@ -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<Dynamic>
where DefaultAllocator: Allocator<(usize, usize), Dynamic>
{