// RUN: mlir-opt %s -split-input-file -verify-diagnostics func @invalid_new_dense(%arg0: !llvm.ptr) -> tensor<32xf32> { // expected-error@+1 {{expected a sparse tensor result}} %0 = sparse_tensor.new %arg0 : !llvm.ptr to tensor<32xf32> return %0 : tensor<32xf32> } // ----- func @invalid_pointers_dense(%arg0: tensor<128xf64>) -> memref { %c = constant 0 : index // expected-error@+1 {{expected a sparse tensor to get pointers}} %0 = sparse_tensor.pointers %arg0, %c : tensor<128xf64> to memref return %0 : memref } // ----- func @invalid_pointers_unranked(%arg0: tensor<*xf64>) -> memref { %c = constant 0 : index // expected-error@+1 {{expected a sparse tensor to get pointers}} %0 = sparse_tensor.pointers %arg0, %c : tensor<*xf64> to memref return %0 : memref } // ----- #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"], pointerBitWidth=32}> func @mismatch_pointers_types(%arg0: tensor<128xf64, #SparseVector>) -> memref { %c = constant 0 : index // expected-error@+1 {{unexpected type for pointers}} %0 = sparse_tensor.pointers %arg0, %c : tensor<128xf64, #SparseVector> to memref return %0 : memref } // ----- #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> func @pointers_oob(%arg0: tensor<128xf64, #SparseVector>) -> memref { %c = constant 1 : index // expected-error@+1 {{requested pointers dimension out of bounds}} %0 = sparse_tensor.pointers %arg0, %c : tensor<128xf64, #SparseVector> to memref return %0 : memref } // ----- func @invalid_indices_dense(%arg0: tensor<10x10xi32>) -> memref { %c = constant 1 : index // expected-error@+1 {{expected a sparse tensor to get indices}} %0 = sparse_tensor.indices %arg0, %c : tensor<10x10xi32> to memref return %0 : memref } // ----- func @invalid_indices_unranked(%arg0: tensor<*xf64>) -> memref { %c = constant 0 : index // expected-error@+1 {{expected a sparse tensor to get indices}} %0 = sparse_tensor.indices %arg0, %c : tensor<*xf64> to memref return %0 : memref } // ----- #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> func @mismatch_indices_types(%arg0: tensor) -> memref { %c = constant 0 : index // expected-error@+1 {{unexpected type for indices}} %0 = sparse_tensor.indices %arg0, %c : tensor to memref return %0 : memref } // ----- #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> func @indices_oob(%arg0: tensor<128xf64, #SparseVector>) -> memref { %c = constant 1 : index // expected-error@+1 {{requested indices dimension out of bounds}} %0 = sparse_tensor.indices %arg0, %c : tensor<128xf64, #SparseVector> to memref return %0 : memref } // ----- func @invalid_values_dense(%arg0: tensor<1024xf32>) -> memref { // expected-error@+1 {{expected a sparse tensor to get values}} %0 = sparse_tensor.values %arg0 : tensor<1024xf32> to memref return %0 : memref } // ----- #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> func @mismatch_values_types(%arg0: tensor) -> memref { // expected-error@+1 {{unexpected mismatch in element types}} %0 = sparse_tensor.values %arg0 : tensor to memref return %0 : memref } // ----- func @sparse_to_unannotated_tensor(%arg0: memref) -> tensor<16x32xf64> { // expected-error@+1 {{expected a sparse tensor as result}} %0 = sparse_tensor.tensor %arg0 : memref to tensor<16x32xf64> return %0 : tensor<16x32xf64> } // ----- func @sparse_convert_unranked(%arg0: tensor<*xf32>) -> tensor<10xf32> { // expected-error@+1 {{unexpected type in convert}} %0 = sparse_tensor.convert %arg0 : tensor<*xf32> to tensor<10xf32> return %0 : tensor<10xf32> } // ----- #CSR = #sparse_tensor.encoding<{dimLevelType = ["dense", "compressed"]}> func @sparse_convert_mismatch(%arg0: tensor<10x10xf32>) -> tensor<10x?xf32, #CSR> { // expected-error@+1 {{unexpected conversion mismatch in dimension 1}} %0 = sparse_tensor.convert %arg0 : tensor<10x10xf32> to tensor<10x?xf32, #CSR> return %0 : tensor<10x?xf32, #CSR> }