Skip to content

Commit 54c2f27

Browse files
committed
Rename .islice() -> .slice_inplace()
1 parent c9c07f2 commit 54c2f27

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

examples/axis_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747
}
4848
a.swap_axes(0, 1);
4949
a.swap_axes(0, 2);
50-
a.islice(s![.., ..;-1, ..]);
50+
a.slice_inplace(s![.., ..;-1, ..]);
5151
regularize(&mut a).ok();
5252

5353
let mut b = Array::<u8, _>::zeros((2, 3, 4));
@@ -64,6 +64,6 @@ fn main() {
6464
for (i, elt) in (0..).zip(&mut a) {
6565
*elt = i;
6666
}
67-
a.islice(s![..;-1, ..;2, ..]);
67+
a.slice_inplace(s![..;-1, ..;2, ..]);
6868
regularize(&mut a).ok();
6969
}

serialization-tests/tests/serialize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn serial_many_dim()
5353
{
5454
// Test a sliced array.
5555
let mut a = RcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
56-
a.islice(s![..;-1, .., .., ..2]);
56+
a.slice_inplace(s![..;-1, .., .., ..2]);
5757
let serial = json::encode(&a).unwrap();
5858
println!("Encode {:?} => {:?}", a, serial);
5959
let res = json::decode::<RcArray<f32, _>>(&serial);
@@ -114,7 +114,7 @@ fn serial_many_dim_serde()
114114
{
115115
// Test a sliced array.
116116
let mut a = RcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
117-
a.islice(s![..;-1, .., .., ..2]);
117+
a.slice_inplace(s![..;-1, .., .., ..2]);
118118
let serial = serde_json::to_string(&a).unwrap();
119119
println!("Encode {:?} => {:?}", a, serial);
120120
let res = serde_json::from_str::<RcArray<f32, _>>(&serial);
@@ -221,7 +221,7 @@ fn serial_many_dim_serde_msgpack()
221221
{
222222
// Test a sliced array.
223223
let mut a = RcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
224-
a.islice(s![..;-1, .., .., ..2]);
224+
a.slice_inplace(s![..;-1, .., .., ..2]);
225225

226226
let mut buf = Vec::new();
227227
serde::Serialize::serialize(&a, &mut rmp_serde::Serializer::new(&mut buf)).ok().unwrap();
@@ -273,7 +273,7 @@ fn serial_many_dim_ron()
273273
{
274274
// Test a sliced array.
275275
let mut a = RcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
276-
a.islice(s![..;-1, .., .., ..2]);
276+
a.slice_inplace(s![..;-1, .., .., ..2]);
277277

278278
let a_s = ron_serialize(&a).unwrap();
279279

src/impl_methods.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
217217
/// (**Panics** if `D` is `IxDyn` and `indexes` does not match the number of array axes.)
218218
pub fn slice(&self, indexes: &D::SliceArg) -> ArrayView<A, D> {
219219
let mut arr = self.view();
220-
arr.islice(indexes);
220+
arr.slice_inplace(indexes);
221221
arr
222222
}
223223

@@ -233,7 +233,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
233233
where S: DataMut
234234
{
235235
let mut arr = self.view_mut();
236-
arr.islice(indexes);
236+
arr.slice_inplace(indexes);
237237
arr
238238
}
239239

@@ -245,7 +245,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
245245
///
246246
/// **Panics** if an index is out of bounds or stride is zero.<br>
247247
/// (**Panics** if `D` is `IxDyn` and `indexes` does not match the number of array axes.)
248-
pub fn islice(&mut self, indexes: &D::SliceArg) {
248+
pub fn slice_inplace(&mut self, indexes: &D::SliceArg) {
249249
let offset = D::do_slices(&mut self.dim, &mut self.strides, indexes);
250250
unsafe {
251251
self.ptr = self.ptr.offset(offset);

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,18 @@ pub type Ixs = isize;
421421
/// ## Slicing
422422
///
423423
/// You can use slicing to create a view of a subset of the data in
424-
/// the array. Slicing methods include `.slice()`, `.islice()`,
425-
/// `.slice_mut()`.
424+
/// the array. Slicing methods include [`.slice()`], [`.slice_mut()`],
425+
/// and [`.slice_inplace()`].
426426
///
427427
/// The slicing argument can be passed using the macro [`s![]`](macro.s!.html),
428428
/// which will be used in all examples. (The explicit form is a reference
429429
/// to a fixed size array of [`Si`]; see its docs for more information.)
430430
/// [`Si`]: struct.Si.html
431431
///
432+
/// [`.slice()`]: #method.slice
433+
/// [`.slice_mut()`]: #method.slice_mut
434+
/// [`.slice_inplace()`]: #method.slice_inplace
435+
///
432436
/// ```
433437
/// // import the s![] macro
434438
/// #[macro_use(s)]

tests/array.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn test_cow()
203203
assert_eq!(n[[0, 1]], 0);
204204
assert_eq!(n.get((0, 1)), Some(&0));
205205
let mut rev = mat.reshape(4);
206-
rev.islice(&[Si(0, None, -1)]);
206+
rev.slice_inplace(&[Si(0, None, -1)]);
207207
assert_eq!(rev[0], 4);
208208
assert_eq!(rev[1], 3);
209209
assert_eq!(rev[2], 2);
@@ -228,7 +228,7 @@ fn test_cow_shrink()
228228
// mutation shrinks the array and gives it different strides
229229
//
230230
let mut mat = RcArray::zeros((2, 3));
231-
//mat.islice(s![.., ..;2]);
231+
//mat.slice_inplace(s![.., ..;2]);
232232
mat[[0, 0]] = 1;
233233
let n = mat.clone();
234234
mat[[0, 1]] = 2;
@@ -243,7 +243,7 @@ fn test_cow_shrink()
243243
assert_eq!(n.get((0, 1)), Some(&0));
244244
// small has non-C strides this way
245245
let mut small = mat.reshape(6);
246-
small.islice(s![4..;-1]);
246+
small.slice_inplace(s![4..;-1]);
247247
assert_eq!(small[0], 6);
248248
assert_eq!(small[1], 5);
249249
let before = small.clone();
@@ -367,7 +367,7 @@ fn assign()
367367
let mut a = arr2(&[[1, 2], [3, 4]]);
368368
{
369369
let mut v = a.view_mut();
370-
v.islice(&[Si(0, Some(1), 1), S]);
370+
v.slice_inplace(&[Si(0, Some(1), 1), S]);
371371
v.fill(0);
372372
}
373373
assert_eq!(a, arr2(&[[0, 0], [3, 4]]));
@@ -1073,7 +1073,7 @@ fn to_owned_memory_order() {
10731073
fn to_owned_neg_stride() {
10741074
let mut c = arr2(&[[1, 2, 3],
10751075
[4, 5, 6]]);
1076-
c.islice(s![.., ..;-1]);
1076+
c.slice_inplace(s![.., ..;-1]);
10771077
let co = c.to_owned();
10781078
assert_eq!(c, co);
10791079
}
@@ -1238,10 +1238,10 @@ fn test_to_vec() {
12381238
[7, 8, 9],
12391239
[10,11,12]]);
12401240

1241-
a.islice(s![..;-1, ..]);
1241+
a.slice_inplace(s![..;-1, ..]);
12421242
assert_eq!(a.row(3).to_vec(), vec![1, 2, 3]);
12431243
assert_eq!(a.column(2).to_vec(), vec![12, 9, 6, 3]);
1244-
a.islice(s![.., ..;-1]);
1244+
a.slice_inplace(s![.., ..;-1]);
12451245
assert_eq!(a.row(3).to_vec(), vec![3, 2, 1]);
12461246
}
12471247

@@ -1257,7 +1257,7 @@ fn test_array_clone_unalias() {
12571257
#[test]
12581258
fn test_array_clone_same_view() {
12591259
let mut a = Array::from_iter(0..9).into_shape((3, 3)).unwrap();
1260-
a.islice(s![..;-1, ..;-1]);
1260+
a.slice_inplace(s![..;-1, ..;-1]);
12611261
let b = a.clone();
12621262
assert_eq!(a, b);
12631263
}

0 commit comments

Comments
 (0)