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

Function test_dicts

dali/test/python/conditionals/test_nests.py:81–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79
80
81def test_dicts():
82 @pipeline_def(enable_conditionals=True, num_threads=4, batch_size=8, device_id=0)
83 def pipeline():
84 pred = fn.external_source(source=lambda x: np.array(x.idx_in_batch % 2), batch=False)
85 if pred:
86 out = {"out": np.array(2)}
87 else:
88 out = {"out": np.array(1)}
89 return out["out"]
90
91 pipe = pipeline()
92 (out,) = pipe.run()
93 check_batch(out, [i % 2 + 1 for i in range(8)])
94
95 @pipeline_def(enable_conditionals=True, num_threads=4, batch_size=8, device_id=0)
96 def pipeline_op():
97 pred = fn.external_source(source=lambda x: np.array(x.idx_in_batch % 2), batch=False)
98 data = types.Constant(np.array(42), device="cpu")
99 if pred:
100 out = {"out": data - 1}
101 else:
102 out = {"out": data + 1}
103 return out["out"]
104
105 pipe_op = pipeline_op()
106 (out,) = pipe_op.run()
107 check_batch(out, [41 if i % 2 else 43 for i in range(8)])
108
109
110def test_tuples():

Callers

nothing calls this directly

Calls 4

check_batchFunction · 0.90
pipeline_opFunction · 0.85
pipelineFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected