Skip to content

Conversation

@AlexRTer
Copy link
Collaborator

This PR adds some test cases for #920.
The existing tests have been renamed and a new test for row and column broadcasting has been added.

EwBinary codegen supports broadcasting for all functions that use the BinaryOpLowering template (at the point of writing this includes EwAdd, EwSub, EwMul, EwDiv, EwMin, EwMax). The operand that is broadcast is assumed to be rhs.

Singletons (1x1 dense matrices) are broadcast to the entire rhs matrix, whereas row/column vectors must have size 1 in the dimension that is broadcast and match lhs in the other dimension. Thus, 2x3 + 2x1 would be valid dimensions where the rows of rhs are broadcast along the columns of lhs, i.e. all values in the first row of lhs are respectively combined with the value in the first row of rhs.

lhsMat = [1, 2, 3, 4, 5, 6](2,);
rhsRowMat = [10, 20, 30](1,);
rhsColMat = [10, 20](,1);

print(lhsMat + rhsRowMat);    // -> [11, 22, 33, 14, 25, 36](2,3)
print(lhsMat + rhsColMat);    // -> [11, 12, 13, 24, 25, 26](2,3)

If dimensions do not match, a compiler error is thrown:

lhsMat = [1, 2, 3, 4, 5, 6](2,);
rhsRowMat = [10, 20, 30](1,);
rhsColMat = [10, 20, 30](,1);

print(rhsRowMat + lhsMat);    // -> ... lhs and rhs must have equal dimensions or allow for broadcasting but operands have dimensions (1,3) and (2,3)
print(lhsMat + rhsColMat);    // -> ... could not broadcast rhs along rows. Rhs must be a scalar value, singleton matrix or have an equal amount of rows to be broadcast but operands have dimensions (2,3) and (3,1)

Currently, the changes trigger some issue with runDaphne within EwBinaryTest. The issue seems to be unrelated to the new tests and causes the tests to run indefinitely (running ./test.sh [codegen]). From what I can tell, execution within test/api/cli/Utils.h in runProgram gets blocked at the first dup2 call at l.117. This might be similar to the issue described in #675 which were first fixed with c2900a3 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant