Hardmax#

  • Domain: ai.onnx

  • Since version: 13

The operator computes the hardmax values for the given input. The “axis” attribute indicates the dimension along which Hardmax is performed. The output tensor has the same shape as the input tensor.

Inputs

  • input (T): The input tensor of rank >= axis.

Outputs

  • output (T): The output values with the same shape as the input tensor.

Attributes

  • axis (int): Describes the dimension Softmax will be performed on. Negative value means counting dimensions from the back.

Type Constraints

  • T: Constrain input and output types to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).

Examples#

test_cc_hardmax_axis_0

Node:
  Hardmax(input) -> (output)
  Attributes:
    axis = 0
Inputs:
  input: shape=(3, 4, 5), dtype=float32
    [[[ 0.,  1.,  2.,  3.,  4.],
      [ 5.,  6.,  7.,  8.,  9.],
      [10., 11., 12., 13., 14.],
      [15., 16., 17., 18., 19.]],

     [[20., 21., 22., 23., 24.],
      [25., 26., 27., 28., 29.],
      [30., 31., 32., 33., 34.],
      [35., 36., 37., 38., 39.]],

     [[40., 41., 42., 43., 44.],
      [45., 46., 47., 48., 49.],
      [50., 51., 52., 53., 54.],
      [55., 56., 57., 58., 59.]]]

Outputs:
  output: shape=(3, 4, 5), dtype=float32
    [[[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.]],

     [[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.]],

     [[1., 1., 1., 1., 1.],
      [1., 1., 1., 1., 1.],
      [1., 1., 1., 1., 1.],
      [1., 1., 1., 1., 1.]]]

test_cc_hardmax_axis_1

Node:
  Hardmax(input) -> (output)
  Attributes:
    axis = 1
Inputs:
  input: shape=(3, 4, 5), dtype=float32
    [[[ 0.,  1.,  2.,  3.,  4.],
      [ 5.,  6.,  7.,  8.,  9.],
      [10., 11., 12., 13., 14.],
      [15., 16., 17., 18., 19.]],

     [[20., 21., 22., 23., 24.],
      [25., 26., 27., 28., 29.],
      [30., 31., 32., 33., 34.],
      [35., 36., 37., 38., 39.]],

     [[40., 41., 42., 43., 44.],
      [45., 46., 47., 48., 49.],
      [50., 51., 52., 53., 54.],
      [55., 56., 57., 58., 59.]]]

Outputs:
  output: shape=(3, 4, 5), dtype=float32
    [[[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [1., 1., 1., 1., 1.]],

     [[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [1., 1., 1., 1., 1.]],

     [[0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [0., 0., 0., 0., 0.],
      [1., 1., 1., 1., 1.]]]

test_cc_hardmax_axis_2

Node:
  Hardmax(input) -> (output)
  Attributes:
    axis = 2
Inputs:
  input: shape=(3, 4, 5), dtype=float32
    [[[ 0.,  1.,  2.,  3.,  4.],
      [ 5.,  6.,  7.,  8.,  9.],
      [10., 11., 12., 13., 14.],
      [15., 16., 17., 18., 19.]],

     [[20., 21., 22., 23., 24.],
      [25., 26., 27., 28., 29.],
      [30., 31., 32., 33., 34.],
      [35., 36., 37., 38., 39.]],

     [[40., 41., 42., 43., 44.],
      [45., 46., 47., 48., 49.],
      [50., 51., 52., 53., 54.],
      [55., 56., 57., 58., 59.]]]

Outputs:
  output: shape=(3, 4, 5), dtype=float32
    [[[0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.]],

     [[0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.]],

     [[0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.],
      [0., 0., 0., 0., 1.]]]

test_cc_hardmax_default_axis

Node:
  Hardmax(input) -> (output)
Inputs:
  input: shape=(2, 3), dtype=float32
    [[ 1.,  2.,  3.],
     [ 4.,  1., -1.]]

Outputs:
  output: shape=(2, 3), dtype=float32
    [[0., 0., 1.],
     [1., 0., 0.]]

test_cc_hardmax_example

Node:
  Hardmax(input) -> (output)
  Attributes:
    axis = 1
Inputs:
  input: shape=(2, 3), dtype=float32
    [[ 1.,  2.,  3.],
     [ 4.,  1., -1.]]

Outputs:
  output: shape=(2, 3), dtype=float32
    [[0., 0., 1.],
     [1., 0., 0.]]

test_cc_hardmax_negative_axis

Node:
  Hardmax(input) -> (output)
  Attributes:
    axis = -2
Inputs:
  input: shape=(2, 2, 2), dtype=float32
    [[[0., 1.],
      [2., 3.]],

     [[4., 5.],
      [6., 7.]]]

Outputs:
  output: shape=(2, 2, 2), dtype=float32
    [[[0., 0.],
      [1., 1.]],

     [[0., 0.],
      [1., 1.]]]

test_cc_hardmax_one_hot

Node:
  Hardmax(input) -> (output)
Inputs:
  input: shape=(1, 4), dtype=float32
    [[3., 3., 3., 1.]]

Outputs:
  output: shape=(1, 4), dtype=float32
    [[1., 0., 0., 0.]]

Differences with previous version (11)#

SchemaDiff: Hardmax (domain 'ai.onnx')

  • old version: 11

  • new version: 13

  • breaking: yes

Breaking reasons:

  • attribute ‘axis’ (changed): default value changed 1 -> -1

Attributes:

  • [BREAKING] changed ‘axis’: default value changed 1 -> -1

Type constraints:

  • changed ‘T’: added types: [‘tensor(bfloat16)’]

Documentation:

  • line similarity: 0.22 (+3/-4 lines)

--- Hardmax v11
+++ Hardmax v13
@@ -1,5 +1,4 @@

-The operator computes the hardmax (1 for the first maximum value, and 0 for all others)
-values for the given input.
-Inputs are conceptually coerced to a 2D matrix and Hardmax is applied on the
-second dimension. The output tensor has the same shape as the input tensor.
+The operator computes the hardmax values for the given input.
+The "axis" attribute indicates the dimension along which Hardmax is
+performed. The output tensor has the same shape as the input tensor.

Version History#