Skip to content

Commit 38fad8f

Browse files
committed
comments from @jturner314 review
1 parent 3cf1200 commit 38fad8f

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

examples/life.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
extern crate ndarray;
22

33
use ndarray::prelude::*;
4+
use std::iter::FromIterator;
45

56
const INPUT: &'static [u8] = include_bytes!("life.txt");
6-
use std::iter::FromIterator;
77

88
const N: usize = 100;
99

src/arraytraits.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,20 @@ impl<A, S> FromIterator<A> for ArrayBase<S, Ix1>
148148
where
149149
S: DataOwned<Elem = A>,
150150
{
151+
/// Create a one-dimensional array from a vector (no copying needed).
152+
///
153+
/// **Panics** if the length is greater than `isize::MAX`.
154+
///
155+
/// ```rust
156+
/// use ndarray::Array;
157+
///
158+
/// let array = Array::from(vec![1., 2., 3., 4.]);
159+
/// ```
151160
fn from_iter<I>(iterable: I) -> ArrayBase<S, Ix1>
152161
where
153162
I: IntoIterator<Item = A>,
154163
{
155-
// TODO: can I put this on one line?
156-
let v: Vec<A> = iterable.into_iter().collect();
157-
Self::from(v)
164+
Self::from(iterable.into_iter().collect::<Vec<A>>())
158165
}
159166
}
160167

src/impl_constructors.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,7 @@ where
4444
/// ```
4545
#[deprecated(note = "use standard `from`", since = "0.13.0")]
4646
pub fn from_vec(v: Vec<A>) -> Self {
47-
if mem::size_of::<A>() == 0 {
48-
assert!(
49-
v.len() <= isize::MAX as usize,
50-
"Length must fit in `isize`.",
51-
);
52-
}
53-
unsafe { Self::from_shape_vec_unchecked(v.len() as Ix, v) }
47+
Self::from(v)
5448
}
5549

5650
// FIXME: Having this uncommented means that `from_iter` references this

src/slice.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,9 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
697697
///
698698
/// use ndarray::multislice;
699699
/// use ndarray::prelude::*;
700-
/// use std::iter::FromIterator;
701700
///
702701
/// # fn main() {
703-
/// let mut arr = Array1::from_iter(0..12);
702+
/// let mut arr: Array1<_> = (0..12).collect();
704703
/// let (a, b, c, d) = multislice!(arr, [0..5], mut [6..;2], [1..6], mut [7..;2]);
705704
/// assert_eq!(a, array![0, 1, 2, 3, 4]);
706705
/// assert_eq!(b, array![6, 8, 10]);
@@ -717,9 +716,8 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
717716
/// # extern crate ndarray;
718717
/// # use ndarray::multislice;
719718
/// # use ndarray::prelude::*;
720-
/// # use std::iter::FromIterator;
721719
/// # fn main() {
722-
/// let mut arr = Array1::from_iter(0..12);
720+
/// let mut arr: Array1<_> = (0..12).collect();
723721
/// multislice!(arr, [0..5], mut [1..;2]); // panic!
724722
/// # }
725723
/// ```
@@ -730,9 +728,8 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
730728
/// # extern crate ndarray;
731729
/// # use ndarray::multislice;
732730
/// # use ndarray::prelude::*;
733-
/// # use std::iter::FromIterator;
734731
/// # fn main() {
735-
/// let mut arr = Array1::from_iter(0..12);
732+
/// let mut arr: Array1<_> = (0..12).collect();
736733
/// multislice!(arr, mut [0..5], mut [1..;2]); // panic!
737734
/// # }
738735
/// ```

0 commit comments

Comments
 (0)