CastMap#

  • Domain: ai.onnx.ml

  • Since version: 1

Converts a map to a tensor. The map key must be an int64 and the values will be ordered in ascending order based on this key. The operator supports dense packing or sparse packing. If using sparse packing, the key cannot exceed the max_map-1 value.

Inputs

  • X (T1): The input map that is to be cast to a tensor

Outputs

  • Y (T2): A tensor representing the same data as the input map, ordered by their keys

Attributes

  • cast_to (string): A string indicating the desired element type of the output tensor, one of ‘TO_FLOAT’, ‘TO_STRING’, ‘TO_INT64’.

  • map_form (string): Indicates whether to only output as many values as are in the input (dense), or position the input based on using the key of the map as the index of the output (sparse).

  • max_map (int): If the value of map_form is ‘SPARSE,’ this attribute indicates the total length of the output tensor.

Type Constraints

  • T1: The input must be an integer map to either string or float. Allowed types: map(int64, float), map(int64, string).

  • T2: The output is a 1-D tensor of string, float, or integer. Allowed types: tensor(float), tensor(int64), tensor(string).

Examples#

test_cc_cast_map_int64_float_dense

Node:
  ai.onnx.ml.CastMap(x) -> (y)
  Attributes:
    cast_to = "TO_FLOAT"
    map_form = "DENSE"
Inputs:
  x: shape=(), dtype=object
    {2: 2.5, 0: 0.5, 1: 1.5}

Outputs:
  y: shape=(3,), dtype=float32
    [0.5, 1.5, 2.5]

test_cc_cast_map_int64_float_sparse

Node:
  ai.onnx.ml.CastMap(x) -> (y)
  Attributes:
    cast_to = "TO_FLOAT"
    map_form = "SPARSE"
    max_map = 5
Inputs:
  x: shape=(), dtype=object
    {1: 10.0, 3: 30.0}

Outputs:
  y: shape=(5,), dtype=float32
    [ 0., 10.,  0., 30.,  0.]

test_cc_cast_map_int64_string_dense

Node:
  ai.onnx.ml.CastMap(x) -> (y)
  Attributes:
    cast_to = "TO_STRING"
    map_form = "DENSE"
Inputs:
  x: shape=(), dtype=object
    {1: 'b', 0: 'a'}

Outputs:
  y: shape=(2,), dtype=object
    ['a', 'b']