Unverified Commit 3396b849 authored by Thomas Michael Timmermanns's avatar Thomas Michael Timmermanns Committed by GitHub

fixed argument sequence error (#22)

parent ab58e090
......@@ -154,8 +154,8 @@ The `?` argument is a special argument which is explained in the next section.
## Special Arguments
There exists special structural arguments which can be used in each method.
These are `->`, `|` and `?`. `->` and `|` can only be positive integers and `?` can only be a boolean.
The argument `?` does not nothing if it is true and removes the layer completely if it is false.
The other two arguments create a repetition of the method.
The argument `?` does nothing if it is true and removes the layer completely if it is false.
The other two arguments create an iteration of the method.
We will show their effect with examples.
Assuming `a` is a method without required arguments,
then `a(-> = 3)->` is equal to `a()->a()->a()->`,
......@@ -163,7 +163,7 @@ then `a(-> = 3)->` is equal to `a()->a()->a()->`,
`a(-> = 3, | = 2)->` is equal to `(a()->a()->a() | a()->a()->a())->`.
## Argument Sequences
It is also possible to create a repetition of a method in another way through the use of argument sequences.
It is also possible to iterate a method through the use of argument sequences.
The following are valid sequences: `[2->5->3]`, `[true|false|false]`, `[2->1|4->4->6]`, `[ |2->3]`, `1->..->5` and `3|..|-2`.
All values in these examples could also be replaced by variable names or expressions.
The first three are standard sequences and the last two are intervals.
......@@ -187,8 +187,22 @@ Assuming the method `m(a, b, c)` exists, the line `m(a=[5->3], b=[3|4|2], c=2)->
m(a=3, b=2, c=2)
) ->
```
And `m(a=[|5|3->4], b=[1|1|2], c=2)` is equal to:
```
(
|
m(a=5, b=1, c=2) ->
m(a=5, b=1, c=2)
|
m(a=3, b=2, c=2) ->
m(a=4, b=2, c=2)
) ->
```
However, the line `m(a=[5->3], b=[2|4->6], c=2)->` would throw an error because it is not possible to expand *a* such that it is the same size as *b*.
## Expressions
This language supports the basic arithmetic operators "+", "-", "\*", "/", the logical operators "&&", "||" and the comparison operators "==", "!=", "<", ">", "<=", ">=".
At the moment, it is sometimes necessary to use parentheses around an expression to avoid a parsing error.
......
......@@ -60,9 +60,9 @@ grammar CNNArch extends de.monticore.lang.math.Math {
interface ArchValueSequence;
ArchParallelSequence implements ArchValueSequence = "[" parallelValues:(ArchSerialSequence || "|")* "]";
ArchParallelSequence implements ArchValueSequence = "[" parallelValues:(ArchSerialSequence || "|")+ "]";
ArchSerialSequence = serialValues:(ArchSimpleExpression || "->")+;
ArchSerialSequence = serialValues:(ArchSimpleExpression || "->")*;
ArchValueRange implements ArchValueSequence = start:ArchSimpleExpression
(serial:"->" | parallel:"|")
......
......@@ -420,16 +420,14 @@ public class MethodLayerSymbol extends LayerSymbol {
}
private int checkSerialLength(List<List<Integer>> allArgumentLengths, int serialIndex){
int serialLength = 0;
int serialLength = -1;
for (List<Integer> argLengths : allArgumentLengths){
int argLength = argLengths.get(serialIndex);
if (serialLength == 0){
if (serialLength == -1){
serialLength = argLength;
}
else if (serialLength == 1) {
if (argLength > 1){
serialLength = argLength;
}
serialLength = argLength;
}
else if (argLength != 1 && argLength != serialLength){
Log.error("0" + ErrorCodes.ILLEGAL_SEQUENCE_LENGTH + " Illegal sequence length. " +
......@@ -438,6 +436,9 @@ public class MethodLayerSymbol extends LayerSymbol {
, getSourcePosition());
}
}
if (serialLength == -1){
serialLength = 1;
}
return serialLength;
}
......
......@@ -44,6 +44,7 @@ public class AllCoCoTest extends AbstractCoCoTest {
checkValid("architectures", "ThreeInputCNN_M14");
checkValid("architectures", "VGG16");
checkValid("valid_tests", "ArgumentSequenceTest");
checkValid("valid_tests", "Fixed_Alexnet");
checkValid("valid_tests", "Fixed_ThreeInputCNN_M14");
checkValid("valid_tests", "ThreeInputCNN_M14_alternative");
......
architecture ArgumentSequenceTest {
def input Z(0:255)^{3, 224, 224} image
def output Q(0:1)^{10} predictions
image ->
Convolution(kernel=(5,5), channels=128, stride=(2,2)) ->
FullyConnected(units=[]) ->
Convolution(kernel=[ |(3,3)| (5,5)->(3,3) ], channels=[128|256|512]) ->
Concatenate() ->
FullyConnected(units=10) ->
Softmax() ->
predictions
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment