File size: 14,794 Bytes
d047a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1056d1c
d047a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1056d1c
d047a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37cd06e
d047a99
 
 
 
 
 
 
 
 
 
 
 
 
 
1056d1c
d047a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1056d1c
d047a99
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
{
  "cases": [
    {
      "name": "float32_to_uint32_like",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [6],
          "data": { "kind": "values", "values": [0.1, 1.9, 2.2, 5.8, 7.0, 9.6] }
        },
        "target": { "dtype": "uint32", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "uint32", "shape": [6] } }
    },
    {
      "name": "uint32_to_float32_like_extremes",
      "provenance": {
        "source": "onnx/onnx/docs/Operators.md#CastLike-25",
        "notes": "Uint32 inputs include values beyond signed-int32 and exact-float32 ranges."
      },
      "inputs": {
        "x": {
          "dtype": "uint32",
          "shape": [4],
          "data": { "kind": "values", "values": [0, 16777217, 2147483648, 4294967295] }
        },
        "target": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0 } }
    },
    {
      "name": "bool_to_int32_like",
      "provenance": {
        "source": "onnx/onnx/docs/Operators.md#CastLike-25",
        "notes": "Logical bool values remain distinct from their widened uint32 storage representation during conversion to int32."
      },
      "inputs": {
        "x": { "dtype": "bool", "shape": [4], "data": { "kind": "values", "values": [0, 1, 1, 0] } },
        "target": { "dtype": "int32", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "int32", "shape": [4], "tolerance": 0 } }
    },
    {
      "name": "int32_to_float32_like_scalar_target",
      "inputs": {
        "x": { "dtype": "int32", "shape": [2, 3], "data": { "kind": "values", "values": [-3, -1, 0, 1, 7, 12] } },
        "target": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [0.0] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [2, 3] } }
    },
    {
      "name": "uint8_to_float16_like",
      "inputs": {
        "x": { "dtype": "uint8", "shape": [4], "data": { "kind": "values", "values": [0, 1, 127, 255] } },
        "target": { "dtype": "float16", "shape": [2, 2], "data": { "kind": "values", "values": [0.0, 0.0, 0.0, 0.0] } }
      },
      "outputs": { "y": { "dtype": "float16", "shape": [4] } },
      "tolerance": 0.001
    },
    {
      "name": "float16_to_int32_like",
      "inputs": {
        "x": { "dtype": "float16", "shape": [5], "data": { "kind": "values", "values": [-2.75, -1.1, 0.0, 1.9, 4.5] } },
        "target": { "dtype": "int32", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "int32", "shape": [5] } }
    },
    {
      "name": "ort_function_scalar_float_to_ranked_float_like",
      "provenance": {
        "source": "onnxruntime/test/framework/function_test.cc",
        "test": "FunctionTest.AttrWithDefault",
        "notes": "Covers ORT's use of CastLike inside a function body; the target tensor contributes only the output dtype, not the output shape."
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [2.0] } },
        "target": { "dtype": "float32", "shape": [3], "data": { "kind": "values", "values": [0.0, 0.0, 0.0] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [], "tolerance": 0 } }
    },
    {
      "name": "ort_scatternd_float32_to_float16_like_initializer",
      "provenance": {
        "source": "onnxruntime/test/python/onnxruntime_test_scatternd.py",
        "test": "TestScatterND.common_scatter",
        "notes": "Adapts ORT's ScatterND helper pattern where CastLike converts float input to the dtype of a float16 initializer before later graph ops."
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [2, 2], "data": { "kind": "values", "values": [-3.5, -0.25, 1.5, 8.0] } },
        "target": { "dtype": "float16", "shape": [1], "data": { "kind": "values", "values": [0.0] } }
      },
      "outputs": { "y": { "dtype": "float16", "shape": [2, 2], "tolerance": 0.001 } }
    },
    {
      "name": "onnx_backend_empty_like_float32_to_int8",
      "provenance": {
        "source": "cmake/external/onnx/onnx/backend/test/case/node/castlike.py",
        "test": "CastLike.export",
        "notes": "Uses the ONNX backend generator pattern where the like tensor is empty and only supplies the target dtype."
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [5], "data": { "kind": "values", "values": [-3.9, -1.1, 0.0, 1.9, 127.9] } },
        "target": { "dtype": "int8", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "int8", "shape": [5], "tolerance": 0 } }
    },
    {
      "name": "onnx_backend_empty_like_float32_to_uint8",
      "provenance": {
        "source": "cmake/external/onnx/onnx/backend/test/case/node/castlike.py",
        "test": "CastLike.export",
        "notes": "Uses the ONNX backend generator pattern where the like tensor is empty and only supplies the target dtype."
      },
      "inputs": {
        "x": { "dtype": "float32", "shape": [4], "data": { "kind": "values", "values": [0.9, 1.9, 127.9, 255.9] } },
        "target": { "dtype": "uint8", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "uint8", "shape": [4], "tolerance": 0 } }
    },
    {
      "name": "onnx_backend_empty_like_int8_to_float32",
      "provenance": {
        "source": "cmake/external/onnx/onnx/backend/test/case/node/castlike.py",
        "test": "CastLike.export",
        "notes": "Uses the ONNX backend generator pattern where the like tensor is empty and only supplies the target dtype."
      },
      "inputs": {
        "x": { "dtype": "int8", "shape": [4], "data": { "kind": "values", "values": [-128, -1, 0, 127] } },
        "target": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [4], "tolerance": 0 } }
    },
    {
      "name": "onnx_backend_empty_like_uint8_to_int32",
      "provenance": {
        "source": "cmake/external/onnx/onnx/backend/test/case/node/castlike.py",
        "test": "CastLike.export",
        "notes": "Uses the ONNX backend generator pattern where the like tensor is empty and only supplies the target dtype."
      },
      "inputs": {
        "x": { "dtype": "uint8", "shape": [4], "data": { "kind": "values", "values": [0, 1, 127, 255] } },
        "target": { "dtype": "int32", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "int32", "shape": [4], "tolerance": 0 } }
    },
    {
      "name": "onnx_backend_castlike_float_to_float16",
      "provenance": {
        "source": "cmake/external/onnx/onnx/backend/test/data/node/test_castlike_FLOAT_to_FLOAT16",
        "test": "test_castlike_FLOAT_to_FLOAT16"
      },
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [3, 4],
          "data": {
            "kind": "values",
            "values": [0.4789254665374756, 0.48033666610717773, 0.4996848702430725, 0.8191054463386536, 0.4703124761581421, 0.8164680004119873, 0.21087194979190826, 0.7229037880897522, "NaN", "Infinity", "Infinity", "-Infinity"]
          }
        },
        "target": { "dtype": "float16", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "float16", "shape": [3, 4], "tolerance": 0.001, "allowNaN": true } }
    },
    {
      "name": "onnx_backend_castlike_float16_to_float",
      "provenance": {
        "source": "cmake/external/onnx/onnx/backend/test/data/node/test_castlike_FLOAT16_to_FLOAT",
        "test": "test_castlike_FLOAT16_to_FLOAT"
      },
      "inputs": {
        "x": {
          "dtype": "float16",
          "shape": [3, 4],
          "data": {
            "kind": "values",
            "values": [0.47900390625, 0.480224609375, 0.499755859375, 0.8193359375, 0.47021484375, 0.81640625, 0.2108154296875, 0.72314453125, "NaN", "Infinity", "Infinity", "-Infinity"]
          }
        },
        "target": { "dtype": "float32", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [3, 4], "tolerance": 0, "allowNaN": true } }
    },
    {
      "name": "vec4_i32_to_f32_lanes",
      "inputs": {
        "x": {
          "dtype": "int32",
          "shape": [8],
          "data": { "kind": "values", "values": [-100, -3, -1, 0, 1, 7, 12, 100] }
        },
        "target": { "dtype": "float32", "shape": [], "data": { "kind": "values", "values": [0.0] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [8], "tolerance": 0 } }
    },
    {
      "name": "vec4_f32_to_i32_like_truncates_toward_zero",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [8],
          "data": { "kind": "values", "values": [1.0, 2.9, -3.0, 0.0, 100.0, -0.5, -2.9, 127.75] }
        },
        "target": { "dtype": "int32", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "int32", "shape": [8], "tolerance": 0 } }
    },
    {
      "name": "vec4_f16_to_i32_like_truncates_toward_zero",
      "inputs": {
        "x": {
          "dtype": "float16",
          "shape": [8],
          "data": { "kind": "values", "values": [1.0, 2.5, -3.0, 0.0, 100.0, -0.5, -2.5, 7.5] }
        },
        "target": { "dtype": "int32", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "int32", "shape": [8], "tolerance": 0 } }
    },
    {
      "name": "vec4_f32_to_i8_like_in_range_truncates",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [8],
          "data": { "kind": "values", "values": [-128.0, -1.9, -0.5, 0.0, 1.9, 127.0, -127.75, 126.5] }
        },
        "target": { "dtype": "int8", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "int8", "shape": [8], "tolerance": 0 } }
    },
    {
      "name": "scalar_x4_f32_to_u32_like_tail",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [17],
          "data": {
            "kind": "values",
            "values": [0.0, 1.9, 2.2, 3.8, 4.0, 5.6, 6.1, 7.9, 8.0, 9.2, 10.7, 11.0, 12.4, 13.8, 14.0, 15.9, 16.2]
          }
        },
        "target": { "dtype": "uint32", "shape": [0], "data": { "kind": "values", "values": [] } }
      },
      "outputs": { "y": { "dtype": "uint32", "shape": [17], "tolerance": 0 } }
    },
    {
      "name": "vec4_tail_i8_to_f32_like_4097",
      "inputs": {
        "x": { "dtype": "int8", "shape": [4097], "data": { "kind": "constant", "value": -3 } },
        "target": { "dtype": "float32", "shape": [1], "data": { "kind": "values", "values": [0.0] } }
      },
      "outputs": { "y": { "dtype": "float32", "shape": [4097], "tolerance": 0 } },
      "provenance": { "notes": "Exercises a packed vec4 bulk followed by a scalar tail in the same dispatch." }
    },
    {
      "name": "vec4_tail_f32_to_i8_like_4099",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [4099],
          "data": { "kind": "cycle", "values": [1.5, -2.5, 126.25, -127.75, 63.5] }
        },
        "target": { "dtype": "int8", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "int8", "shape": [4099], "tolerance": 0 } },
      "provenance": {
        "notes": "A 4099-element float32-to-int8 CastLike (target dtype int8) is not four-aligned, leaving a 3-element tail. All values are within int8 range, verifying truncation toward zero rather than undefined out-of-range behavior."
      }
    },
    {
      "name": "vec4_tail_f16_to_u8_like_4099",
      "inputs": {
        "x": {
          "dtype": "float16",
          "shape": [4099],
          "data": { "kind": "cycle", "values": [0.5, 200.75, 255.0, 254.25, 1.5, 44.5, 127.5] }
        },
        "target": { "dtype": "uint8", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "uint8", "shape": [4099], "tolerance": 0 } },
      "provenance": {
        "notes": "Casting 4,099 float16 values to uint8 combines vectorized conversion with a three-element scalar tail. Every source value is exactly representable in float16 and lies within the uint8 range."
      }
    },
    {
      "name": "int32_to_bool_like",
      "inputs": {
        "x": { "dtype": "int32", "shape": [2, 3], "data": { "kind": "values", "values": [-3, 1, 0, 42, -1, 0] } },
        "target": { "dtype": "bool", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": {
        "y": {
          "dtype": "bool",
          "shape": [2, 3],
          "tolerance": 0,
          "data": { "kind": "values", "values": [1, 1, 0, 1, 1, 0] }
        }
      }
    },
    {
      "name": "vec4_f32_finite_overflow_to_float16_like_saturate_vs_inf",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [8],
          "data": { "kind": "values", "values": [70000.0, -1e+30, 65504.0, 65600.0, 1.0, -2.5, 0.0, -70000.0] }
        },
        "target": { "dtype": "float16", "shape": [1], "data": { "kind": "values", "values": [0.0] } }
      },
      "outputs": { "y": { "dtype": "float16", "shape": [8], "tolerance": 0.001 } }
    },
    {
      "name": "vec4_f32_nonzero_special_to_bool_like",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [8],
          "data": { "kind": "values", "values": ["NaN", "Infinity", "-Infinity", 0.0, 0.0, 1.0, -2.5, 1e-30] }
        },
        "target": { "dtype": "bool", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": {
        "y": {
          "dtype": "bool",
          "shape": [8],
          "tolerance": 0,
          "data": { "kind": "values", "values": [1, 1, 1, 0, 0, 1, 1, 1] }
        }
      }
    },
    {
      "name": "rank7_vec4_f32_to_i32",
      "inputs": {
        "x": {
          "dtype": "float32",
          "shape": [1, 1, 1, 1, 1, 1, 8],
          "data": { "kind": "values", "values": [0.1, 1.9, 2.2, 5.8, 7.0, 9.6, -3.7, -1.2] }
        },
        "target": { "dtype": "int32", "shape": [1], "data": { "kind": "values", "values": [0] } }
      },
      "outputs": { "y": { "dtype": "int32", "shape": [1, 1, 1, 1, 1, 1, 8], "tolerance": 0 } },
      "provenance": {
        "notes": "A rank-7 flat input exercises float32-to-int32 conversion by flat element count on the shared vec4 path."
      }
    }
  ]
}