Skip to content

Commit

Permalink
[SYSTEMDS-3818] Fix parsing of indexing operations (scalar datatype)
Browse files Browse the repository at this point in the history
This patch fixes an edge case of print(X[1,]) where the indexing
is mistakenly created with scalar data type because the print accepts
scalar. However, later we introduce print(toString(X[1,])). We now
simply make the parsing more robust as indexing is never scalar
other than forced by internal rewrites.
  • Loading branch information
mboehm7 committed Jan 30, 2025
1 parent 615cd9a commit f7af63f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/apache/sysds/parser/DMLTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1686,11 +1686,13 @@ private Hop processIndexingExpression(IndexedIdentifier source, DataIdentifier t
if (target == null) {
target = createTarget(source);
}

//unknown nnz after range indexing (applies to indexing op but also
//data dependent operations)
target.setNnz(-1);

Hop indexOp = new IndexingOp(target.getName(), target.getDataType(), target.getValueType(),
DataType dt = target.getDataType().isScalar() ? DataType.MATRIX : target.getDataType();
Hop indexOp = new IndexingOp(target.getName(), dt, target.getValueType(),
hops.get(source.getName()), ixRange[0], ixRange[1], ixRange[2], ixRange[3],
source.getRowLowerEqualsUpper(), source.getColLowerEqualsUpper());

Expand Down
3 changes: 1 addition & 2 deletions src/test/scripts/functions/rewrite/RewriteNonScalarPrint.dml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ else if(type==3){ # standard list case
print(A_list)
}
else if(type==4){ # slice row from matrix
A_row = A[1,]
print(A_row) # print(A[1,]) produces incorrect output
print(A[1,])
}
else if(type==5){ # slice column from matrix
A_col = A[,1]
Expand Down

0 comments on commit f7af63f

Please sign in to comment.