Skip to content

Commit

Permalink
[HOTFIX] Fix validation of scalar-scalar binary min/max operations
Browse files Browse the repository at this point in the history
This recent introduction of nary min/max operations corrupted the
language validation path for scalar-scalar operations. This patch fixes
various issues related to (1) value type inference, (2) output
dimension/blocksize propagation, and (3) the handling of all scalar nary
min/max operations.
  • Loading branch information
mboehm7 committed Jun 8, 2018
1 parent 4d370a8 commit 87bc358
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,18 +574,19 @@ public void validateExpression(HashMap<String, DataIdentifier> ids, HashMap<Stri
case MIN:
case MAX:
//min(X), min(X,s), min(s,X), min(s,r), min(X,Y)
//unary
if (getSecondExpr() == null) {
if (getSecondExpr() == null) { //unary
checkNumParameters(1);
checkMatrixParam(getFirstExpr());
output.setDataType(DataType.SCALAR);
output.setValueType(id.getValueType());
output.setDimensions(0, 0);
output.setBlockDimensions (0, 0);
}

//nary operation
else {
else if( getAllExpr().length == 2 ) { //binary
checkNumParameters(2);
setBinaryOutputProperties(output);
}
else { //nary
for( Expression e : getAllExpr() )
checkMatrixScalarParam(e);
setNaryOutputProperties(output);
Expand Down Expand Up @@ -1463,17 +1464,18 @@ private void setNaryOutputProperties(DataIdentifier output) {
e -> e.getOutput().getDataType().isScalar()) ? DataType.SCALAR : DataType.MATRIX;
Expression firstM = dt.isMatrix() ? Arrays.stream(getAllExpr()).filter(
e -> e.getOutput().getDataType().isMatrix()).findFirst().get() : null;
ValueType vt = dt.isMatrix() ? ValueType.DOUBLE : ValueType.BOOLEAN;
ValueType vt = dt.isMatrix() ? ValueType.DOUBLE : ValueType.INT;
for( Expression e : getAllExpr() ) {
vt = computeValueType(e, e.getOutput().getValueType(), vt, true);
if( e.getOutput().getDataType().isMatrix() )
checkMatchingDimensions(firstM, e, true);
}
output.setDataType(dt);
output.setValueType(vt);
output.setDimensions(firstM.getOutput().getDim1(), firstM.getOutput().getDim2());
output.setBlockDimensions (
firstM.getOutput().getRowsInBlock(), firstM.getOutput().getColumnsInBlock());
output.setDimensions(dt.isMatrix() ? firstM.getOutput().getDim1() : 0,
dt.isMatrix() ? firstM.getOutput().getDim2() : 0);
output.setBlockDimensions (dt.isMatrix() ? firstM.getOutput().getRowsInBlock() : 0,
dt.isMatrix() ? firstM.getOutput().getColumnsInBlock() : 0);
}

private void expandArguments() {
Expand Down

0 comments on commit 87bc358

Please sign in to comment.