From 84767e20b19bff9a8c0bce6772e8c4706e594d0c Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Fri, 11 Dec 2020 17:18:59 +0800 Subject: [PATCH 01/20] Replace the replaceable "std" with "core" --- src/argument_traits.rs | 4 ++-- src/array_serde.rs | 4 ++-- src/arrayformat.rs | 10 +++++----- src/arraytraits.rs | 18 +++++++++--------- src/data_repr.rs | 6 +++--- src/data_traits.rs | 4 ++-- src/dimension/conversion.rs | 2 +- src/dimension/dim.rs | 4 ++-- src/dimension/dimension_trait.rs | 6 +++--- src/dimension/dynindeximpl.rs | 4 ++-- src/dimension/mod.rs | 4 ++-- src/dimension/ndindex.rs | 2 +- src/error.rs | 2 +- src/extension/nonnull.rs | 2 +- src/free_functions.rs | 2 +- src/impl_constructors.rs | 2 +- src/impl_methods.rs | 4 ++-- src/impl_ops.rs | 4 ++-- src/impl_owned_array.rs | 2 +- src/impl_raw_views.rs | 4 ++-- src/impl_special_element_types.rs | 6 +++--- src/impl_views/constructors.rs | 2 +- src/iterators/lanes.rs | 2 +- src/iterators/mod.rs | 6 +++--- src/itertools.rs | 2 +- src/layout/layoutfmt.rs | 2 +- src/lib.rs | 6 +++--- src/linalg/impl_linalg.rs | 10 +++++----- src/linalg_traits.rs | 6 +++--- src/numeric/impl_numeric.rs | 2 +- src/numeric_util.rs | 2 +- src/parallel/impl_par_methods.rs | 2 +- src/parallel/send_producer.rs | 2 +- src/partial.rs | 2 +- src/slice.rs | 16 ++++++++-------- src/zip/mod.rs | 2 +- 36 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/argument_traits.rs b/src/argument_traits.rs index a93e33a12..ef1390485 100644 --- a/src/argument_traits.rs +++ b/src/argument_traits.rs @@ -1,5 +1,5 @@ -use std::cell::Cell; -use std::mem::MaybeUninit; +use core::cell::Cell; +use core::mem::MaybeUninit; /// A producer element that can be assigned to once diff --git a/src/array_serde.rs b/src/array_serde.rs index c8b485d26..ffadfdc4f 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -9,8 +9,8 @@ use serde::de::{self, MapAccess, SeqAccess, Visitor}; use serde::ser::{SerializeSeq, SerializeStruct}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::fmt; -use std::marker::PhantomData; +use core::fmt; +use core::marker::PhantomData; use crate::imp_prelude::*; diff --git a/src/arrayformat.rs b/src/arrayformat.rs index a7203b38a..d719e255b 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -7,7 +7,7 @@ // except according to those terms. use super::{ArrayBase, ArrayView, Axis, Data, Dimension, NdProducer}; use crate::aliases::{Ix1, IxDyn}; -use std::fmt; +use core::fmt; /// Default threshold, below this element count, we don't ellipsize const ARRAY_MANY_ELEMENT_LIMIT: usize = 500; @@ -46,9 +46,9 @@ impl FormatOptions { fn set_no_limit(mut self, no_limit: bool) -> Self { if no_limit { - self.axis_collapse_limit = std::usize::MAX; - self.axis_collapse_limit_next_last = std::usize::MAX; - self.axis_collapse_limit_last = std::usize::MAX; + self.axis_collapse_limit = core::usize::MAX; + self.axis_collapse_limit_next_last = core::usize::MAX; + self.axis_collapse_limit_last = core::usize::MAX; self } else { self @@ -286,7 +286,7 @@ where #[cfg(test)] mod formatting_with_omit { use itertools::Itertools; - use std::fmt; + use core::fmt; use super::*; use crate::prelude::*; diff --git a/src/arraytraits.rs b/src/arraytraits.rs index 143bb5faf..55604eddd 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -6,12 +6,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::hash; -use std::isize; -use std::iter::FromIterator; -use std::iter::IntoIterator; -use std::mem; -use std::ops::{Index, IndexMut}; +use core::hash; +use core::isize; +use core::iter::FromIterator; +use core::iter::IntoIterator; +use core::mem; +use core::ops::{Index, IndexMut}; use crate::imp_prelude::*; use crate::iter::{Iter, IterMut}; @@ -154,7 +154,7 @@ where /// /// ```rust /// use ndarray::{Array, arr1}; - /// use std::iter::FromIterator; + /// use core::iter::FromIterator; /// /// // Either use `from_iter` directly or use `Iterator::collect`. /// let array = Array::from_iter((0..5).map(|x| x * x)); @@ -281,7 +281,7 @@ where let xs = slice.as_ref(); if mem::size_of::() == 0 { assert!( - xs.len() <= ::std::isize::MAX as usize, + xs.len() <= ::core::isize::MAX as usize, "Slice length must fit in `isize`.", ); } @@ -313,7 +313,7 @@ where let xs = slice.as_mut(); if mem::size_of::() == 0 { assert!( - xs.len() <= ::std::isize::MAX as usize, + xs.len() <= ::core::isize::MAX as usize, "Slice length must fit in `isize`.", ); } diff --git a/src/data_repr.rs b/src/data_repr.rs index 4839a8439..469e12629 100644 --- a/src/data_repr.rs +++ b/src/data_repr.rs @@ -1,7 +1,7 @@ -use std::mem; -use std::mem::ManuallyDrop; -use std::ptr::NonNull; +use core::mem; +use core::mem::ManuallyDrop; +use core::ptr::NonNull; use std::slice; use crate::extension::nonnull; diff --git a/src/data_traits.rs b/src/data_traits.rs index 8c22a225c..2263e7ba8 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -9,8 +9,8 @@ //! The data (inner representation) traits for ndarray use rawpointer::PointerExt; -use std::mem::{self, size_of}; -use std::ptr::NonNull; +use core::mem::{self, size_of}; +use core::ptr::NonNull; use std::sync::Arc; use crate::{ diff --git a/src/dimension/conversion.rs b/src/dimension/conversion.rs index bf48dae2f..a41e46411 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -9,7 +9,7 @@ //! Tuple to array conversion, IntoDimension, and related things use num_traits::Zero; -use std::ops::{Index, IndexMut}; +use core::ops::{Index, IndexMut}; use crate::{Dim, Dimension, Ix, Ix1, IxDyn, IxDynImpl}; diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 3f47e15ae..213bfe120 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 core::fmt; use super::Dimension; use super::IntoDimension; use crate::itertools::zip; @@ -82,7 +82,7 @@ where } } -use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; +use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; macro_rules! impl_op { ($op:ident, $op_m:ident, $opassign:ident, $opassign_m:ident, $expr:ident) => { diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index b2ef92e43..b7831f76c 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -6,9 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::fmt::Debug; -use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; -use std::ops::{Index, IndexMut}; +use core::fmt::Debug; +use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; +use core::ops::{Index, IndexMut}; use super::axes_of; use super::conversion::Convert; diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 76087aa52..8f39652ab 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -1,6 +1,6 @@ use crate::imp_prelude::*; -use std::hash::{Hash, Hasher}; -use std::ops::{Deref, DerefMut, Index, IndexMut}; +use core::hash::{Hash, Hasher}; +use core::ops::{Deref, DerefMut, Index, IndexMut}; const CAP: usize = 4; diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index 212197fed..9d2d0424b 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -19,8 +19,8 @@ pub use self::dynindeximpl::IxDynImpl; pub use self::ndindex::NdIndex; pub use self::remove_axis::RemoveAxis; -use std::isize; -use std::mem; +use core::isize; +use core::mem; #[macro_use] mod macros; diff --git a/src/dimension/ndindex.rs b/src/dimension/ndindex.rs index d9bac1d94..fb5b29990 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use core::fmt::Debug; use super::{stride_offset, stride_offset_checked}; use crate::itertools::zip; diff --git a/src/error.rs b/src/error.rs index 79acdd8b3..ddf665059 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,7 @@ // except according to those terms. use super::Dimension; use std::error::Error; -use std::fmt; +use core::fmt; /// An error related to array shape or layout. #[derive(Clone)] diff --git a/src/extension/nonnull.rs b/src/extension/nonnull.rs index 32fbb07c4..a63c97568 100644 --- a/src/extension/nonnull.rs +++ b/src/extension/nonnull.rs @@ -1,4 +1,4 @@ -use std::ptr::NonNull; +use core::ptr::NonNull; /// 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..6efa70062 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::mem::{forget, size_of}; +use core::mem::{forget, size_of}; use std::slice; use crate::imp_prelude::*; diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 8d1471e78..7a3add3a1 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -13,7 +13,7 @@ #![allow(clippy::match_wild_err_arm)] use num_traits::{Float, One, Zero}; -use std::mem::MaybeUninit; +use core::mem::MaybeUninit; use crate::dimension; use crate::error::{self, ShapeError}; diff --git a/src/impl_methods.rs b/src/impl_methods.rs index ca5b5499a..2903d22cc 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::ptr as std_ptr; +use core::ptr as std_ptr; use std::slice; use rawpointer::PointerExt; @@ -1067,7 +1067,7 @@ where /// ``` /// use ndarray::Array; /// use ndarray::{arr3, Axis}; - /// use std::iter::FromIterator; + /// use core::iter::FromIterator; /// /// let a = Array::from_iter(0..28).into_shape((2, 7, 2)).unwrap(); /// let mut iter = a.axis_chunks_iter(Axis(1), 2); diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 4804356e8..45bf367a2 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -226,7 +226,7 @@ mod arithmetic_ops { use crate::imp_prelude::*; use num_complex::Complex; - use std::ops::*; + use core::ops::*; impl_binary_op!(Add, +, add, +=, "addition"); impl_binary_op!(Sub, -, sub, -=, "subtraction"); @@ -357,7 +357,7 @@ mod assign_ops { macro_rules! impl_assign_op { ($trt:ident, $method:ident, $doc:expr) => { - use std::ops::$trt; + use core::ops::$trt; #[doc=$doc] /// If their shapes disagree, `rhs` is broadcast to the shape of `self`. diff --git a/src/impl_owned_array.rs b/src/impl_owned_array.rs index f219b7b69..f244555e5 100644 --- a/src/impl_owned_array.rs +++ b/src/impl_owned_array.rs @@ -21,7 +21,7 @@ impl Array { /// assert_eq!(scalar, Foo); /// ``` pub fn into_scalar(self) -> A { - let size = ::std::mem::size_of::(); + let size = ::core::mem::size_of::(); if size == 0 { // Any index in the `Vec` is fine since all elements are identical. self.data.into_vec().remove(0) diff --git a/src/impl_raw_views.rs b/src/impl_raw_views.rs index 22e76277a..5f0d88423 100644 --- a/src/impl_raw_views.rs +++ b/src/impl_raw_views.rs @@ -1,5 +1,5 @@ -use std::mem; -use std::ptr::NonNull; +use core::mem; +use core::ptr::NonNull; use crate::dimension::{self, stride_offset}; use crate::extension::nonnull::nonnull_debug_checked_from_ptr; diff --git a/src/impl_special_element_types.rs b/src/impl_special_element_types.rs index 40cba5822..9e7c82656 100644 --- a/src/impl_special_element_types.rs +++ b/src/impl_special_element_types.rs @@ -6,9 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::mem::size_of; -use std::mem::ManuallyDrop; -use std::mem::MaybeUninit; +use core::mem::size_of; +use core::mem::ManuallyDrop; +use core::mem::MaybeUninit; use crate::imp_prelude::*; use crate::RawDataSubst; diff --git a/src/impl_views/constructors.rs b/src/impl_views/constructors.rs index e2244dd09..4ee020c46 100644 --- a/src/impl_views/constructors.rs +++ b/src/impl_views/constructors.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::ptr::NonNull; +use core::ptr::NonNull; use crate::dimension; use crate::error::ShapeError; diff --git a/src/iterators/lanes.rs b/src/iterators/lanes.rs index 2163c58a6..e648445da 100644 --- a/src/iterators/lanes.rs +++ b/src/iterators/lanes.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use core::marker::PhantomData; use super::LanesIter; use super::LanesIterMut; diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 621c141ff..20f120e8c 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -13,9 +13,9 @@ pub mod iter; mod lanes; mod windows; -use std::iter::FromIterator; -use std::marker::PhantomData; -use std::ptr; +use core::iter::FromIterator; +use core::marker::PhantomData; +use core::ptr; use crate::Ix1; diff --git a/src/itertools.rs b/src/itertools.rs index 96732f903..60ad8eee8 100644 --- a/src/itertools.rs +++ b/src/itertools.rs @@ -9,7 +9,7 @@ //! A few iterator-related utilities and tools -use std::iter; +use core::iter; /// Iterate `iterable` with a running index. /// diff --git a/src/layout/layoutfmt.rs b/src/layout/layoutfmt.rs index 3d7fad00a..65f4dcfb2 100644 --- a/src/layout/layoutfmt.rs +++ b/src/layout/layoutfmt.rs @@ -10,7 +10,7 @@ use super::Layout; const LAYOUT_NAMES: &[&str] = &["C", "F", "c", "f"]; -use std::fmt; +use core::fmt; impl fmt::Debug for Layout { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/lib.rs b/src/lib.rs index 1b7590da1..200e183a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ extern crate cblas_sys; #[cfg(feature = "docs")] pub mod doc; -use std::marker::PhantomData; +use core::marker::PhantomData; use std::sync::Arc; pub use crate::dimension::dim::*; @@ -1232,7 +1232,7 @@ where data: S, /// A non-null pointer into the buffer held by `data`; may point anywhere /// in its range. If `S: Data`, this pointer must be aligned. - ptr: std::ptr::NonNull, + ptr: core::ptr::NonNull, /// The lengths of the axes. dim: D, /// The element count stride per axis. To be parsed as `isize`. @@ -1628,5 +1628,5 @@ pub struct StrideShape { /// Returns `true` if the pointer is aligned. pub(crate) fn is_aligned(ptr: *const T) -> bool { - (ptr as usize) % ::std::mem::align_of::() == 0 + (ptr as usize) % ::core::mem::align_of::() == 0 } diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index fd8d77d85..9b2cebc51 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -11,12 +11,12 @@ use crate::numeric_util; use crate::{LinalgScalar, Zip}; -use std::any::TypeId; +use core::any::TypeId; #[cfg(feature = "blas")] -use std::cmp; +use core::cmp; #[cfg(feature = "blas")] -use std::mem::swap; +use core::mem::swap; #[cfg(feature = "blas")] use std::os::raw::c_int; @@ -285,7 +285,7 @@ where #[inline(never)] fn dot_shape_error(m: usize, k: usize, k2: usize, n: usize) -> ! { match m.checked_mul(n) { - Some(len) if len <= ::std::isize::MAX as usize => {} + Some(len) if len <= ::core::isize::MAX as usize => {} _ => panic!("ndarray: shape {} × {} overflows isize", m, n), } panic!( @@ -677,7 +677,7 @@ fn same_type() -> bool { // **Panics** if `A` and `B` are not the same type fn cast_as(a: &A) -> B { assert!(same_type::()); - unsafe { ::std::ptr::read(a as *const _ as *const B) } + unsafe { ::core::ptr::read(a as *const _ as *const B) } } #[cfg(feature = "blas")] diff --git a/src/linalg_traits.rs b/src/linalg_traits.rs index a7f5a1a3e..46ce60cc1 100644 --- a/src/linalg_traits.rs +++ b/src/linalg_traits.rs @@ -7,9 +7,9 @@ // except according to those terms. use crate::ScalarOperand; use num_traits::{Float, One, Zero}; -use std::fmt; -use std::ops::{Add, Div, Mul, Sub}; -use std::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; +use core::fmt; +use core::ops::{Add, Div, Mul, Sub}; +use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; /// Elements that support linear algebra operations. /// diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index 85f69444d..0fd060eac 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -7,7 +7,7 @@ // except according to those terms. use num_traits::{self, Float, FromPrimitive, Zero}; -use std::ops::{Add, Div, Mul}; +use core::ops::{Add, Div, Mul}; use crate::imp_prelude::*; use crate::itertools::enumerate; diff --git a/src/numeric_util.rs b/src/numeric_util.rs index b06850fd0..f8e2a2e43 100644 --- a/src/numeric_util.rs +++ b/src/numeric_util.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cmp; +use core::cmp; use crate::LinalgScalar; diff --git a/src/parallel/impl_par_methods.rs b/src/parallel/impl_par_methods.rs index a4efa560f..0f4592ca1 100644 --- a/src/parallel/impl_par_methods.rs +++ b/src/parallel/impl_par_methods.rs @@ -107,7 +107,7 @@ macro_rules! zip_impl { }) .reduce(Partial::stub, Partial::try_merge); - if std::mem::needs_drop::() { + if core::mem::needs_drop::() { debug_assert_eq!(total_len, collect_result.len, "collect len is not correct, expected {}", total_len); assert!(collect_result.len == total_len, diff --git a/src/parallel/send_producer.rs b/src/parallel/send_producer.rs index 5324b3490..00ae680f4 100644 --- a/src/parallel/send_producer.rs +++ b/src/parallel/send_producer.rs @@ -1,7 +1,7 @@ use crate::imp_prelude::*; use crate::{Layout, NdProducer}; -use std::ops::{Deref, DerefMut}; +use core::ops::{Deref, DerefMut}; /// An NdProducer that is unconditionally `Send`. #[repr(transparent)] diff --git a/src/partial.rs b/src/partial.rs index 887e93824..7036dc588 100644 --- a/src/partial.rs +++ b/src/partial.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::ptr; +use core::ptr; /// Partial is a partially written contiguous slice of data; /// it is the owner of the elements, but not the allocation, diff --git a/src/slice.rs b/src/slice.rs index 15765c61d..0c812dc48 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -8,9 +8,9 @@ use crate::dimension::slices_intersect; use crate::error::{ErrorKind, ShapeError}; use crate::{ArrayViewMut, Dimension}; -use std::fmt; -use std::marker::PhantomData; -use std::ops::{Deref, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}; +use core::fmt; +use core::marker::PhantomData; +use core::ops::{Deref, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}; /// A slice (range with step size). /// @@ -602,11 +602,11 @@ macro_rules! s( } }; // empty call, i.e. `s![]` - (@parse ::std::marker::PhantomData::<$crate::Ix0>, []) => { + (@parse ::core::marker::PhantomData::<$crate::Ix0>, []) => { { #[allow(unsafe_code)] unsafe { - $crate::SliceInfo::new_unchecked([], ::std::marker::PhantomData::<$crate::Ix0>) + $crate::SliceInfo::new_unchecked([], ::core::marker::PhantomData::<$crate::Ix0>) } } }; @@ -614,16 +614,16 @@ macro_rules! s( (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") }; // convert range/index into SliceOrIndex (@convert $r:expr) => { - <$crate::SliceOrIndex as ::std::convert::From<_>>::from($r) + <$crate::SliceOrIndex as ::core::convert::From<_>>::from($r) }; // convert range/index and step into SliceOrIndex (@convert $r:expr, $s:expr) => { - <$crate::SliceOrIndex as ::std::convert::From<_>>::from($r).step_by($s as isize) + <$crate::SliceOrIndex as ::core::convert::From<_>>::from($r).step_by($s as isize) }; ($($t:tt)*) => { // The extra `*&` is a workaround for this compiler bug: // https://github.com/rust-lang/rust/issues/23014 - &*&$crate::s![@parse ::std::marker::PhantomData::<$crate::Ix0>, [] $($t)*] + &*&$crate::s![@parse ::core::marker::PhantomData::<$crate::Ix0>, [] $($t)*] }; ); diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 333911c6b..ac8572956 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -9,7 +9,7 @@ #[macro_use] mod zipmacro; -use std::mem::MaybeUninit; +use core::mem::MaybeUninit; use crate::imp_prelude::*; use crate::AssignElem; From 599536e58389fbd242e910a2430afa04a4dd630f Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Fri, 11 Dec 2020 18:11:34 +0800 Subject: [PATCH 02/20] Replace the replaceable "std" with "core" --- benches/bench1.rs | 4 ++-- benches/higher-order.rs | 2 +- blas-tests/tests/oper.rs | 2 +- examples/axis_ops.rs | 2 +- examples/life.rs | 2 +- examples/sort-axis.rs | 4 ++-- tests/array-construct.rs | 2 +- tests/array.rs | 8 ++++---- tests/azip.rs | 10 +++++----- tests/dimension.rs | 2 +- tests/iterators.rs | 4 ++-- tests/numeric.rs | 2 +- tests/oper.rs | 4 ++-- tests/raw_views.rs | 2 +- tests/windows.rs | 2 +- 15 files changed, 26 insertions(+), 26 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index 8cd04c458..d68b94f50 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -271,7 +271,7 @@ fn add_2d_alloc_zip_uninit(bench: &mut test::Bencher) { bench.iter(|| unsafe { let mut c = Array::uninitialized(a.dim()); azip!((&a in &a, &b in &b, c in c.raw_view_mut()) - std::ptr::write(c, a + b) + core::ptr::write(c, a + b) ); c }); @@ -632,7 +632,7 @@ fn iadd_scalar_2d_strided_dyn(bench: &mut test::Bencher) { fn scaled_add_2d_f32_regular(bench: &mut test::Bencher) { let mut av = Array::::zeros((ADD2DSZ, ADD2DSZ)); let bv = Array::::zeros((ADD2DSZ, ADD2DSZ)); - let scalar = std::f32::consts::PI; + let scalar = core::f32::consts::PI; bench.iter(|| { av.scaled_add(scalar, &bv); }); diff --git a/benches/higher-order.rs b/benches/higher-order.rs index 2ea0721af..e7963218f 100644 --- a/benches/higher-order.rs +++ b/benches/higher-order.rs @@ -6,7 +6,7 @@ clippy::many_single_char_names )] extern crate test; -use std::iter::FromIterator; +use core::iter::FromIterator; use test::black_box; use test::Bencher; diff --git a/blas-tests/tests/oper.rs b/blas-tests/tests/oper.rs index 2741123f9..9fab9099e 100644 --- a/blas-tests/tests/oper.rs +++ b/blas-tests/tests/oper.rs @@ -8,7 +8,7 @@ use ndarray::linalg::general_mat_vec_mul; use ndarray::prelude::*; use ndarray::{Data, LinalgScalar}; use ndarray::{Ix, Ixs, SliceInfo, SliceOrIndex}; -use std::iter::FromIterator; +use core::iter::FromIterator; use approx::{assert_abs_diff_eq, assert_relative_eq}; use defmac::defmac; diff --git a/examples/axis_ops.rs b/examples/axis_ops.rs index 3dbf0eee9..eaebaeda7 100644 --- a/examples/axis_ops.rs +++ b/examples/axis_ops.rs @@ -10,7 +10,7 @@ use ndarray::prelude::*; fn regularize(a: &mut Array) -> Result<(), ()> where D: Dimension, - A: ::std::fmt::Debug, + A: ::core::fmt::Debug, { println!("Regularize:\n{:?}", a); // reverse all neg axes diff --git a/examples/life.rs b/examples/life.rs index 1c2789389..7421de6fa 100644 --- a/examples/life.rs +++ b/examples/life.rs @@ -6,7 +6,7 @@ )] use ndarray::prelude::*; -use std::iter::FromIterator; +use core::iter::FromIterator; const INPUT: &[u8] = include_bytes!("life.txt"); diff --git a/examples/sort-axis.rs b/examples/sort-axis.rs index eabf9bb50..c888fa9de 100644 --- a/examples/sort-axis.rs +++ b/examples/sort-axis.rs @@ -1,8 +1,8 @@ use ndarray::prelude::*; use ndarray::{Data, RemoveAxis, Zip}; -use std::cmp::Ordering; -use std::ptr::copy_nonoverlapping; +use core::cmp::Ordering; +use core::ptr::copy_nonoverlapping; // Type invariant: Each index appears exactly once #[derive(Clone, Debug)] diff --git a/tests/array-construct.rs b/tests/array-construct.rs index 97e4ef491..18951c3df 100644 --- a/tests/array-construct.rs +++ b/tests/array-construct.rs @@ -199,7 +199,7 @@ fn deny_wraparound_uninit() { #[test] fn maybe_uninit_1() { - use std::mem::MaybeUninit; + use core::mem::MaybeUninit; unsafe { // Array diff --git a/tests/array.rs b/tests/array.rs index db54b7e5f..d16555b4e 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -13,7 +13,7 @@ use ndarray::indices; use ndarray::prelude::*; use ndarray::{arr3, rcarr2}; use ndarray::{Slice, SliceInfo, SliceOrIndex}; -use std::iter::FromIterator; +use core::iter::FromIterator; macro_rules! assert_panics { ($body:expr) => { @@ -1048,7 +1048,7 @@ fn owned_array_with_stride() { #[test] fn owned_array_discontiguous() { - use std::iter::repeat; + use core::iter::repeat; let v: Vec<_> = (0..12).flat_map(|x| repeat(x).take(2)).collect(); let dim = (3, 2, 2); let strides = (8, 4, 2); @@ -1061,7 +1061,7 @@ fn owned_array_discontiguous() { #[test] fn owned_array_discontiguous_drop() { - use std::cell::RefCell; + use core::cell::RefCell; use std::collections::BTreeSet; use std::rc::Rc; @@ -2018,7 +2018,7 @@ fn array_macros() { mod as_standard_layout_tests { use super::*; use ndarray::Data; - use std::fmt::Debug; + use core::fmt::Debug; fn test_as_standard_layout_for(orig: ArrayBase) where diff --git a/tests/azip.rs b/tests/azip.rs index 9027927ff..8666bb7de 100644 --- a/tests/azip.rs +++ b/tests/azip.rs @@ -8,11 +8,11 @@ use ndarray::prelude::*; use ndarray::Zip; -use std::iter::FromIterator; +use core::iter::FromIterator; use itertools::{assert_equal, cloned}; -use std::mem::swap; +use core::mem::swap; #[test] fn test_azip1() { @@ -95,7 +95,7 @@ fn test_zip_assign_into() { #[cfg(feature = "approx")] fn test_zip_assign_into_cell() { use approx::assert_abs_diff_eq; - use std::cell::Cell; + use core::cell::Cell; let a = Array::, _>::default((5, 10)); let b = Array::from_shape_fn((5, 10), |(i, j)| 1. / (i + 2 * j + 1) as f32); @@ -109,8 +109,8 @@ fn test_zip_assign_into_cell() { #[test] fn test_zip_collect_drop() { - use std::cell::RefCell; - use std::panic; + use core::cell::RefCell; + use core::panic; struct Recorddrop<'a>((usize, usize), &'a RefCell>); diff --git a/tests/dimension.rs b/tests/dimension.rs index 7e76132aa..c82ccf9e2 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -4,7 +4,7 @@ use defmac::defmac; use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, IntoDimension, IxDyn, RemoveAxis}; -use std::hash::{Hash, Hasher}; +use core::hash::{Hash, Hasher}; #[test] fn insert_axis() { diff --git a/tests/iterators.rs b/tests/iterators.rs index 371339b96..8169bdbf6 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -11,7 +11,7 @@ use ndarray::{arr2, arr3, aview1, indices, s, Axis, Data, Dimension, Slice, Zip} use itertools::assert_equal; use itertools::{enumerate, rev}; -use std::iter::FromIterator; +use core::iter::FromIterator; macro_rules! assert_panics { ($body:expr) => { @@ -80,7 +80,7 @@ fn assert_slice_correct(v: &ArrayBase) where S: Data, D: Dimension, - A: PartialEq + std::fmt::Debug, + A: PartialEq + core::fmt::Debug, { let slc = v.as_slice(); assert!(slc.is_some()); diff --git a/tests/numeric.rs b/tests/numeric.rs index 7c6f1441e..77d72f496 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -8,7 +8,7 @@ use approx::assert_abs_diff_eq; use ndarray::{arr0, arr1, arr2, array, aview1, Array, Array1, Array2, Array3, Axis}; -use std::f64; +use core::f64; #[test] fn test_mean_with_nan_values() { diff --git a/tests/oper.rs b/tests/oper.rs index 89c45888c..b1154586f 100644 --- a/tests/oper.rs +++ b/tests/oper.rs @@ -10,11 +10,11 @@ use ndarray::prelude::*; use ndarray::{rcarr1, rcarr2}; use ndarray::{Data, LinalgScalar}; use ndarray::{Ix, Ixs}; -use std::iter::FromIterator; +use core::iter::FromIterator; use approx::assert_abs_diff_eq; use defmac::defmac; -use std::ops::Neg; +use core::ops::Neg; fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32]) { let aa = rcarr1(a); diff --git a/tests/raw_views.rs b/tests/raw_views.rs index b63e42926..42f152195 100644 --- a/tests/raw_views.rs +++ b/tests/raw_views.rs @@ -1,7 +1,7 @@ use ndarray::prelude::*; use ndarray::Zip; -use std::cell::Cell; +use core::cell::Cell; #[test] fn raw_view_cast_cell() { diff --git a/tests/windows.rs b/tests/windows.rs index eb1a33411..ff353bdca 100644 --- a/tests/windows.rs +++ b/tests/windows.rs @@ -7,7 +7,7 @@ use ndarray::prelude::*; use ndarray::Zip; -use std::iter::FromIterator; +use core::iter::FromIterator; // Edge Cases for Windows iterator: // From 7e7735dc8db66de77aa5d6bbfda731b05e642406 Mon Sep 17 00:00:00 2001 From: Sparrow Li <68270294+SparrowLii@users.noreply.github.com> Date: Thu, 17 Dec 2020 21:12:26 +0800 Subject: [PATCH 03/20] Update azip.rs catch_unwind is implemented in std --- tests/azip.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/azip.rs b/tests/azip.rs index 4baeb5038..12d76a635 100644 --- a/tests/azip.rs +++ b/tests/azip.rs @@ -110,7 +110,7 @@ fn test_zip_assign_into_cell() { #[test] fn test_zip_collect_drop() { use core::cell::RefCell; - use core::panic; + use std::panic; struct Recorddrop<'a>((usize, usize), &'a RefCell>); From b59f41cdf244c977cd6222b036eec8d0dca94a86 Mon Sep 17 00:00:00 2001 From: Sparrow Li <68270294+SparrowLii@users.noreply.github.com> Date: Thu, 17 Dec 2020 21:47:07 +0800 Subject: [PATCH 04/20] Update oper.rs It looks like core is not found in oper.rs --- blas-tests/tests/oper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blas-tests/tests/oper.rs b/blas-tests/tests/oper.rs index 9fab9099e..2741123f9 100644 --- a/blas-tests/tests/oper.rs +++ b/blas-tests/tests/oper.rs @@ -8,7 +8,7 @@ use ndarray::linalg::general_mat_vec_mul; use ndarray::prelude::*; use ndarray::{Data, LinalgScalar}; use ndarray::{Ix, Ixs, SliceInfo, SliceOrIndex}; -use core::iter::FromIterator; +use std::iter::FromIterator; use approx::{assert_abs_diff_eq, assert_relative_eq}; use defmac::defmac; From ffc6780f3be6c8a06f5de806162cf5d51d948e35 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Sat, 19 Dec 2020 10:30:55 +0800 Subject: [PATCH 05/20] use std in tests --- tests/array-construct.rs | 2 +- tests/array.rs | 8 ++++---- tests/azip.rs | 8 ++++---- tests/dimension.rs | 2 +- tests/iterators.rs | 4 ++-- tests/numeric.rs | 2 +- tests/oper.rs | 4 ++-- tests/raw_views.rs | 2 +- tests/windows.rs | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/array-construct.rs b/tests/array-construct.rs index 76d0cfe1a..738e3b1fc 100644 --- a/tests/array-construct.rs +++ b/tests/array-construct.rs @@ -200,7 +200,7 @@ fn deny_wraparound_uninit() { #[test] fn maybe_uninit_1() { - use core::mem::MaybeUninit; + use std::mem::MaybeUninit; unsafe { // Array diff --git a/tests/array.rs b/tests/array.rs index d16555b4e..db54b7e5f 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -13,7 +13,7 @@ use ndarray::indices; use ndarray::prelude::*; use ndarray::{arr3, rcarr2}; use ndarray::{Slice, SliceInfo, SliceOrIndex}; -use core::iter::FromIterator; +use std::iter::FromIterator; macro_rules! assert_panics { ($body:expr) => { @@ -1048,7 +1048,7 @@ fn owned_array_with_stride() { #[test] fn owned_array_discontiguous() { - use core::iter::repeat; + use std::iter::repeat; let v: Vec<_> = (0..12).flat_map(|x| repeat(x).take(2)).collect(); let dim = (3, 2, 2); let strides = (8, 4, 2); @@ -1061,7 +1061,7 @@ fn owned_array_discontiguous() { #[test] fn owned_array_discontiguous_drop() { - use core::cell::RefCell; + use std::cell::RefCell; use std::collections::BTreeSet; use std::rc::Rc; @@ -2018,7 +2018,7 @@ fn array_macros() { mod as_standard_layout_tests { use super::*; use ndarray::Data; - use core::fmt::Debug; + use std::fmt::Debug; fn test_as_standard_layout_for(orig: ArrayBase) where diff --git a/tests/azip.rs b/tests/azip.rs index 12d76a635..b553d7fb5 100644 --- a/tests/azip.rs +++ b/tests/azip.rs @@ -8,11 +8,11 @@ use ndarray::prelude::*; use ndarray::Zip; -use core::iter::FromIterator; +use std::iter::FromIterator; use itertools::{assert_equal, cloned}; -use core::mem::swap; +use std::mem::swap; #[test] fn test_azip1() { @@ -95,7 +95,7 @@ fn test_zip_assign_into() { #[cfg(feature = "approx")] fn test_zip_assign_into_cell() { use approx::assert_abs_diff_eq; - use core::cell::Cell; + use std::cell::Cell; let a = Array::, _>::default((5, 10)); let b = Array::from_shape_fn((5, 10), |(i, j)| 1. / (i + 2 * j + 1) as f32); @@ -109,7 +109,7 @@ fn test_zip_assign_into_cell() { #[test] fn test_zip_collect_drop() { - use core::cell::RefCell; + use std::cell::RefCell; use std::panic; struct Recorddrop<'a>((usize, usize), &'a RefCell>); diff --git a/tests/dimension.rs b/tests/dimension.rs index c82ccf9e2..7e76132aa 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -4,7 +4,7 @@ use defmac::defmac; use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, IntoDimension, IxDyn, RemoveAxis}; -use core::hash::{Hash, Hasher}; +use std::hash::{Hash, Hasher}; #[test] fn insert_axis() { diff --git a/tests/iterators.rs b/tests/iterators.rs index 8169bdbf6..371339b96 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -11,7 +11,7 @@ use ndarray::{arr2, arr3, aview1, indices, s, Axis, Data, Dimension, Slice, Zip} use itertools::assert_equal; use itertools::{enumerate, rev}; -use core::iter::FromIterator; +use std::iter::FromIterator; macro_rules! assert_panics { ($body:expr) => { @@ -80,7 +80,7 @@ fn assert_slice_correct(v: &ArrayBase) where S: Data, D: Dimension, - A: PartialEq + core::fmt::Debug, + A: PartialEq + std::fmt::Debug, { let slc = v.as_slice(); assert!(slc.is_some()); diff --git a/tests/numeric.rs b/tests/numeric.rs index 77d72f496..7c6f1441e 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -8,7 +8,7 @@ use approx::assert_abs_diff_eq; use ndarray::{arr0, arr1, arr2, array, aview1, Array, Array1, Array2, Array3, Axis}; -use core::f64; +use std::f64; #[test] fn test_mean_with_nan_values() { diff --git a/tests/oper.rs b/tests/oper.rs index 32ada1485..7193a49da 100644 --- a/tests/oper.rs +++ b/tests/oper.rs @@ -11,11 +11,11 @@ use ndarray::{rcarr1, rcarr2}; use ndarray::{Data, LinalgScalar}; use ndarray::{Ix, Ixs}; use num_traits::Zero; -use core::iter::FromIterator; +use std::iter::FromIterator; use approx::assert_abs_diff_eq; use defmac::defmac; -use core::ops::Neg; +use std::ops::Neg; fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32]) { let aa = rcarr1(a); diff --git a/tests/raw_views.rs b/tests/raw_views.rs index 42f152195..b63e42926 100644 --- a/tests/raw_views.rs +++ b/tests/raw_views.rs @@ -1,7 +1,7 @@ use ndarray::prelude::*; use ndarray::Zip; -use core::cell::Cell; +use std::cell::Cell; #[test] fn raw_view_cast_cell() { diff --git a/tests/windows.rs b/tests/windows.rs index ff353bdca..eb1a33411 100644 --- a/tests/windows.rs +++ b/tests/windows.rs @@ -7,7 +7,7 @@ use ndarray::prelude::*; use ndarray::Zip; -use core::iter::FromIterator; +use std::iter::FromIterator; // Edge Cases for Windows iterator: // From 770d902966ea75f36d27912aeed3297b6c0d0a36 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Sat, 19 Dec 2020 10:33:40 +0800 Subject: [PATCH 06/20] add #![no_std] in lib.rs --- src/argument_traits.rs | 4 ++-- src/array_approx.rs | 1 + src/array_serde.rs | 6 ++++-- src/arrayformat.rs | 13 ++++++++----- src/arraytraits.rs | 19 ++++++++++--------- src/data_repr.rs | 11 ++++++----- src/data_traits.rs | 5 +++-- src/dimension/conversion.rs | 3 ++- src/dimension/dim.rs | 4 ++-- src/dimension/dimension_trait.rs | 7 ++++--- src/dimension/dynindeximpl.rs | 8 +++++--- src/dimension/mod.rs | 10 +++++----- src/dimension/ndindex.rs | 2 +- src/error.rs | 2 +- src/extension/nonnull.rs | 3 ++- src/free_functions.rs | 6 ++++-- src/impl_1d.rs | 1 + src/impl_constructors.rs | 4 +++- src/impl_methods.rs | 9 +++++---- src/impl_ops.rs | 4 ++-- src/impl_owned_array.rs | 3 ++- src/impl_raw_views.rs | 4 ++-- src/impl_special_element_types.rs | 6 +++--- src/impl_views/constructors.rs | 2 +- src/impl_views/conversions.rs | 2 +- src/iterators/lanes.rs | 2 +- src/iterators/macros.rs | 4 ++-- src/iterators/mod.rs | 9 +++++---- src/itertools.rs | 2 +- src/layout/layoutfmt.rs | 2 +- src/lib.rs | 13 +++++++++---- src/linalg/impl_linalg.rs | 11 ++++++----- src/linalg_traits.rs | 6 +++--- src/numeric/impl_numeric.rs | 2 +- src/numeric_util.rs | 2 +- src/parallel/impl_par_methods.rs | 2 +- src/parallel/send_producer.rs | 2 +- src/partial.rs | 4 ++-- src/slice.rs | 16 ++++++++-------- src/stacking.rs | 2 +- src/zip/mod.rs | 3 ++- 41 files changed, 125 insertions(+), 96 deletions(-) diff --git a/src/argument_traits.rs b/src/argument_traits.rs index ef1390485..a93e33a12 100644 --- a/src/argument_traits.rs +++ b/src/argument_traits.rs @@ -1,5 +1,5 @@ -use core::cell::Cell; -use core::mem::MaybeUninit; +use std::cell::Cell; +use std::mem::MaybeUninit; /// A producer element that can be assigned to once 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 ffadfdc4f..41f7d60c1 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -9,8 +9,10 @@ use serde::de::{self, MapAccess, SeqAccess, Visitor}; use serde::ser::{SerializeSeq, SerializeStruct}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use core::fmt; -use core::marker::PhantomData; +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 d719e255b..de6caf12c 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -7,7 +7,10 @@ // except according to those terms. use super::{ArrayBase, ArrayView, Axis, Data, Dimension, NdProducer}; use crate::aliases::{Ix1, IxDyn}; -use core::fmt; +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; @@ -46,9 +49,9 @@ impl FormatOptions { fn set_no_limit(mut self, no_limit: bool) -> Self { if no_limit { - self.axis_collapse_limit = core::usize::MAX; - self.axis_collapse_limit_next_last = core::usize::MAX; - self.axis_collapse_limit_last = core::usize::MAX; + self.axis_collapse_limit = std::usize::MAX; + self.axis_collapse_limit_next_last = std::usize::MAX; + self.axis_collapse_limit_last = std::usize::MAX; self } else { self @@ -286,7 +289,7 @@ where #[cfg(test)] mod formatting_with_omit { use itertools::Itertools; - use core::fmt; + use std::fmt; use super::*; use crate::prelude::*; diff --git a/src/arraytraits.rs b/src/arraytraits.rs index 55604eddd..449d57781 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -6,12 +6,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::hash; -use core::isize; -use core::iter::FromIterator; -use core::iter::IntoIterator; -use core::mem; -use core::ops::{Index, IndexMut}; +use std::hash; +use std::isize; +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}; @@ -154,7 +155,7 @@ where /// /// ```rust /// use ndarray::{Array, arr1}; - /// use core::iter::FromIterator; + /// use std::iter::FromIterator; /// /// // Either use `from_iter` directly or use `Iterator::collect`. /// let array = Array::from_iter((0..5).map(|x| x * x)); @@ -281,7 +282,7 @@ where let xs = slice.as_ref(); if mem::size_of::() == 0 { assert!( - xs.len() <= ::core::isize::MAX as usize, + xs.len() <= ::std::isize::MAX as usize, "Slice length must fit in `isize`.", ); } @@ -313,7 +314,7 @@ where let xs = slice.as_mut(); if mem::size_of::() == 0 { assert!( - xs.len() <= ::core::isize::MAX as usize, + xs.len() <= ::std::isize::MAX as usize, "Slice length must fit in `isize`.", ); } diff --git a/src/data_repr.rs b/src/data_repr.rs index 469e12629..07c7c1a54 100644 --- a/src/data_repr.rs +++ b/src/data_repr.rs @@ -1,8 +1,9 @@ - -use core::mem; -use core::mem::ManuallyDrop; -use core::ptr::NonNull; -use std::slice; +use std::mem; +use std::mem::ManuallyDrop; +use std::ptr::NonNull; +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 2ce217baf..27be5cb0d 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -9,9 +9,10 @@ //! The data (inner representation) traits for ndarray use rawpointer::PointerExt; -use core::mem::{self, size_of}; -use core::ptr::NonNull; +use std::mem::{self, size_of}; +use std::ptr::NonNull; use std::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 a41e46411..6b53a4eef 100644 --- a/src/dimension/conversion.rs +++ b/src/dimension/conversion.rs @@ -9,7 +9,8 @@ //! Tuple to array conversion, IntoDimension, and related things use num_traits::Zero; -use core::ops::{Index, IndexMut}; +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 213bfe120..97de6d842 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -7,7 +7,7 @@ // except according to those terms. -use core::fmt; +use std::fmt; use super::Dimension; use super::IntoDimension; use crate::itertools::zip; @@ -82,7 +82,7 @@ where } } -use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; +use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; macro_rules! impl_op { ($op:ident, $op_m:ident, $opassign:ident, $opassign_m:ident, $expr:ident) => { diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index b7831f76c..d98eedd65 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -6,9 +6,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::fmt::Debug; -use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; -use core::ops::{Index, IndexMut}; +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 8f39652ab..5c9cd0d61 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -1,7 +1,9 @@ use crate::imp_prelude::*; -use core::hash::{Hash, Hasher}; -use core::ops::{Deref, DerefMut, Index, IndexMut}; - +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 55e1b9259..b4610f0dc 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -21,8 +21,8 @@ pub use self::remove_axis::RemoveAxis; use crate::shape_builder::Strides; -use core::isize; -use core::mem; +use std::isize; +use std::mem; #[macro_use] mod macros; @@ -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/dimension/ndindex.rs b/src/dimension/ndindex.rs index fb5b29990..d9bac1d94 100644 --- a/src/dimension/ndindex.rs +++ b/src/dimension/ndindex.rs @@ -1,4 +1,4 @@ -use core::fmt::Debug; +use std::fmt::Debug; use super::{stride_offset, stride_offset_checked}; use crate::itertools::zip; diff --git a/src/error.rs b/src/error.rs index 68741c97d..090937561 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,7 @@ // except according to those terms. use super::Dimension; use std::error::Error; -use core::fmt; +use std::fmt; /// An error related to array shape or layout. #[derive(Clone)] diff --git a/src/extension/nonnull.rs b/src/extension/nonnull.rs index a63c97568..5aa50fdc2 100644 --- a/src/extension/nonnull.rs +++ b/src/extension/nonnull.rs @@ -1,4 +1,5 @@ -use core::ptr::NonNull; +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 6efa70062..95eb7dc81 100644 --- a/src/free_functions.rs +++ b/src/free_functions.rs @@ -6,8 +6,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::mem::{forget, size_of}; -use std::slice; +use std::mem::{forget, size_of}; +use alloc::slice; +use alloc::vec; +use alloc::vec::Vec; use crate::imp_prelude::*; use crate::{dimension, ArcArray1, ArcArray2}; 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 9904ef56b..9f3de4907 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -13,7 +13,9 @@ #![allow(clippy::match_wild_err_arm)] use num_traits::{Float, One, Zero}; -use core::mem::MaybeUninit; +use std::mem::MaybeUninit; +use alloc::vec; +use alloc::vec::Vec; use crate::dimension; use crate::error::{self, ShapeError}; diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 56fc3c9ce..7a3e4b200 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -6,9 +6,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::ptr as std_ptr; -use std::slice; - +use std::ptr as std_ptr; +use alloc::slice; +use alloc::vec; +use alloc::vec::Vec; use rawpointer::PointerExt; use crate::imp_prelude::*; @@ -1013,7 +1014,7 @@ where /// ``` /// use ndarray::Array; /// use ndarray::{arr3, Axis}; - /// use core::iter::FromIterator; + /// use std::iter::FromIterator; /// /// let a = Array::from_iter(0..28).into_shape((2, 7, 2)).unwrap(); /// let mut iter = a.axis_chunks_iter(Axis(1), 2); diff --git a/src/impl_ops.rs b/src/impl_ops.rs index 45bf367a2..4804356e8 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -226,7 +226,7 @@ mod arithmetic_ops { use crate::imp_prelude::*; use num_complex::Complex; - use core::ops::*; + use std::ops::*; impl_binary_op!(Add, +, add, +=, "addition"); impl_binary_op!(Sub, -, sub, -=, "subtraction"); @@ -357,7 +357,7 @@ mod assign_ops { macro_rules! impl_assign_op { ($trt:ident, $method:ident, $doc:expr) => { - use core::ops::$trt; + use std::ops::$trt; #[doc=$doc] /// If their shapes disagree, `rhs` is broadcast to the shape of `self`. diff --git a/src/impl_owned_array.rs b/src/impl_owned_array.rs index f244555e5..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`. @@ -21,7 +22,7 @@ impl Array { /// assert_eq!(scalar, Foo); /// ``` pub fn into_scalar(self) -> A { - let size = ::core::mem::size_of::(); + let size = ::std::mem::size_of::(); if size == 0 { // Any index in the `Vec` is fine since all elements are identical. self.data.into_vec().remove(0) diff --git a/src/impl_raw_views.rs b/src/impl_raw_views.rs index 8ad097fee..8377dc93c 100644 --- a/src/impl_raw_views.rs +++ b/src/impl_raw_views.rs @@ -1,5 +1,5 @@ -use core::mem; -use core::ptr::NonNull; +use std::mem; +use std::ptr::NonNull; use crate::dimension::{self, stride_offset}; use crate::extension::nonnull::nonnull_debug_checked_from_ptr; diff --git a/src/impl_special_element_types.rs b/src/impl_special_element_types.rs index 9e7c82656..40cba5822 100644 --- a/src/impl_special_element_types.rs +++ b/src/impl_special_element_types.rs @@ -6,9 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::mem::size_of; -use core::mem::ManuallyDrop; -use core::mem::MaybeUninit; +use std::mem::size_of; +use std::mem::ManuallyDrop; +use std::mem::MaybeUninit; use crate::imp_prelude::*; use crate::RawDataSubst; diff --git a/src/impl_views/constructors.rs b/src/impl_views/constructors.rs index fa5e918b4..bc1602af4 100644 --- a/src/impl_views/constructors.rs +++ b/src/impl_views/constructors.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::ptr::NonNull; +use std::ptr::NonNull; use crate::dimension; use crate::error::ShapeError; diff --git a/src/impl_views/conversions.rs b/src/impl_views/conversions.rs index 303541b8b..87d3d9ea9 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/lanes.rs b/src/iterators/lanes.rs index e648445da..2163c58a6 100644 --- a/src/iterators/lanes.rs +++ b/src/iterators/lanes.rs @@ -1,4 +1,4 @@ -use core::marker::PhantomData; +use std::marker::PhantomData; use super::LanesIter; use super::LanesIterMut; diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index d3a54453e..973c0e3ea 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -1,7 +1,7 @@ // Send and Sync // All the iterators are thread safe the same way the slice's iterator are -// read-only iterators use Sync => Send rules, same as `std::slice::Iter`. +// read-only iterators use Sync => Send rules, same as `alloc::slice::Iter`. macro_rules! send_sync_read_only { ($name:ident) => { unsafe impl<'a, A, D> Send for $name<'a, A, D> @@ -19,7 +19,7 @@ macro_rules! send_sync_read_only { }; } -// read-write iterators use Send => Send rules, same as `std::slice::IterMut`. +// read-write iterators use Send => Send rules, same as `alloc::slice::IterMut`. macro_rules! send_sync_read_write { ($name:ident) => { unsafe impl<'a, A, D> Send for $name<'a, A, D> diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 20f120e8c..c61008712 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -13,9 +13,10 @@ pub mod iter; mod lanes; mod windows; -use core::iter::FromIterator; -use core::marker::PhantomData; -use core::ptr; +use std::iter::FromIterator; +use std::marker::PhantomData; +use std::ptr; +use alloc::vec::Vec; use crate::Ix1; @@ -26,7 +27,7 @@ pub use self::chunks::{ExactChunks, ExactChunksIter, ExactChunksIterMut, ExactCh pub use self::lanes::{Lanes, LanesMut}; pub use self::windows::Windows; -use std::slice::{self, Iter as SliceIter, IterMut as SliceIterMut}; +use alloc::slice::{self, Iter as SliceIter, IterMut as SliceIterMut}; /// Base for iterators over all axes. /// diff --git a/src/itertools.rs b/src/itertools.rs index 60ad8eee8..96732f903 100644 --- a/src/itertools.rs +++ b/src/itertools.rs @@ -9,7 +9,7 @@ //! A few iterator-related utilities and tools -use core::iter; +use std::iter; /// Iterate `iterable` with a running index. /// diff --git a/src/layout/layoutfmt.rs b/src/layout/layoutfmt.rs index 65f4dcfb2..3d7fad00a 100644 --- a/src/layout/layoutfmt.rs +++ b/src/layout/layoutfmt.rs @@ -10,7 +10,7 @@ use super::Layout; const LAYOUT_NAMES: &[&str] = &["C", "F", "c", "f"]; -use core::fmt; +use std::fmt; impl fmt::Debug for Layout { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/lib.rs b/src/lib.rs index 1e239dad7..048f32cbb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ clippy::deref_addrof, clippy::unreadable_literal )] +#![no_std] //! The `ndarray` crate provides an *n*-dimensional container for general elements //! and for numerics. @@ -109,6 +110,10 @@ //! 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; +extern crate std; + #[cfg(feature = "blas")] extern crate blas_src; #[cfg(feature = "blas")] @@ -117,7 +122,7 @@ extern crate cblas_sys; #[cfg(feature = "docs")] pub mod doc; -use core::marker::PhantomData; +use std::marker::PhantomData; use std::sync::Arc; pub use crate::dimension::dim::*; @@ -135,7 +140,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}; @@ -1236,7 +1241,7 @@ where data: S, /// A non-null pointer into the buffer held by `data`; may point anywhere /// in its range. If `S: Data`, this pointer must be aligned. - ptr: core::ptr::NonNull, + ptr: std::ptr::NonNull, /// The lengths of the axes. dim: D, /// The element count stride per axis. To be parsed as `isize`. @@ -1599,5 +1604,5 @@ mod impl_cow; /// Returns `true` if the pointer is aligned. pub(crate) fn is_aligned(ptr: *const T) -> bool { - (ptr as usize) % ::core::mem::align_of::() == 0 + (ptr as usize) % ::std::mem::align_of::() == 0 } diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index 9b2cebc51..0215e8bd7 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -11,12 +11,13 @@ use crate::numeric_util; use crate::{LinalgScalar, Zip}; -use core::any::TypeId; +use std::any::TypeId; +use alloc::vec::Vec; #[cfg(feature = "blas")] -use core::cmp; +use std::cmp; #[cfg(feature = "blas")] -use core::mem::swap; +use std::mem::swap; #[cfg(feature = "blas")] use std::os::raw::c_int; @@ -285,7 +286,7 @@ where #[inline(never)] fn dot_shape_error(m: usize, k: usize, k2: usize, n: usize) -> ! { match m.checked_mul(n) { - Some(len) if len <= ::core::isize::MAX as usize => {} + Some(len) if len <= ::std::isize::MAX as usize => {} _ => panic!("ndarray: shape {} × {} overflows isize", m, n), } panic!( @@ -677,7 +678,7 @@ fn same_type() -> bool { // **Panics** if `A` and `B` are not the same type fn cast_as(a: &A) -> B { assert!(same_type::()); - unsafe { ::core::ptr::read(a as *const _ as *const B) } + unsafe { ::std::ptr::read(a as *const _ as *const B) } } #[cfg(feature = "blas")] diff --git a/src/linalg_traits.rs b/src/linalg_traits.rs index 943180832..43fe5f8d3 100644 --- a/src/linalg_traits.rs +++ b/src/linalg_traits.rs @@ -9,9 +9,9 @@ use crate::ScalarOperand; #[cfg(feature = "std")] use num_traits::Float; use num_traits::{One, Zero}; -use core::fmt; -use core::ops::{Add, Div, Mul, Sub}; -use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; +use std::fmt; +use std::ops::{Add, Div, Mul, Sub}; +use std::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; /// Elements that support linear algebra operations. /// diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index 0fd060eac..85f69444d 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -7,7 +7,7 @@ // except according to those terms. use num_traits::{self, Float, FromPrimitive, Zero}; -use core::ops::{Add, Div, Mul}; +use std::ops::{Add, Div, Mul}; use crate::imp_prelude::*; use crate::itertools::enumerate; diff --git a/src/numeric_util.rs b/src/numeric_util.rs index f8e2a2e43..b06850fd0 100644 --- a/src/numeric_util.rs +++ b/src/numeric_util.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::cmp; +use std::cmp; use crate::LinalgScalar; diff --git a/src/parallel/impl_par_methods.rs b/src/parallel/impl_par_methods.rs index 0f4592ca1..a4efa560f 100644 --- a/src/parallel/impl_par_methods.rs +++ b/src/parallel/impl_par_methods.rs @@ -107,7 +107,7 @@ macro_rules! zip_impl { }) .reduce(Partial::stub, Partial::try_merge); - if core::mem::needs_drop::() { + if std::mem::needs_drop::() { debug_assert_eq!(total_len, collect_result.len, "collect len is not correct, expected {}", total_len); assert!(collect_result.len == total_len, diff --git a/src/parallel/send_producer.rs b/src/parallel/send_producer.rs index 00ae680f4..5324b3490 100644 --- a/src/parallel/send_producer.rs +++ b/src/parallel/send_producer.rs @@ -1,7 +1,7 @@ use crate::imp_prelude::*; use crate::{Layout, NdProducer}; -use core::ops::{Deref, DerefMut}; +use std::ops::{Deref, DerefMut}; /// An NdProducer that is unconditionally `Send`. #[repr(transparent)] diff --git a/src/partial.rs b/src/partial.rs index 7036dc588..a8146aff0 100644 --- a/src/partial.rs +++ b/src/partial.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::ptr; +use std::ptr; /// Partial is a partially written contiguous slice of data; /// it is the owner of the elements, but not the allocation, @@ -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/slice.rs b/src/slice.rs index 2dc476e10..86a2b0b8f 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -8,9 +8,9 @@ use crate::dimension::slices_intersect; use crate::error::{ErrorKind, ShapeError}; use crate::{ArrayViewMut, Dimension}; -use core::fmt; -use core::marker::PhantomData; -use core::ops::{Deref, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}; +use std::fmt; +use std::marker::PhantomData; +use std::ops::{Deref, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}; /// A slice (range with step size). /// @@ -596,11 +596,11 @@ macro_rules! s( } }; // empty call, i.e. `s![]` - (@parse ::core::marker::PhantomData::<$crate::Ix0>, []) => { + (@parse ::std::marker::PhantomData::<$crate::Ix0>, []) => { { #[allow(unsafe_code)] unsafe { - $crate::SliceInfo::new_unchecked([], ::core::marker::PhantomData::<$crate::Ix0>) + $crate::SliceInfo::new_unchecked([], ::std::marker::PhantomData::<$crate::Ix0>) } } }; @@ -608,16 +608,16 @@ macro_rules! s( (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") }; // convert range/index into SliceOrIndex (@convert $r:expr) => { - <$crate::SliceOrIndex as ::core::convert::From<_>>::from($r) + <$crate::SliceOrIndex as ::std::convert::From<_>>::from($r) }; // convert range/index and step into SliceOrIndex (@convert $r:expr, $s:expr) => { - <$crate::SliceOrIndex as ::core::convert::From<_>>::from($r).step_by($s as isize) + <$crate::SliceOrIndex as ::std::convert::From<_>>::from($r).step_by($s as isize) }; ($($t:tt)*) => { // The extra `*&` is a workaround for this compiler bug: // https://github.com/rust-lang/rust/issues/23014 - &*&$crate::s![@parse ::core::marker::PhantomData::<$crate::Ix0>, [] $($t)*] + &*&$crate::s![@parse ::std::marker::PhantomData::<$crate::Ix0>, [] $($t)*] }; ); diff --git a/src/stacking.rs b/src/stacking.rs index 2c2db7b59..efbf37d4d 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::*; diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 29972b78a..534f97f3f 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -9,7 +9,8 @@ #[macro_use] mod zipmacro; -use core::mem::MaybeUninit; +use std::mem::MaybeUninit; +use alloc::vec::Vec; use crate::imp_prelude::*; use crate::AssignElem; From 70665971eea9b84d31662a19bbc9e8de877bd7de Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Sat, 19 Dec 2020 10:45:31 +0800 Subject: [PATCH 07/20] use std in other tests --- benches/bench1.rs | 4 ++-- benches/higher-order.rs | 2 +- examples/axis_ops.rs | 2 +- examples/life.rs | 2 +- examples/sort-axis.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index d68b94f50..8cd04c458 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -271,7 +271,7 @@ fn add_2d_alloc_zip_uninit(bench: &mut test::Bencher) { bench.iter(|| unsafe { let mut c = Array::uninitialized(a.dim()); azip!((&a in &a, &b in &b, c in c.raw_view_mut()) - core::ptr::write(c, a + b) + std::ptr::write(c, a + b) ); c }); @@ -632,7 +632,7 @@ fn iadd_scalar_2d_strided_dyn(bench: &mut test::Bencher) { fn scaled_add_2d_f32_regular(bench: &mut test::Bencher) { let mut av = Array::::zeros((ADD2DSZ, ADD2DSZ)); let bv = Array::::zeros((ADD2DSZ, ADD2DSZ)); - let scalar = core::f32::consts::PI; + let scalar = std::f32::consts::PI; bench.iter(|| { av.scaled_add(scalar, &bv); }); diff --git a/benches/higher-order.rs b/benches/higher-order.rs index e7963218f..2ea0721af 100644 --- a/benches/higher-order.rs +++ b/benches/higher-order.rs @@ -6,7 +6,7 @@ clippy::many_single_char_names )] extern crate test; -use core::iter::FromIterator; +use std::iter::FromIterator; use test::black_box; use test::Bencher; diff --git a/examples/axis_ops.rs b/examples/axis_ops.rs index eaebaeda7..3dbf0eee9 100644 --- a/examples/axis_ops.rs +++ b/examples/axis_ops.rs @@ -10,7 +10,7 @@ use ndarray::prelude::*; fn regularize(a: &mut Array) -> Result<(), ()> where D: Dimension, - A: ::core::fmt::Debug, + A: ::std::fmt::Debug, { println!("Regularize:\n{:?}", a); // reverse all neg axes diff --git a/examples/life.rs b/examples/life.rs index 7421de6fa..1c2789389 100644 --- a/examples/life.rs +++ b/examples/life.rs @@ -6,7 +6,7 @@ )] use ndarray::prelude::*; -use core::iter::FromIterator; +use std::iter::FromIterator; const INPUT: &[u8] = include_bytes!("life.txt"); diff --git a/examples/sort-axis.rs b/examples/sort-axis.rs index c888fa9de..eabf9bb50 100644 --- a/examples/sort-axis.rs +++ b/examples/sort-axis.rs @@ -1,8 +1,8 @@ use ndarray::prelude::*; use ndarray::{Data, RemoveAxis, Zip}; -use core::cmp::Ordering; -use core::ptr::copy_nonoverlapping; +use std::cmp::Ordering; +use std::ptr::copy_nonoverlapping; // Type invariant: Each index appears exactly once #[derive(Clone, Debug)] From 32fc25562c85654280bc64b684b2f0efd24d2f9d Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Tue, 22 Dec 2020 15:02:16 +0800 Subject: [PATCH 08/20] add "use crate core as std" --- src/data_traits.rs | 2 +- src/error.rs | 2 ++ src/iterators/mod.rs | 2 +- src/lib.rs | 5 ++++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/data_traits.rs b/src/data_traits.rs index 27be5cb0d..bdcc40aa2 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -11,7 +11,7 @@ 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::{ 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/iterators/mod.rs b/src/iterators/mod.rs index c61008712..98f78851f 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -27,7 +27,7 @@ pub use self::chunks::{ExactChunks, ExactChunksIter, ExactChunksIterMut, ExactCh pub use self::lanes::{Lanes, LanesMut}; pub use self::windows::Windows; -use alloc::slice::{self, Iter as SliceIter, IterMut as SliceIterMut}; +use std::slice::{self, Iter as SliceIter, IterMut as SliceIterMut}; /// Base for iterators over all axes. /// diff --git a/src/lib.rs b/src/lib.rs index 048f32cbb..a00be7bf3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,10 @@ 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; @@ -123,7 +126,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}; From 93d4f6e6435ee3f5e1d4bb3daab45d16e273b2ba Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Wed, 23 Dec 2020 15:38:27 +0800 Subject: [PATCH 09/20] Change dependent crate features for no_std --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b312fd4a6..bb6bfa1d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,19 +28,19 @@ bench = false test = true [dependencies] -num-integer = "0.1.39" -num-traits = { version = "0.2", default-features = false } +num-integer = { version = "0.1.39", default-features = false } +num-traits = { version = "0.2", default-features = false , features = ["libm"] } 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" } From c621b70eddbfa01b8e09b7e0595bfdd2159f8fae Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Thu, 24 Dec 2020 15:18:31 +0800 Subject: [PATCH 10/20] =?UTF-8?q?use=20FloatCore=20as=20Float=20in=20no=5F?= =?UTF-8?q?std=20environment.=20Therefore=20geomspace=E3=80=81logspace?= =?UTF-8?q?=E3=80=81var=5Faxis=E3=80=81std=5Faxis=20cannot=20use.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/convo.rs | 3 +-- src/geomspace.rs | 1 + src/impl_constructors.rs | 10 ++++++++-- src/iterators/mod.rs | 9 ++++++--- src/lib.rs | 7 ++++++- src/linspace.rs | 2 +- src/logspace.rs | 3 ++- src/numeric/impl_numeric.rs | 5 ++++- tests/numeric.rs | 6 ++++++ 9 files changed, 35 insertions(+), 11 deletions(-) diff --git a/examples/convo.rs b/examples/convo.rs index a9f073bd5..7d987d86b 100644 --- a/examples/convo.rs +++ b/examples/convo.rs @@ -1,8 +1,7 @@ #![allow(unused)] extern crate ndarray; -extern crate num_traits; -use num_traits::Float; +use ndarray::Float; use ndarray::prelude::*; 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_constructors.rs b/src/impl_constructors.rs index 9f3de4907..876db2273 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -12,7 +12,8 @@ #![allow(clippy::match_wild_err_arm)] -use num_traits::{Float, One, Zero}; +use crate::Float; +use num_traits::{One, Zero}; use std::mem::MaybeUninit; use alloc::vec; use alloc::vec::Vec; @@ -25,7 +26,10 @@ use crate::indexes; use crate::indices; use crate::iterators::{to_vec, to_vec_mapped}; use crate::StrideShape; -use crate::{geomspace, linspace, logspace}; +use crate::linspace; +#[cfg(feature = "std")] +use crate::{geomspace, logspace}; + /// # Constructor Methods for Owned Arrays /// @@ -114,6 +118,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, @@ -148,6 +153,7 @@ where /// # /// # example().unwrap(); /// ``` + #[cfg(feature = "std")] pub fn geomspace(start: A, end: A, n: usize) -> Option where A: Float, diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 98f78851f..5e8c50165 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1447,10 +1447,13 @@ pub unsafe trait TrustedIterator {} use crate::indexes::IndicesIterF; use crate::iter::IndicesIter; -use crate::{geomspace::Geomspace, linspace::Linspace, logspace::Logspace}; - -unsafe impl TrustedIterator for Geomspace {} +use crate::linspace::Linspace; unsafe impl TrustedIterator for Linspace {} +#[cfg(feature = "std")] +use crate::{geomspace::Geomspace, logspace::Logspace}; +#[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 a00be7bf3..b289e2563 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,11 +112,17 @@ extern crate alloc; + #[cfg(feature = "std")] extern crate std; #[cfg(not(feature = "std"))] extern crate core as std; +#[cfg(feature = "std")] +pub use num_traits::Float; +#[cfg(not(feature = "std"))] +pub use num_traits::float::FloatCore as Float; + #[cfg(feature = "blas")] extern crate blas_src; #[cfg(feature = "blas")] @@ -169,7 +175,6 @@ mod data_repr; mod data_traits; pub use crate::aliases::*; - #[allow(deprecated)] pub use crate::data_traits::{ Data, DataClone, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut, diff --git a/src/linspace.rs b/src/linspace.rs index ca0eae470..2932def29 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use num_traits::Float; +use crate::Float; /// An iterator of a sequence of evenly spaced floats. /// diff --git a/src/logspace.rs b/src/logspace.rs index 55b5397c8..117bdfafb 100644 --- a/src/logspace.rs +++ b/src/logspace.rs @@ -5,7 +5,8 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use num_traits::Float; +#![cfg(feature = "std")] +use crate::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 85f69444d..b0efd7d64 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -6,7 +6,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use num_traits::{self, Float, FromPrimitive, Zero}; +use crate::Float; +use num_traits::{self, FromPrimitive, Zero}; use std::ops::{Add, Div, Mul}; use crate::imp_prelude::*; @@ -230,6 +231,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, @@ -298,6 +300,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/tests/numeric.rs b/tests/numeric.rs index 7c6f1441e..475d12294 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -183,6 +183,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.); @@ -190,12 +191,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); @@ -204,6 +207,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.); @@ -213,12 +217,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.); From 08c65f12a88bad0ce920f090d164c36e6046dfbc Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Thu, 24 Dec 2020 15:22:54 +0800 Subject: [PATCH 11/20] not use libm; use std in matrixmultiply --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb6bfa1d0..35c0a68da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ test = true [dependencies] num-integer = { version = "0.1.39", default-features = false } -num-traits = { version = "0.2", default-features = false , features = ["libm"] } +num-traits = { version = "0.2", default-features = false } num-complex = { version = "0.3", default-features = false } rayon = { version = "1.0.3", optional = true } @@ -66,7 +66,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] From d9b8db6b0a4ce401e300f88c8cf266fe8fdc1b33 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Thu, 24 Dec 2020 20:25:14 +0800 Subject: [PATCH 12/20] delete pub use Float in lib.rs --- examples/convo.rs | 5 ++++- src/impl_constructors.rs | 6 ++++-- src/lib.rs | 5 ----- src/linspace.rs | 5 ++++- src/logspace.rs | 2 +- src/numeric/impl_numeric.rs | 5 ++++- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/convo.rs b/examples/convo.rs index 7d987d86b..6f8d33282 100644 --- a/examples/convo.rs +++ b/examples/convo.rs @@ -1,7 +1,10 @@ #![allow(unused)] extern crate ndarray; -use ndarray::Float; +#[cfg(feature = "std")] +use num_traits::Float; +#[cfg(not(feature = "std"))] +use num_traits::float::FloatCore as Float; use ndarray::prelude::*; diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 876db2273..c24ce34e9 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -11,8 +11,10 @@ //! #![allow(clippy::match_wild_err_arm)] - -use crate::Float; +#[cfg(feature = "std")] +use num_traits::Float; +#[cfg(not(feature = "std"))] +use num_traits::float::FloatCore as Float; use num_traits::{One, Zero}; use std::mem::MaybeUninit; use alloc::vec; diff --git a/src/lib.rs b/src/lib.rs index b289e2563..dc5fd0774 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,11 +118,6 @@ extern crate std; #[cfg(not(feature = "std"))] extern crate core as std; -#[cfg(feature = "std")] -pub use num_traits::Float; -#[cfg(not(feature = "std"))] -pub use num_traits::float::FloatCore as Float; - #[cfg(feature = "blas")] extern crate blas_src; #[cfg(feature = "blas")] diff --git a/src/linspace.rs b/src/linspace.rs index 2932def29..dbef756e6 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -5,7 +5,10 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use crate::Float; +#[cfg(feature = "std")] +use num_traits::Float; +#[cfg(not(feature = "std"))] +use num_traits::float::FloatCore as Float; /// An iterator of a sequence of evenly spaced floats. /// diff --git a/src/logspace.rs b/src/logspace.rs index 117bdfafb..4dc6e1f32 100644 --- a/src/logspace.rs +++ b/src/logspace.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. #![cfg(feature = "std")] -use crate::Float; +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 b0efd7d64..0f9e84153 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -6,7 +6,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use crate::Float; +#[cfg(feature = "std")] +use num_traits::Float; +#[cfg(not(feature = "std"))] +use num_traits::float::FloatCore as Float; use num_traits::{self, FromPrimitive, Zero}; use std::ops::{Add, Div, Mul}; From 97f95720f5a21e2562b77aae039ff1dde8a7b035 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Fri, 25 Dec 2020 15:05:20 +0800 Subject: [PATCH 13/20] add libm feature to support Float in no_std --- Cargo.toml | 6 +++++- examples/convo.rs | 4 ++-- src/geomspace.rs | 2 +- src/impl_constructors.rs | 10 +++++----- src/iterators/mod.rs | 6 +++--- src/linspace.rs | 4 ++-- src/logspace.rs | 2 +- src/numeric/impl_numeric.rs | 8 ++++---- tests/numeric.rs | 12 ++++++------ 9 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 35c0a68da..25281b90e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,10 @@ itertools = { version = "0.9.0", default-features = false, features = ["use_std" [features] default = ["std"] + +# This feature enalbe num_trait::Float in no_std environment +libm = ["num-traits/libm"] + # Enable blas usage # See README for more instructions blas = ["cblas-sys", "blas-src"] @@ -74,7 +78,7 @@ debug = true [workspace] members = ["ndarray-rand", "serialization-tests", "blas-tests"] -exclude = ["numeric-tests"] +exclude = ["numeric-tests","ensure_no_std"] [package.metadata.release] no-dev-version = true diff --git a/examples/convo.rs b/examples/convo.rs index 6f8d33282..d97d26e08 100644 --- a/examples/convo.rs +++ b/examples/convo.rs @@ -1,9 +1,9 @@ #![allow(unused)] extern crate ndarray; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use num_traits::Float; -#[cfg(not(feature = "std"))] +#[cfg(not(any(feature = "std", feature = "libm")))] use num_traits::float::FloatCore as Float; use ndarray::prelude::*; diff --git a/src/geomspace.rs b/src/geomspace.rs index c1935c71e..4aa923bc2 100644 --- a/src/geomspace.rs +++ b/src/geomspace.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(feature = "std")] +#![cfg(any(feature = "std", feature = "libm"))] use num_traits::Float; /// An iterator of a sequence of geometrically spaced floats. diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index c24ce34e9..d85c38c43 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -11,9 +11,9 @@ //! #![allow(clippy::match_wild_err_arm)] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use num_traits::Float; -#[cfg(not(feature = "std"))] +#[cfg(not(any(feature = "std", feature = "libm")))] use num_traits::float::FloatCore as Float; use num_traits::{One, Zero}; use std::mem::MaybeUninit; @@ -29,7 +29,7 @@ use crate::indices; use crate::iterators::{to_vec, to_vec_mapped}; use crate::StrideShape; use crate::linspace; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use crate::{geomspace, logspace}; @@ -120,7 +120,7 @@ where /// assert_abs_diff_eq!(array, arr1(&[-1e3, -1e2, -1e1, -1e0])); /// # } /// ``` - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] pub fn logspace(base: A, start: A, end: A, n: usize) -> Self where A: Float, @@ -155,7 +155,7 @@ where /// # /// # example().unwrap(); /// ``` - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] pub fn geomspace(start: A, end: A, n: usize) -> Option where A: Float, diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 5e8c50165..511fafda3 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1449,11 +1449,11 @@ use crate::indexes::IndicesIterF; use crate::iter::IndicesIter; use crate::linspace::Linspace; unsafe impl TrustedIterator for Linspace {} -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use crate::{geomspace::Geomspace, logspace::Logspace}; -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] unsafe impl TrustedIterator for Geomspace {} -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] 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/linspace.rs b/src/linspace.rs index dbef756e6..2daeec406 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -5,9 +5,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use num_traits::Float; -#[cfg(not(feature = "std"))] +#[cfg(not(any(feature = "std", feature = "libm")))] use num_traits::float::FloatCore as Float; /// An iterator of a sequence of evenly spaced floats. diff --git a/src/logspace.rs b/src/logspace.rs index 4dc6e1f32..c55af151a 100644 --- a/src/logspace.rs +++ b/src/logspace.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(feature = "std")] +#![cfg(any(feature = "std", feature = "libm"))] 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 0f9e84153..22fae4743 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -6,9 +6,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] use num_traits::Float; -#[cfg(not(feature = "std"))] +#[cfg(not(any(feature = "std", feature = "libm")))] use num_traits::float::FloatCore as Float; use num_traits::{self, FromPrimitive, Zero}; use std::ops::{Add, Div, Mul}; @@ -234,7 +234,7 @@ where /// let var = a.var_axis(Axis(0), 1.); /// assert_eq!(var, aview1(&[4., 4.])); /// ``` - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] pub fn var_axis(&self, axis: Axis, ddof: A) -> Array where A: Float + FromPrimitive, @@ -303,7 +303,7 @@ where /// let stddev = a.std_axis(Axis(0), 1.); /// assert_eq!(stddev, aview1(&[2., 2.])); /// ``` - #[cfg(feature = "std")] + #[cfg(any(feature = "std", feature = "libm"))] pub fn std_axis(&self, axis: Axis, ddof: A) -> Array where A: Float + FromPrimitive, diff --git a/tests/numeric.rs b/tests/numeric.rs index 475d12294..f4f312ca9 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -183,7 +183,7 @@ fn std_axis() { #[test] #[should_panic] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] fn var_axis_negative_ddof() { let a = array![1., 2., 3.]; a.var_axis(Axis(0), -1.); @@ -191,14 +191,14 @@ fn var_axis_negative_ddof() { #[test] #[should_panic] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] fn var_axis_too_large_ddof() { let a = array![1., 2., 3.]; a.var_axis(Axis(0), 4.); } #[test] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] fn var_axis_nan_ddof() { let a = Array2::::zeros((2, 3)); let v = a.var_axis(Axis(1), ::std::f64::NAN); @@ -207,7 +207,7 @@ fn var_axis_nan_ddof() { } #[test] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] fn var_axis_empty_axis() { let a = Array2::::zeros((2, 0)); let v = a.var_axis(Axis(1), 0.); @@ -217,14 +217,14 @@ fn var_axis_empty_axis() { #[test] #[should_panic] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] fn std_axis_bad_dof() { let a = array![1., 2., 3.]; a.std_axis(Axis(0), 4.); } #[test] -#[cfg(feature = "std")] +#[cfg(any(feature = "std", feature = "libm"))] fn std_axis_empty_axis() { let a = Array2::::zeros((2, 0)); let v = a.std_axis(Axis(1), 0.); From a66c23c264bda409eb1c9f5e16f45796ac4003bd Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Wed, 6 Jan 2021 17:35:54 +0800 Subject: [PATCH 14/20] not use Float in no_std --- Cargo.toml | 3 --- examples/convo.rs | 8 +++++--- examples/sort-axis.rs | 4 +++- src/geomspace.rs | 2 +- src/impl_constructors.rs | 15 +++++++-------- src/iterators/mod.rs | 10 +++++----- src/lib.rs | 4 ++-- src/linspace.rs | 4 +--- src/logspace.rs | 2 +- src/numeric/impl_numeric.rs | 9 ++++----- tests/array-construct.rs | 1 + tests/array.rs | 6 ++++++ tests/broadcast.rs | 3 +++ tests/dimension.rs | 1 + tests/iterator_chunks.rs | 1 + tests/iterators.rs | 4 ++++ tests/ixdyn.rs | 1 + tests/numeric.rs | 12 ++++++------ tests/oper.rs | 2 +- 19 files changed, 53 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25281b90e..234688904 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,9 +53,6 @@ itertools = { version = "0.9.0", default-features = false, features = ["use_std" [features] default = ["std"] -# This feature enalbe num_trait::Float in no_std environment -libm = ["num-traits/libm"] - # Enable blas usage # See README for more instructions blas = ["cblas-sys", "blas-src"] diff --git a/examples/convo.rs b/examples/convo.rs index d97d26e08..b50ab5247 100644 --- a/examples/convo.rs +++ b/examples/convo.rs @@ -1,10 +1,8 @@ #![allow(unused)] extern crate ndarray; -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] use num_traits::Float; -#[cfg(not(any(feature = "std", feature = "libm")))] -use num_traits::float::FloatCore as Float; use ndarray::prelude::*; @@ -15,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, @@ -43,6 +42,7 @@ where } } +#[cfg(feature = "std")] fn main() { let n = 16; let mut a = Array::zeros((n, n)); @@ -63,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/geomspace.rs b/src/geomspace.rs index 4aa923bc2..c1935c71e 100644 --- a/src/geomspace.rs +++ b/src/geomspace.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(any(feature = "std", feature = "libm"))] +#![cfg(feature = "std")] use num_traits::Float; /// An iterator of a sequence of geometrically spaced floats. diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index d85c38c43..9b84f3105 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -11,10 +11,8 @@ //! #![allow(clippy::match_wild_err_arm)] -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] use num_traits::Float; -#[cfg(not(any(feature = "std", feature = "libm")))] -use num_traits::float::FloatCore as Float; use num_traits::{One, Zero}; use std::mem::MaybeUninit; use alloc::vec; @@ -28,9 +26,8 @@ use crate::indexes; use crate::indices; use crate::iterators::{to_vec, to_vec_mapped}; use crate::StrideShape; -use crate::linspace; -#[cfg(any(feature = "std", feature = "libm"))] -use crate::{geomspace, logspace}; +#[cfg(feature = "std")] +use crate::{geomspace, linspace, logspace}; /// # Constructor Methods for Owned Arrays @@ -74,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, @@ -92,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, @@ -120,7 +119,7 @@ where /// assert_abs_diff_eq!(array, arr1(&[-1e3, -1e2, -1e1, -1e0])); /// # } /// ``` - #[cfg(any(feature = "std", feature = "libm"))] + #[cfg(feature = "std")] pub fn logspace(base: A, start: A, end: A, n: usize) -> Self where A: Float, @@ -155,7 +154,7 @@ where /// # /// # example().unwrap(); /// ``` - #[cfg(any(feature = "std", feature = "libm"))] + #[cfg(feature = "std")] pub fn geomspace(start: A, end: A, n: usize) -> Option where A: Float, diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 511fafda3..df81858ea 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1447,13 +1447,13 @@ pub unsafe trait TrustedIterator {} use crate::indexes::IndicesIterF; use crate::iter::IndicesIter; -use crate::linspace::Linspace; +#[cfg(feature = "std")] +use crate::{geomspace::Geomspace, linspace::Linspace, logspace::Logspace}; +#[cfg(feature = "std")] unsafe impl TrustedIterator for Linspace {} -#[cfg(any(feature = "std", feature = "libm"))] -use crate::{geomspace::Geomspace, logspace::Logspace}; -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] unsafe impl TrustedIterator for Geomspace {} -#[cfg(any(feature = "std", feature = "libm"))] +#[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 dc5fd0774..8d9d48c50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ clippy::deref_addrof, clippy::unreadable_literal )] -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] //! The `ndarray` crate provides an *n*-dimensional container for general elements //! and for numerics. @@ -170,7 +170,7 @@ mod data_repr; mod data_traits; pub use crate::aliases::*; -#[allow(deprecated)] + pub use crate::data_traits::{ Data, DataClone, DataMut, DataOwned, DataShared, RawData, RawDataClone, RawDataMut, RawDataSubst, diff --git a/src/linspace.rs b/src/linspace.rs index 2daeec406..6e9b1203c 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -5,10 +5,8 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(any(feature = "std", feature = "libm"))] +#![cfg(feature = "std")] use num_traits::Float; -#[cfg(not(any(feature = "std", feature = "libm")))] -use num_traits::float::FloatCore as Float; /// An iterator of a sequence of evenly spaced floats. /// diff --git a/src/logspace.rs b/src/logspace.rs index c55af151a..4dc6e1f32 100644 --- a/src/logspace.rs +++ b/src/logspace.rs @@ -5,7 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(any(feature = "std", feature = "libm"))] +#![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 22fae4743..ee8220852 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -6,10 +6,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] use num_traits::Float; -#[cfg(not(any(feature = "std", feature = "libm")))] -use num_traits::float::FloatCore as Float; use num_traits::{self, FromPrimitive, Zero}; use std::ops::{Add, Div, Mul}; @@ -234,7 +232,7 @@ where /// let var = a.var_axis(Axis(0), 1.); /// assert_eq!(var, aview1(&[4., 4.])); /// ``` - #[cfg(any(feature = "std", feature = "libm"))] + #[cfg(feature = "std")] pub fn var_axis(&self, axis: Axis, ddof: A) -> Array where A: Float + FromPrimitive, @@ -303,7 +301,7 @@ where /// let stddev = a.std_axis(Axis(0), 1.); /// assert_eq!(stddev, aview1(&[2., 2.])); /// ``` - #[cfg(any(feature = "std", feature = "libm"))] + #[cfg(feature = "std")] pub fn std_axis(&self, axis: Axis, ddof: A) -> Array where A: Float + FromPrimitive, @@ -322,6 +320,7 @@ where note = "Use `abs_diff_eq` - it requires the `approx` crate feature", since = "0.13.0" )] + #[cfg(feature = "std")] pub fn all_close(&self, rhs: &ArrayBase, tol: A) -> bool where A: Float, 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 db54b7e5f..a3f651bd3 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); @@ -1788,6 +1793,7 @@ fn test_contiguous() { #[test] #[allow(deprecated)] +#[cfg(feature = "std")] fn test_all_close() { let c = arr3(&[ [[1., 2., 3.], [1.5, 1.5, 3.]], 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 371339b96..9e00cedf6 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 f4f312ca9..475d12294 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -183,7 +183,7 @@ fn std_axis() { #[test] #[should_panic] -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] fn var_axis_negative_ddof() { let a = array![1., 2., 3.]; a.var_axis(Axis(0), -1.); @@ -191,14 +191,14 @@ fn var_axis_negative_ddof() { #[test] #[should_panic] -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] fn var_axis_too_large_ddof() { let a = array![1., 2., 3.]; a.var_axis(Axis(0), 4.); } #[test] -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] fn var_axis_nan_ddof() { let a = Array2::::zeros((2, 3)); let v = a.var_axis(Axis(1), ::std::f64::NAN); @@ -207,7 +207,7 @@ fn var_axis_nan_ddof() { } #[test] -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] fn var_axis_empty_axis() { let a = Array2::::zeros((2, 0)); let v = a.var_axis(Axis(1), 0.); @@ -217,14 +217,14 @@ fn var_axis_empty_axis() { #[test] #[should_panic] -#[cfg(any(feature = "std", feature = "libm"))] +#[cfg(feature = "std")] fn std_axis_bad_dof() { let a = array![1., 2., 3.]; a.std_axis(Axis(0), 4.); } #[test] -#[cfg(any(feature = "std", feature = "libm"))] +#[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}; From f2ff012c4c50da1d8ccb8577d63628558c0d260f Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Fri, 8 Jan 2021 11:21:18 +0800 Subject: [PATCH 15/20] Update some documents --- Cargo.toml | 2 +- README.rst | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 234688904..5acdd7589 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ debug = true [workspace] members = ["ndarray-rand", "serialization-tests", "blas-tests"] -exclude = ["numeric-tests","ensure_no_std"] +exclude = ["numeric-tests"] [package.metadata.release] no-dev-version = true diff --git a/README.rst b/README.rst index df416919e..1a89e508e 100644 --- a/README.rst +++ b/README.rst @@ -48,6 +48,17 @@ Crate Feature Flags The following crate feature flags are available. They are configured in your `Cargo.toml`. +- ``std`` + + - This crate can be used without the standard library by disabling the + default `std` feature. Use this in `Cargo.toml`: + + [dependencies] + ndarray = { version = "0.14.0", default-features = false } + + - The `geomspace` `linspace` `logspace` `range` `var_axis` `std_axis` + and `all_close` methods are only available when `std` is enabled. + - ``serde`` - Optional, compatible with Rust stable From 999c2fd5853d4af71f38cd560b357f222400eeb5 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Sat, 9 Jan 2021 17:19:57 +0800 Subject: [PATCH 16/20] update document --- README.rst | 6 ++++-- src/lib.rs | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 1a89e508e..bb95c3a39 100644 --- a/README.rst +++ b/README.rst @@ -50,11 +50,13 @@ your `Cargo.toml`. - ``std`` + - Rust Standard Library + - This crate can be used without the standard library by disabling the - default `std` feature. Use this in `Cargo.toml`: + default `std` feature. To do so, use this in your `Cargo.toml`: [dependencies] - ndarray = { version = "0.14.0", default-features = false } + ndarray = { version = "0.x.y", default-features = false } - The `geomspace` `linspace` `logspace` `range` `var_axis` `std_axis` and `all_close` methods are only available when `std` is enabled. diff --git a/src/lib.rs b/src/lib.rs index 8d9d48c50..2920abbbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,13 @@ //! 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` `var_axis` `std_axis` +//! and `all_close` methods are only available when `std` is enabled. //! - `serde` //! - Optional, compatible with Rust stable //! - Enables serialization support for serde 1.x From 8be45a07e662b83b353c0f39d84acc4ce59067bd Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Sat, 9 Jan 2021 18:02:06 +0800 Subject: [PATCH 17/20] Resolve errors caused by the updates --- src/numeric/impl_numeric.rs | 2 ++ tests/numeric.rs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index af9851f2c..3d7e15d0d 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -154,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, @@ -216,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, diff --git a/tests/numeric.rs b/tests/numeric.rs index b845e3894..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()); From 0a5434286620446531a9c62192b9db306786a545 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Sat, 9 Jan 2021 18:09:05 +0800 Subject: [PATCH 18/20] update document --- README.rst | 2 +- src/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index bb95c3a39..fb3fca854 100644 --- a/README.rst +++ b/README.rst @@ -58,7 +58,7 @@ your `Cargo.toml`. [dependencies] ndarray = { version = "0.x.y", default-features = false } - - The `geomspace` `linspace` `logspace` `range` `var_axis` `std_axis` + - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` `std_axis` and `all_close` methods are only available when `std` is enabled. - ``serde`` diff --git a/src/lib.rs b/src/lib.rs index b1343d341..6f11b25e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,8 +74,9 @@ //! - 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` `var_axis` `std_axis` -//! and `all_close` methods are only available when `std` is enabled. +//! - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` +//! `std_axis` and `all_close` methods are only available when `std` is +//! enabled. //! - `serde` //! - Optional, compatible with Rust stable //! - Enables serialization support for serde 1.x From 9f9e5f87a8677af971a031ec51f1233567db0034 Mon Sep 17 00:00:00 2001 From: bluss Date: Sun, 10 Jan 2021 14:44:29 +0100 Subject: [PATCH 19/20] Remove mention of `all_close` - this method is removed --- README.rst | 5 ++--- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index fb3fca854..0dc32b19b 100644 --- a/README.rst +++ b/README.rst @@ -58,8 +58,8 @@ your `Cargo.toml`. [dependencies] ndarray = { version = "0.x.y", default-features = false } - - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` `std_axis` - and `all_close` methods are only available when `std` is enabled. + - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` and `std_axis` + methods are only available when `std` is enabled. - ``serde`` @@ -125,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/src/lib.rs b/src/lib.rs index 6f11b25e6..6ca3c0be0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,7 @@ //! default `std` feature. To do so, use `default-features = false` in //! your `Cargo.toml`. //! - The `geomspace` `linspace` `logspace` `range` `std` `var` `var_axis` -//! `std_axis` and `all_close` methods are only available when `std` is +//! and `std_axis` methods are only available when `std` is //! enabled. //! - `serde` //! - Optional, compatible with Rust stable From 391824be159da7e7ceddeb76aa2ec73316bfbf23 Mon Sep 17 00:00:00 2001 From: bluss Date: Sun, 10 Jan 2021 14:46:26 +0100 Subject: [PATCH 20/20] Small edits to comments --- src/iterators/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index 973c0e3ea..d3a54453e 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -1,7 +1,7 @@ // Send and Sync // All the iterators are thread safe the same way the slice's iterator are -// read-only iterators use Sync => Send rules, same as `alloc::slice::Iter`. +// read-only iterators use Sync => Send rules, same as `std::slice::Iter`. macro_rules! send_sync_read_only { ($name:ident) => { unsafe impl<'a, A, D> Send for $name<'a, A, D> @@ -19,7 +19,7 @@ macro_rules! send_sync_read_only { }; } -// read-write iterators use Send => Send rules, same as `alloc::slice::IterMut`. +// read-write iterators use Send => Send rules, same as `std::slice::IterMut`. macro_rules! send_sync_read_write { ($name:ident) => { unsafe impl<'a, A, D> Send for $name<'a, A, D>