// 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 } // ----- #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 } // ----- #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> } // ----- #SparseMatrix = #sparse_tensor.encoding<{dimLevelType = ["dense","compressed"]}> func @sparse_to_sparse_tensor(%arg0: memref) -> tensor<16x32xf64, #SparseMatrix> { // expected-error@+1 {{unexpected non-dense dimension}} %0 = sparse_tensor.tensor %arg0 : memref to tensor<16x32xf64, #SparseMatrix> return %0 : tensor<16x32xf64, #SparseMatrix> } // ----- #DenseMatrix = #sparse_tensor.encoding<{dimLevelType = ["dense","dense"]}> func @sparse_to_tensor(%arg0: memref, %arg1: memref, %arg2: memref) -> tensor<16x32xf64, #DenseMatrix> { // expected-error@+1 {{expected single values array}} %0 = sparse_tensor.tensor %arg0, %arg1, %arg2 : memref, memref, memref to tensor<16x32xf64, #DenseMatrix> return %0 : tensor<16x32xf64, #DenseMatrix> }