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

Function test_runtime_stride_dim1

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

Source from the content-addressed store, hash-verified

130
131
132def test_runtime_stride_dim1():
133 def data_gen():
134 return [
135 np.arange(12, dtype=np.float32).reshape(4, 3),
136 np.arange(20, dtype=np.float32).reshape(4, 5),
137 ]
138
139 src = fn.external_source(data_gen)
140 strides = [np.array(x, dtype=np.int64) for x in [1, 2, -1, -2, -5]]
141 stride = fn.external_source(source=strides, batch=False, cycle=True)
142 pipe = index_pipe(src, lambda x: x[::stride])
143
144 j = 0
145 for _ in range(4):
146 inp, cpu, gpu = tuple(out.as_cpu() for out in pipe.run())
147 for i in range(len(inp)):
148 x = inp.at(i)
149 # fmt: off
150 ref = x[::strides[j]]
151 # fmt: on
152 assert np.array_equal(ref, cpu.at(i))
153 assert np.array_equal(ref, gpu.at(i))
154 j = (j + 1) % len(strides)
155
156
157def test_runtime_stride_dim2():

Callers

nothing calls this directly

Calls 3

index_pipeFunction · 0.85
runMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected