MCPcopy Create free account
hub / github.com/NVIDIA/DALI / test_runtime_stride_dim2

Function test_runtime_stride_dim2

dali/test/python/operator_2/test_subscript.py:157–179  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155
156
157def test_runtime_stride_dim2():
158 def data_gen():
159 return [
160 np.arange(12, dtype=np.float32).reshape(4, 3),
161 np.arange(20, dtype=np.float32).reshape(4, 5),
162 ]
163
164 src = fn.external_source(data_gen)
165 strides = [np.array(x, dtype=np.int64) for x in [1, 2, -1, -2, -5]]
166 stride = fn.external_source(source=strides, batch=False, cycle=True)
167 pipe = index_pipe(src, lambda x: x[:, ::stride])
168
169 j = 0
170 for _ in range(4):
171 inp, cpu, gpu = tuple(out.as_cpu() for out in pipe.run())
172 for i in range(len(inp)):
173 x = inp.at(i)
174 # fmt: off
175 ref = x[:, ::strides[j]]
176 # fmt: on
177 assert np.array_equal(ref, cpu.at(i))
178 assert np.array_equal(ref, gpu.at(i))
179 j = (j + 1) % len(strides)
180
181
182def test_new_axis():

Callers

nothing calls this directly

Calls 3

index_pipeFunction · 0.85
runMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected