diff --git a/examples/life.rs b/examples/life.rs
index c48d4778a..9583f4283 100644
--- a/examples/life.rs
+++ b/examples/life.rs
@@ -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;
diff --git a/src/arraytraits.rs b/src/arraytraits.rs
index 9ec3c0d18..44b7b4441 100644
--- a/src/arraytraits.rs
+++ b/src/arraytraits.rs
@@ -148,13 +148,20 @@ impl FromIterator for ArrayBase
where
S: DataOwned,
{
+ /// 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(iterable: I) -> ArrayBase
where
I: IntoIterator- ,
{
- // TODO: can I put this on one line?
- let v: Vec = iterable.into_iter().collect();
- Self::from(v)
+ Self::from(iterable.into_iter().collect::>())
}
}
diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs
index 67a11ad7d..6475bf12b 100644
--- a/src/impl_constructors.rs
+++ b/src/impl_constructors.rs
@@ -44,13 +44,7 @@ where
/// ```
#[deprecated(note = "use standard `from`", since = "0.13.0")]
pub fn from_vec(v: Vec) -> Self {
- if mem::size_of::() == 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
diff --git a/src/slice.rs b/src/slice.rs
index ce0b0d049..491107a87 100644
--- a/src/slice.rs
+++ b/src/slice.rs
@@ -700,7 +700,9 @@ pub unsafe fn deref_raw_view_mut_into_view_mut_with_life<'a, A, D: Dimension>(
/// use std::iter::FromIterator;
///
/// # fn main() {
-/// let mut arr = Array1::from_iter(0..12);
+// TODO: the first line doesn't yet work: https://github.com/rust-ndarray/ndarray/pull/648#discussion_r297478854
+/// let arr: Array1<_> = (0..12).collect();
+/// // let mut arr = Array1::from_iter(0..12);
/// 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]);