From 0d78367b9abbb2468c398d51e11cc8f0573112e2 Mon Sep 17 00:00:00 2001 From: dehnert Date: Tue, 28 Nov 2017 08:53:24 +0100 Subject: [PATCH] Catching empty selection in getSubmatrix pointed out by Timo Gros --- src/storm/storage/SparseMatrix.cpp | 1 + src/test/storm/storage/SparseMatrixTest.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/storm/storage/SparseMatrix.cpp b/src/storm/storage/SparseMatrix.cpp index d4c9ba5ad..9d92d5e35 100644 --- a/src/storm/storage/SparseMatrix.cpp +++ b/src/storm/storage/SparseMatrix.cpp @@ -892,6 +892,7 @@ namespace storm { template SparseMatrix SparseMatrix::getSubmatrix(storm::storage::BitVector const& rowGroupConstraint, storm::storage::BitVector const& columnConstraint, std::vector const& rowGroupIndices, bool insertDiagonalEntries) const { + STORM_LOG_THROW(!rowGroupConstraint.empty() && !columnConstraint.empty(), storm::exceptions::InvalidArgumentException, "Cannot build empty submatrix."); uint_fast64_t submatrixColumnCount = columnConstraint.getNumberOfSetBits(); // Start by creating a temporary vector that stores for each index whose bit is set to true the number of diff --git a/src/test/storm/storage/SparseMatrixTest.cpp b/src/test/storm/storage/SparseMatrixTest.cpp index 1b468c318..1cb2ae9ca 100644 --- a/src/test/storm/storage/SparseMatrixTest.cpp +++ b/src/test/storm/storage/SparseMatrixTest.cpp @@ -331,13 +331,15 @@ TEST(SparseMatrix, Submatrix) { storm::storage::SparseMatrix matrix; ASSERT_NO_THROW(matrix = matrixBuilder.build()); + storm::storage::BitVector rowGroupConstraint(4); + storm::storage::BitVector columnConstraint(4); + + ASSERT_THROW(matrix.getSubmatrix(true, rowGroupConstraint, columnConstraint), storm::exceptions::InvalidArgumentException); + std::vector rowGroupIndices = {0, 1, 2, 4, 5}; - storm::storage::BitVector rowGroupConstraint(4); rowGroupConstraint.set(2); rowGroupConstraint.set(3); - - storm::storage::BitVector columnConstraint(4); columnConstraint.set(0); columnConstraint.set(3);