Skip to content

Commit a3c415b

Browse files
committed
Remove as many feature = "std" gates in tests as possible
1 parent d633d64 commit a3c415b

File tree

7 files changed

+40
-53
lines changed

7 files changed

+40
-53
lines changed

tests/array.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,16 @@ fn arrayviewmut_shrink_lifetime<'a, 'b: 'a>(view: ArrayViewMut1<'b, f64>) -> Arr
6868
}
6969

7070
#[test]
71-
#[cfg(feature = "std")]
7271
fn test_mat_mul()
7372
{
7473
// smoke test, a big matrix multiplication of uneven size
7574
let (n, m) = (45, 33);
76-
let a = ArcArray::linspace(0., ((n * m) - 1) as f32, n as usize * m as usize)
75+
let a = Array::from_iter(0..(n * m))
7776
.into_shape_with_order((n, m))
7877
.unwrap();
79-
let b = ArcArray::eye(m);
78+
let b = Array::eye(m);
8079
assert_eq!(a.dot(&b), a);
81-
let c = ArcArray::eye(n);
80+
let c = Array::eye(n);
8281
assert_eq!(c.dot(&a), a);
8382
}
8483

@@ -692,32 +691,30 @@ fn test_cow_shrink()
692691
}
693692

694693
#[test]
695-
#[cfg(feature = "std")]
696694
fn test_sub()
697695
{
698-
let mat = ArcArray::linspace(0., 15., 16)
696+
let mat = Array::from_iter(0..16)
699697
.into_shape_with_order((2, 4, 2))
700698
.unwrap();
701699
let s1 = mat.index_axis(Axis(0), 0);
702700
let s2 = mat.index_axis(Axis(0), 1);
703701
assert_eq!(s1.shape(), &[4, 2]);
704702
assert_eq!(s2.shape(), &[4, 2]);
705-
let n = ArcArray::linspace(8., 15., 8)
703+
let n = Array::from_iter(8..16)
706704
.into_shape_with_order((4, 2))
707705
.unwrap();
708706
assert_eq!(n, s2);
709-
let m = ArcArray::from(vec![2., 3., 10., 11.])
707+
let m = Array::from(vec![2, 3, 10, 11])
710708
.into_shape_with_order((2, 2))
711709
.unwrap();
712710
assert_eq!(m, mat.index_axis(Axis(1), 1));
713711
}
714712

715713
#[should_panic]
716714
#[test]
717-
#[cfg(feature = "std")]
718715
fn test_sub_oob_1()
719716
{
720-
let mat = ArcArray::linspace(0., 15., 16)
717+
let mat = Array::from_iter(0..16)
721718
.into_shape_with_order((2, 4, 2))
722719
.unwrap();
723720
mat.index_axis(Axis(0), 2);
@@ -1845,7 +1842,6 @@ fn scalar_ops()
18451842
}
18461843

18471844
#[test]
1848-
#[cfg(feature = "std")]
18491845
fn split_at()
18501846
{
18511847
let mut a = arr2(&[[1., 2.], [3., 4.]]);
@@ -1864,7 +1860,7 @@ fn split_at()
18641860
}
18651861
assert_eq!(a, arr2(&[[1., 5.], [8., 4.]]));
18661862

1867-
let b = ArcArray::linspace(0., 59., 60)
1863+
let b = ArcArray::from_iter(0..60)
18681864
.into_shape_with_order((3, 4, 5))
18691865
.unwrap();
18701866

@@ -1874,9 +1870,9 @@ fn split_at()
18741870
assert_eq!(
18751871
left,
18761872
arr3(&[
1877-
[[0., 1.], [5., 6.], [10., 11.], [15., 16.]],
1878-
[[20., 21.], [25., 26.], [30., 31.], [35., 36.]],
1879-
[[40., 41.], [45., 46.], [50., 51.], [55., 56.]]
1873+
[[0, 1], [5, 6], [10, 11], [15, 16]],
1874+
[[20, 21], [25, 26], [30, 31], [35, 36]],
1875+
[[40, 41], [45, 46], [50, 51], [55, 56]]
18801876
])
18811877
);
18821878

tests/broadcast.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
use ndarray::prelude::*;
22

33
#[test]
4-
#[cfg(feature = "std")]
54
fn broadcast_1()
65
{
76
let a_dim = Dim([2, 4, 2, 2]);
87
let b_dim = Dim([2, 1, 2, 1]);
9-
let a = ArcArray::linspace(0., 1., a_dim.size())
8+
let a = Array::from_iter(0..a_dim.size())
109
.into_shape_with_order(a_dim)
1110
.unwrap();
12-
let b = ArcArray::linspace(0., 1., b_dim.size())
11+
let b = Array::from_iter(0..b_dim.size())
1312
.into_shape_with_order(b_dim)
1413
.unwrap();
1514
assert!(b.broadcast(a.dim()).is_some());
1615

1716
let c_dim = Dim([2, 1]);
18-
let c = ArcArray::linspace(0., 1., c_dim.size())
17+
let c = Array::from_iter(0..c_dim.size())
1918
.into_shape_with_order(c_dim)
2019
.unwrap();
2120
assert!(c.broadcast(1).is_none());
@@ -26,40 +25,38 @@ fn broadcast_1()
2625
assert!(c.broadcast((32, 1, 2)).is_none());
2726

2827
/* () can be broadcast to anything */
29-
let z = ArcArray::<f32, _>::zeros(());
28+
let z = Array::<f32, _>::zeros(());
3029
assert!(z.broadcast(()).is_some());
3130
assert!(z.broadcast(1).is_some());
3231
assert!(z.broadcast(3).is_some());
3332
assert!(z.broadcast((7, 2, 9)).is_some());
3433
}
3534

3635
#[test]
37-
#[cfg(feature = "std")]
3836
fn test_add()
3937
{
4038
let a_dim = Dim([2, 4, 2, 2]);
4139
let b_dim = Dim([2, 1, 2, 1]);
42-
let mut a = ArcArray::linspace(0.0, 1., a_dim.size())
40+
let mut a = Array::from_iter(0..a_dim.size())
4341
.into_shape_with_order(a_dim)
4442
.unwrap();
45-
let b = ArcArray::linspace(0.0, 1., b_dim.size())
43+
let b = Array::from_iter(0..b_dim.size())
4644
.into_shape_with_order(b_dim)
4745
.unwrap();
4846
a += &b;
49-
let t = ArcArray::from_elem((), 1.0f32);
47+
let t = Array::from_elem((), 1);
5048
a += &t;
5149
}
5250

5351
#[test]
5452
#[should_panic]
55-
#[cfg(feature = "std")]
5653
fn test_add_incompat()
5754
{
5855
let a_dim = Dim([2, 4, 2, 2]);
59-
let mut a = ArcArray::linspace(0.0, 1., a_dim.size())
56+
let mut a = Array::from_iter(0..a_dim.size())
6057
.into_shape_with_order(a_dim)
6158
.unwrap();
62-
let incompat = ArcArray::from_elem(3, 1.0f32);
59+
let incompat = Array::from_elem(3, 1);
6360
a += &incompat;
6461
}
6562

tests/dimension.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ fn test_array_view()
324324

325325
#[test]
326326
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
327-
#[cfg(feature = "std")]
328327
#[allow(clippy::cognitive_complexity)]
329328
fn test_all_ndindex()
330329
{
@@ -334,7 +333,7 @@ fn test_all_ndindex()
334333
for &rev in &[false, true] {
335334
// rev is for C / F order
336335
let size = $($i *)* 1;
337-
let mut a = Array::linspace(0., (size - 1) as f64, size);
336+
let mut a = Array::from_iter(0..size);
338337
if rev {
339338
a = a.reversed_axes();
340339
}

tests/iterator_chunks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
use ndarray::prelude::*;
77

88
#[test]
9-
#[cfg(feature = "std")]
109
fn chunks()
1110
{
1211
use ndarray::NdProducer;
13-
let a = <Array1<f32>>::linspace(1., 100., 10 * 10)
12+
let a = Array1::from_iter(0..100)
1413
.into_shape_with_order((10, 10))
1514
.unwrap();
1615

tests/iterators.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ macro_rules! assert_panics {
2222
}
2323

2424
#[test]
25-
#[cfg(feature = "std")]
2625
fn double_ended()
2726
{
28-
let a = ArcArray::linspace(0., 7., 8);
27+
let a = Array::from_iter(0..8);
2928
let mut it = a.iter().cloned();
30-
assert_eq!(it.next(), Some(0.));
31-
assert_eq!(it.next_back(), Some(7.));
32-
assert_eq!(it.next(), Some(1.));
33-
assert_eq!(it.rev().last(), Some(2.));
29+
assert_eq!(it.next(), Some(0));
30+
assert_eq!(it.next_back(), Some(7));
31+
assert_eq!(it.next(), Some(1));
32+
assert_eq!(it.rev().last(), Some(2));
3433
assert_equal(aview1(&[1, 2, 3]), &[1, 2, 3]);
3534
assert_equal(aview1(&[1, 2, 3]).into_iter().rev(), [1, 2, 3].iter().rev());
3635
}
@@ -82,7 +81,7 @@ fn iter_size_hint()
8281
#[cfg(feature = "std")]
8382
fn indexed()
8483
{
85-
let a = ArcArray::linspace(0., 7., 8);
84+
let a = Array::from_iter(0..8);
8685
for (i, elt) in a.indexed_iter() {
8786
assert_eq!(i, *elt as usize);
8887
}
@@ -100,7 +99,6 @@ fn indexed()
10099
}
101100

102101
#[test]
103-
#[cfg(feature = "std")]
104102
fn as_slice()
105103
{
106104
use ndarray::Data;
@@ -118,7 +116,7 @@ fn as_slice()
118116
assert_equal(v.iter(), slc);
119117
}
120118

121-
let a = ArcArray::linspace(0., 7., 8);
119+
let a = Array::from_iter(0..8);
122120
let a = a.into_shape_with_order((2, 4, 1)).unwrap();
123121

124122
assert_slice_correct(&a);
@@ -546,15 +544,14 @@ fn axis_iter_mut_zip_partially_consumed_discontiguous()
546544
}
547545

548546
#[test]
549-
#[cfg(feature = "std")]
550547
fn axis_chunks_iter_corner_cases()
551548
{
552549
// examples provided by @bluss in PR #65
553550
// these tests highlight corner cases of the axis_chunks_iter implementation
554551
// and enable checking if no pointer offsetting is out of bounds. However
555552
// checking the absence of of out of bounds offsetting cannot (?) be
556553
// done automatically, so one has to launch this test in a debugger.
557-
let a = ArcArray::<f32, _>::linspace(0., 7., 8)
554+
let a = Array::from_iter(0..8)
558555
.into_shape_with_order((8, 1))
559556
.unwrap();
560557
let it = a.axis_chunks_iter(Axis(0), 4);
@@ -564,9 +561,9 @@ fn axis_chunks_iter_corner_cases()
564561
assert_equal(it, vec![a.view()]);
565562
let it = a.axis_chunks_iter(Axis(0), 3);
566563
assert_equal(it, vec![
567-
array![[7.], [6.], [5.]],
568-
array![[4.], [3.], [2.]],
569-
array![[1.], [0.]],
564+
array![[7], [6], [5]],
565+
array![[4], [3], [2]],
566+
array![[1], [0]],
570567
]);
571568

572569
let b = ArcArray::<f32, _>::zeros((8, 2));

tests/ixdyn.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,11 @@ fn test_0_add_broad()
163163
}
164164

165165
#[test]
166-
#[cfg(feature = "std")]
167166
fn test_into_dimension()
168167
{
169168
use ndarray::{Ix0, Ix1, Ix2, IxDyn};
170169

171-
let a = Array::linspace(0., 41., 6 * 7)
170+
let a = Array::from_iter(0..42)
172171
.into_shape_with_order((6, 7))
173172
.unwrap();
174173
let a2 = a.clone().into_shape_with_order(IxDyn(&[6, 7])).unwrap();

tests/oper.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(
22
clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, clippy::many_single_char_names
33
)]
4-
#![cfg(feature = "std")]
54
use ndarray::linalg::general_mat_mul;
65
use ndarray::linalg::kron;
76
use ndarray::prelude::*;
@@ -133,7 +132,7 @@ where
133132
#[test]
134133
fn dot_product()
135134
{
136-
let a = Array::range(0., 69., 1.);
135+
let a = Array::from_iter((0..69).map(|x| x as f32));
137136
let b = &a * 2. - 7.;
138137
let dot = 197846.;
139138
assert_abs_diff_eq!(a.dot(&b), reference_dot(&a, &b), epsilon = 1e-5);
@@ -172,7 +171,7 @@ fn dot_product()
172171
#[test]
173172
fn dot_product_0()
174173
{
175-
let a = Array::range(0., 69., 1.);
174+
let a = Array::from_iter((0..69).map(|x| x as f32));
176175
let x = 1.5;
177176
let b = aview0(&x);
178177
let b = b.broadcast(a.dim()).unwrap();
@@ -194,7 +193,7 @@ fn dot_product_0()
194193
fn dot_product_neg_stride()
195194
{
196195
// test that we can dot with negative stride
197-
let a = Array::range(0., 69., 1.);
196+
let a = Array::from_iter((0..69).map(|x| x as f32));
198197
let b = &a * 2. - 7.;
199198
for stride in -10..0 {
200199
// both negative
@@ -213,7 +212,7 @@ fn dot_product_neg_stride()
213212
#[test]
214213
fn fold_and_sum()
215214
{
216-
let a = Array::linspace(0., 127., 128)
215+
let a = Array::from_iter((0..128).map(|x| x as f32))
217216
.into_shape_with_order((8, 16))
218217
.unwrap();
219218
assert_abs_diff_eq!(a.fold(0., |acc, &x| acc + x), a.sum(), epsilon = 1e-5);
@@ -255,7 +254,8 @@ fn fold_and_sum()
255254
#[test]
256255
fn product()
257256
{
258-
let a = Array::linspace(0.5, 2., 128)
257+
let step = (2. - 0.5) / 127.;
258+
let a = Array::from_iter((0..128).map(|i| 0.5 + step * (i as f64)))
259259
.into_shape_with_order((8, 16))
260260
.unwrap();
261261
assert_abs_diff_eq!(a.fold(1., |acc, &x| acc * x), a.product(), epsilon = 1e-5);

0 commit comments

Comments
 (0)