Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -193,12 +193,12 @@ impl<D: Dimension + Copy> NdProducer for Indices<D>
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()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/iterators/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/iterators/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/iterators/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<$($typarm)*> NdProducer for $fulltype {
self.$base.raw_dim()
}

fn layout(&self) -> Layout {
fn layout(&self) -> LayoutBitset {
self.$base.layout()
}

Expand Down
8 changes: 4 additions & 4 deletions src/iterators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,9 @@ impl<A, D: Dimension> 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
Expand Down Expand Up @@ -1250,9 +1250,9 @@ impl<A, D: Dimension> 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
Expand Down
4 changes: 2 additions & 2 deletions src/iterators/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions src/layout/layoutfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
89 changes: 47 additions & 42 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,61 +28,61 @@ 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
/// Subject to change when we can describe other layouts
#[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)
}
}

Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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]
Expand Down Expand Up @@ -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());
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -223,21 +228,21 @@ 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());
{
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));
}
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/parallel/send_producer.rs
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down Expand Up @@ -66,7 +66,7 @@ where P: NdProducer
}

#[inline(always)]
fn layout(&self) -> Layout
fn layout(&self) -> LayoutBitset
{
self.inner.layout()
}
Expand Down
Loading