diff --git a/Cargo.toml b/Cargo.toml index b312fd4a6..5acdd7589 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,19 +28,19 @@ bench = false test = true [dependencies] -num-integer = "0.1.39" +num-integer = { version = "0.1.39", default-features = false } num-traits = { version = "0.2", default-features = false } num-complex = { version = "0.3", default-features = false } rayon = { version = "1.0.3", optional = true } -approx = { version = "0.4", optional = true } +approx = { version = "0.4", optional = true , default-features = false } # Use via the `blas` crate feature! cblas-sys = { version = "0.1.4", optional = true, default-features = false } blas-src = { version = "0.6.1", optional = true, default-features = false } -matrixmultiply = { version = "0.2.0" } +matrixmultiply = { version = "0.2.0", default-features = false} serde = { version = "1.0", optional = true } rawpointer = { version = "0.2" } @@ -52,6 +52,7 @@ itertools = { version = "0.9.0", default-features = false, features = ["use_std" [features] default = ["std"] + # Enable blas usage # See README for more instructions blas = ["cblas-sys", "blas-src"] @@ -66,7 +67,7 @@ test = ["test-blas-openblas-sys"] # This feature is used for docs docs = ["approx", "serde", "rayon"] -std = ["num-traits/std"] +std = ["num-traits/std", "matrixmultiply/std"] [profile.release] [profile.bench] diff --git a/README.rst b/README.rst index df416919e..0dc32b19b 100644 --- a/README.rst +++ b/README.rst @@ -48,6 +48,19 @@ Crate Feature Flags The following crate feature flags are available. They are configured in your `Cargo.toml`. +- ``std`` + + - Rust Standard Library + + - This crate can be used without the standard library by disabling the + default `std` feature. To do so, use this in your `Cargo.toml`: + + [dependencies] + ndarray = { version = "0.x.y", default-features = false } + + - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` and `std_axis` + methods are only available when `std` is enabled. + - ``serde`` - Optional, compatible with Rust stable @@ -112,4 +125,3 @@ http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms. - diff --git a/examples/convo.rs b/examples/convo.rs index a9f073bd5..b50ab5247 100644 --- a/examples/convo.rs +++ b/examples/convo.rs @@ -1,7 +1,7 @@ #![allow(unused)] extern crate ndarray; -extern crate num_traits; +#[cfg(feature = "std")] use num_traits::Float; use ndarray::prelude::*; @@ -13,6 +13,7 @@ const SHARPEN: [[f32; 3]; 3] = [[0., -1., 0.], [-1., 5., -1.], [0., -1., 0.]]; type Kernel3x3 = [[A; 3]; 3]; #[inline(never)] +#[cfg(feature = "std")] fn conv_3x3(a: &ArrayView2<'_, F>, out: &mut ArrayViewMut2<'_, F>, kernel: &Kernel3x3) where F: Float, @@ -41,6 +42,7 @@ where } } +#[cfg(feature = "std")] fn main() { let n = 16; let mut a = Array::zeros((n, n)); @@ -61,3 +63,5 @@ fn main() { } println!("{:2}", res); } +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/examples/sort-axis.rs b/examples/sort-axis.rs index eabf9bb50..ab5dfdab0 100644 --- a/examples/sort-axis.rs +++ b/examples/sort-axis.rs @@ -129,7 +129,7 @@ where } } } - +#[cfg(feature = "std")] fn main() { let a = Array::linspace(0., 63., 64).into_shape((8, 8)).unwrap(); let strings = a.map(|x| x.to_string()); @@ -143,3 +143,5 @@ fn main() { let c = strings.permute_axis(Axis(1), &perm); println!("{:?}", c); } +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/src/array_approx.rs b/src/array_approx.rs index 82c95a224..a2e9c2327 100644 --- a/src/array_approx.rs +++ b/src/array_approx.rs @@ -81,6 +81,7 @@ where #[cfg(test)] mod tests { use crate::prelude::*; + use alloc::vec; use approx::{ assert_abs_diff_eq, assert_abs_diff_ne, assert_relative_eq, assert_relative_ne, assert_ulps_eq, assert_ulps_ne, diff --git a/src/array_serde.rs b/src/array_serde.rs index c8b485d26..41f7d60c1 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -11,6 +11,8 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; use std::marker::PhantomData; +use alloc::format; +use alloc::vec::Vec; use crate::imp_prelude::*; diff --git a/src/arrayformat.rs b/src/arrayformat.rs index a7203b38a..de6caf12c 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -8,6 +8,9 @@ use super::{ArrayBase, ArrayView, Axis, Data, Dimension, NdProducer}; use crate::aliases::{Ix1, IxDyn}; use std::fmt; +use alloc::format; +use alloc::string::String; +use alloc::vec::Vec; /// Default threshold, below this element count, we don't ellipsize const ARRAY_MANY_ELEMENT_LIMIT: usize = 500; diff --git a/src/arraytraits.rs b/src/arraytraits.rs index 143bb5faf..449d57781 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -12,6 +12,7 @@ use std::iter::FromIterator; use std::iter::IntoIterator; use std::mem; use std::ops::{Index, IndexMut}; +use alloc::vec::Vec; use crate::imp_prelude::*; use crate::iter::{Iter, IterMut}; diff --git a/src/data_repr.rs b/src/data_repr.rs index 56682d9ba..b34f0a4ca 100644 --- a/src/data_repr.rs +++ b/src/data_repr.rs @@ -1,8 +1,9 @@ - use std::mem; use std::mem::ManuallyDrop; use std::ptr::NonNull; -use std::slice; +use alloc::slice; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; use crate::extension::nonnull; /// Array's representation. diff --git a/src/data_traits.rs b/src/data_traits.rs index 057ef9249..3d6ce88b6 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -11,7 +11,8 @@ use rawpointer::PointerExt; use std::mem::{self, size_of}; use std::ptr::NonNull; -use std::sync::Arc; +use alloc::sync::Arc; +use alloc::vec::Vec; use crate::{ ArrayBase, CowRepr, Dimension, OwnedArcRepr, OwnedRepr, RawViewRepr, ViewRepr, diff --git a/src/dimension/conversion.rs b/src/dimension/conversion.rs index bf48dae2f..6b53a4eef 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -10,6 +10,7 @@ use num_traits::Zero; use std::ops::{Index, IndexMut}; +use alloc::vec::Vec; use crate::{Dim, Dimension, Ix, Ix1, IxDyn, IxDynImpl}; diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 3f47e15ae..97de6d842 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -6,8 +6,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::fmt; +use std::fmt; use super::Dimension; use super::IntoDimension; use crate::itertools::zip; diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index b2ef92e43..d98eedd65 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -9,6 +9,7 @@ use std::fmt::Debug; use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; use std::ops::{Index, IndexMut}; +use alloc::vec::Vec; use super::axes_of; use super::conversion::Convert; diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 76087aa52..5c9cd0d61 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -1,7 +1,9 @@ use crate::imp_prelude::*; use std::hash::{Hash, Hasher}; use std::ops::{Deref, DerefMut, Index, IndexMut}; - +use alloc::vec; +use alloc::boxed::Box; +use alloc::vec::Vec; const CAP: usize = 4; /// T is usize or isize diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index 9ee1f44d6..b4610f0dc 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -676,7 +676,7 @@ mod test { #[test] fn slice_indexing_uncommon_strides() { - let v: Vec<_> = (0..12).collect(); + let v: alloc::vec::Vec<_> = (0..12).collect(); let dim = (2, 3, 2).into_dimension(); let strides = (1, 2, 6).into_dimension(); assert!(super::can_index_slice(&v, &dim, &strides).is_ok()); @@ -784,7 +784,7 @@ mod test { } quickcheck! { - fn can_index_slice_not_custom_same_as_can_index_slice(data: Vec, dim: Vec) -> bool { + fn can_index_slice_not_custom_same_as_can_index_slice(data: alloc::vec::Vec, dim: alloc::vec::Vec) -> bool { let dim = IxDyn(&dim); let result = can_index_slice_not_custom(data.len(), &dim); if dim.size_checked().is_none() { @@ -871,7 +871,7 @@ mod test { let (min2, max2) = (cmp::min(first2, last2), cmp::max(first2, last2)); // Naively determine if the sequences intersect. - let seq1: Vec<_> = (0..len1) + let seq1: alloc::vec::Vec<_> = (0..len1) .map(|n| first1 + step1 * n) .collect(); let intersects = (0..len2) diff --git a/src/error.rs b/src/error.rs index 090937561..c45496142 100644 --- a/src/error.rs +++ b/src/error.rs @@ -6,6 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. use super::Dimension; +#[cfg(feature = "std")] use std::error::Error; use std::fmt; @@ -69,6 +70,7 @@ impl PartialEq for ShapeError { } } +#[cfg(feature = "std")] impl Error for ShapeError {} impl fmt::Display for ShapeError { diff --git a/src/extension/nonnull.rs b/src/extension/nonnull.rs index 32fbb07c4..5aa50fdc2 100644 --- a/src/extension/nonnull.rs +++ b/src/extension/nonnull.rs @@ -1,4 +1,5 @@ use std::ptr::NonNull; +use alloc::vec::Vec; /// Return a NonNull pointer to the vector's data pub(crate) fn nonnull_from_vec_data(v: &mut Vec) -> NonNull { diff --git a/src/free_functions.rs b/src/free_functions.rs index ff7984ee6..95eb7dc81 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -7,7 +7,9 @@ // except according to those terms. use std::mem::{forget, size_of}; -use std::slice; +use alloc::slice; +use alloc::vec; +use alloc::vec::Vec; use crate::imp_prelude::*; use crate::{dimension, ArcArray1, ArcArray2}; diff --git a/src/geomspace.rs b/src/geomspace.rs index 06242f68e..c1935c71e 100644 --- a/src/geomspace.rs +++ b/src/geomspace.rs @@ -5,6 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg(feature = "std")] use num_traits::Float; /// An iterator of a sequence of geometrically spaced floats. diff --git a/src/impl_1d.rs b/src/impl_1d.rs index fa877eff0..704d8643d 100644 --- a/src/impl_1d.rs +++ b/src/impl_1d.rs @@ -7,6 +7,7 @@ // except according to those terms. //! Methods for one-dimensional arrays. +use alloc::vec::Vec; use crate::imp_prelude::*; /// # Methods For 1-D Arrays diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 4353a827e..9b84f3105 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -11,9 +11,12 @@ //! #![allow(clippy::match_wild_err_arm)] - -use num_traits::{Float, One, Zero}; +#[cfg(feature = "std")] +use num_traits::Float; +use num_traits::{One, Zero}; use std::mem::MaybeUninit; +use alloc::vec; +use alloc::vec::Vec; use crate::dimension; use crate::error::{self, ShapeError}; @@ -23,8 +26,10 @@ use crate::indexes; use crate::indices; use crate::iterators::{to_vec, to_vec_mapped}; use crate::StrideShape; +#[cfg(feature = "std")] use crate::{geomspace, linspace, logspace}; + /// # Constructor Methods for Owned Arrays /// /// Note that the constructor methods apply to `Array` and `ArcArray`, @@ -66,6 +71,7 @@ where /// let array = Array::linspace(0., 1., 5); /// assert!(array == arr1(&[0.0, 0.25, 0.5, 0.75, 1.0])) /// ``` + #[cfg(feature = "std")] pub fn linspace(start: A, end: A, n: usize) -> Self where A: Float, @@ -84,6 +90,7 @@ where /// let array = Array::range(0., 5., 1.); /// assert!(array == arr1(&[0., 1., 2., 3., 4.])) /// ``` + #[cfg(feature = "std")] pub fn range(start: A, end: A, step: A) -> Self where A: Float, @@ -112,6 +119,7 @@ where /// assert_abs_diff_eq!(array, arr1(&[-1e3, -1e2, -1e1, -1e0])); /// # } /// ``` + #[cfg(feature = "std")] pub fn logspace(base: A, start: A, end: A, n: usize) -> Self where A: Float, @@ -146,6 +154,7 @@ where /// # /// # example().unwrap(); /// ``` + #[cfg(feature = "std")] pub fn geomspace(start: A, end: A, n: usize) -> Option where A: Float, diff --git a/src/impl_methods.rs b/src/impl_methods.rs index fd89df211..3afb68147 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -7,8 +7,9 @@ // except according to those terms. use std::ptr as std_ptr; -use std::slice; - +use alloc::slice; +use alloc::vec; +use alloc::vec::Vec; use rawpointer::PointerExt; use crate::imp_prelude::*; diff --git a/src/impl_owned_array.rs b/src/impl_owned_array.rs index f219b7b69..41eff2b11 100644 --- a/src/impl_owned_array.rs +++ b/src/impl_owned_array.rs @@ -1,4 +1,5 @@ +use alloc::vec::Vec; use crate::imp_prelude::*; /// Methods specific to `Array0`. diff --git a/src/impl_views/conversions.rs b/src/impl_views/conversions.rs index 8c4230108..cfd7f9aa0 100644 --- a/src/impl_views/conversions.rs +++ b/src/impl_views/conversions.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::slice; +use alloc::slice; use crate::imp_prelude::*; diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 8cb7a9088..595f0897d 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -16,6 +16,7 @@ mod windows; use std::iter::FromIterator; use std::marker::PhantomData; use std::ptr; +use alloc::vec::Vec; use crate::Ix1; @@ -1446,10 +1447,13 @@ pub unsafe trait TrustedIterator {} use crate::indexes::IndicesIterF; use crate::iter::IndicesIter; +#[cfg(feature = "std")] use crate::{geomspace::Geomspace, linspace::Linspace, logspace::Logspace}; - -unsafe impl TrustedIterator for Geomspace {} +#[cfg(feature = "std")] unsafe impl TrustedIterator for Linspace {} +#[cfg(feature = "std")] +unsafe impl TrustedIterator for Geomspace {} +#[cfg(feature = "std")] unsafe impl TrustedIterator for Logspace {} unsafe impl<'a, A, D> TrustedIterator for Iter<'a, A, D> {} unsafe impl<'a, A, D> TrustedIterator for IterMut<'a, A, D> {} diff --git a/src/lib.rs b/src/lib.rs index e49445a82..6ca3c0be0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ clippy::deref_addrof, clippy::unreadable_literal )] +#![cfg_attr(not(feature = "std"), no_std)] //! The `ndarray` crate provides an *n*-dimensional container for general elements //! and for numerics. @@ -68,6 +69,14 @@ //! The following crate feature flags are available. They are configured in your //! `Cargo.toml`. //! +//! - `std` +//! - Rust Standard Library +//! - This crate can be used without the standard library by disabling the +//! default `std` feature. To do so, use `default-features = false` in +//! your `Cargo.toml`. +//! - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` +//! and `std_axis` methods are only available when `std` is +//! enabled. //! - `serde` //! - Optional, compatible with Rust stable //! - Enables serialization support for serde 1.x @@ -109,6 +118,14 @@ //! For conversion between `ndarray`, [`nalgebra`](https://crates.io/crates/nalgebra) and //! [`image`](https://crates.io/crates/image) check out [`nshare`](https://crates.io/crates/nshare). + +extern crate alloc; + +#[cfg(feature = "std")] +extern crate std; +#[cfg(not(feature = "std"))] +extern crate core as std; + #[cfg(feature = "blas")] extern crate blas_src; #[cfg(feature = "blas")] @@ -118,7 +135,7 @@ extern crate cblas_sys; pub mod doc; use std::marker::PhantomData; -use std::sync::Arc; +use alloc::sync::Arc; pub use crate::dimension::dim::*; pub use crate::dimension::{Axis, AxisDescription, Dimension, IntoDimension, RemoveAxis}; @@ -135,7 +152,7 @@ use crate::iterators::{ElementsBase, ElementsBaseMut, Iter, IterMut, Lanes, Lane pub use crate::arraytraits::AsArray; #[cfg(feature = "std")] pub use crate::linalg_traits::NdFloat; -pub use crate::linalg_traits::LinalgScalar; +pub use crate::linalg_traits::LinalgScalar; pub use crate::stacking::{concatenate, stack, stack_new_axis}; diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index f54f14431..5201d55e2 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -12,6 +12,7 @@ use crate::numeric_util; use crate::{LinalgScalar, Zip}; use std::any::TypeId; +use alloc::vec::Vec; #[cfg(feature = "blas")] use std::cmp; diff --git a/src/linspace.rs b/src/linspace.rs index ca0eae470..6e9b1203c 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -5,6 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg(feature = "std")] use num_traits::Float; /// An iterator of a sequence of evenly spaced floats. diff --git a/src/logspace.rs b/src/logspace.rs index 55b5397c8..4dc6e1f32 100644 --- a/src/logspace.rs +++ b/src/logspace.rs @@ -5,6 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg(feature = "std")] use num_traits::Float; /// An iterator of a sequence of logarithmically spaced number. diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index a3858f829..3d7e15d0d 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -6,7 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use num_traits::{self, Float, FromPrimitive, Zero}; +#[cfg(feature = "std")] +use num_traits::Float; +use num_traits::{self, FromPrimitive, Zero}; use std::ops::{Add, Div, Mul}; use crate::imp_prelude::*; @@ -152,6 +154,7 @@ where /// let var = a.var(1.); /// assert_abs_diff_eq!(var, 6.7331, epsilon = 1e-4); /// ``` + #[cfg(feature = "std")] pub fn var(&self, ddof: A) -> A where A: Float + FromPrimitive, @@ -214,6 +217,7 @@ where /// let stddev = a.std(1.); /// assert_abs_diff_eq!(stddev, 2.59483, epsilon = 1e-4); /// ``` + #[cfg(feature = "std")] pub fn std(&self, ddof: A) -> A where A: Float + FromPrimitive, @@ -337,6 +341,7 @@ where /// let var = a.var_axis(Axis(0), 1.); /// assert_eq!(var, aview1(&[4., 4.])); /// ``` + #[cfg(feature = "std")] pub fn var_axis(&self, axis: Axis, ddof: A) -> Array where A: Float + FromPrimitive, @@ -405,6 +410,7 @@ where /// let stddev = a.std_axis(Axis(0), 1.); /// assert_eq!(stddev, aview1(&[2., 2.])); /// ``` + #[cfg(feature = "std")] pub fn std_axis(&self, axis: Axis, ddof: A) -> Array where A: Float + FromPrimitive, diff --git a/src/partial.rs b/src/partial.rs index 887e93824..a8146aff0 100644 --- a/src/partial.rs +++ b/src/partial.rs @@ -81,7 +81,7 @@ impl Drop for Partial { fn drop(&mut self) { if !self.ptr.is_null() { unsafe { - ptr::drop_in_place(std::slice::from_raw_parts_mut(self.ptr, self.len)); + ptr::drop_in_place(alloc::slice::from_raw_parts_mut(self.ptr, self.len)); } } } diff --git a/src/stacking.rs b/src/stacking.rs index 604a7cc5b..39126a2dc 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - +use alloc::vec::Vec; use crate::error::{from_kind, ErrorKind, ShapeError}; use crate::imp_prelude::*; use crate::traversal_utils::assign_to; diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 835ae5d31..3c61d8110 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -10,6 +10,7 @@ mod zipmacro; use std::mem::MaybeUninit; +use alloc::vec::Vec; use crate::imp_prelude::*; use crate::AssignElem; diff --git a/tests/array-construct.rs b/tests/array-construct.rs index 738e3b1fc..4513dd453 100644 --- a/tests/array-construct.rs +++ b/tests/array-construct.rs @@ -51,6 +51,7 @@ fn test_arcarray_thread_safe() { } #[test] +#[cfg(feature = "std")] fn test_uninit() { unsafe { let mut a = Array::::uninitialized((3, 4).f()); diff --git a/tests/array.rs b/tests/array.rs index 3d917f72b..c1976511c 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -67,6 +67,7 @@ fn arrayviewmut_shrink_lifetime<'a, 'b: 'a>( } #[test] +#[cfg(feature = "std")] fn test_mat_mul() { // smoke test, a big matrix multiplication of uneven size let (n, m) = (45, 33); @@ -609,6 +610,7 @@ fn test_cow_shrink() { } #[test] +#[cfg(feature = "std")] fn test_sub() { let mat = ArcArray::linspace(0., 15., 16).reshape((2, 4, 2)); let s1 = mat.index_axis(Axis(0), 0); @@ -623,6 +625,7 @@ fn test_sub() { #[should_panic] #[test] +#[cfg(feature = "std")] fn test_sub_oob_1() { let mat = ArcArray::linspace(0., 15., 16).reshape((2, 4, 2)); mat.index_axis(Axis(0), 2); @@ -1610,6 +1613,7 @@ fn scalar_ops() { } #[test] +#[cfg(feature = "std")] fn split_at() { let mut a = arr2(&[[1., 2.], [3., 4.]]); @@ -1661,6 +1665,7 @@ fn deny_split_at_index_out_of_bounds() { } #[test] +#[cfg(feature = "std")] fn test_range() { let a = Array::range(0., 5., 1.); assert_eq!(a.len(), 5); diff --git a/tests/broadcast.rs b/tests/broadcast.rs index 6840947bb..5416e9017 100644 --- a/tests/broadcast.rs +++ b/tests/broadcast.rs @@ -1,6 +1,7 @@ use ndarray::prelude::*; #[test] +#[cfg(feature = "std")] fn broadcast_1() { let a_dim = Dim([2, 4, 2, 2]); let b_dim = Dim([2, 1, 2, 1]); @@ -26,6 +27,7 @@ fn broadcast_1() { } #[test] +#[cfg(feature = "std")] fn test_add() { let a_dim = Dim([2, 4, 2, 2]); let b_dim = Dim([2, 1, 2, 1]); @@ -38,6 +40,7 @@ fn test_add() { #[test] #[should_panic] +#[cfg(feature = "std")] fn test_add_incompat() { let a_dim = Dim([2, 4, 2, 2]); let mut a = ArcArray::linspace(0.0, 1., a_dim.size()).reshape(a_dim); diff --git a/tests/dimension.rs b/tests/dimension.rs index 7e76132aa..cfc122e40 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -287,6 +287,7 @@ fn test_array_view() { } #[test] +#[cfg(feature = "std")] #[allow(clippy::cognitive_complexity)] fn test_all_ndindex() { macro_rules! ndindex { diff --git a/tests/iterator_chunks.rs b/tests/iterator_chunks.rs index 8ac885022..995557173 100644 --- a/tests/iterator_chunks.rs +++ b/tests/iterator_chunks.rs @@ -10,6 +10,7 @@ use ndarray::prelude::*; use ndarray::NdProducer; #[test] +#[cfg(feature = "std")] fn chunks() { let a = >::linspace(1., 100., 10 * 10) .into_shape((10, 10)) diff --git a/tests/iterators.rs b/tests/iterators.rs index 7a30003c4..7bb856adf 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -28,6 +28,7 @@ macro_rules! assert_panics { } #[test] +#[cfg(feature = "std")] fn double_ended() { let a = ArcArray::linspace(0., 7., 8); let mut it = a.iter().cloned(); @@ -58,6 +59,7 @@ fn iter_size_hint() { } #[test] +#[cfg(feature = "std")] fn indexed() { let a = ArcArray::linspace(0., 7., 8); for (i, elt) in a.indexed_iter() { @@ -90,6 +92,7 @@ where } #[test] +#[cfg(feature = "std")] fn as_slice() { let a = ArcArray::linspace(0., 7., 8); let a = a.reshape((2, 4, 1)); @@ -524,6 +527,7 @@ fn axis_iter_mut_zip_partially_consumed_discontiguous() { } #[test] +#[cfg(feature = "std")] fn axis_chunks_iter_corner_cases() { // examples provided by @bluss in PR #65 // these tests highlight corner cases of the axis_chunks_iter implementation diff --git a/tests/ixdyn.rs b/tests/ixdyn.rs index 3d96967a0..3c96cd746 100644 --- a/tests/ixdyn.rs +++ b/tests/ixdyn.rs @@ -155,6 +155,7 @@ fn test_0_add_broad() { } #[test] +#[cfg(feature = "std")] fn test_into_dimension() { let a = Array::linspace(0., 41., 6 * 7).into_shape((6, 7)).unwrap(); let a2 = a.clone().into_shape(IxDyn(&[6, 7])).unwrap(); diff --git a/tests/numeric.rs b/tests/numeric.rs index 13f8433c5..15df53287 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -65,12 +65,14 @@ fn sum_mean_empty() { } #[test] +#[cfg(feature = "std")] fn var() { let a = array![1., -4.32, 1.14, 0.32]; assert_abs_diff_eq!(a.var(0.), 5.049875, epsilon = 1e-8); } #[test] +#[cfg(feature = "std")] #[should_panic] fn var_negative_ddof() { let a = array![1., 2., 3.]; @@ -78,6 +80,7 @@ fn var_negative_ddof() { } #[test] +#[cfg(feature = "std")] #[should_panic] fn var_too_large_ddof() { let a = array![1., 2., 3.]; @@ -85,6 +88,7 @@ fn var_too_large_ddof() { } #[test] +#[cfg(feature = "std")] fn var_nan_ddof() { let a = Array2::::zeros((2, 3)); let v = a.var(::std::f64::NAN); @@ -92,18 +96,21 @@ fn var_nan_ddof() { } #[test] +#[cfg(feature = "std")] fn var_empty_arr() { let a: Array1 = array![]; assert!(a.var(0.0).is_nan()); } #[test] +#[cfg(feature = "std")] fn std() { let a = array![1., -4.32, 1.14, 0.32]; assert_abs_diff_eq!(a.std(0.), 2.24719, epsilon = 1e-5); } #[test] +#[cfg(feature = "std")] #[should_panic] fn std_negative_ddof() { let a = array![1., 2., 3.]; @@ -111,6 +118,7 @@ fn std_negative_ddof() { } #[test] +#[cfg(feature = "std")] #[should_panic] fn std_too_large_ddof() { let a = array![1., 2., 3.]; @@ -118,6 +126,7 @@ fn std_too_large_ddof() { } #[test] +#[cfg(feature = "std")] fn std_nan_ddof() { let a = Array2::::zeros((2, 3)); let v = a.std(::std::f64::NAN); @@ -125,6 +134,7 @@ fn std_nan_ddof() { } #[test] +#[cfg(feature = "std")] fn std_empty_arr() { let a: Array1 = array![]; assert!(a.std(0.0).is_nan()); @@ -249,6 +259,7 @@ fn std_axis() { #[test] #[should_panic] +#[cfg(feature = "std")] fn var_axis_negative_ddof() { let a = array![1., 2., 3.]; a.var_axis(Axis(0), -1.); @@ -256,12 +267,14 @@ fn var_axis_negative_ddof() { #[test] #[should_panic] +#[cfg(feature = "std")] fn var_axis_too_large_ddof() { let a = array![1., 2., 3.]; a.var_axis(Axis(0), 4.); } #[test] +#[cfg(feature = "std")] fn var_axis_nan_ddof() { let a = Array2::::zeros((2, 3)); let v = a.var_axis(Axis(1), ::std::f64::NAN); @@ -270,6 +283,7 @@ fn var_axis_nan_ddof() { } #[test] +#[cfg(feature = "std")] fn var_axis_empty_axis() { let a = Array2::::zeros((2, 0)); let v = a.var_axis(Axis(1), 0.); @@ -279,12 +293,14 @@ fn var_axis_empty_axis() { #[test] #[should_panic] +#[cfg(feature = "std")] fn std_axis_bad_dof() { let a = array![1., 2., 3.]; a.std_axis(Axis(0), 4.); } #[test] +#[cfg(feature = "std")] fn std_axis_empty_axis() { let a = Array2::::zeros((2, 0)); let v = a.std_axis(Axis(1), 0.); diff --git a/tests/oper.rs b/tests/oper.rs index 7193a49da..a3d179760 100644 --- a/tests/oper.rs +++ b/tests/oper.rs @@ -4,7 +4,7 @@ clippy::unreadable_literal, clippy::many_single_char_names )] - +#![cfg(feature = "std")] use ndarray::linalg::general_mat_mul; use ndarray::prelude::*; use ndarray::{rcarr1, rcarr2};