Fix compilation with and without #![no_std].

This commit is contained in:
sebcrozet 2018-05-19 18:05:56 +02:00 committed by Sébastien Crozet
parent ca093fad29
commit 40e74e0186
6 changed files with 50 additions and 29 deletions

View File

@ -16,6 +16,9 @@ Some feature are no longer available when libstd is not used:
* Support for dynamically-sized matrices. * Support for dynamically-sized matrices.
* Support for the `::new_random()` matrix constructor. * Support for the `::new_random()` matrix constructor.
* Support for the `.resize(...)` method since it returns a dynamically-sized matrix. * Support for the `.resize(...)` method since it returns a dynamically-sized matrix.
* Entries of matrices displayed using `println!("{}", matrix)` will not be correctly aligned vertically.
* The computation of the orthogonormal subspace basis of a vector is limited to vector with dimension up
to 3 (we will attempt to lift this restriction in a future release).
All other feature, including matrix factorizations, will still work on statically-sized matrices! All other feature, including matrix factorizations, will still work on statically-sized matrices!
### Modified ### Modified
* Rename the `core` module to `base` to avoid conflicts with the `core` crate implicitly imported when * Rename the `core` module to `base` to avoid conflicts with the `core` crate implicitly imported when

View File

@ -17,7 +17,7 @@ path = "src/lib.rs"
[features] [features]
default = [ "std" ] default = [ "std" ]
std = [ "matrixmultiply" ] std = [ "matrixmultiply", "rand/std" ]
arbitrary = [ "quickcheck" ] arbitrary = [ "quickcheck" ]
serde-serialize = [ "serde", "serde_derive", "num-complex/serde" ] serde-serialize = [ "serde", "serde_derive", "num-complex/serde" ]
abomonation-serialize = [ "abomonation" ] abomonation-serialize = [ "abomonation" ]

View File

@ -459,7 +459,7 @@ where
+ SameNumberOfColumns<C1, C3> + SameNumberOfColumns<C1, C3>
+ AreMultipliable<R2, C2, R3, C3>, + AreMultipliable<R2, C2, R3, C3>,
{ {
let ncols1 = self.shape(); let ncols1 = self.ncols();
#[cfg(feature = "std")] #[cfg(feature = "std")]
{ {

View File

@ -919,6 +919,7 @@ where
DefaultAllocator: Allocator<usize, R, C>, DefaultAllocator: Allocator<usize, R, C>,
{ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[cfg(feature = "std")]
fn val_width<N: Scalar + fmt::Display>(val: N, f: &mut fmt::Formatter) -> usize { fn val_width<N: Scalar + fmt::Display>(val: N, f: &mut fmt::Formatter) -> usize {
match f.precision() { match f.precision() {
Some(precision) => format!("{:.1$}", val, precision).chars().count(), Some(precision) => format!("{:.1$}", val, precision).chars().count(),
@ -926,6 +927,11 @@ where
} }
} }
#[cfg(not(feature = "std"))]
fn val_width<N: Scalar + fmt::Display>(val: N, f: &mut fmt::Formatter) -> usize {
4
}
let (nrows, ncols) = self.data.shape(); let (nrows, ncols) = self.data.shape();
if nrows.value() == 0 || ncols.value() == 0 { if nrows.value() == 0 || ncols.value() == 0 {

View File

@ -1,16 +1,19 @@
use num::{One, Zero}; use num::{One, Zero};
use alga::general::{AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma, use alga::general::{
AbstractModule, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma, AbstractModule,
Additive, ClosedAdd, ClosedMul, ClosedNeg, Field, Identity, Inverse, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Additive, ClosedAdd, ClosedMul,
JoinSemilattice, Lattice, MeetSemilattice, Module, Multiplicative, Real, ClosedNeg, Field, Identity, Inverse, JoinSemilattice, Lattice, MeetSemilattice, Module,
RingCommutative}; Multiplicative, Real, RingCommutative,
use alga::linear::{FiniteDimInnerSpace, FiniteDimVectorSpace, InnerSpace, NormedSpace, VectorSpace}; };
use alga::linear::{
FiniteDimInnerSpace, FiniteDimVectorSpace, InnerSpace, NormedSpace, VectorSpace,
};
use base::{DefaultAllocator, MatrixMN, MatrixN, Scalar}; use base::allocator::Allocator;
use base::dimension::{Dim, DimName}; use base::dimension::{Dim, DimName};
use base::storage::{Storage, StorageMut}; use base::storage::{Storage, StorageMut};
use base::allocator::Allocator; use base::{DefaultAllocator, MatrixMN, MatrixN, Scalar};
/* /*
* *
@ -283,6 +286,8 @@ where
} }
} }
_ => { _ => {
#[cfg(any(feature = "std", feature = "alloc"))]
{
// XXX: use a GenericArray instead. // XXX: use a GenericArray instead.
let mut known_basis = Vec::new(); let mut known_basis = Vec::new();
@ -306,6 +311,12 @@ where
} }
} }
} }
#[cfg(all(not(feature = "std"), 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

@ -56,6 +56,7 @@ where
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))]
impl PermutationSequence<Dynamic> impl PermutationSequence<Dynamic>
where where
DefaultAllocator: Allocator<(usize, usize), Dynamic>, DefaultAllocator: Allocator<(usize, usize), Dynamic>,