Skip to content

Commit a5a4b98

Browse files
committed
shape: More explicit examples for to_shape and into_shape
1 parent 49f5870 commit a5a4b98

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/impl_methods.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,9 +1815,20 @@ where
18151815
/// number of rows and columns (or more axes if applicable), it is important to pick an index
18161816
/// ordering, and that's the reason for the function parameter for `order`.
18171817
///
1818+
/// The `new_shape` parameter should be a dimension and an optional order like these examples:
1819+
///
1820+
/// ```text
1821+
/// (3, 4) // Shape 3 x 4 with default order (RowMajor)
1822+
/// ((3, 4), Order::RowMajor)) // use specific order
1823+
/// ((3, 4), Order::ColumnMajor)) // use specific order
1824+
/// ((3, 4), Order::C)) // use shorthand for order - shorthands C and F
1825+
/// ```
1826+
///
18181827
/// **Errors** if the new shape doesn't have the same number of elements as the array's current
18191828
/// shape.
18201829
///
1830+
/// # Example
1831+
///
18211832
/// ```
18221833
/// use ndarray::array;
18231834
/// use ndarray::Order;
@@ -1890,10 +1901,10 @@ where
18901901
///
18911902
/// If an index ordering is not specified, the default is `RowMajor`.
18921903
/// The operation will only succeed if the array's memory layout is compatible with
1893-
/// the index ordering.
1904+
/// the index ordering, so that the array elements can be rearranged in place.
18941905
///
1895-
/// Use `.to_shape()` instead for more flexible reshaping of arrays, which
1896-
/// allows copying elements if required.
1906+
/// If required use `.to_shape()` or `.into_shape_clone` instead for more flexible reshaping of
1907+
/// arrays, which allows copying elements if required.
18971908
///
18981909
/// **Errors** if the shapes don't have the same number of elements.<br>
18991910
/// **Errors** if order RowMajor is given but input is not c-contiguous.
@@ -1903,6 +1914,17 @@ where
19031914
/// reshaped using row major index ordering, column major arrays with column major index
19041915
/// ordering.
19051916
///
1917+
/// The `new_shape` parameter should be a dimension and an optional order like these examples:
1918+
///
1919+
/// ```text
1920+
/// (3, 4) // Shape 3 x 4 with default order (RowMajor)
1921+
/// ((3, 4), Order::RowMajor)) // use specific order
1922+
/// ((3, 4), Order::ColumnMajor)) // use specific order
1923+
/// ((3, 4), Order::C)) // use shorthand for order - shorthands C and F
1924+
/// ```
1925+
///
1926+
/// # Example
1927+
///
19061928
/// ```
19071929
/// use ndarray::{aview1, aview2};
19081930
/// use ndarray::Order;
@@ -1960,7 +1982,7 @@ where
19601982
/// is C-contig or F-contig, it follows the index order that corresponds to the memory order.
19611983
/// Prefer to use `.to_shape()` or `.into_shape_with_order()`.
19621984
///
1963-
/// Because of this, the method is deprecated. That reshapes depend on memory order is not
1985+
/// Because of this, the method **is deprecated**. That reshapes depend on memory order is not
19641986
/// intuitive.
19651987
///
19661988
/// **Errors** if the shapes don't have the same number of elements.<br>

0 commit comments

Comments
 (0)