|
13 | 13 | #![allow(clippy::match_wild_err_arm)] |
14 | 14 |
|
15 | 15 | use num_traits::{Float, One, Zero}; |
16 | | -use std::isize; |
17 | | -use std::mem; |
18 | 16 |
|
19 | 17 | use crate::dimension; |
20 | 18 | use crate::error::{self, ShapeError}; |
@@ -42,35 +40,11 @@ where |
42 | 40 | /// ```rust |
43 | 41 | /// use ndarray::Array; |
44 | 42 | /// |
45 | | - /// let array = Array::from_vec(vec![1., 2., 3., 4.]); |
| 43 | + /// let array = Array::from(vec![1., 2., 3., 4.]); |
46 | 44 | /// ``` |
| 45 | + #[deprecated(note = "use standard `from`", since = "0.13.0")] |
47 | 46 | pub fn from_vec(v: Vec<A>) -> Self { |
48 | | - if mem::size_of::<A>() == 0 { |
49 | | - assert!( |
50 | | - v.len() <= isize::MAX as usize, |
51 | | - "Length must fit in `isize`.", |
52 | | - ); |
53 | | - } |
54 | | - unsafe { Self::from_shape_vec_unchecked(v.len() as Ix, v) } |
55 | | - } |
56 | | - |
57 | | - /// Create a one-dimensional array from an iterable. |
58 | | - /// |
59 | | - /// **Panics** if the length is greater than `isize::MAX`. |
60 | | - /// |
61 | | - /// ```rust |
62 | | - /// use ndarray::{Array, arr1}; |
63 | | - /// |
64 | | - /// let array = Array::from_iter((0..5).map(|x| x * x)); |
65 | | - /// assert!(array == arr1(&[0, 1, 4, 9, 16])) |
66 | | - /// ``` |
67 | | - // Potentially remove; see https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296068930 |
68 | | - #[allow(clippy::should_implement_trait)] |
69 | | - pub fn from_iter<I>(iterable: I) -> Self |
70 | | - where |
71 | | - I: IntoIterator<Item = A>, |
72 | | - { |
73 | | - Self::from_vec(iterable.into_iter().collect()) |
| 47 | + Self::from(v) |
74 | 48 | } |
75 | 49 |
|
76 | 50 | /// Create a one-dimensional array with `n` evenly spaced elements from |
|
94 | 68 | where |
95 | 69 | A: Float, |
96 | 70 | { |
97 | | - Self::from_vec(to_vec(linspace::linspace(start, end, n))) |
| 71 | + Self::from(to_vec(linspace::linspace(start, end, n))) |
98 | 72 | } |
99 | 73 |
|
100 | 74 | /// Create a one-dimensional array with elements from `start` to `end` |
|
112 | 86 | where |
113 | 87 | A: Float, |
114 | 88 | { |
115 | | - Self::from_vec(to_vec(linspace::range(start, end, step))) |
| 89 | + Self::from(to_vec(linspace::range(start, end, step))) |
116 | 90 | } |
117 | 91 |
|
118 | 92 | /// Create a one-dimensional array with `n` logarithmically spaced |
@@ -140,7 +114,7 @@ where |
140 | 114 | where |
141 | 115 | A: Float, |
142 | 116 | { |
143 | | - Self::from_vec(to_vec(logspace::logspace(base, start, end, n))) |
| 117 | + Self::from(to_vec(logspace::logspace(base, start, end, n))) |
144 | 118 | } |
145 | 119 |
|
146 | 120 | /// Create a one-dimensional array with `n` geometrically spaced elements |
@@ -174,7 +148,7 @@ where |
174 | 148 | where |
175 | 149 | A: Float, |
176 | 150 | { |
177 | | - Some(Self::from_vec(to_vec(geomspace::geomspace(start, end, n)?))) |
| 151 | + Some(Self::from(to_vec(geomspace::geomspace(start, end, n)?))) |
178 | 152 | } |
179 | 153 | } |
180 | 154 |
|
|
0 commit comments