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

Function check_arithm_mod

dali/test/python/operator_1/test_arithmetic_ops.py:907–939  ·  view source on GitHub ↗
(kinds, types, shape)

Source from the content-addressed store, hash-verified

905
906
907def check_arithm_mod(kinds, types, shape):
908 # DALI uses C-style truncated remainder (same sign as the dividend), matching np.fmod.
909 # bool is excluded: bool % bool = 0 but disallow_zeros makes it tricky with bool generators.
910 left_type, right_type = types
911 target_type = bin_promote(left_type, right_type)
912 # Avoid zeros in the right operand.
913 iterator = iter(
914 ExternalInputIterator(
915 batch_size,
916 shape,
917 types,
918 kinds,
919 disallow_zeros=(False, True),
920 limited_range=[(-1000, 1000), (-100, 100)],
921 )
922 )
923 pipe = ExprOpPipeline(
924 kinds,
925 types,
926 iterator,
927 (lambda x, y: x % y),
928 batch_size=batch_size,
929 num_threads=2,
930 device_id=0,
931 )
932 pipe_out = pipe.run()
933 for sample in range(batch_size):
934 l_np, r_np, out = extract_data(pipe_out, sample, kinds, target_type)
935 assert_equals(out.dtype, target_type)
936
937 assert np.array_equal(
938 out, np.fmod(l_np.astype(np.float64), r_np.astype(np.float64)).astype(target_type)
939 )
940
941
942@cartesian_params(selected_bin_input_kinds, iter_pow(selected_integer_types, 2))

Callers 3

test_mod_selectedFunction · 0.85
slow_test_mod2Function · 0.85

Calls 7

assert_equalsFunction · 0.90
bin_promoteFunction · 0.85
ExprOpPipelineClass · 0.85
fmodMethod · 0.80
extract_dataFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected