Skip to content

Commit aca8473

Browse files
bddppqhouseroad
authored andcommitted
Add Erf operator for computing error function (onnx#1675)
* Add Erf operator for computing error function * update test coverage
1 parent 3fc82ca commit aca8473

File tree

9 files changed

+170
-1
lines changed

9 files changed

+170
-1
lines changed

docs/Changelog.md

+29
Original file line numberDiff line numberDiff line change
@@ -8648,6 +8648,35 @@ This version of the operator has been available since version 9 of the default O
86488648
<dd>Constrain indices to integer types</dd>
86498649
</dl>
86508650

8651+
### <a name="Erf-9"></a>**Erf-9**</a>
8652+
8653+
Computes the error function of the given input tensor element-wise.
8654+
8655+
#### Version
8656+
8657+
This version of the operator has been available since version 9 of the default ONNX operator set.
8658+
8659+
#### Inputs
8660+
8661+
<dl>
8662+
<dt><tt>input</tt> : T</dt>
8663+
<dd>Input tensor</dd>
8664+
</dl>
8665+
8666+
#### Outputs
8667+
8668+
<dl>
8669+
<dt><tt>output</tt> : T</dt>
8670+
<dd>The error function of the input tensor computed element-wise. It has the same shape and type of the input.</dd>
8671+
</dl>
8672+
8673+
#### Type Constraints
8674+
8675+
<dl>
8676+
<dt><tt>T</tt> : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)</dt>
8677+
<dd>Constrain input and output types to all numeric tensors.</dd>
8678+
</dl>
8679+
86518680
### <a name="EyeLike-9"></a>**EyeLike-9**</a>
86528681

86538682
Generate a 2D tensor (matrix) with ones on the diagonal and zeros everywhere else. Only 2D

docs/Operators.md

+52
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* <a href="#Dropout">Dropout</a>
3434
* <a href="#Elu">Elu</a>
3535
* <a href="#Equal">Equal</a>
36+
* <a href="#Erf">Erf</a>
3637
* <a href="#Exp">Exp</a>
3738
* <a href="#Expand">Expand</a>
3839
* <a href="#EyeLike">EyeLike</a>
@@ -3252,6 +3253,57 @@ expect(node, inputs=[x, y], outputs=[z],
32523253
</details>
32533254

32543255

3256+
### <a name="Erf"></a><a name="erf">**Erf**</a>
3257+
3258+
Computes the error function of the given input tensor element-wise.
3259+
3260+
#### Version
3261+
3262+
This version of the operator has been available since version 9 of the default ONNX operator set.
3263+
3264+
#### Inputs
3265+
3266+
<dl>
3267+
<dt><tt>input</tt> : T</dt>
3268+
<dd>Input tensor</dd>
3269+
</dl>
3270+
3271+
#### Outputs
3272+
3273+
<dl>
3274+
<dt><tt>output</tt> : T</dt>
3275+
<dd>The error function of the input tensor computed element-wise. It has the same shape and type of the input.</dd>
3276+
</dl>
3277+
3278+
#### Type Constraints
3279+
3280+
<dl>
3281+
<dt><tt>T</tt> : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)</dt>
3282+
<dd>Constrain input and output types to all numeric tensors.</dd>
3283+
</dl>
3284+
3285+
3286+
#### Examples
3287+
3288+
<details>
3289+
<summary>erf</summary>
3290+
3291+
```python
3292+
node = onnx.helper.make_node(
3293+
'Erf',
3294+
inputs=['x'],
3295+
outputs=['y'],
3296+
)
3297+
3298+
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
3299+
y = np.vectorize(math.erf)(x).astype(np.float32)
3300+
expect(node, inputs=[x], outputs=[y],
3301+
name='test_erf')
3302+
```
3303+
3304+
</details>
3305+
3306+
32553307
### <a name="Exp"></a><a name="exp">**Exp**</a>
32563308

32573309
Calculates the exponential of the given input tensor, element-wise.

docs/TestCoverage.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* [Overall Test Coverage](#overall-test-coverage)
66
# Node Test Coverage
77
## Summary
8-
Node tests have covered 104/111 (93.69%, 5 generators excluded) common operators.
8+
Node tests have covered 105/112 (93.75%, 5 generators excluded) common operators.
99

1010
Node tests have covered 2/12 (16.67%, 0 generators excluded) experimental operators.
1111

@@ -1889,6 +1889,27 @@ expect(node, inputs=[x, y], outputs=[z],
18891889
</details>
18901890

18911891

1892+
### Erf
1893+
There are 1 test cases, listed as following:
1894+
<details>
1895+
<summary>erf</summary>
1896+
1897+
```python
1898+
node = onnx.helper.make_node(
1899+
'Erf',
1900+
inputs=['x'],
1901+
outputs=['y'],
1902+
)
1903+
1904+
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
1905+
y = np.vectorize(math.erf)(x).astype(np.float32)
1906+
expect(node, inputs=[x], outputs=[y],
1907+
name='test_erf')
1908+
```
1909+
1910+
</details>
1911+
1912+
18921913
### Exp
18931914
There are 1 test cases, listed as following:
18941915
<details>

onnx/backend/test/case/node/erf.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
from __future__ import unicode_literals
5+
6+
import math
7+
8+
import numpy as np # type: ignore
9+
10+
import onnx
11+
from ..base import Base
12+
from . import expect
13+
14+
15+
class Erf(Base):
16+
17+
@staticmethod
18+
def export(): # type: () -> None
19+
node = onnx.helper.make_node(
20+
'Erf',
21+
inputs=['x'],
22+
outputs=['y'],
23+
)
24+
25+
x = np.random.randn(1, 3, 32, 32).astype(np.float32)
26+
y = np.vectorize(math.erf)(x).astype(np.float32)
27+
expect(node, inputs=[x], outputs=[y],
28+
name='test_erf')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
 backend-test:Q
2+
3+
xy"Erftest_erfZ
4+
x
5+

6+

7+

8+

9+
 b
10+
y
11+

12+

13+

14+

15+
 B
Binary file not shown.
Binary file not shown.

onnx/defs/math/defs.cc

+22
Original file line numberDiff line numberDiff line change
@@ -1192,4 +1192,26 @@ ONNX_OPERATOR_SET_SCHEMA(
11921192
OpSchema::all_numeric_types(),
11931193
"Constrain input and output types to all numeric tensors.")
11941194
.TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput));
1195+
1196+
static const char* Erf_ver9_doc = R"DOC(
1197+
Computes the error function of the given input tensor element-wise.
1198+
)DOC";
1199+
1200+
ONNX_OPERATOR_SET_SCHEMA(
1201+
Erf,
1202+
9,
1203+
OpSchema()
1204+
.SetDoc(Erf_ver9_doc)
1205+
.Input(0, "input", "Input tensor", "T")
1206+
.Output(
1207+
0,
1208+
"output",
1209+
"The error function of the input tensor "
1210+
"computed element-wise. It has the same shape and type of the input.",
1211+
"T")
1212+
.TypeConstraint(
1213+
"T",
1214+
OpSchema::all_numeric_types(),
1215+
"Constrain input and output types to all numeric tensors.")
1216+
.TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput));
11951217
} // namespace ONNX_NAMESPACE

onnx/defs/operator_sets.h

+2
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Atanh);
490490
class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, IsNaN);
491491
class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Sign);
492492
class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Scan);
493+
class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Erf);
493494

494495
// Iterate over schema from ai.onnx version 9
495496
class OpSet_Onnx_ver9 {
@@ -520,6 +521,7 @@ class OpSet_Onnx_ver9 {
520521
fn(GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, IsNaN)>());
521522
fn(GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Sign)>());
522523
fn(GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Scan)>());
524+
fn(GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 9, Erf)>());
523525
}
524526
static void ForEachFunctionBuilder(
525527
std::function<void(FunctionBuilder&&)> fn) {

0 commit comments

Comments
 (0)