Skip to content

Commit 462829b

Browse files
committed
Rename as_slice_no_order to as_slice_memory_order
1 parent 2a4a0de commit 462829b

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/impl_methods.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,11 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
597597
self.ptr
598598
}
599599

600-
/// Return the array’s data as a slice, if it is contiguous and
601-
/// the element order corresponds to the memory order. Return `None` otherwise.
600+
/// Return the array’s data as a slice, if it is contiguous and in standard order.
601+
/// Return `None` otherwise.
602+
///
603+
/// If this function returns `Some(_)`, then the element order in the slice
604+
/// corresponds to the logical order of the array’s elements.
602605
pub fn as_slice(&self) -> Option<&[A]> {
603606
if self.is_standard_layout() {
604607
unsafe {
@@ -609,8 +612,8 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
609612
}
610613
}
611614

612-
/// Return the array’s data as a slice, if it is contiguous and
613-
/// the element order corresponds to the memory order. Return `None` otherwise.
615+
/// Return the array’s data as a slice, if it is contiguous and in standard order.
616+
/// Return `None` otherwise.
614617
pub fn as_slice_mut(&mut self) -> Option<&mut [A]>
615618
where S: DataMut
616619
{
@@ -626,7 +629,12 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
626629

627630
/// Return the array’s data as a slice if it is contiguous,
628631
/// return `None` otherwise.
629-
pub fn as_slice_no_order(&self) -> Option<&[A]> {
632+
///
633+
/// If this function returns `Some(_)`, then the elements in the slice
634+
/// have whatever order the elements have in memory.
635+
///
636+
/// Implementation notes: Does not yet support negatively strided arrays.
637+
pub fn as_slice_memory_order(&self) -> Option<&[A]> {
630638
if self.is_contiguous() {
631639
unsafe {
632640
Some(slice::from_raw_parts(self.ptr, self.len()))
@@ -638,7 +646,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
638646

639647
/// Return the array’s data as a slice if it is contiguous,
640648
/// return `None` otherwise.
641-
pub fn as_slice_mut_no_order(&mut self) -> Option<&mut [A]>
649+
pub fn as_slice_memory_order_mut(&mut self) -> Option<&mut [A]>
642650
where S: DataMut
643651
{
644652
if self.is_contiguous() {

src/impl_numeric.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<A, S, D> ArrayBase<S, D>
6262
pub fn scalar_sum(&self) -> A
6363
where A: Clone + Add<Output=A> + libnum::Zero,
6464
{
65-
if let Some(slc) = self.as_slice_no_order() {
65+
if let Some(slc) = self.as_slice_memory_order() {
6666
return numeric_util::unrolled_sum(slc);
6767
}
6868
let mut sum = A::zero();

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<A, S, D> ArrayBase<S, D>
506506
where S: DataMut,
507507
F: FnMut(&mut A)
508508
{
509-
if let Some(slc) = self.as_slice_mut_no_order() {
509+
if let Some(slc) = self.as_slice_memory_order_mut() {
510510
for elt in slc {
511511
f(elt);
512512
}

tests/array.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -887,19 +887,19 @@ fn test_contiguous() {
887887
[[4, 5, 6],
888888
[7, 7, 7]]]);
889889
assert!(c.is_standard_layout());
890-
assert!(c.as_slice_no_order().is_some());
890+
assert!(c.as_slice_memory_order().is_some());
891891
let v = c.slice(s![.., 0..1, ..]);
892892
assert!(!v.is_standard_layout());
893-
assert!(!v.as_slice_no_order().is_some());
893+
assert!(!v.as_slice_memory_order().is_some());
894894

895895
let v = c.slice(s![1..2, .., ..]);
896896
assert!(v.is_standard_layout());
897-
assert!(v.as_slice_no_order().is_some());
897+
assert!(v.as_slice_memory_order().is_some());
898898
let v = v.reversed_axes();
899899
assert!(!v.is_standard_layout());
900-
assert!(v.as_slice_no_order().is_some());
900+
assert!(v.as_slice_memory_order().is_some());
901901
let mut v = v.reversed_axes();
902902
v.swap_axes(1, 2);
903903
assert!(!v.is_standard_layout());
904-
assert!(v.as_slice_no_order().is_some());
904+
assert!(v.as_slice_memory_order().is_some());
905905
}

0 commit comments

Comments
 (0)