diff --git a/docs/Changelog.md b/docs/Changelog.md index f9b21494112..2aa0d5f5a73 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -14832,6 +14832,42 @@ This version of the operator has been available since version 12 of the default
Constrain target to integer types
+### **Pow-12** + + Pow takes input data (Tensor) and exponent Tensor, and + produces one output data (Tensor) where the function `f(x) = x^exponent`, + is applied to the data tensor elementwise. + This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [the doc](Broadcasting.md). + +#### Version + +This version of the operator has been available since version 12 of the default ONNX operator set. + +#### Inputs + +
+
X : T
+
First operand, base of the exponent.
+
Y : T1
+
Second operand, power of the exponent.
+
+ +#### Outputs + +
+
Z : T
+
Output tensor (same size as X)
+
+ +#### Type Constraints + +
+
T : tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input X and output types to float/int tensors.
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input Y types to float/int tensors.
+
+ ### **ReduceMax-12** Computes the max of the input tensor's element along the provided axes. The resulted diff --git a/docs/Operators.md b/docs/Operators.md index bedee1a1732..7e8cbf17d6c 100644 --- a/docs/Operators.md +++ b/docs/Operators.md @@ -11954,16 +11954,16 @@ for mode in ['edge', 'reflect']: #### Version -This version of the operator has been available since version 7 of the default ONNX operator set. +This version of the operator has been available since version 12 of the default ONNX operator set. -Other versions of this operator: Pow-1 +Other versions of this operator: Pow-1, Pow-7 #### Inputs
X : T
First operand, base of the exponent.
-
Y : T
+
Y : T1
Second operand, power of the exponent.
@@ -11977,8 +11977,10 @@ Other versions of this operator: Pow-1 #### Type Constraints
-
T : tensor(float16), tensor(float), tensor(double)
-
Constrain input and output types to float tensors.
+
T : tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input X and output types to float/int tensors.
+
T1 : tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double)
+
Constrain input Y types to float/int tensors.
@@ -11996,13 +11998,13 @@ node = onnx.helper.make_node( x = np.array([1, 2, 3]).astype(np.float32) y = np.array([4, 5, 6]).astype(np.float32) -z = np.power(x, y) # expected output [1., 32., 729.] +z = pow(x, y) # expected output [1., 32., 729.] expect(node, inputs=[x, y], outputs=[z], name='test_pow_example') x = np.arange(60).reshape(3, 4, 5).astype(np.float32) y = np.random.randn(3, 4, 5).astype(np.float32) -z = np.power(x, y) +z = pow(x, y) expect(node, inputs=[x, y], outputs=[z], name='test_pow') ``` @@ -12022,7 +12024,7 @@ node = onnx.helper.make_node( x = np.array([1, 2, 3]).astype(np.float32) y = np.array(2).astype(np.float32) -z = np.power(x, y) # expected output [1., 4., 9.] +z = pow(x, y) # expected output [1., 4., 9.] expect(node, inputs=[x, y], outputs=[z], name='test_pow_bcast_scalar') @@ -12034,7 +12036,7 @@ node = onnx.helper.make_node( x = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) y = np.array([1, 2, 3]).astype(np.float32) # expected output [[1, 4, 27], [4, 25, 216]] -z = np.power(x, y).astype(np.float32) +z = pow(x, y) expect(node, inputs=[x, y], outputs=[z], name='test_pow_bcast_array') ``` @@ -12042,6 +12044,68 @@ expect(node, inputs=[x, y], outputs=[z], +
+types + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int64') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int32') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint64') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint32') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_int64') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_int32') +``` + +
+ + ### **QLinearConv** The convolution operator consumes a quantized input tensor, its scale and zero point, diff --git a/docs/TestCoverage.md b/docs/TestCoverage.md index fb426d1a66b..3871f402626 100644 --- a/docs/TestCoverage.md +++ b/docs/TestCoverage.md @@ -6967,7 +6967,7 @@ for mode in ['edge', 'reflect']: ### Pow -There are 2 test cases, listed as following: +There are 3 test cases, listed as following:
pow @@ -6980,13 +6980,13 @@ node = onnx.helper.make_node( x = np.array([1, 2, 3]).astype(np.float32) y = np.array([4, 5, 6]).astype(np.float32) -z = np.power(x, y) # expected output [1., 32., 729.] +z = pow(x, y) # expected output [1., 32., 729.] expect(node, inputs=[x, y], outputs=[z], name='test_pow_example') x = np.arange(60).reshape(3, 4, 5).astype(np.float32) y = np.random.randn(3, 4, 5).astype(np.float32) -z = np.power(x, y) +z = pow(x, y) expect(node, inputs=[x, y], outputs=[z], name='test_pow') ``` @@ -7004,7 +7004,7 @@ node = onnx.helper.make_node( x = np.array([1, 2, 3]).astype(np.float32) y = np.array(2).astype(np.float32) -z = np.power(x, y) # expected output [1., 4., 9.] +z = pow(x, y) # expected output [1., 4., 9.] expect(node, inputs=[x, y], outputs=[z], name='test_pow_bcast_scalar') @@ -7016,11 +7016,71 @@ node = onnx.helper.make_node( x = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) y = np.array([1, 2, 3]).astype(np.float32) # expected output [[1, 4, 27], [4, 25, 216]] -z = np.power(x, y).astype(np.float32) +z = pow(x, y) expect(node, inputs=[x, y], outputs=[z], name='test_pow_bcast_array') ``` +
+
+types + +```python +node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], +) + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int64') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int32') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.float32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_float32') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint64) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint64') + +x = np.array([1, 2, 3]).astype(np.float32) +y = np.array([4, 5, 6]).astype(np.uint32) +z = pow(x, y) # expected output [1., 32., 729.] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint32') + +x = np.array([1, 2, 3]).astype(np.int64) +y = np.array([4, 5, 6]).astype(np.int64) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_int64') + +x = np.array([1, 2, 3]).astype(np.int32) +y = np.array([4, 5, 6]).astype(np.int32) +z = pow(x, y) # expected output [1, 32, 729] +expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_int32') +``` +
diff --git a/onnx/backend/test/case/node/pow.py b/onnx/backend/test/case/node/pow.py index a48dfbdcabe..14d73aa6c66 100644 --- a/onnx/backend/test/case/node/pow.py +++ b/onnx/backend/test/case/node/pow.py @@ -10,6 +10,11 @@ from . import expect +def pow(x, y): # type: ignore + z = np.power(x, y).astype(x.dtype) + return z + + class Pow(Base): @staticmethod @@ -22,13 +27,13 @@ def export(): # type: () -> None x = np.array([1, 2, 3]).astype(np.float32) y = np.array([4, 5, 6]).astype(np.float32) - z = np.power(x, y) # expected output [1., 32., 729.] + z = pow(x, y) # expected output [1., 32., 729.] expect(node, inputs=[x, y], outputs=[z], name='test_pow_example') x = np.arange(60).reshape(3, 4, 5).astype(np.float32) y = np.random.randn(3, 4, 5).astype(np.float32) - z = np.power(x, y) + z = pow(x, y) expect(node, inputs=[x, y], outputs=[z], name='test_pow') @@ -42,7 +47,7 @@ def export_pow_broadcast(): # type: () -> None x = np.array([1, 2, 3]).astype(np.float32) y = np.array(2).astype(np.float32) - z = np.power(x, y) # expected output [1., 4., 9.] + z = pow(x, y) # expected output [1., 4., 9.] expect(node, inputs=[x, y], outputs=[z], name='test_pow_bcast_scalar') @@ -54,6 +59,62 @@ def export_pow_broadcast(): # type: () -> None x = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) y = np.array([1, 2, 3]).astype(np.float32) # expected output [[1, 4, 27], [4, 25, 216]] - z = np.power(x, y).astype(np.float32) + z = pow(x, y) expect(node, inputs=[x, y], outputs=[z], name='test_pow_bcast_array') + + @staticmethod + def export_types(): # type: () -> None + node = onnx.helper.make_node( + 'Pow', + inputs=['x', 'y'], + outputs=['z'], + ) + + x = np.array([1, 2, 3]).astype(np.float32) + y = np.array([4, 5, 6]).astype(np.int64) + z = pow(x, y) # expected output [1., 32., 729.] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int64') + + x = np.array([1, 2, 3]).astype(np.int64) + y = np.array([4, 5, 6]).astype(np.float32) + z = pow(x, y) # expected output [1, 32, 729] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_float32') + + x = np.array([1, 2, 3]).astype(np.float32) + y = np.array([4, 5, 6]).astype(np.int32) + z = pow(x, y) # expected output [1., 32., 729.] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_int32') + + x = np.array([1, 2, 3]).astype(np.int32) + y = np.array([4, 5, 6]).astype(np.float32) + z = pow(x, y) # expected output [1, 32, 729] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_float32') + + x = np.array([1, 2, 3]).astype(np.float32) + y = np.array([4, 5, 6]).astype(np.uint64) + z = pow(x, y) # expected output [1., 32., 729.] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint64') + + x = np.array([1, 2, 3]).astype(np.float32) + y = np.array([4, 5, 6]).astype(np.uint32) + z = pow(x, y) # expected output [1., 32., 729.] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_float32_uint32') + + x = np.array([1, 2, 3]).astype(np.int64) + y = np.array([4, 5, 6]).astype(np.int64) + z = pow(x, y) # expected output [1, 32, 729] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int64_int64') + + x = np.array([1, 2, 3]).astype(np.int32) + y = np.array([4, 5, 6]).astype(np.int32) + z = pow(x, y) # expected output [1, 32, 729] + expect(node, inputs=[x, y], outputs=[z], + name='test_pow_types_int32_int32') diff --git a/onnx/backend/test/data/node/test_pow/model.onnx b/onnx/backend/test/data/node/test_pow/model.onnx index c49de5707db..b79fad40158 100644 --- a/onnx/backend/test/data/node/test_pow/model.onnx +++ b/onnx/backend/test/data/node/test_pow/model.onnx @@ -1,4 +1,4 @@ - backend-test:e + backend-test:e  x yz"Powtest_powZ @@ -16,4 +16,4 @@    -B \ No newline at end of file +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow/test_data_set_0/output_0.pb index 06e5fda91c4..68db533213a 100644 Binary files a/onnx/backend/test/data/node/test_pow/test_data_set_0/output_0.pb and b/onnx/backend/test/data/node/test_pow/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_bcast_array/model.onnx b/onnx/backend/test/data/node/test_pow_bcast_array/model.onnx index 8b630fa48b5..0edfc2fb0ef 100644 --- a/onnx/backend/test/data/node/test_pow_bcast_array/model.onnx +++ b/onnx/backend/test/data/node/test_pow_bcast_array/model.onnx @@ -1,4 +1,4 @@ - backend-test:a + backend-test:a  x yz"Powtest_pow_bcast_arrayZ @@ -13,4 +13,4 @@ z   -B \ No newline at end of file +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_bcast_scalar/model.onnx b/onnx/backend/test/data/node/test_pow_bcast_scalar/model.onnx index b9eaabe2114..bea5d68cad0 100644 Binary files a/onnx/backend/test/data/node/test_pow_bcast_scalar/model.onnx and b/onnx/backend/test/data/node/test_pow_bcast_scalar/model.onnx differ diff --git a/onnx/backend/test/data/node/test_pow_example/model.onnx b/onnx/backend/test/data/node/test_pow_example/model.onnx index ddc1ea3ac00..a4aa9a398bf 100644 --- a/onnx/backend/test/data/node/test_pow_example/model.onnx +++ b/onnx/backend/test/data/node/test_pow_example/model.onnx @@ -1,4 +1,4 @@ - backend-test:U + backend-test:U  x yz"Powtest_pow_exampleZ @@ -13,4 +13,4 @@ z  -B \ No newline at end of file +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_float/model.onnx b/onnx/backend/test/data/node/test_pow_types_float/model.onnx new file mode 100644 index 00000000000..c0fd50393cd --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_float/model.onnx @@ -0,0 +1,16 @@ + backend-test:Y + +x +yz"Powtest_pow_types_floatZ +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..d91963f15c8 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..a760307aaa9 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..c77d2103a13 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int32/model.onnx b/onnx/backend/test/data/node/test_pow_types_float32_int32/model.onnx new file mode 100644 index 00000000000..fd29f330a52 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_float32_int32/model.onnx @@ -0,0 +1,16 @@ + backend-test:a + +x +yz"Powtest_pow_types_float32_int32Z +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..62e4e87e30c Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..194c2ad3ae1 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..0cc39708ca5 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_int32/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int64/model.onnx b/onnx/backend/test/data/node/test_pow_types_float32_int64/model.onnx new file mode 100644 index 00000000000..9fe81897e54 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_float32_int64/model.onnx @@ -0,0 +1,16 @@ + backend-test:a + +x +yz"Powtest_pow_types_float32_int64Z +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..62e4e87e30c Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..2a776165494 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..0cc39708ca5 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_int64/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint32/model.onnx b/onnx/backend/test/data/node/test_pow_types_float32_uint32/model.onnx new file mode 100644 index 00000000000..110e4dc2fc7 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_float32_uint32/model.onnx @@ -0,0 +1,16 @@ + backend-test:b + +x +yz"Powtest_pow_types_float32_uint32Z +x + + +Z +y + +  +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..62e4e87e30c Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..7918aa428c7 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..0cc39708ca5 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_uint32/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint64/model.onnx b/onnx/backend/test/data/node/test_pow_types_float32_uint64/model.onnx new file mode 100644 index 00000000000..46cdbc7e253 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_float32_uint64/model.onnx @@ -0,0 +1,16 @@ + backend-test:b + +x +yz"Powtest_pow_types_float32_uint64Z +x + + +Z +y + +  +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..62e4e87e30c Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..015d9afbace Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..0cc39708ca5 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_float32_uint64/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int/model.onnx b/onnx/backend/test/data/node/test_pow_types_int/model.onnx new file mode 100644 index 00000000000..2e62ba5ad4f --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_int/model.onnx @@ -0,0 +1,16 @@ + backend-test:W + +x +yz"Powtest_pow_types_intZ +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..62e4e87e30c Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..2a776165494 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..0cc39708ca5 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int32_float32/model.onnx b/onnx/backend/test/data/node/test_pow_types_int32_float32/model.onnx new file mode 100644 index 00000000000..bc90f825a44 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_int32_float32/model.onnx @@ -0,0 +1,16 @@ + backend-test:a + +x +yz"Powtest_pow_types_int32_float32Z +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..bb7ca3491e3 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..a760307aaa9 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..67fd11d8712 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int32_float32/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int32_int32/model.onnx b/onnx/backend/test/data/node/test_pow_types_int32_int32/model.onnx new file mode 100644 index 00000000000..ee0ccee1ac5 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_int32_int32/model.onnx @@ -0,0 +1,16 @@ + backend-test:_ + +x +yz"Powtest_pow_types_int32_int32Z +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..bb7ca3491e3 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..194c2ad3ae1 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..67fd11d8712 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int32_int32/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int64_float32/model.onnx b/onnx/backend/test/data/node/test_pow_types_int64_float32/model.onnx new file mode 100644 index 00000000000..3aa62ec7f97 --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_int64_float32/model.onnx @@ -0,0 +1,16 @@ + backend-test:a + +x +yz"Powtest_pow_types_int64_float32Z +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..d91963f15c8 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..a760307aaa9 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..c77d2103a13 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int64_float32/test_data_set_0/output_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int64_int64/model.onnx b/onnx/backend/test/data/node/test_pow_types_int64_int64/model.onnx new file mode 100644 index 00000000000..6f95347f43d --- /dev/null +++ b/onnx/backend/test/data/node/test_pow_types_int64_int64/model.onnx @@ -0,0 +1,16 @@ + backend-test:_ + +x +yz"Powtest_pow_types_int64_int64Z +x + + +Z +y + + +b +z + + +B \ No newline at end of file diff --git a/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/input_0.pb b/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/input_0.pb new file mode 100644 index 00000000000..d91963f15c8 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/input_0.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/input_1.pb b/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/input_1.pb new file mode 100644 index 00000000000..2a776165494 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/input_1.pb differ diff --git a/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/output_0.pb b/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/output_0.pb new file mode 100644 index 00000000000..c77d2103a13 Binary files /dev/null and b/onnx/backend/test/data/node/test_pow_types_int64_int64/test_data_set_0/output_0.pb differ diff --git a/onnx/defs/math/defs.cc b/onnx/defs/math/defs.cc index a66eac72fab..efed3077f2d 100644 --- a/onnx/defs/math/defs.cc +++ b/onnx/defs/math/defs.cc @@ -505,7 +505,7 @@ ONNX_OPERATOR_SET_SCHEMA( "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); -static const char* Pow_ver7_doc = R"DOC( +static const char* Pow_ver12_doc = R"DOC( Pow takes input data (Tensor) and exponent Tensor, and produces one output data (Tensor) where the function `f(x) = x^exponent`, is applied to the data tensor elementwise. @@ -513,16 +513,34 @@ is applied to the data tensor elementwise. ONNX_OPERATOR_SET_SCHEMA( Pow, - 7, + 12, OpSchema() - .SetDoc(std::string(Pow_ver7_doc) + GenerateBroadcastingDocMul()) + .SetDoc(std::string(Pow_ver12_doc) + GenerateBroadcastingDocMul()) .Input(0, "X", "First operand, base of the exponent.", "T") - .Input(1, "Y", "Second operand, power of the exponent.", "T") + .Input(1, "Y", "Second operand, power of the exponent.", "T1") .Output(0, "Z", "Output tensor (same size as X)", "T") .TypeConstraint( "T", - {"tensor(float16)", "tensor(float)", "tensor(double)"}, - "Constrain input and output types to float tensors.") + {"tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)"}, + "Constrain input X and output types to float/int tensors.") + .TypeConstraint( + "T1", + {"tensor(uint8)", + "tensor(uint16)", + "tensor(uint32)", + "tensor(uint64)", + "tensor(int8)", + "tensor(int16)", + "tensor(int32)", + "tensor(int64)", + "tensor(float16)", + "tensor(float)", + "tensor(double)"}, + "Constrain input Y types to float/int tensors.") .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { propagateElemTypeFromInputToOutput(ctx, 0, 0); if (hasNInputShapes(ctx, 2)) diff --git a/onnx/defs/math/old.cc b/onnx/defs/math/old.cc index 7244c03af89..d7a594f9b7a 100644 --- a/onnx/defs/math/old.cc +++ b/onnx/defs/math/old.cc @@ -257,6 +257,33 @@ ONNX_OPERATOR_SET_SCHEMA( "Constrain input and output types to float tensors.") .TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)); +static const char* Pow_ver7_doc = R"DOC( +Pow takes input data (Tensor) and exponent Tensor, and +produces one output data (Tensor) where the function `f(x) = x^exponent`, +is applied to the data tensor elementwise. +)DOC"; + +ONNX_OPERATOR_SET_SCHEMA( + Pow, + 7, + OpSchema() + .SetDoc(std::string(Pow_ver7_doc) + GenerateBroadcastingDocMul()) + .Input(0, "X", "First operand, base of the exponent.", "T") + .Input(1, "Y", "Second operand, power of the exponent.", "T") + .Output(0, "Z", "Output tensor (same size as X)", "T") + .TypeConstraint( + "T", + {"tensor(float16)", "tensor(float)", "tensor(double)"}, + "Constrain input and output types to float tensors.") + .TypeAndShapeInferenceFunction([](InferenceContext& ctx) { + propagateElemTypeFromInputToOutput(ctx, 0, 0); + if (hasNInputShapes(ctx, 2)) + bidirectionalBroadcastShapeInference( + ctx.getInputType(0)->tensor_type().shape(), + ctx.getInputType(1)->tensor_type().shape(), + *ctx.getOutputType(0)->mutable_tensor_type()->mutable_shape()); + })); + static const char* Neg_ver1_doc = R"DOC( Neg takes one input data (Tensor) and produces one output data (Tensor) where each element flipped sign, y = -x, is applied to diff --git a/onnx/defs/operator_sets.h b/onnx/defs/operator_sets.h index 8895988ff59..2668a1950d9 100644 --- a/onnx/defs/operator_sets.h +++ b/onnx/defs/operator_sets.h @@ -732,6 +732,7 @@ class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 12, MeanSquaredDistance); class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 12, LessOrEqual); class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 12, GreaterOrEqual); class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 12, SoftmaxCrossEntropyLoss); +class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, 12, Pow); // Iterate over schema from ai.onnx version 12 class OpSet_Onnx_ver12 { @@ -758,6 +759,7 @@ class OpSet_Onnx_ver12 { fn(GetOpSchema()); fn(GetOpSchema()); fn(GetOpSchema()); + fn(GetOpSchema()); } };