Skip to content

Commit 81c5a51

Browse files
committed
revert the allowance of allocating empty MatrixBlockDictionaries
1 parent 45d60b9 commit 81c5a51

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/main/java/org/apache/sysds/runtime/compress/colgroup/dictionary/ADictionary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final CM_COV_Object centralMomentWithReference(ValueFunction fn, int[] co
5454

5555
@Override
5656
public final boolean equals(Object o) {
57-
if(o instanceof IDictionary)
57+
if(o != null && o instanceof IDictionary)
5858
return equals((IDictionary) o);
5959
return false;
6060
}

src/main/java/org/apache/sysds/runtime/compress/colgroup/dictionary/MatrixBlockDictionary.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public static MatrixBlockDictionary create(MatrixBlock mb, boolean check) {
8282
throw new DMLCompressionException("Invalid construction of dictionary with null array");
8383
else if(mb.getNumRows() == 0 || mb.getNumColumns() == 0)
8484
throw new DMLCompressionException("Invalid construction of dictionary with zero rows and/or cols array");
85+
else if(mb.isEmpty())
86+
return null;
8587
else if(check) {
86-
if(mb.isEmpty())
87-
return null;
8888
mb.examSparsity(true);
8989
if(mb.isInSparseFormat() && mb.getSparseBlock() instanceof SparseBlockMCSR) {
9090
// make CSR sparse block to make it smaller.
@@ -2140,7 +2140,7 @@ private IDictionary replaceWithReferenceNan(double replace, double[] reference)
21402140
int j = 0;
21412141
for(int k = apos; k < alen; k++) {
21422142
final double v = avals[k];
2143-
retV[off++] = Util.eq(Double.NaN, v) ? replace -reference[j] : v;
2143+
retV[off++] = Util.eq(Double.NaN, v) ? replace - reference[j] : v;
21442144
}
21452145
}
21462146
}
@@ -2149,7 +2149,7 @@ private IDictionary replaceWithReferenceNan(double replace, double[] reference)
21492149
for(int i = 0; i < nRow; i++) {
21502150
for(int j = 0; j < nCol; j++) {
21512151
final double v = values[off];
2152-
retV[off++] = Util.eq(Double.NaN, v) ? replace -reference[j] : v;
2152+
retV[off++] = Util.eq(Double.NaN, v) ? replace - reference[j] : v;
21532153
}
21542154
}
21552155
}
@@ -2267,10 +2267,9 @@ public void productWithReference(double[] ret, int[] counts, double[] reference,
22672267
final int nCol = _data.getNumColumns();
22682268
final int nRow = _data.getNumRows();
22692269

2270-
22712270
final double[] values;
22722271
// force dense ... if this ever is a bottleneck i will be surprised
2273-
if(_data.isInSparseFormat()){
2272+
if(_data.isInSparseFormat()) {
22742273
MatrixBlock tmp = new MatrixBlock();
22752274
tmp.copy(_data);
22762275
tmp.sparseToDense();
@@ -2511,7 +2510,9 @@ public void TSMMToUpperTriangleSparseScaling(SparseBlock left, IColIndex rowsLef
25112510

25122511
@Override
25132512
public boolean equals(IDictionary o) {
2514-
if(o instanceof MatrixBlockDictionary)
2513+
if(o == null)
2514+
return false;
2515+
else if(o instanceof MatrixBlockDictionary)
25152516
return _data.equals(((MatrixBlockDictionary) o)._data);
25162517
else if(o instanceof Dictionary) {
25172518
double[] dVals = ((Dictionary) o)._values;
@@ -2529,10 +2530,10 @@ else if(_data.isInSparseFormat())
25292530
final double[] dv = _data.getDenseBlockValues();
25302531
return Arrays.equals(dv, dVals);
25312532
}
2532-
else if (o != null)
2533-
return o.equals(this);
25342533

2535-
return false;
2534+
// fallback
2535+
return o.equals(this);
2536+
25362537
}
25372538

25382539
@Override

0 commit comments

Comments
 (0)