Skip to content

Commit 4fc2c29

Browse files
committed
[mlir][tensor] Add tests to invalid.mlir
Adds two test with invalid usage of `tensor.extract_slice` that were missing. Also moves one other test for `tensor.extract_slice`, so that all tests for this Op are clustered together.
1 parent 37ad65f commit 4fc2c29

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

mlir/test/Dialect/Tensor/invalid.mlir

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,27 @@ func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {
213213
return
214214
}
215215

216+
217+
// -----
218+
219+
func.func @extract_slice_size_and_output_dim_mismatch_static_size(%t: tensor<16xf32>) {
220+
// expected-error @+1 {{expected type to be 'tensor<4xf32>' or a rank-reduced version. (size mismatch)}}
221+
%0 = tensor.extract_slice %t[0][4][1]
222+
: tensor<16xf32> to tensor<6xf32>
223+
224+
return
225+
}
226+
227+
// -----
228+
229+
func.func @extract_slice_size_and_output_dim_mismatch_dynamic_size(%t: tensor<?xf32>, %idx : index) {
230+
// expected-error @+2 {{expected type to be 'tensor<?xf32>' or a rank-reduced version. (size mismatch)}}
231+
%c4 = arith.constant 4 : index
232+
%0 = tensor.extract_slice %t[0][%c4][1] : tensor<?xf32> to tensor<4xi8>
233+
234+
return
235+
}
236+
216237
// -----
217238

218239
func.func @extract_slice_wrong_static_type(%t: tensor<8x16x4xf32>, %idx : index) {
@@ -235,6 +256,14 @@ func.func @extract_slice_wrong_dynamic_type(%t: tensor<8x16x4xf32>, %idx : index
235256

236257
// -----
237258

259+
func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
260+
// expected-error@+1 {{expected 3 offset values}}
261+
%0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
262+
return
263+
}
264+
265+
// -----
266+
238267
func.func @insert_slice_wrong_result_rank(%t1: tensor<?xf32>, %t2: tensor<?x?xf32>, %idx : index) {
239268
// expected-error @+1 {{expected rank to be smaller or equal to the other rank.}}
240269
%0 = tensor.insert_slice %t2 into %t1[0][4][1] : tensor<?x?xf32> into tensor<?xf32>
@@ -349,14 +378,6 @@ func.func @rank(%0: f32) {
349378

350379
// -----
351380

352-
func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
353-
// expected-error@+1 {{expected 3 offset values}}
354-
%0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
355-
return
356-
}
357-
358-
// -----
359-
360381
func.func @illegal_num_offsets(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?x?xf32>,
361382
%arg2 : index, %arg3 : index) {
362383
// expected-error@+1 {{expected 3 offset values}}

0 commit comments

Comments
 (0)