1// RUN: mlir-opt %s -split-input-file -verify-diagnostics 2 3func @invalid_new_dense(%arg0: !llvm.ptr<i8>) -> tensor<32xf32> { 4 // expected-error@+1 {{expected a sparse tensor result}} 5 %0 = sparse_tensor.new %arg0 : !llvm.ptr<i8> to tensor<32xf32> 6 return %0 : tensor<32xf32> 7} 8 9// ----- 10 11func @invalid_pointers_dense(%arg0: tensor<128xf64>) -> memref<?xindex> { 12 %c = constant 0 : index 13 // expected-error@+1 {{expected a sparse tensor to get pointers}} 14 %0 = sparse_tensor.pointers %arg0, %c : tensor<128xf64> to memref<?xindex> 15 return %0 : memref<?xindex> 16} 17 18// ----- 19 20#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"], pointerBitWidth=32}> 21 22func @mismatch_pointers_types(%arg0: tensor<128xf64, #SparseVector>) -> memref<?xindex> { 23 %c = constant 0 : index 24 // expected-error@+1 {{unexpected type for pointers}} 25 %0 = sparse_tensor.pointers %arg0, %c : tensor<128xf64, #SparseVector> to memref<?xindex> 26 return %0 : memref<?xindex> 27} 28 29// ----- 30 31#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> 32 33func @pointers_oob(%arg0: tensor<128xf64, #SparseVector>) -> memref<?xindex> { 34 %c = constant 1 : index 35 // expected-error@+1 {{requested pointers dimension out of bounds}} 36 %0 = sparse_tensor.pointers %arg0, %c : tensor<128xf64, #SparseVector> to memref<?xindex> 37 return %0 : memref<?xindex> 38} 39 40// ----- 41 42func @invalid_indices_dense(%arg0: tensor<10x10xi32>) -> memref<?xindex> { 43 %c = constant 1 : index 44 // expected-error@+1 {{expected a sparse tensor to get indices}} 45 %0 = sparse_tensor.indices %arg0, %c : tensor<10x10xi32> to memref<?xindex> 46 return %0 : memref<?xindex> 47} 48 49// ----- 50 51#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> 52 53func @mismatch_indices_types(%arg0: tensor<?xf64, #SparseVector>) -> memref<?xi32> { 54 %c = constant 0 : index 55 // expected-error@+1 {{unexpected type for indices}} 56 %0 = sparse_tensor.indices %arg0, %c : tensor<?xf64, #SparseVector> to memref<?xi32> 57 return %0 : memref<?xi32> 58} 59 60// ----- 61 62#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> 63 64func @indices_oob(%arg0: tensor<128xf64, #SparseVector>) -> memref<?xindex> { 65 %c = constant 1 : index 66 // expected-error@+1 {{requested indices dimension out of bounds}} 67 %0 = sparse_tensor.indices %arg0, %c : tensor<128xf64, #SparseVector> to memref<?xindex> 68 return %0 : memref<?xindex> 69} 70 71// ----- 72 73func @invalid_values_dense(%arg0: tensor<1024xf32>) -> memref<?xf32> { 74 // expected-error@+1 {{expected a sparse tensor to get values}} 75 %0 = sparse_tensor.values %arg0 : tensor<1024xf32> to memref<?xf32> 76 return %0 : memref<?xf32> 77} 78 79// ----- 80 81#SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> 82 83func @mismatch_values_types(%arg0: tensor<?xf64, #SparseVector>) -> memref<?xf32> { 84 // expected-error@+1 {{unexpected mismatch in element types}} 85 %0 = sparse_tensor.values %arg0 : tensor<?xf64, #SparseVector> to memref<?xf32> 86 return %0 : memref<?xf32> 87} 88