From b0fc281cc616140d29c6e7406665b027dac0686e Mon Sep 17 00:00:00 2001 From: Sebastian Baunsgaard Date: Sun, 7 Jan 2024 19:59:58 +0100 Subject: [PATCH] [MINOR] Fix incorrect merge of MatrixBlock --- .../runtime/matrix/data/MatrixBlock.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/sysds/runtime/matrix/data/MatrixBlock.java b/src/main/java/org/apache/sysds/runtime/matrix/data/MatrixBlock.java index 085b6a5c52b..6e3ad9f8b93 100644 --- a/src/main/java/org/apache/sysds/runtime/matrix/data/MatrixBlock.java +++ b/src/main/java/org/apache/sysds/runtime/matrix/data/MatrixBlock.java @@ -586,16 +586,19 @@ public final boolean isEmpty() { public final boolean isEmptyBlock() { return isEmptyBlock(true); } - - public boolean isEmptyBlock(boolean safe) - { - boolean ret = ( sparse && sparseBlock==null ) || ( !sparse && denseBlock==null ); - if( nonZeros==0 ) - { - //prevent under-estimation - if(safe) + /** + * Get if this MatrixBlock is an empty block. The call can potentially tricker a recomputation of non zeros if the + * non-zero count is unknown. + * + * @param safe True if we want to ensure the count non zeros if the nnz is unknown. + * @return If the block is empty. + */ + public boolean isEmptyBlock(boolean safe) { + boolean ret = (sparse && sparseBlock == null) || (!sparse && denseBlock == null); + if(nonZeros <= 0) { // estimate non zeros if unknown or 0. + if(safe) // only allow the recompute if safe flag is false. recomputeNonZeros(); - ret = (nonZeros==0); + ret = (nonZeros == 0); } return ret; }