Skip to content

Commit

Permalink
fixing some of Mod test cases (#1962)
Browse files Browse the repository at this point in the history
* fixing one of Mod test cases

* further corrections to tests

* adding another example/test

* removing redundant test

* adding more tests- incomplete checkin

* adding more tests

* formatting

* fixing test names
  • Loading branch information
jeffsaremi authored and gramalingam committed Apr 30, 2019
1 parent f1311e7 commit 68630bb
Show file tree
Hide file tree
Showing 60 changed files with 741 additions and 83 deletions.
224 changes: 208 additions & 16 deletions docs/Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -7475,7 +7475,7 @@ This version of the operator has been available since version 10 of the default
#### Examples

<details>
<summary>float_mixed_sign</summary>
<summary>mod_broadcast</summary>

```python
node = onnx.helper.make_node(
Expand All @@ -7484,18 +7484,69 @@ node = onnx.helper.make_node(
outputs=['z'],
)

x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0])
y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0])
z = np.mod(x, y) # expected output [2., -3., 5., -2., 3., 3.]
x = np.arange(0, 30).reshape([3, 2, 5])
y = np.array([7])
z = np.mod(x, y)
z
# array([[[0, 1, 2, 3, 4],
# [5, 6, 0, 1, 2]],

# [[3, 4, 5, 6, 0],
# [1, 2, 3, 4, 5]],

# [[6, 0, 1, 2, 3],
# [4, 5, 6, 0, 1]]], dtype=int32)
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_broadcast')
```

</details>


<details>
<summary>mod_int64_fmod</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
fmod=1
)

x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64)
y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64)
z = np.fmod(x, y) # expected output [ 0, 1, 5, 0, -1, 3]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_int64_fmod')
```

</details>


<details>
<summary>mod_mixed_sign_float16</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
fmod=1
)

x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float16)
y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float16)
z = np.fmod(x, y) # expected output [-0.10156, 0.3984 , 5. , 0.10156, -0.3984 , 3.]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_float_mixed_sign_example')
name='test_mod_mixed_sign_float16')
```

</details>


<details>
<summary>fmod_mixed_sign</summary>
<summary>mod_mixed_sign_float32</summary>

```python
node = onnx.helper.make_node(
Expand All @@ -7505,18 +7556,79 @@ node = onnx.helper.make_node(
fmod=1
)

x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0])
y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0])
x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float32)
y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float32)
z = np.fmod(x, y) # expected output [-0.10000038, 0.39999962, 5. , 0.10000038, -0.39999962, 3.]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_mixed_sign_float32')
```

</details>


<details>
<summary>mod_mixed_sign_float64</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
fmod=1
)

x = np.array([-4.3, 7.2, 5.0, 4.3, -7.2, 8.0]).astype(np.float64)
y = np.array([2.1, -3.4, 8.0, -2.1, 3.4, 5.0]).astype(np.float64)
z = np.fmod(x, y) # expected output [-0.1, 0.4, 5. , 0.1, -0.4, 3.]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_fmod_mixed_sign_example')
name='test_mod_mixed_sign_float64')
```

</details>


<details>
<summary>mod_mixed_sign_int16</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
)

x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int16)
y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int16)
z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_mixed_sign_int16')
```

</details>


<details>
<summary>mod_mixed_sign_int32</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
)

x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int32)
y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int32)
z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_mixed_sign_int32')
```

</details>


<details>
<summary>int64_mixed_sign</summary>
<summary>mod_mixed_sign_int64</summary>

```python
node = onnx.helper.make_node(
Expand All @@ -7529,14 +7641,14 @@ x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int64)
y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int64)
z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_int64_mixed_sign_example')
name='test_mod_mixed_sign_int64')
```

</details>


<details>
<summary>mul_broadcast</summary>
<summary>mod_mixed_sign_int8</summary>

```python
node = onnx.helper.make_node(
Expand All @@ -7545,11 +7657,91 @@ node = onnx.helper.make_node(
outputs=['z'],
)

x = np.arange(0, 30).reshape([3, 2, 5])
y = np.array([7])
z = np.mod(x, y)
x = np.array([-4, 7, 5, 4, -7, 8]).astype(np.int8)
y = np.array([2, -3, 8, -2, 3, 5]).astype(np.int8)
z = np.mod(x, y) # expected output [ 0, -2, 5, 0, 2, 3]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_mixed_sign_int8')
```

</details>


<details>
<summary>mod_uint16</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
)

x = np.array([4, 7, 5]).astype(np.uint16)
y = np.array([2, 3, 8]).astype(np.uint16)
z = np.mod(x, y) # expected output [0, 1, 5]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_uint16')
```

</details>


<details>
<summary>mod_uint32</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
)

x = np.array([4, 7, 5]).astype(np.uint32)
y = np.array([2, 3, 8]).astype(np.uint32)
z = np.mod(x, y) # expected output [0, 1, 5]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_uint32')
```

</details>


<details>
<summary>mod_uint64</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
)

x = np.array([4, 7, 5]).astype(np.uint64)
y = np.array([2, 3, 8]).astype(np.uint64)
z = np.mod(x, y) # expected output [0, 1, 5]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_uint64')
```

</details>


<details>
<summary>mod_uint8</summary>

```python
node = onnx.helper.make_node(
'Mod',
inputs=['x', 'y'],
outputs=['z'],
)

x = np.array([4, 7, 5]).astype(np.uint8)
y = np.array([2, 3, 8]).astype(np.uint8)
z = np.mod(x, y) # expected output [0, 1, 5]
expect(node, inputs=[x, y], outputs=[z],
name='test_mod_bcast')
name='test_mod_uint8')
```

</details>
Expand Down
Loading

0 comments on commit 68630bb

Please sign in to comment.