.. _op_ai_onnx_Neg: Neg === - **Domain**: ``ai.onnx`` - **Since version**: 13 Neg takes one input data (Tensor ) and produces one output data (Tensor ) where each element flipped sign, y = -x, is applied to the tensor elementwise. **Inputs** - **X** (*T*): Input tensor **Outputs** - **Y** (*T*): Output tensor **Type Constraints** - **T**: Constrain input and output types to signed numeric tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8). Examples -------- **test_cc_neg** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=float32 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] Outputs: y: shape=(2, 3), dtype=float32 [[ 1. , -0. , -1.5 ], [ 2.25, -3.5 , 4.75]] **test_cc_neg_bfloat16** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=bfloat16 [[-1, 0, 1.5], [-2.25, 3.5, -4.75]] Outputs: y: shape=(2, 3), dtype=bfloat16 [[1, -0, -1.5], [2.25, -3.5, 4.75]] **test_cc_neg_double** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=float64 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] Outputs: y: shape=(2, 3), dtype=float64 [[ 1. , -0. , -1.5 ], [ 2.25, -3.5 , 4.75]] **test_cc_neg_float16** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=float16 [[-1. , 0. , 1.5 ], [-2.25, 3.5 , -4.75]] Outputs: y: shape=(2, 3), dtype=float16 [[ 1. , -0. , -1.5 ], [ 2.25, -3.5 , 4.75]] **test_cc_neg_int16** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=int16 [[ -1, 0, 2], [-1000, 3, -5]] Outputs: y: shape=(2, 3), dtype=int16 [[ 1, 0, -2], [1000, -3, 5]] **test_cc_neg_int32** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=int32 [[ -1, 0, 2], [-100000, 3, -5]] Outputs: y: shape=(2, 3), dtype=int32 [[ 1, 0, -2], [100000, -3, 5]] **test_cc_neg_int64** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=int64 [[ -1, 0, 2], [-1000000000000, 3, -5]] Outputs: y: shape=(2, 3), dtype=int64 [[ 1, 0, -2], [1000000000000, -3, 5]] **test_cc_neg_int8** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2, 3), dtype=int8 [[ -1, 0, 2], [-127, 3, -5]] Outputs: y: shape=(2, 3), dtype=int8 [[ 1, 0, -2], [127, -3, 5]] **test_cc_shape_inference_if_symbolic_shapes** .. code-block:: text Node: Neg(I2) -> (Y2) .. code-block:: text Inputs: I2: shape=(), dtype=bool True input_1: shape=(3, 4), dtype=float32 [[1. , 1.1 , 1.2 , 1.3 ], [1.4 , 1.5 , 1.6 , 1.7 ], [1.8 , 1.9000001, 2. , 2.1 ]] input_2: shape=(5, 4), dtype=float32 [[-1. , -0.9 , -0.8 , -0.7 ], [-0.6 , -0.5 , -0.39999998, -0.3 ], [-0.19999999, -0.09999996, 0. , 0.10000002], [ 0.20000005, 0.30000007, 0.39999998, 0.5 ], [ 0.6 , 0.70000005, 0.8000001 , 0.9 ]] input_3: shape=(5,), dtype=bool [ True, False, True, False, True] input_4: shape=(3,), dtype=int64 [1, 2, 3] input_5: shape=(5,), dtype=int64 [-1, -2, -3, -4, -5] Outputs: Y2: shape=(3, 4), dtype=float32 [[1. , 1.1 , 1.2 , 1.3 ], [1.4 , 1.5 , 1.6 , 1.7 ], [1.8 , 1.9000001, 2. , 2.1 ]] output_1: shape=(3,), dtype=int64 [-1, -2, -3] **test_neg** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(3, 4, 5), dtype=float32 [[[ 1.4243481 , -0.61890423, -0.5907667 , 1.4329695 , 0.5837956 ], [-1.3854368 , 1.2791865 , 0.32735094, 0.6038593 , 0.24222691], [-0.89236253, -1.1303798 , -0.09180629, -0.12591071, -1.2615176 ], [-0.55638343, -0.747256 , -0.59118223, -0.9279915 , -0.73401135]], [[ 1.1054384 , -0.69560546, -2.1534553 , 0.11396561, -0.8268097 ], [ 1.2137318 , -0.22223468, 0.32949635, -0.21049212, 1.3518724 ], [ 0.01262847, 0.6841954 , -1.2623075 , 0.20052178, -1.1255072 ], [-0.6395738 , 1.5355366 , -1.1466801 , -0.42676184, -0.74427605]], [[-1.5989435 , 2.3646672 , -1.0641551 , 0.90345967, -0.24993172], [-1.784248 , -0.47239977, 0.09873669, -0.36464727, 0.6651279 ], [-1.01641 , -0.39525023, 0.45574856, -0.3439513 , -0.5487247 ], [ 0.06280329, -0.14411083, -1.1603392 , 0.49200374, -0.16951095]]] Outputs: y: shape=(3, 4, 5), dtype=float32 [[[-1.4243481 , 0.61890423, 0.5907667 , -1.4329695 , -0.5837956 ], [ 1.3854368 , -1.2791865 , -0.32735094, -0.6038593 , -0.24222691], [ 0.89236253, 1.1303798 , 0.09180629, 0.12591071, 1.2615176 ], [ 0.55638343, 0.747256 , 0.59118223, 0.9279915 , 0.73401135]], [[-1.1054384 , 0.69560546, 2.1534553 , -0.11396561, 0.8268097 ], [-1.2137318 , 0.22223468, -0.32949635, 0.21049212, -1.3518724 ], [-0.01262847, -0.6841954 , 1.2623075 , -0.20052178, 1.1255072 ], [ 0.6395738 , -1.5355366 , 1.1466801 , 0.42676184, 0.74427605]], [[ 1.5989435 , -2.3646672 , 1.0641551 , -0.90345967, 0.24993172], [ 1.784248 , 0.47239977, -0.09873669, 0.36464727, -0.6651279 ], [ 1.01641 , 0.39525023, -0.45574856, 0.3439513 , 0.5487247 ], [-0.06280329, 0.14411083, 1.1603392 , -0.49200374, 0.16951095]]] **test_neg_example** .. code-block:: text Node: Neg(x) -> (y) .. code-block:: text Inputs: x: shape=(2,), dtype=float32 [-4., 2.] Outputs: y: shape=(2,), dtype=float32 [ 4., -2.] Differences with previous version (6) ------------------------------------- **SchemaDiff**: ``Neg`` (domain ``'ai.onnx'``) * old version: 6 * new version: 13 * breaking: no **Type constraints:** * changed 'T': added types: ['tensor(bfloat16)'] Version History --------------- - :doc:`Version 6 ` - :doc:`Version 1 `