Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features rework #1

Merged
merged 2 commits into from
Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ name = "nalgebra"
path = "src/lib.rs"

[features]
default = [ "std" ]
std = [ "matrixmultiply", "rand/std", "alga/std", "rand_distr" ]
stdweb = [ "rand/stdweb" ]
default = [ ]
std = [ "alloc", "matrixmultiply", "rand/std", "alga/std", "rand_distr" ]
alloc = [ ]
arbitrary = [ "quickcheck" ]
serde-serialize = [ "serde", "serde_derive", "num-complex/serde" ]
abomonation-serialize = [ "abomonation" ]
sparse = [ ]
debug = [ "approx/num-complex", "rand/std" ]
alloc = [ ]
io = [ "pest", "pest_derive" ]

[dependencies]
typenum = "1.10"
generic-array = "0.12"
rand = { version = "0.7", default-features = false }
rand = { version = "0.7", optional = true, default-features = false }
rand_distr = { version = "0.2", optional = true }
num-traits = { version = "0.2", default-features = false }
num-complex = { version = "0.2", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion nalgebra-glm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ edition = "2018"
[features]
default = [ "std" ]
std = [ "nalgebra/std", "alga/std" ]
stdweb = [ "nalgebra/stdweb" ]
arbitrary = [ "nalgebra/arbitrary" ]
serde-serialize = [ "nalgebra/serde-serialize" ]
abomonation-serialize = [ "nalgebra/abomonation-serialize" ]
Expand Down
1 change: 0 additions & 1 deletion nalgebra-glm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
extern crate num_traits as num;
#[macro_use]
extern crate approx;
extern crate alga;
extern crate nalgebra as na;

pub use crate::aliases::*;
Expand Down
4 changes: 0 additions & 4 deletions nalgebra-lapack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@
html_root_url = "http://nalgebra.org/rustdoc"
)]

extern crate alga;
extern crate lapack;
extern crate lapack_src;
extern crate nalgebra as na;
extern crate num_complex;
extern crate num_traits as num;

mod lapack_check;
Expand Down
10 changes: 5 additions & 5 deletions src/base/alias.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/base/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Abstract definition of a matrix data storage allocator.

use std::any::Any;
use core::any::Any;

use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
use crate::base::dimension::{Dim, U1};
Expand Down
10 changes: 5 additions & 5 deletions src/base/array_storage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use core::fmt::{self, Debug, Formatter};
use core::hash::{Hash, Hasher};
#[cfg(feature = "abomonation-serialize")]
use std::io::{Result as IOResult, Write};
use std::ops::{Deref, DerefMut, Mul};
use core::ops::{Deref, DerefMut, Mul};

#[cfg(feature = "serde-serialize")]
use serde::de::{Error, SeqAccess, Visitor};
Expand All @@ -11,9 +11,9 @@ use serde::ser::SerializeSeq;
#[cfg(feature = "serde-serialize")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "serde-serialize")]
use std::marker::PhantomData;
use core::marker::PhantomData;
#[cfg(feature = "serde-serialize")]
use std::mem;
use core::mem;

#[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation;
Expand Down
8 changes: 4 additions & 4 deletions src/base/blas.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alga::general::{ClosedAdd, ClosedMul, ComplexField};
#[cfg(feature = "std")]
#[cfg(feature = "matrixmultiply")]
use matrixmultiply;
use num::{One, Signed, Zero};
#[cfg(feature = "std")]
use std::mem;
#[cfg(feature = "matrixmultiply")]
use core::mem;

use crate::base::allocator::Allocator;
use crate::base::constraint::{
Expand Down Expand Up @@ -989,7 +989,7 @@ where N: Scalar + Zero + ClosedAdd + ClosedMul
{
let ncols1 = self.ncols();

#[cfg(feature = "std")]
#[cfg(feature = "matrixmultiply")]
{
// matrixmultiply can be used only if the std feature is available.
let nrows1 = self.nrows();
Expand Down
2 changes: 1 addition & 1 deletion src/base/componentwise.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Non-conventional component-wise operators.

use num::{Signed, Zero};
use std::ops::{Add, Mul};
use core::ops::{Add, Mul};

use alga::general::{ClosedDiv, ClosedMul};

Expand Down
22 changes: 13 additions & 9 deletions src/base/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use crate::base::storage::Owned;
use quickcheck::{Arbitrary, Gen};

use num::{Bounded, One, Zero};
use rand::distributions::{Distribution, Standard};
use rand::Rng;
#[cfg(feature = "std")]
#[cfg(feature = "rand")]
use rand::{Rng, distributions::{Distribution, Standard}};
#[cfg(feature = "rand_distr")]
use rand_distr::StandardNormal;
use std::iter;
use core::iter;
use typenum::{self, Cmp, Greater};

#[cfg(feature = "std")]
use alga::general::RealField;
use alga::general::{ClosedAdd, ClosedMul};

use crate::base::allocator::Allocator;
Expand Down Expand Up @@ -248,6 +246,7 @@ where DefaultAllocator: Allocator<N, R, C>
}

/// Creates a matrix filled with random values from the given distribution.
#[cfg(feature = "rand")]
#[inline]
pub fn from_distribution_generic<Distr: Distribution<N> + ?Sized, G: Rng + ?Sized>(
nrows: R,
Expand Down Expand Up @@ -277,7 +276,7 @@ where DefaultAllocator: Allocator<N, R, C>
/// assert_eq!(matrix_storage_ptr, vec_ptr);
/// ```
#[inline]
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
pub fn from_vec_generic(nrows: R, ncols: C, data: Vec<N>) -> Self {
Self::from_iterator_generic(nrows, ncols, data)
}
Expand Down Expand Up @@ -548,6 +547,7 @@ macro_rules! impl_constructors(
}

/// Creates a matrix or vector filled with random values from the given distribution.
#[cfg(feature = "rand")]
#[inline]
pub fn from_distribution<Distr: Distribution<N> + ?Sized, G: Rng + ?Sized>(
$($args: usize,)*
Expand All @@ -558,6 +558,7 @@ macro_rules! impl_constructors(
}
}

#[cfg(feature = "rand")]
impl<N: Scalar, $($DimIdent: $DimBound, )*> MatrixMN<N $(, $Dims)*>
where
DefaultAllocator: Allocator<N $(, $Dims)*>,
Expand Down Expand Up @@ -682,7 +683,7 @@ macro_rules! impl_constructors_from_data(
/// dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5);
/// ```
#[inline]
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
pub fn from_vec($($args: usize,)* $data: Vec<N>) -> Self {
Self::from_vec_generic($($gargs, )* $data)
}
Expand Down Expand Up @@ -761,6 +762,7 @@ where
}
}

#[cfg(feature = "rand")]
impl<N: Scalar, R: Dim, C: Dim> Distribution<MatrixMN<N, R, C>> for Standard
where
DefaultAllocator: Allocator<N, R, C>,
Expand Down Expand Up @@ -797,8 +799,10 @@ where

// TODO(specialization): faster impls possible for D≤4 (see rand_distr::{UnitCircle, UnitSphere})
#[cfg(feature = "std")]
impl<N: RealField, D: DimName> Distribution<Unit<VectorN<N, D>>> for Standard
impl<N, D> Distribution<Unit<VectorN<N, D>>> for Standard
where
N: alga::general::RealField,
D: DimName,
DefaultAllocator: Allocator<N, D>,
StandardNormal: Distribution<N>,
{
Expand Down
18 changes: 8 additions & 10 deletions src/base/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
use alga::general::{SubsetOf, SupersetOf};
#[cfg(feature = "mint")]
use mint;
use std::convert::{AsMut, AsRef, From, Into};
use std::mem;
use std::ptr;
use core::convert::{AsMut, AsRef, From, Into};
use core::{mem, ops::Mul, ptr};

use generic_array::ArrayLength;
use std::ops::Mul;
use typenum::Prod;

use crate::base::allocator::{Allocator, SameShapeAllocator};
use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
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};

Expand Down Expand Up @@ -353,7 +351,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
Expand All @@ -367,7 +365,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
Expand Down Expand Up @@ -397,7 +395,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
Expand All @@ -411,7 +409,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
Expand Down
4 changes: 2 additions & 2 deletions src/base/coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//! components using their names. For example, if `v` is a 3D vector, one can write `v.z` instead
//! of `v[2]`.

use std::mem;
use std::ops::{Deref, DerefMut};
use core::mem;
use core::ops::{Deref, DerefMut};

use crate::base::dimension::{U1, U2, U3, U4, U5, U6};
use crate::base::storage::{ContiguousStorage, ContiguousStorageMut};
Expand Down
Loading