Skip to content

Commit

Permalink
comments from @jturner314 review
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jun 26, 2019
1 parent 3cf1200 commit 38fad8f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/life.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate ndarray;

use ndarray::prelude::*;
use std::iter::FromIterator;

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

const N: usize = 100;

Expand Down
13 changes: 10 additions & 3 deletions src/arraytraits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,20 @@ impl<A, S> FromIterator<A> for ArrayBase<S, Ix1>
where
S: DataOwned<Elem = A>,
{
/// Create a one-dimensional array from a vector (no copying needed).
///
/// **Panics** if the length is greater than `isize::MAX`.
///
/// ```rust
/// use ndarray::Array;
///
/// let array = Array::from(vec![1., 2., 3., 4.]);
/// ```
fn from_iter<I>(iterable: I) -> ArrayBase<S, Ix1>
where
I: IntoIterator<Item = A>,
{
// TODO: can I put this on one line?
let v: Vec<A> = iterable.into_iter().collect();
Self::from(v)
Self::from(iterable.into_iter().collect::<Vec<A>>())
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/impl_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,7 @@ where
/// ```
#[deprecated(note = "use standard `from`", since = "0.13.0")]
pub fn from_vec(v: Vec<A>) -> Self {
if mem::size_of::<A>() == 0 {
assert!(
v.len() <= isize::MAX as usize,
"Length must fit in `isize`.",
);
}
unsafe { Self::from_shape_vec_unchecked(v.len() as Ix, v) }
Self::from(v)
}

// FIXME: Having this uncommented means that `from_iter` references this
Expand Down
9 changes: 3 additions & 6 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,9 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
///
/// use ndarray::multislice;
/// use ndarray::prelude::*;
/// use std::iter::FromIterator;
///
/// # fn main() {
/// let mut arr = Array1::from_iter(0..12);
/// let mut arr: Array1<_> = (0..12).collect();
/// let (a, b, c, d) = multislice!(arr, [0..5], mut [6..;2], [1..6], mut [7..;2]);
/// assert_eq!(a, array![0, 1, 2, 3, 4]);
/// assert_eq!(b, array![6, 8, 10]);
Expand All @@ -717,9 +716,8 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
/// # extern crate ndarray;
/// # use ndarray::multislice;
/// # use ndarray::prelude::*;
/// # use std::iter::FromIterator;
/// # fn main() {
/// let mut arr = Array1::from_iter(0..12);
/// let mut arr: Array1<_> = (0..12).collect();
/// multislice!(arr, [0..5], mut [1..;2]); // panic!
/// # }
/// ```
Expand All @@ -730,9 +728,8 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
/// # extern crate ndarray;
/// # use ndarray::multislice;
/// # use ndarray::prelude::*;
/// # use std::iter::FromIterator;
/// # fn main() {
/// let mut arr = Array1::from_iter(0..12);
/// let mut arr: Array1<_> = (0..12).collect();
/// multislice!(arr, mut [0..5], mut [1..;2]); // panic!
/// # }
/// ```
Expand Down

0 comments on commit 38fad8f

Please # to comment.