(l-onnx-doc-Div)= # Div (l-onnx-op-div-14)= ## Div - 14 ### Version - **name**: [Div (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#Div) - **domain**: `main` - **since_version**: `14` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 14**. ### Summary Performs element-wise binary division (with Numpy-style broadcasting support). This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [Broadcasting in ONNX](https://github.com/onnx/onnx/blob/main/docs/Broadcasting.md). For integer inputs, the result is computed using truncating division (rounding toward zero). For example, `-11 / 3` yields `-3`. (Opset 14 change): Extend supported types to include uint8, int8, uint16, and int16. ### Inputs - **A** (heterogeneous) - **T**: First operand. - **B** (heterogeneous) - **T**: Second operand. ### Outputs - **C** (heterogeneous) - **T**: Result, has same element type as two inputs ### Type Constraints * **T** in ( `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int16)`, `tensor(int32)`, `tensor(int64)`, `tensor(int8)`, `tensor(uint16)`, `tensor(uint32)`, `tensor(uint64)`, `tensor(uint8)` ): Constrain input and output types to all numeric tensors. ### Examples #### default ```python import numpy as np import onnx node = onnx.helper.make_node( "Div", inputs=["x", "y"], outputs=["z"], ) x = np.array([3, 4]).astype(np.float32) y = np.array([1, 2]).astype(np.float32) z = x / y # expected output [3., 2.] expect(node, inputs=[x, y], outputs=[z], name="test_div_example") x = np.random.randn(3, 4, 5).astype(np.float32) y = np.random.rand(3, 4, 5).astype(np.float32) + 1.0 z = x / y expect(node, inputs=[x, y], outputs=[z], name="test_div") x = np.random.randint(24, size=(3, 4, 5), dtype=np.int8) y = np.random.randint(24, size=(3, 4, 5), dtype=np.int8) + 1 z = x // y expect(node, inputs=[x, y], outputs=[z], name="test_div_int8") x = np.random.randint(24, size=(3, 4, 5), dtype=np.int16) y = np.random.randint(24, size=(3, 4, 5), dtype=np.int16) + 1 z = x // y expect(node, inputs=[x, y], outputs=[z], name="test_div_int16") x = np.array([-3, 3, -3, 3], dtype=np.int32) y = np.array([2, 2, -2, -2], dtype=np.int32) z = np.array([-1, 1, 1, -1], dtype=np.int32) expect(node, inputs=[x, y], outputs=[z], name="test_div_int32_trunc") x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint8) + 1 z = x // y expect(node, inputs=[x, y], outputs=[z], name="test_div_uint8") x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint16) y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint16) + 1 z = x // y expect(node, inputs=[x, y], outputs=[z], name="test_div_uint16") x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint32) y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint32) + 1 z = x // y expect(node, inputs=[x, y], outputs=[z], name="test_div_uint32") x = np.random.randint(24, size=(3, 4, 5), dtype=np.uint64) y = np.random.randint(24, size=(3, 4, 5), dtype=np.uint64) + 1 z = x // y expect(node, inputs=[x, y], outputs=[z], name="test_div_uint64") ``` #### _div_broadcast ```python import numpy as np import onnx node = onnx.helper.make_node( "Div", inputs=["x", "y"], outputs=["z"], ) x = np.random.randn(3, 4, 5).astype(np.float32) y = np.random.rand(5).astype(np.float32) + 1.0 z = x / y expect(node, inputs=[x, y], outputs=[z], name="test_div_bcast") ``` ```{toctree} text_diff_Div_13_14 ``` (l-onnx-op-div-13)= ## Div - 13 ### Version - **name**: [Div (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#Div) - **domain**: `main` - **since_version**: `13` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 13**. ### Summary Performs element-wise binary division (with Numpy-style broadcasting support). This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [Broadcasting in ONNX](https://github.com/onnx/onnx/blob/main/docs/Broadcasting.md). For integer inputs, the result is computed using truncating division (rounding toward zero). For example, `-11 / 3` yields `-3`. ### Inputs - **A** (heterogeneous) - **T**: First operand. - **B** (heterogeneous) - **T**: Second operand. ### Outputs - **C** (heterogeneous) - **T**: Result, has same element type as two inputs ### Type Constraints * **T** in ( `tensor(bfloat16)`, `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` ): Constrain input and output types to high-precision numeric tensors. ```{toctree} text_diff_Div_7_14 text_diff_Div_7_13 ``` (l-onnx-op-div-7)= ## Div - 7 ### Version - **name**: [Div (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#Div) - **domain**: `main` - **since_version**: `7` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 7**. ### Summary Performs element-wise binary division (with Numpy-style broadcasting support). This operator supports **multidirectional (i.e., Numpy-style) broadcasting**; for more details please check [Broadcasting in ONNX](https://github.com/onnx/onnx/blob/main/docs/Broadcasting.md). For integer inputs, the result is computed using truncating division (rounding toward zero). For example, `-11 / 3` yields `-3`. ### Inputs - **A** (heterogeneous) - **T**: First operand. - **B** (heterogeneous) - **T**: Second operand. ### Outputs - **C** (heterogeneous) - **T**: Result, has same element type as two inputs ### Type Constraints * **T** in ( `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` ): Constrain input and output types to high-precision numeric tensors. ```{toctree} text_diff_Div_6_14 text_diff_Div_6_13 text_diff_Div_6_7 ``` (l-onnx-op-div-6)= ## Div - 6 ### Version - **name**: [Div (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#Div) - **domain**: `main` - **since_version**: `6` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `True` This version of the operator has been available **since version 6**. ### Summary Performs element-wise binary division (with limited broadcast support). If necessary the right-hand-side argument will be broadcasted to match the shape of left-hand-side argument. When broadcasting is specified, the second tensor can either be of element size 1 (including a scalar tensor and any tensor with rank equal to or smaller than the first tensor), or having its shape as a contiguous subset of the first tensor's shape. The starting of the mutually equal shape is specified by the argument "axis", and if it is not set, suffix matching is assumed. 1-dim expansion doesn't work yet. For example, the following tensor shapes are supported (with broadcast=1): shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor shape(A) = (2, 3, 4, 5), shape(B) = (5,) shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 Attribute `broadcast=1` needs to be passed to enable broadcasting. For integer inputs, the result is computed using truncating division (rounding toward zero). For example, `-11 / 3` yields `-3`. ### Attributes * **axis - INT** : If set, defines the broadcast dimensions. See doc for details. * **broadcast - INT** (default is `0`): Pass 1 to enable broadcasting ### Inputs - **A** (heterogeneous) - **T**: First operand, should share the type with the second operand. - **B** (heterogeneous) - **T**: Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size. ### Outputs - **C** (heterogeneous) - **T**: Result, has same dimensions and type as A ### Type Constraints * **T** in ( `tensor(double)`, `tensor(float)`, `tensor(float16)`, `tensor(int32)`, `tensor(int64)`, `tensor(uint32)`, `tensor(uint64)` ): Constrain input and output types to high-precision numeric tensors. ```{toctree} text_diff_Div_1_14 text_diff_Div_1_13 text_diff_Div_1_7 text_diff_Div_1_6 ``` (l-onnx-op-div-1)= ## Div - 1 ### Version - **name**: [Div (GitHub)](https://github.com/onnx/onnx/blob/main/docs/Operators.md#Div) - **domain**: `main` - **since_version**: `1` - **function**: `False` - **support_level**: `SupportType.COMMON` - **shape inference**: `False` This version of the operator has been available **since version 1**. ### Summary Performs element-wise binary division (with limited broadcast support). If necessary the right-hand-side argument will be broadcasted to match the shape of left-hand-side argument. When broadcasting is specified, the second tensor can either be of element size 1 (including a scalar tensor and any tensor with rank equal to or smaller than the first tensor), or having its shape as a contiguous subset of the first tensor's shape. The starting of the mutually equal shape is specified by the argument "axis", and if it is not set, suffix matching is assumed. 1-dim expansion doesn't work yet. For example, the following tensor shapes are supported (with broadcast=1): shape(A) = (2, 3, 4, 5), shape(B) = (,), i.e. B is a scalar tensor shape(A) = (2, 3, 4, 5), shape(B) = (1, 1), i.e. B is an 1-element tensor shape(A) = (2, 3, 4, 5), shape(B) = (5,) shape(A) = (2, 3, 4, 5), shape(B) = (4, 5) shape(A) = (2, 3, 4, 5), shape(B) = (3, 4), with axis=1 shape(A) = (2, 3, 4, 5), shape(B) = (2), with axis=0 Attribute `broadcast=1` needs to be passed to enable broadcasting. ### Attributes * **axis - INT** : If set, defines the broadcast dimensions. See doc for details. * **broadcast - INT** (default is `0`): Pass 1 to enable broadcasting * **consumed_inputs - INTS** : legacy optimization attribute. ### Inputs - **A** (heterogeneous) - **T**: First operand, should share the type with the second operand. - **B** (heterogeneous) - **T**: Second operand. With broadcasting can be of smaller size than A. If broadcasting is disabled it should be of the same size. ### Outputs - **C** (heterogeneous) - **T**: Result, has same dimensions and type as A ### Type Constraints * **T** in ( `tensor(double)`, `tensor(float)`, `tensor(float16)` ): Constrain input and output types to float tensors.