Skip to content

Commit d573745

Browse files
authored
Rename Layout to LayoutBitset (#1563)
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 d573745

File tree

12 files changed

+88
-82
lines changed

12 files changed

+88
-82
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: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ 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+
/// Memory layout description, deprecated. See [`LayoutBitset`] instead.
14+
pub type Layout = LayoutBitset;
15+
16+
impl LayoutBitset
1217
{
1318
pub(crate) const CORDER: u32 = 0b01;
1419
pub(crate) const FORDER: u32 = 0b10;
@@ -23,61 +28,61 @@ impl Layout
2328

2429
/// Return layout common to both inputs
2530
#[inline(always)]
26-
pub(crate) fn intersect(self, other: Layout) -> Layout
31+
pub(crate) fn intersect(self, other: LayoutBitset) -> LayoutBitset
2732
{
28-
Layout(self.0 & other.0)
33+
LayoutBitset(self.0 & other.0)
2934
}
3035

3136
/// Return a layout that simultaneously "is" what both of the inputs are
3237
#[inline(always)]
33-
pub(crate) fn also(self, other: Layout) -> Layout
38+
pub(crate) fn also(self, other: LayoutBitset) -> LayoutBitset
3439
{
35-
Layout(self.0 | other.0)
40+
LayoutBitset(self.0 | other.0)
3641
}
3742

3843
#[inline(always)]
39-
pub(crate) fn one_dimensional() -> Layout
44+
pub(crate) fn one_dimensional() -> LayoutBitset
4045
{
41-
Layout::c().also(Layout::f())
46+
LayoutBitset::c().also(LayoutBitset::f())
4247
}
4348

4449
#[inline(always)]
45-
pub(crate) fn c() -> Layout
50+
pub(crate) fn c() -> LayoutBitset
4651
{
47-
Layout(Layout::CORDER | Layout::CPREFER)
52+
LayoutBitset(LayoutBitset::CORDER | LayoutBitset::CPREFER)
4853
}
4954

5055
#[inline(always)]
51-
pub(crate) fn f() -> Layout
56+
pub(crate) fn f() -> LayoutBitset
5257
{
53-
Layout(Layout::FORDER | Layout::FPREFER)
58+
LayoutBitset(LayoutBitset::FORDER | LayoutBitset::FPREFER)
5459
}
5560

5661
#[inline(always)]
57-
pub(crate) fn cpref() -> Layout
62+
pub(crate) fn cpref() -> LayoutBitset
5863
{
59-
Layout(Layout::CPREFER)
64+
LayoutBitset(LayoutBitset::CPREFER)
6065
}
6166

6267
#[inline(always)]
63-
pub(crate) fn fpref() -> Layout
68+
pub(crate) fn fpref() -> LayoutBitset
6469
{
65-
Layout(Layout::FPREFER)
70+
LayoutBitset(LayoutBitset::FPREFER)
6671
}
6772

6873
#[inline(always)]
69-
pub(crate) fn none() -> Layout
74+
pub(crate) fn none() -> LayoutBitset
7075
{
71-
Layout(0)
76+
LayoutBitset(0)
7277
}
7378

7479
/// A simple "score" method which scores positive for preferring C-order, negative for F-order
7580
/// Subject to change when we can describe other layouts
7681
#[inline]
7782
pub(crate) fn tendency(self) -> i32
7883
{
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)
84+
(self.is(LayoutBitset::CORDER) as i32 - self.is(LayoutBitset::FORDER) as i32)
85+
+ (self.is(LayoutBitset::CPREFER) as i32 - self.is(LayoutBitset::FPREFER) as i32)
8186
}
8287
}
8388

@@ -96,7 +101,7 @@ mod tests
96101
($mat:expr, $($layout:ident),*) => {{
97102
let layout = $mat.view().layout();
98103
$(
99-
assert!(layout.is(Layout::$layout),
104+
assert!(layout.is(LayoutBitset::$layout),
100105
"Assertion failed: array {:?} is not layout {}",
101106
$mat,
102107
stringify!($layout));
@@ -108,7 +113,7 @@ mod tests
108113
($mat:expr, $($layout:ident),*) => {{
109114
let layout = $mat.view().layout();
110115
$(
111-
assert!(!layout.is(Layout::$layout),
116+
assert!(!layout.is(LayoutBitset::$layout),
112117
"Assertion failed: array {:?} show not have layout {}",
113118
$mat,
114119
stringify!($layout));
@@ -123,10 +128,10 @@ mod tests
123128
let b = M::zeros((5, 5).f());
124129
let ac = a.view().layout();
125130
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));
131+
assert!(ac.is(LayoutBitset::CORDER) && ac.is(LayoutBitset::CPREFER));
132+
assert!(!ac.is(LayoutBitset::FORDER) && !ac.is(LayoutBitset::FPREFER));
133+
assert!(!af.is(LayoutBitset::CORDER) && !af.is(LayoutBitset::CPREFER));
134+
assert!(af.is(LayoutBitset::FORDER) && af.is(LayoutBitset::FPREFER));
130135
}
131136

132137
#[test]
@@ -167,10 +172,10 @@ mod tests
167172
let v1 = a.slice(s![1.., ..]).layout();
168173
let v2 = a.slice(s![.., 1..]).layout();
169174

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));
175+
assert!(v1.is(LayoutBitset::CORDER) && v1.is(LayoutBitset::CPREFER));
176+
assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER));
177+
assert!(!v2.is(LayoutBitset::CORDER) && v2.is(LayoutBitset::CPREFER));
178+
assert!(!v2.is(LayoutBitset::FORDER) && !v2.is(LayoutBitset::FPREFER));
174179
}
175180

176181
let b = M::zeros((5, 5).f());
@@ -179,10 +184,10 @@ mod tests
179184
let v1 = b.slice(s![1.., ..]).layout();
180185
let v2 = b.slice(s![.., 1..]).layout();
181186

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));
187+
assert!(!v1.is(LayoutBitset::CORDER) && !v1.is(LayoutBitset::CPREFER));
188+
assert!(!v1.is(LayoutBitset::FORDER) && v1.is(LayoutBitset::FPREFER));
189+
assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER));
190+
assert!(v2.is(LayoutBitset::FORDER) && v2.is(LayoutBitset::FPREFER));
186191
}
187192
}
188193

@@ -223,21 +228,21 @@ mod tests
223228
let v1 = a.slice(s![..;2, ..]).layout();
224229
let v2 = a.slice(s![.., ..;2]).layout();
225230

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));
231+
assert!(!v1.is(LayoutBitset::CORDER) && v1.is(LayoutBitset::CPREFER));
232+
assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER));
233+
assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER));
234+
assert!(!v2.is(LayoutBitset::FORDER) && !v2.is(LayoutBitset::FPREFER));
230235
}
231236

232237
let b = M::zeros((5, 5).f());
233238
{
234239
let v1 = b.slice(s![..;2, ..]).layout();
235240
let v2 = b.slice(s![.., ..;2]).layout();
236241

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));
242+
assert!(!v1.is(LayoutBitset::CORDER) && !v1.is(LayoutBitset::CPREFER));
243+
assert!(!v1.is(LayoutBitset::FORDER) && !v1.is(LayoutBitset::FPREFER));
244+
assert!(!v2.is(LayoutBitset::CORDER) && !v2.is(LayoutBitset::CPREFER));
245+
assert!(!v2.is(LayoutBitset::FORDER) && v2.is(LayoutBitset::FPREFER));
241246
}
242247
}
243248
}

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

src/parallel/send_producer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::imp_prelude::*;
2-
use crate::{Layout, NdProducer};
2+
use crate::{LayoutBitset, NdProducer};
33
use std::ops::{Deref, DerefMut};
44

55
/// An NdProducer that is unconditionally `Send`.
@@ -66,7 +66,7 @@ where P: NdProducer
6666
}
6767

6868
#[inline(always)]
69-
fn layout(&self) -> Layout
69+
fn layout(&self) -> LayoutBitset
7070
{
7171
self.inner.layout()
7272
}

0 commit comments

Comments
 (0)