|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | from nvidia.dali import Pipeline, pipeline_def, ops, fn, types
|
16 |
| -import nvidia.dali as dali |
17 |
| -from nvidia.dali.backend_impl import TensorListGPU |
18 | 16 | import numpy as np
|
19 |
| -from numpy.testing import assert_array_equal, assert_allclose |
20 | 17 | import os
|
21 | 18 | from functools import partial
|
22 | 19 | from math import floor
|
@@ -789,3 +786,33 @@ def test_wrong_axes():
|
789 | 786 | for wrong_axes_range in [(-10, -4), (3, 10)]:
|
790 | 787 | for named_args in [False, True]:
|
791 | 788 | yield check_wrong_axes, device, wrong_axes_range, named_args
|
| 789 | + |
| 790 | +def check_scalar(device): |
| 791 | + batch_size = 5 |
| 792 | + def get_data(): |
| 793 | + out = [np.random.ranf(size=[1000]).astype(dtype=np.single) for _ in range(batch_size)] |
| 794 | + return out |
| 795 | + |
| 796 | + @pipeline_def(batch_size=batch_size, num_threads=1, device_id=0) |
| 797 | + def test_pipe(): |
| 798 | + data = fn.external_source(source=get_data) |
| 799 | + shape = types.ScalarConstant(10) |
| 800 | + anchor = types.ScalarConstant(5) |
| 801 | + if device != 'cpu': |
| 802 | + data = data.gpu() |
| 803 | + sliced = fn.slice(data, start = anchor, shape = shape, axes=[0], device=device) |
| 804 | + return data, sliced, shape, anchor |
| 805 | + |
| 806 | + pipe = test_pipe() |
| 807 | + pipe.build() |
| 808 | + ref, data, shape, anchor = pipe.run() |
| 809 | + for sample_idx in range(batch_size): |
| 810 | + d = as_array(data[sample_idx]) |
| 811 | + r = as_array(ref[sample_idx]) |
| 812 | + s = as_array(shape[sample_idx]) |
| 813 | + a = as_array(anchor[sample_idx]) |
| 814 | + np.testing.assert_allclose(d, r[a:a+s]) |
| 815 | + |
| 816 | +def test_scalar(): |
| 817 | + for device in ['cpu', 'gpu']: |
| 818 | + yield check_scalar, device |
0 commit comments