def test_cast_to_bool(val_type, input_data): expected = np.array(input_data, dtype=val_type) model = get_node_model('Cast', input_data, opset=6, to=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[val_type]) result = run_model(model, [input_data]) assert np.allclose(result, expected) model = get_node_model('Cast', input_data, opset=5, to=np_dtype_to_tensor_type_name(val_type)) result = run_model(model, [input_data]) assert np.allclose(result, expected)
def test_cast_to_uint(val_type): np.random.seed(133391) input_data = np.ceil(np.random.rand(2, 3, 4) * 16) expected = np.array(input_data, dtype=val_type) model = get_node_model('Cast', input_data, opset=6, to=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[val_type]) result = run_model(model, [input_data]) assert np.allclose(result, expected) model = get_node_model('Cast', input_data, opset=5, to=np_dtype_to_tensor_type_name(val_type)) result = run_model(model, [input_data]) assert np.allclose(result, expected)
def test_cast_to_float(val_type, range_start, range_end, in_dtype): np.random.seed(133391) input_data = np.random.randint(range_start, range_end, size=(2, 2), dtype=in_dtype) expected = np.array(input_data, dtype=val_type) model = get_node_model('Cast', input_data, opset=6, to=onnx.mapping.NP_TYPE_TO_TENSOR_TYPE[val_type]) result = run_model(model, [input_data]) assert np.allclose(result, expected) model = get_node_model('Cast', input_data, opset=5, to=np_dtype_to_tensor_type_name(in_dtype)) result = run_model(model, [input_data]) assert np.allclose(result, expected)