Skip to content

Commit 1120b56

Browse files
committed
Improve basic docs for array, array views
1 parent 4dc8aa2 commit 1120b56

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

src/lib.rs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ pub type Ixs = isize;
192192
///
193193
/// ## Contents
194194
///
195-
/// + [Array and RcArray](#ownedarray-and-rcarray)
195+
/// + [Array](#array)
196+
/// + [RcArray](#rcarray)
197+
/// + [Array Views](#array-views)
196198
/// + [Indexing and Dimension](#indexing-and-dimension)
197199
/// + [Slicing](#slicing)
198200
/// + [Subviews](#subviews)
@@ -202,16 +204,51 @@ pub type Ixs = isize;
202204
/// + [Methods For All Array Types](#methods-for-all-array-types)
203205
/// + [Methods Specific to Array Views](#methods-specific-to-array-views)
204206
///
205-
/// ## `Array` and `RcArray`
206207
///
207-
/// `Array` owns the underlying array elements directly (just like
208-
/// a `Vec`), while [`RcArray`](type.RcArray.html) is a an array with reference
209-
/// counted data. `RcArray` can act both as an owner or as a view in that regard.
208+
///
209+
///
210+
/// ## `Array`
211+
///
212+
/// [`Array`](type.Array.html) is an owned array that ows the underlying array
213+
/// elements directly (just like a `Vec`) and it is the default way to create and
214+
/// store n-dimensional data. `Array<A, D>` has two type parameters: `A` for
215+
/// the element type, and `D` for the dimensionality. A particular
216+
/// dimensionality's type alias like `Array3<A>` just has the type parameter
217+
/// `A` for element type.
218+
///
219+
/// An example:
220+
///
221+
/// ```
222+
/// // Create a three-dimensional f64 array, initialized with zeros
223+
/// use ndarray::Array3;
224+
/// let mut temperature = Array3::<f64>::zeros((3, 4, 5));
225+
/// // Increase the temperature in this location
226+
/// temperature[[2, 2, 2]] += 0.5;
227+
/// ```
228+
///
229+
/// ## `RcArray`
230+
///
231+
/// [`RcArray`](type.RcArray.html) is an owned array with reference counted
232+
/// data (shared ownership).
210233
/// Sharing requires that it uses copy-on-write for mutable operations.
211234
/// Calling a method for mutating elements on `RcArray`, for example
212235
/// [`view_mut()`](#method.view_mut) or [`get_mut()`](#method.get_mut),
213236
/// will break sharing and require a clone of the data (if it is not uniquely held).
214237
///
238+
/// ## Array Views
239+
///
240+
/// `ArrayView` and `ArrayViewMut` are read-only and read-write array views
241+
/// respectively. They use dimensionality, indexing, and almost all other
242+
/// methods the same was as the other array types.
243+
///
244+
/// A view is created from an array using `.view()`, `.view_mut()`, using
245+
/// slicing (`.slice()`, `.slice_mut()`) or from one of the many iterators
246+
/// that yield array views.
247+
///
248+
/// You can also create an array view from a regular slice of data not
249+
/// allocated with `Array` — see [Methods Specific to Array
250+
/// Views](#methods-specific-to-array-views).
251+
///
215252
/// Note that all `ArrayBase` variants can change their view (slicing) of the
216253
/// data freely, even when their data can’t be mutated.
217254
///

0 commit comments

Comments
 (0)