@@ -16,23 +16,18 @@ use crate::{dimension, ArcArray1, ArcArray2};
16
16
/// three dimensions.
17
17
///
18
18
/// ```
19
- /// extern crate ndarray;
20
- ///
21
19
/// use ndarray::array;
20
+ /// let a1 = array![1, 2, 3, 4];
22
21
///
23
- /// fn main() {
24
- /// let a1 = array![1, 2, 3, 4];
25
- ///
26
- /// let a2 = array![[1, 2],
27
- /// [3, 4]];
22
+ /// let a2 = array![[1, 2],
23
+ /// [3, 4]];
28
24
///
29
- /// let a3 = array![[[1, 2], [3, 4]],
30
- /// [[5, 6], [7, 8]]];
25
+ /// let a3 = array![[[1, 2], [3, 4]],
26
+ /// [[5, 6], [7, 8]]];
31
27
///
32
- /// assert_eq!(a1.shape(), &[4]);
33
- /// assert_eq!(a2.shape(), &[2, 2]);
34
- /// assert_eq!(a3.shape(), &[2, 2, 2]);
35
- /// }
28
+ /// assert_eq!(a1.shape(), &[4]);
29
+ /// assert_eq!(a2.shape(), &[2, 2]);
30
+ /// assert_eq!(a3.shape(), &[2, 2, 2]);
36
31
/// ```
37
32
///
38
33
/// This macro uses `vec![]`, and has the same ownership semantics;
@@ -115,19 +110,14 @@ pub fn aview2<A, V: FixedInitializer<Elem = A>>(xs: &[V]) -> ArrayView2<'_, A> {
115
110
/// Create a one-dimensional read-write array view with elements borrowing `xs`.
116
111
///
117
112
/// ```
118
- /// extern crate ndarray;
119
- ///
120
113
/// use ndarray::{aview_mut1, s};
121
- ///
122
114
/// // Create an array view over some data, then slice it and modify it.
123
- /// fn main() {
124
- /// let mut data = [0; 1024];
125
- /// {
126
- /// let mut a = aview_mut1(&mut data).into_shape((32, 32)).unwrap();
127
- /// a.slice_mut(s![.., ..;3]).fill(5);
128
- /// }
129
- /// assert_eq!(&data[..10], [5, 0, 0, 5, 0, 0, 5, 0, 0, 5]);
115
+ /// let mut data = [0; 1024];
116
+ /// {
117
+ /// let mut a = aview_mut1(&mut data).into_shape((32, 32)).unwrap();
118
+ /// a.slice_mut(s![.., ..;3]).fill(5);
130
119
/// }
120
+ /// assert_eq!(&data[..10], [5, 0, 0, 5, 0, 0, 5, 0, 0, 5]);
131
121
/// ```
132
122
pub fn aview_mut1 < A > ( xs : & mut [ A ] ) -> ArrayViewMut1 < ' _ , A > {
133
123
ArrayViewMut :: from ( xs)
@@ -143,20 +133,18 @@ pub fn aview_mut1<A>(xs: &mut [A]) -> ArrayViewMut1<'_, A> {
143
133
/// ```
144
134
/// use ndarray::aview_mut2;
145
135
///
146
- /// fn main() {
147
- /// // The inner (nested) array must be of length 1 to 16, but the outer
148
- /// // can be of any length.
149
- /// let mut data = [[0.; 2]; 128];
150
- /// {
151
- /// // Make a 128 x 2 mut array view then turn it into 2 x 128
152
- /// let mut a = aview_mut2(&mut data).reversed_axes();
153
- /// // Make the first row ones and second row minus ones.
154
- /// a.row_mut(0).fill(1.);
155
- /// a.row_mut(1).fill(-1.);
156
- /// }
157
- /// // look at the start of the result
158
- /// assert_eq!(&data[..3], [[1., -1.], [1., -1.], [1., -1.]]);
136
+ /// // The inner (nested) array must be of length 1 to 16, but the outer
137
+ /// // can be of any length.
138
+ /// let mut data = [[0.; 2]; 128];
139
+ /// {
140
+ /// // Make a 128 x 2 mut array view then turn it into 2 x 128
141
+ /// let mut a = aview_mut2(&mut data).reversed_axes();
142
+ /// // Make the first row ones and second row minus ones.
143
+ /// a.row_mut(0).fill(1.);
144
+ /// a.row_mut(1).fill(-1.);
159
145
/// }
146
+ /// // look at the start of the result
147
+ /// assert_eq!(&data[..3], [[1., -1.], [1., -1.], [1., -1.]]);
160
148
/// ```
161
149
pub fn aview_mut2 < A , V : FixedInitializer < Elem = A > > ( xs : & mut [ V ] ) -> ArrayViewMut2 < ' _ , A > {
162
150
let cols = V :: len ( ) ;
0 commit comments