(kinds, types, shape)
| 905 | |
| 906 | |
| 907 | def 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)) |
no test coverage detected