Skip to content

Commit 1aa0bc1

Browse files
committed
Rename Layout to LayoutBitset
In preparation for reworking the inner dimension types (see #1506), we'd like to prepare the name `Layout` to be used for new traits and types. Although the type is largely internal (with hidden documentation), we opt for a conservative deprecation approach. In the future, we should consider making `LayoutBitset` entirely internal, but this would require larger changes to the codebase.
1 parent 13a8963 commit 1aa0bc1

File tree

11 files changed

+85
-80
lines changed

11 files changed

+85
-80
lines changed

src/indexes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::dimension::IntoDimension;
1010
use crate::split_at::SplitAt;
1111
use crate::zip::Offset;
1212
use crate::Axis;
13-
use crate::Layout;
13+
use crate::LayoutBitset;
1414
use crate::NdProducer;
1515
use crate::{ArrayBase, Data};
1616

@@ -193,12 +193,12 @@ impl<D: Dimension + Copy> NdProducer for Indices<D>
193193
IndexPtr { index: self.start }
194194
}
195195

196-
fn layout(&self) -> Layout
196+
fn layout(&self) -> LayoutBitset
197197
{
198198
if self.dim.ndim() <= 1 {
199-
Layout::one_dimensional()
199+
LayoutBitset::one_dimensional()
200200
} else {
201-
Layout::none()
201+
LayoutBitset::none()
202202
}
203203
}
204204

src/iterators/chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
33
use crate::imp_prelude::*;
44
use crate::Baseiter;
55
use crate::IntoDimension;
6-
use crate::{Layout, NdProducer};
6+
use crate::{LayoutBitset, NdProducer};
77

88
impl_ndproducer! {
99
['a, A, D: Dimension]

src/iterators/lanes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
33
use super::LanesIter;
44
use super::LanesIterMut;
55
use crate::imp_prelude::*;
6-
use crate::{Layout, NdProducer};
6+
use crate::{LayoutBitset, NdProducer};
77

88
impl_ndproducer! {
99
['a, A, D: Dimension]

src/iterators/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<$($typarm)*> NdProducer for $fulltype {
6767
self.$base.raw_dim()
6868
}
6969

70-
fn layout(&self) -> Layout {
70+
fn layout(&self) -> LayoutBitset {
7171
self.$base.layout()
7272
}
7373

src/iterators/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,9 @@ impl<A, D: Dimension> NdProducer for AxisIter<'_, A, D>
11911191
type Ptr = *mut A;
11921192
type Stride = isize;
11931193

1194-
fn layout(&self) -> crate::Layout
1194+
fn layout(&self) -> crate::LayoutBitset
11951195
{
1196-
crate::Layout::one_dimensional()
1196+
crate::LayoutBitset::one_dimensional()
11971197
}
11981198

11991199
fn raw_dim(&self) -> Self::Dim
@@ -1250,9 +1250,9 @@ impl<A, D: Dimension> NdProducer for AxisIterMut<'_, A, D>
12501250
type Ptr = *mut A;
12511251
type Stride = isize;
12521252

1253-
fn layout(&self) -> crate::Layout
1253+
fn layout(&self) -> crate::LayoutBitset
12541254
{
1255-
crate::Layout::one_dimensional()
1255+
crate::LayoutBitset::one_dimensional()
12561256
}
12571257

12581258
fn raw_dim(&self) -> Self::Dim

src/iterators/windows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
33
use super::Baseiter;
44
use crate::imp_prelude::*;
55
use crate::IntoDimension;
6-
use crate::Layout;
6+
use crate::LayoutBitset;
77
use crate::NdProducer;
88
use crate::Slice;
99

@@ -176,7 +176,7 @@ impl<'a, A, D: Dimension> NdProducer for AxisWindows<'a, A, D>
176176
Ix1(self.base.raw_dim()[self.axis_idx])
177177
}
178178

179-
fn layout(&self) -> Layout
179+
fn layout(&self) -> LayoutBitset
180180
{
181181
self.base.layout()
182182
}

src/layout/layoutfmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use super::Layout;
9+
use super::LayoutBitset;
1010

1111
const LAYOUT_NAMES: &[&str] = &["C", "F", "c", "f"];
1212

1313
use std::fmt;
1414

15-
impl fmt::Debug for Layout
15+
impl fmt::Debug for LayoutBitset
1616
{
1717
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
1818
{

src/layout/mod.rs

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ mod layoutfmt;
66
#[doc(hidden)]
77
/// Memory layout description
88
#[derive(Copy, Clone)]
9-
pub struct Layout(u32);
9+
pub struct LayoutBitset(u32);
1010

11-
impl Layout
11+
#[deprecated(since = "0.18.0", note = "Layout has been renamed to LayoutBitset")]
12+
#[allow(dead_code)]
13+
pub type Layout = LayoutBitset;
14+
15+
impl LayoutBitset
1216
{
1317
pub(crate) const CORDER: u32 = 0b01;
1418
pub(crate) const FORDER: u32 = 0b10;
@@ -23,61 +27,61 @@ impl Layout
2327

2428
/// Return layout common to both inputs
2529
#[inline(always)]
26-
pub(crate) fn intersect(self, other: Layout) -> Layout
30+
pub(crate) fn intersect(self, other: LayoutBitset) -> LayoutBitset
2731
{
28-
Layout(self.0 & other.0)
32+
LayoutBitset(self.0 & other.0)
2933
}
3034

3135
/// Return a layout that simultaneously "is" what both of the inputs are
3236
#[inline(always)]
33-
pub(crate) fn also(self, other: Layout) -> Layout
37+
pub(crate) fn also(self, other: LayoutBitset) -> LayoutBitset
3438
{
35-
Layout(self.0 | other.0)
39+
LayoutBitset(self.0 | other.0)
3640
}
3741

3842
#[inline(always)]
39-
pub(crate) fn one_dimensional() -> Layout
43+
pub(crate) fn one_dimensional() -> LayoutBitset
4044
{
41-
Layout::c().also(Layout::f())
45+
LayoutBitset::c().also(LayoutBitset::f())
4246
}
4347

4448
#[inline(always)]
45-
pub(crate) fn c() -> Layout
49+
pub(crate) fn c() -> LayoutBitset
4650
{
47-
Layout(Layout::CORDER | Layout::CPREFER)
51+
LayoutBitset(LayoutBitset::CORDER | LayoutBitset::CPREFER)
4852
}
4953

5054
#[inline(always)]
51-
pub(crate) fn f() -> Layout
55+
pub(crate) fn f() -> LayoutBitset
5256
{
53-
Layout(Layout::FORDER | Layout::FPREFER)
57+
LayoutBitset(LayoutBitset::FORDER | LayoutBitset::FPREFER)
5458
}
5559

5660
#[inline(always)]
57-
pub(crate) fn cpref() -> Layout
61+
pub(crate) fn cpref() -> LayoutBitset
5862
{
59-
Layout(Layout::CPREFER)
63+
LayoutBitset(LayoutBitset::CPREFER)
6064
}
6165

6266
#[inline(always)]
63-
pub(crate) fn fpref() -> Layout
67+
pub(crate) fn fpref() -> LayoutBitset
6468
{
65-
Layout(Layout::FPREFER)
69+
LayoutBitset(LayoutBitset::FPREFER)
6670
}
6771

6872
#[inline(always)]
69-
pub(crate) fn none() -> Layout
73+
pub(crate) fn none() -> LayoutBitset
7074
{
71-
Layout(0)
75+
LayoutBitset(0)
7276
}
7377

7478
/// A simple "score" method which scores positive for preferring C-order, negative for F-order
7579
/// Subject to change when we can describe other layouts
7680
#[inline]
7781
pub(crate) fn tendency(self) -> i32
7882
{
79-
(self.is(Layout::CORDER) as i32 - self.is(Layout::FORDER) as i32)
80-
+ (self.is(Layout::CPREFER) as i32 - self.is(Layout::FPREFER) as i32)
83+
(self.is(LayoutBitset::CORDER) as i32 - self.is(LayoutBitset::FORDER) as i32)
84+
+ (self.is(LayoutBitset::CPREFER) as i32 - self.is(LayoutBitset::FPREFER) as i32)
8185
}
8286
}
8387

@@ -96,7 +100,7 @@ mod tests
96100
($mat:expr, $($layout:ident),*) => {{
97101
let layout = $mat.view().layout();
98102
$(
99-
assert!(layout.is(Layout::$layout),
103+
assert!(layout.is(LayoutBitset::$layout),
100104
"Assertion failed: array {:?} is not layout {}",
101105
$mat,
102106
stringify!($layout));
@@ -108,7 +112,7 @@ mod tests
108112
($mat:expr, $($layout:ident),*) => {{
109113
let layout = $mat.view().layout();
110114
$(
111-
assert!(!layout.is(Layout::$layout),
115+
assert!(!layout.is(LayoutBitset::$layout),
112116
"Assertion failed: array {:?} show not have layout {}",
113117
$mat,
114118
stringify!($layout));
@@ -123,10 +127,10 @@ mod tests
123127
let b = M::zeros((5, 5).f());
124128
let ac = a.view().layout();
125129
let af = b.view().layout();
126-
assert!(ac.is(Layout::CORDER) && ac.is(Layout::CPREFER));
127-
assert!(!ac.is(Layout::FORDER) && !ac.is(Layout::FPREFER));
128-
assert!(!af.is(Layout::CORDER) && !af.is(Layout::CPREFER));
129-
assert!(af.is(Layout::FORDER) && af.is(Layout::FPREFER));
130+
assert!(ac.is(LayoutBitset::CORDER) && ac.is(LayoutBitset::CPREFER));
131+
assert!(!ac.is(LayoutBitset::FORDER) && !ac.is(LayoutBitset::FPREFER));
132+
assert!(!af.is(LayoutBitset::CORDER) && !af.is(LayoutBitset::CPREFER));
133+
assert!(af.is(LayoutBitset::FORDER) && af.is(LayoutBitset::FPREFER));
130134
}
131135

132136
#[test]
@@ -167,10 +171,10 @@ mod tests
167171
let v1 = a.slice(s![1.., ..]).layout();
168172
let v2 = a.slice(s![.., 1..]).layout();
169173

170-
assert!(v1.is(Layout::CORDER) && v1.is(Layout::CPREFER));
171-
assert!(!v1.is(Layout::FORDER) && !v1.is(Layout::FPREFER));
172-
assert!(!v2.is(Layout::CORDER) && v2.is(Layout::CPREFER));
173-
assert!(!v2.is(Layout::FORDER) && !v2.is(Layout::FPREFER));
174+
assert!(v1.is(LayoutBitset::CORDER) && v1.is(LayoutBitset::CPREFER));
175+
assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER));
176+
assert!(!v2.is(LayoutBitset::CORDER) && v2.is(LayoutBitset::CPREFER));
177+
assert!(!v2.is(LayoutBitset::FORDER) && !v2.is(LayoutBitset::FPREFER));
174178
}
175179

176180
let b = M::zeros((5, 5).f());
@@ -179,10 +183,10 @@ mod tests
179183
let v1 = b.slice(s![1.., ..]).layout();
180184
let v2 = b.slice(s![.., 1..]).layout();
181185

182-
assert!(!v1.is(Layout::CORDER) && !v1.is(Layout::CPREFER));
183-
assert!(!v1.is(Layout::FORDER) && v1.is(Layout::FPREFER));
184-
assert!(!v2.is(Layout::CORDER) && !v2.is(Layout::CPREFER));
185-
assert!(v2.is(Layout::FORDER) && v2.is(Layout::FPREFER));
186+
assert!(!v1.is(LayoutBitset::CORDER) && !v1.is(LayoutBitset::CPREFER));
187+
assert!(!v1.is(LayoutBitset::FORDER) && v1.is(LayoutBitset::FPREFER));
188+
assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER));
189+
assert!(v2.is(LayoutBitset::FORDER) && v2.is(LayoutBitset::FPREFER));
186190
}
187191
}
188192

@@ -223,21 +227,21 @@ mod tests
223227
let v1 = a.slice(s![..;2, ..]).layout();
224228
let v2 = a.slice(s![.., ..;2]).layout();
225229

226-
assert!(!v1.is(Layout::CORDER) && v1.is(Layout::CPREFER));
227-
assert!(!v1.is(Layout::FORDER) && !v1.is(Layout::FPREFER));
228-
assert!(!v2.is(Layout::CORDER) && !v2.is(Layout::CPREFER));
229-
assert!(!v2.is(Layout::FORDER) && !v2.is(Layout::FPREFER));
230+
assert!(!v1.is(LayoutBitset::CORDER) && v1.is(LayoutBitset::CPREFER));
231+
assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER));
232+
assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER));
233+
assert!(!v2.is(LayoutBitset::FORDER) && !v2.is(LayoutBitset::FPREFER));
230234
}
231235

232236
let b = M::zeros((5, 5).f());
233237
{
234238
let v1 = b.slice(s![..;2, ..]).layout();
235239
let v2 = b.slice(s![.., ..;2]).layout();
236240

237-
assert!(!v1.is(Layout::CORDER) && !v1.is(Layout::CPREFER));
238-
assert!(!v1.is(Layout::FORDER) && !v1.is(Layout::FPREFER));
239-
assert!(!v2.is(Layout::CORDER) && !v2.is(Layout::CPREFER));
240-
assert!(!v2.is(Layout::FORDER) && v2.is(Layout::FPREFER));
241+
assert!(!v1.is(LayoutBitset::CORDER) && !v1.is(LayoutBitset::CPREFER));
242+
assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER));
243+
assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER));
244+
assert!(!v2.is(LayoutBitset::FORDER) && v2.is(LayoutBitset::FPREFER));
241245
}
242246
}
243247
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ mod dimension;
224224

225225
pub use crate::zip::{FoldWhile, IntoNdProducer, NdProducer, Zip};
226226

227-
pub use crate::layout::Layout;
227+
#[allow(deprecated)]
228+
pub use crate::layout::{Layout, LayoutBitset};
228229

229230
/// Implementation's prelude. Common types used everywhere.
230231
mod imp_prelude

0 commit comments

Comments
 (0)