|
14 | 14 | predict_shape, read_segments, _positive_slice,
|
15 | 15 | threshold_heuristic, optimize_slicer, slice2len,
|
16 | 16 | fill_slicer, optimize_read_slicers, slicers2segments,
|
17 |
| - calc_slicedefs, _simple_fileslice, slice2outax) |
| 17 | + calc_slicedefs, _simple_fileslice, slice2outax, |
| 18 | + strided_scalar) |
18 | 19 |
|
19 | 20 | from nose.tools import assert_true, assert_false, assert_equal, assert_raises
|
20 | 21 |
|
@@ -627,6 +628,23 @@ def test_predict_shape():
|
627 | 628 | assert_equal(predict_shape((1, slice(None), None), (2, 3)), (3, 1))
|
628 | 629 |
|
629 | 630 |
|
| 631 | +def test_strided_scalar(): |
| 632 | + # Utility to make numpy array of given shape from scalar using striding |
| 633 | + for shape, scalar in product( |
| 634 | + ((2,), (2, 3,), (2, 3, 4)), |
| 635 | + (1, 2, np.int16(3))): |
| 636 | + expected = np.zeros(shape, dtype=np.array(scalar).dtype) + scalar |
| 637 | + observed = strided_scalar(shape, scalar) |
| 638 | + assert_array_equal(observed, expected) |
| 639 | + assert_equal(observed.shape, shape) |
| 640 | + assert_equal(observed.dtype, expected.dtype) |
| 641 | + assert_array_equal(observed.strides, 0) |
| 642 | + observed[..., 0] = 99 |
| 643 | + assert_array_equal(observed, expected * 0 + 99) |
| 644 | + # Default scalar value is 0 |
| 645 | + assert_array_equal(strided_scalar((2, 3, 4)), np.zeros((2, 3, 4))) |
| 646 | + |
| 647 | + |
630 | 648 | def _check_bytes(bytes, arr):
|
631 | 649 | barr = np.ndarray(arr.shape, arr.dtype, buffer=bytes)
|
632 | 650 | assert_array_equal(barr, arr)
|
|
0 commit comments