forked from daphne-eu/daphne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…s operator (daphne-eu#607) [DAPHNE-daphne-eu#560] Parsing unary minus operator - This change decouples the '-' from INT_LITERAL and FLOAT_LITERAL and handles a unary minus separately. - The additive inverse is internally achieved by EwMinusOp, a concrete elementwise unary operation. - Accordingly, a new unary op code for the ewUnarySca/ewUnaryMat kernels was added. - As a leading minus is technically not part of the literal anymore, the parsing of integer literals needs a special case for (-)2^63. - Added script-level test cases for unary minus, its interplay with other operators, and its use in matrix literals. - Updated the DaphneDSL language reference. - No changes to the description of literals: leading minus is still presented as a part of the literal here, since this is more intuitive from a user's point of view. - Mentioning unary -/+ in the operators table. - And some more minor things. - Closes daphne-eu#186, closes daphne-eu#560, closes daphne-eu#667. --------- Co-authored-by: Patrick Damme <patrick.damme@tu-berlin.de>
- Loading branch information
1 parent
81667eb
commit 5a47688
Showing
19 changed files
with
244 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
enum class UnaryOpCode { | ||
// Arithmetic/general math. | ||
MINUS, | ||
ABS, | ||
SIGN, // signum (-1, 0, +1) | ||
SQRT, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
DenseMatrix(4x1, double) | ||
DenseMatrix(5x1, double) | ||
10 | ||
1.1 | ||
1.73205 | ||
4 | ||
-5.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// '-' for subtraction. | ||
// binary '-' for subtraction. | ||
|
||
print("scalar - scalar"); | ||
print(1 - 2); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// binary '-' for subtraction, no spaces around the operator (used to be a problem in the past). | ||
|
||
print("scalar - scalar"); | ||
print(1-2); | ||
print(1.1-2.2); | ||
print(1-2.3); | ||
|
||
print("matrix - matrix"); | ||
print([1, 2]-[3, 4]); | ||
print([1.1, 2.2]-[3.3, 4.4]); | ||
print([1, 2]-[3.4, 4.6]); | ||
|
||
print("matrix - scalar"); | ||
print([1, 2]-3); | ||
print([1.1, 2.2]-3.3); | ||
print([1, 2]-3.3); | ||
|
||
print("scalar - matrix"); | ||
print(3-[1, 2]); | ||
print(3.3-[1.1, 2.2]); | ||
print(3.3-[1, 2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
scalar - scalar | ||
-1 | ||
-1.1 | ||
-1.3 | ||
matrix - matrix | ||
DenseMatrix(2x1, int64_t) | ||
-2 | ||
-2 | ||
DenseMatrix(2x1, double) | ||
-2.2 | ||
-2.2 | ||
DenseMatrix(2x1, double) | ||
-2.4 | ||
-2.6 | ||
matrix - scalar | ||
DenseMatrix(2x1, int64_t) | ||
-2 | ||
-1 | ||
DenseMatrix(2x1, double) | ||
-2.2 | ||
-1.1 | ||
DenseMatrix(2x1, double) | ||
-2.3 | ||
-1.3 | ||
scalar - matrix | ||
DenseMatrix(2x1, int64_t) | ||
2 | ||
1 | ||
DenseMatrix(2x1, double) | ||
2.2 | ||
1.1 | ||
DenseMatrix(2x1, double) | ||
2.3 | ||
1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// unary '-' for additive inverse. | ||
|
||
print("scalar"); | ||
# single minus | ||
print(-2); | ||
print(-2.2); | ||
# single plus | ||
print(+2); | ||
print(+2.2); | ||
# double minus (cancels out) | ||
print(--2); | ||
print(--2.2); | ||
# double plus (cancels out) | ||
print(++2); | ||
print(++2.2); | ||
# mix of plus and minus | ||
print(+-2); | ||
print(+-2.2); | ||
print(+-+2); | ||
print(+-+2.2); | ||
|
||
print("matrix"); | ||
# single minus | ||
print(-[2]); | ||
print(-[2.2]); | ||
# single plus | ||
print(+[2]); | ||
print(+[2.2]); | ||
# double minus (cancels out) | ||
print(--[2]); | ||
print(--[2.2]); | ||
# double plus (cancels out) | ||
print(++[2]); | ||
print(++[2.2]); | ||
# mix of plus and minus | ||
print(+-[2]); | ||
print(+-[2.2]); | ||
print(+-+[2]); | ||
print(+-+[2.2]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
scalar | ||
-2 | ||
-2.2 | ||
2 | ||
2.2 | ||
2 | ||
2.2 | ||
2 | ||
2.2 | ||
-2 | ||
-2.2 | ||
-2 | ||
-2.2 | ||
matrix | ||
DenseMatrix(1x1, int64_t) | ||
-2 | ||
DenseMatrix(1x1, double) | ||
-2.2 | ||
DenseMatrix(1x1, int64_t) | ||
2 | ||
DenseMatrix(1x1, double) | ||
2.2 | ||
DenseMatrix(1x1, int64_t) | ||
2 | ||
DenseMatrix(1x1, double) | ||
2.2 | ||
DenseMatrix(1x1, int64_t) | ||
2 | ||
DenseMatrix(1x1, double) | ||
2.2 | ||
DenseMatrix(1x1, int64_t) | ||
-2 | ||
DenseMatrix(1x1, double) | ||
-2.2 | ||
DenseMatrix(1x1, int64_t) | ||
-2 | ||
DenseMatrix(1x1, double) | ||
-2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// unary '-' for additive inverse, interplay with other operators. | ||
|
||
a = 2; | ||
print("interplay with binary plus/minus"); | ||
print(1 + -a); | ||
print(1 + +a); | ||
print(1 - -a); | ||
print(1 - +a); | ||
print(-1 + -a); | ||
print(-1 + +a); | ||
print(-1 - -a); | ||
print(-1 - +a); | ||
|
||
print("interplay with other operators"); | ||
print(-log(8, 2)); | ||
print(-sum([1, 2, 3])); | ||
print(-[10, 20, 30][1, 0]); | ||
print(-(3 * 5)); | ||
print(10.0^-3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
interplay with binary plus/minus | ||
-1 | ||
3 | ||
3 | ||
-1 | ||
-3 | ||
1 | ||
1 | ||
-3 | ||
interplay with other operators | ||
-3 | ||
-6 | ||
DenseMatrix(1x1, int64_t) | ||
-20 | ||
-15 | ||
0.001 |
Oops, something went wrong.