diff --git a/src/indexes.rs b/src/indexes.rs index 0fa2b50fb..a73c7fcb4 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -10,7 +10,7 @@ use crate::dimension::IntoDimension; use crate::split_at::SplitAt; use crate::zip::Offset; use crate::Axis; -use crate::Layout; +use crate::LayoutBitset; use crate::NdProducer; use crate::{ArrayBase, Data}; @@ -193,12 +193,12 @@ impl NdProducer for Indices IndexPtr { index: self.start } } - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { if self.dim.ndim() <= 1 { - Layout::one_dimensional() + LayoutBitset::one_dimensional() } else { - Layout::none() + LayoutBitset::none() } } diff --git a/src/iterators/chunks.rs b/src/iterators/chunks.rs index 178ead7e0..aff194d53 100644 --- a/src/iterators/chunks.rs +++ b/src/iterators/chunks.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::imp_prelude::*; use crate::Baseiter; use crate::IntoDimension; -use crate::{Layout, NdProducer}; +use crate::{LayoutBitset, NdProducer}; impl_ndproducer! { ['a, A, D: Dimension] diff --git a/src/iterators/lanes.rs b/src/iterators/lanes.rs index 9fd39607b..2f5e14774 100644 --- a/src/iterators/lanes.rs +++ b/src/iterators/lanes.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use super::LanesIter; use super::LanesIterMut; use crate::imp_prelude::*; -use crate::{Layout, NdProducer}; +use crate::{LayoutBitset, NdProducer}; impl_ndproducer! { ['a, A, D: Dimension] diff --git a/src/iterators/macros.rs b/src/iterators/macros.rs index 78697ec25..041d09021 100644 --- a/src/iterators/macros.rs +++ b/src/iterators/macros.rs @@ -67,7 +67,7 @@ impl<$($typarm)*> NdProducer for $fulltype { self.$base.raw_dim() } - fn layout(&self) -> Layout { + fn layout(&self) -> LayoutBitset { self.$base.layout() } diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index f7892a8c9..85ef78c8c 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1191,9 +1191,9 @@ impl NdProducer for AxisIter<'_, A, D> type Ptr = *mut A; type Stride = isize; - fn layout(&self) -> crate::Layout + fn layout(&self) -> crate::LayoutBitset { - crate::Layout::one_dimensional() + crate::LayoutBitset::one_dimensional() } fn raw_dim(&self) -> Self::Dim @@ -1250,9 +1250,9 @@ impl NdProducer for AxisIterMut<'_, A, D> type Ptr = *mut A; type Stride = isize; - fn layout(&self) -> crate::Layout + fn layout(&self) -> crate::LayoutBitset { - crate::Layout::one_dimensional() + crate::LayoutBitset::one_dimensional() } fn raw_dim(&self) -> Self::Dim diff --git a/src/iterators/windows.rs b/src/iterators/windows.rs index e6fccce46..f64b9fd4d 100644 --- a/src/iterators/windows.rs +++ b/src/iterators/windows.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use super::Baseiter; use crate::imp_prelude::*; use crate::IntoDimension; -use crate::Layout; +use crate::LayoutBitset; use crate::NdProducer; use crate::Slice; @@ -176,7 +176,7 @@ impl<'a, A, D: Dimension> NdProducer for AxisWindows<'a, A, D> Ix1(self.base.raw_dim()[self.axis_idx]) } - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { self.base.layout() } diff --git a/src/layout/layoutfmt.rs b/src/layout/layoutfmt.rs index f20f0caaa..f4cf3396f 100644 --- a/src/layout/layoutfmt.rs +++ b/src/layout/layoutfmt.rs @@ -6,13 +6,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use super::Layout; +use super::LayoutBitset; const LAYOUT_NAMES: &[&str] = &["C", "F", "c", "f"]; use std::fmt; -impl fmt::Debug for Layout +impl fmt::Debug for LayoutBitset { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 36853848e..4c9833e23 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -6,9 +6,14 @@ mod layoutfmt; #[doc(hidden)] /// Memory layout description #[derive(Copy, Clone)] -pub struct Layout(u32); +pub struct LayoutBitset(u32); -impl Layout +#[deprecated(since = "0.18.0", note = "Layout has been renamed to LayoutBitset")] +#[allow(dead_code)] +/// Memory layout description, deprecated. See [`LayoutBitset`] instead. +pub type Layout = LayoutBitset; + +impl LayoutBitset { pub(crate) const CORDER: u32 = 0b01; pub(crate) const FORDER: u32 = 0b10; @@ -23,52 +28,52 @@ impl Layout /// Return layout common to both inputs #[inline(always)] - pub(crate) fn intersect(self, other: Layout) -> Layout + pub(crate) fn intersect(self, other: LayoutBitset) -> LayoutBitset { - Layout(self.0 & other.0) + LayoutBitset(self.0 & other.0) } /// Return a layout that simultaneously "is" what both of the inputs are #[inline(always)] - pub(crate) fn also(self, other: Layout) -> Layout + pub(crate) fn also(self, other: LayoutBitset) -> LayoutBitset { - Layout(self.0 | other.0) + LayoutBitset(self.0 | other.0) } #[inline(always)] - pub(crate) fn one_dimensional() -> Layout + pub(crate) fn one_dimensional() -> LayoutBitset { - Layout::c().also(Layout::f()) + LayoutBitset::c().also(LayoutBitset::f()) } #[inline(always)] - pub(crate) fn c() -> Layout + pub(crate) fn c() -> LayoutBitset { - Layout(Layout::CORDER | Layout::CPREFER) + LayoutBitset(LayoutBitset::CORDER | LayoutBitset::CPREFER) } #[inline(always)] - pub(crate) fn f() -> Layout + pub(crate) fn f() -> LayoutBitset { - Layout(Layout::FORDER | Layout::FPREFER) + LayoutBitset(LayoutBitset::FORDER | LayoutBitset::FPREFER) } #[inline(always)] - pub(crate) fn cpref() -> Layout + pub(crate) fn cpref() -> LayoutBitset { - Layout(Layout::CPREFER) + LayoutBitset(LayoutBitset::CPREFER) } #[inline(always)] - pub(crate) fn fpref() -> Layout + pub(crate) fn fpref() -> LayoutBitset { - Layout(Layout::FPREFER) + LayoutBitset(LayoutBitset::FPREFER) } #[inline(always)] - pub(crate) fn none() -> Layout + pub(crate) fn none() -> LayoutBitset { - Layout(0) + LayoutBitset(0) } /// A simple "score" method which scores positive for preferring C-order, negative for F-order @@ -76,8 +81,8 @@ impl Layout #[inline] pub(crate) fn tendency(self) -> i32 { - (self.is(Layout::CORDER) as i32 - self.is(Layout::FORDER) as i32) - + (self.is(Layout::CPREFER) as i32 - self.is(Layout::FPREFER) as i32) + (self.is(LayoutBitset::CORDER) as i32 - self.is(LayoutBitset::FORDER) as i32) + + (self.is(LayoutBitset::CPREFER) as i32 - self.is(LayoutBitset::FPREFER) as i32) } } @@ -96,7 +101,7 @@ mod tests ($mat:expr, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( - assert!(layout.is(Layout::$layout), + assert!(layout.is(LayoutBitset::$layout), "Assertion failed: array {:?} is not layout {}", $mat, stringify!($layout)); @@ -108,7 +113,7 @@ mod tests ($mat:expr, $($layout:ident),*) => {{ let layout = $mat.view().layout(); $( - assert!(!layout.is(Layout::$layout), + assert!(!layout.is(LayoutBitset::$layout), "Assertion failed: array {:?} show not have layout {}", $mat, stringify!($layout)); @@ -123,10 +128,10 @@ mod tests let b = M::zeros((5, 5).f()); let ac = a.view().layout(); let af = b.view().layout(); - assert!(ac.is(Layout::CORDER) && ac.is(Layout::CPREFER)); - assert!(!ac.is(Layout::FORDER) && !ac.is(Layout::FPREFER)); - assert!(!af.is(Layout::CORDER) && !af.is(Layout::CPREFER)); - assert!(af.is(Layout::FORDER) && af.is(Layout::FPREFER)); + assert!(ac.is(LayoutBitset::CORDER) && ac.is(LayoutBitset::CPREFER)); + assert!(!ac.is(LayoutBitset::FORDER) && !ac.is(LayoutBitset::FPREFER)); + assert!(!af.is(LayoutBitset::CORDER) && !af.is(LayoutBitset::CPREFER)); + assert!(af.is(LayoutBitset::FORDER) && af.is(LayoutBitset::FPREFER)); } #[test] @@ -167,10 +172,10 @@ mod tests let v1 = a.slice(s![1.., ..]).layout(); let v2 = a.slice(s![.., 1..]).layout(); - assert!(v1.is(Layout::CORDER) && v1.is(Layout::CPREFER)); - assert!(!v1.is(Layout::FORDER) && !v1.is(Layout::FPREFER)); - assert!(!v2.is(Layout::CORDER) && v2.is(Layout::CPREFER)); - assert!(!v2.is(Layout::FORDER) && !v2.is(Layout::FPREFER)); + assert!(v1.is(LayoutBitset::CORDER) && v1.is(LayoutBitset::CPREFER)); + assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER)); + assert!(!v2.is(LayoutBitset::CORDER) && v2.is(LayoutBitset::CPREFER)); + assert!(!v2.is(LayoutBitset::FORDER) && !v2.is(LayoutBitset::FPREFER)); } let b = M::zeros((5, 5).f()); @@ -179,10 +184,10 @@ mod tests let v1 = b.slice(s![1.., ..]).layout(); let v2 = b.slice(s![.., 1..]).layout(); - assert!(!v1.is(Layout::CORDER) && !v1.is(Layout::CPREFER)); - assert!(!v1.is(Layout::FORDER) && v1.is(Layout::FPREFER)); - assert!(!v2.is(Layout::CORDER) && !v2.is(Layout::CPREFER)); - assert!(v2.is(Layout::FORDER) && v2.is(Layout::FPREFER)); + assert!(!v1.is(LayoutBitset::CORDER) && !v1.is(LayoutBitset::CPREFER)); + assert!(!v1.is(LayoutBitset::FORDER) && v1.is(LayoutBitset::FPREFER)); + assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER)); + assert!(v2.is(LayoutBitset::FORDER) && v2.is(LayoutBitset::FPREFER)); } } @@ -223,10 +228,10 @@ mod tests let v1 = a.slice(s![..;2, ..]).layout(); let v2 = a.slice(s![.., ..;2]).layout(); - assert!(!v1.is(Layout::CORDER) && v1.is(Layout::CPREFER)); - assert!(!v1.is(Layout::FORDER) && !v1.is(Layout::FPREFER)); - assert!(!v2.is(Layout::CORDER) && !v2.is(Layout::CPREFER)); - assert!(!v2.is(Layout::FORDER) && !v2.is(Layout::FPREFER)); + assert!(!v1.is(LayoutBitset::CORDER) && v1.is(LayoutBitset::CPREFER)); + assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER)); + assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER)); + assert!(!v2.is(LayoutBitset::FORDER) && !v2.is(LayoutBitset::FPREFER)); } let b = M::zeros((5, 5).f()); @@ -234,10 +239,10 @@ mod tests let v1 = b.slice(s![..;2, ..]).layout(); let v2 = b.slice(s![.., ..;2]).layout(); - assert!(!v1.is(Layout::CORDER) && !v1.is(Layout::CPREFER)); - assert!(!v1.is(Layout::FORDER) && !v1.is(Layout::FPREFER)); - assert!(!v2.is(Layout::CORDER) && !v2.is(Layout::CPREFER)); - assert!(!v2.is(Layout::FORDER) && v2.is(Layout::FPREFER)); + assert!(!v1.is(LayoutBitset::CORDER) && !v1.is(LayoutBitset::CPREFER)); + assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER)); + assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER)); + assert!(!v2.is(LayoutBitset::FORDER) && v2.is(LayoutBitset::FPREFER)); } } } diff --git a/src/lib.rs b/src/lib.rs index 6a5ea8280..4e92d3000 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -224,7 +224,8 @@ mod dimension; pub use crate::zip::{FoldWhile, IntoNdProducer, NdProducer, Zip}; -pub use crate::layout::Layout; +#[allow(deprecated)] +pub use crate::layout::{Layout, LayoutBitset}; /// Implementation's prelude. Common types used everywhere. mod imp_prelude diff --git a/src/parallel/send_producer.rs b/src/parallel/send_producer.rs index ecfb77af0..ebf973091 100644 --- a/src/parallel/send_producer.rs +++ b/src/parallel/send_producer.rs @@ -1,5 +1,5 @@ use crate::imp_prelude::*; -use crate::{Layout, NdProducer}; +use crate::{LayoutBitset, NdProducer}; use std::ops::{Deref, DerefMut}; /// An NdProducer that is unconditionally `Send`. @@ -66,7 +66,7 @@ where P: NdProducer } #[inline(always)] - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { self.inner.layout() } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 668eac093..16555721d 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -17,7 +17,7 @@ use crate::imp_prelude::*; use crate::partial::Partial; use crate::AssignElem; use crate::IntoDimension; -use crate::Layout; +use crate::LayoutBitset; use crate::dimension; use crate::indexes::{indices, Indices}; @@ -51,35 +51,35 @@ where E: IntoDimension } /// Compute `Layout` hints for array shape dim, strides -fn array_layout(dim: &D, strides: &D) -> Layout +fn array_layout(dim: &D, strides: &D) -> LayoutBitset { let n = dim.ndim(); if dimension::is_layout_c(dim, strides) { // effectively one-dimensional => C and F layout compatible if n <= 1 || dim.slice().iter().filter(|&&len| len > 1).count() <= 1 { - Layout::one_dimensional() + LayoutBitset::one_dimensional() } else { - Layout::c() + LayoutBitset::c() } } else if n > 1 && dimension::is_layout_f(dim, strides) { - Layout::f() + LayoutBitset::f() } else if n > 1 { if dim[0] > 1 && strides[0] == 1 { - Layout::fpref() + LayoutBitset::fpref() } else if dim[n - 1] > 1 && strides[n - 1] == 1 { - Layout::cpref() + LayoutBitset::cpref() } else { - Layout::none() + LayoutBitset::none() } } else { - Layout::none() + LayoutBitset::none() } } impl LayoutRef where D: Dimension { - pub(crate) fn layout_impl(&self) -> Layout + pub(crate) fn layout_impl(&self) -> LayoutBitset { array_layout(self._dim(), self._strides()) } @@ -194,7 +194,7 @@ pub struct Zip { parts: Parts, dimension: D, - layout: Layout, + layout: LayoutBitset, /// The sum of the layout tendencies of the parts; /// positive for c- and negative for f-layout preference. layout_tendency: i32, @@ -277,7 +277,7 @@ where D: Dimension fn prefer_f(&self) -> bool { - !self.layout.is(Layout::CORDER) && (self.layout.is(Layout::FORDER) || self.layout_tendency < 0) + !self.layout.is(LayoutBitset::CORDER) && (self.layout.is(LayoutBitset::FORDER) || self.layout_tendency < 0) } /// Return an *approximation* to the max stride axis; if @@ -313,7 +313,7 @@ where D: Dimension { if self.dimension.ndim() == 0 { function(acc, unsafe { self.parts.as_ref(self.parts.as_ptr()) }) - } else if self.layout.is(Layout::CORDER | Layout::FORDER) { + } else if self.layout.is(LayoutBitset::CORDER | LayoutBitset::FORDER) { self.for_each_core_contiguous(acc, function) } else { self.for_each_core_strided(acc, function) @@ -325,7 +325,7 @@ where D: Dimension F: FnMut(Acc, P::Item) -> FoldWhile, P: ZippableTuple, { - debug_assert!(self.layout.is(Layout::CORDER | Layout::FORDER)); + debug_assert!(self.layout.is(LayoutBitset::CORDER | LayoutBitset::FORDER)); let size = self.dimension.size(); let ptrs = self.parts.as_ptr(); let inner_strides = self.parts.contiguous_stride(); @@ -442,7 +442,7 @@ where #[inline] pub(crate) fn debug_assert_c_order(self) -> Self { - debug_assert!(self.layout.is(Layout::CORDER) || self.layout_tendency >= 0 || + debug_assert!(self.layout.is(LayoutBitset::CORDER) || self.layout_tendency >= 0 || self.dimension.slice().iter().filter(|&&d| d > 1).count() <= 1, "Assertion failed: traversal is not c-order or 1D for \ layout {:?}, tendency {}, dimension {:?}", @@ -841,7 +841,7 @@ macro_rules! map_impl { // debug assert that the output is contiguous in the memory layout we need if cfg!(debug_assertions) { let out_layout = output.layout(); - assert!(out_layout.is(Layout::CORDER | Layout::FORDER)); + assert!(out_layout.is(LayoutBitset::CORDER | LayoutBitset::FORDER)); assert!( (self.layout_tendency <= 0 && out_layout.tendency() <= 0) || (self.layout_tendency >= 0 && out_layout.tendency() >= 0), diff --git a/src/zip/ndproducer.rs b/src/zip/ndproducer.rs index fe666e81e..f06497c29 100644 --- a/src/zip/ndproducer.rs +++ b/src/zip/ndproducer.rs @@ -1,6 +1,6 @@ use crate::imp_prelude::*; use crate::ArrayRef; -use crate::Layout; +use crate::LayoutBitset; use crate::NdIndex; #[cfg(not(feature = "std"))] use alloc::vec::Vec; @@ -74,7 +74,7 @@ pub trait NdProducer type Stride: Copy; #[doc(hidden)] - fn layout(&self) -> Layout; + fn layout(&self) -> LayoutBitset; /// Return the shape of the producer. fn raw_dim(&self) -> Self::Dim; #[doc(hidden)] @@ -282,7 +282,7 @@ impl<'a, A, D: Dimension> NdProducer for ArrayView<'a, A, D> (**self).as_ptr() as _ } - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { self.layout_impl() } @@ -340,7 +340,7 @@ impl<'a, A, D: Dimension> NdProducer for ArrayViewMut<'a, A, D> (**self).as_ptr() as _ } - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { self.layout_impl() } @@ -398,7 +398,7 @@ impl NdProducer for RawArrayView self.as_ptr() as _ } - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { AsRef::>::as_ref(self).layout_impl() } @@ -457,7 +457,7 @@ impl NdProducer for RawArrayViewMut self.as_ptr() as _ } - fn layout(&self) -> Layout + fn layout(&self) -> LayoutBitset { AsRef::>::as_ref(self).layout_impl() }