Commit 66cceaa9 authored by Ahmed's avatar Ahmed
Browse files

Merge branch 'voidFunc-branch' into adi-dev

parents ae510ae1 026a0f67
...@@ -29,6 +29,10 @@ public class BluePrint { ...@@ -29,6 +29,10 @@ public class BluePrint {
this.variables = variables; this.variables = variables;
} }
public List<Variable> getVariables() {
return variables;
}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
...@@ -45,10 +49,6 @@ public class BluePrint { ...@@ -45,10 +49,6 @@ public class BluePrint {
return packageName; return packageName;
} }
public List<Variable> getVariables() {
return variables;
}
public int howManyVariables() { public int howManyVariables() {
return variables.size(); return variables.size();
} }
...@@ -60,7 +60,6 @@ public class BluePrint { ...@@ -60,7 +60,6 @@ public class BluePrint {
return Optional.empty(); return Optional.empty();
} }
public void addVariable(Variable v) { public void addVariable(Variable v) {
variables.add(v); variables.add(v);
} }
......
...@@ -63,6 +63,7 @@ public class ErodeCommand extends MathCommand{ ...@@ -63,6 +63,7 @@ public class ErodeCommand extends MathCommand{
MathStringExpression stringExpression = new MathStringExpression("erode" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols()); MathStringExpression stringExpression = new MathStringExpression("erode" + valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression)); newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols); mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
} }
......
...@@ -31,6 +31,7 @@ public class MathAbsCommand extends MathCommand { ...@@ -31,6 +31,7 @@ public class MathAbsCommand extends MathCommand {
convertUsingOctaveBackend(mathExpressionSymbol, bluePrint); convertUsingOctaveBackend(mathExpressionSymbol, bluePrint);
} else if (backendName.equals("ArmadilloBackend")) { } else if (backendName.equals("ArmadilloBackend")) {
convertUsingArmadilloBackend(mathExpressionSymbol, bluePrint); convertUsingArmadilloBackend(mathExpressionSymbol, bluePrint);
} }
} }
...@@ -72,5 +73,7 @@ public class MathAbsCommand extends MathCommand { ...@@ -72,5 +73,7 @@ public class MathAbsCommand extends MathCommand {
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols); mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
//((BluePrintCPP) bluePrint).addAdditionalIncludeString("octave/builtin-defun-decls"); //((BluePrintCPP) bluePrint).addAdditionalIncludeString("octave/builtin-defun-decls");
//String name = bluePrint.getVariables().get(0).getNameTargetLanguageFormat();
} }
} }
...@@ -59,21 +59,34 @@ public class MathMaxCommand extends MathCommand { ...@@ -59,21 +59,34 @@ public class MathMaxCommand extends MathCommand {
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) { public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol; MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess(""); mathMatrixNameExpressionSymbol.setNameToAccess("");
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
int parametersNumber = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().size();
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols()) for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint); MathFunctionFixer.fixMathFunctions(accessSymbol,bluePrintCPP);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>()); if (parametersNumber == 1){
//OctaveHelper.getCallOctaveFunction(mathExpressionSymbol, "sum","Double", valueListString)); convertMaxAramadillo(mathMatrixNameExpressionSymbol, bluePrintCPP);
}else if (parametersNumber == 2) {
convertMaxStd(mathMatrixNameExpressionSymbol, bluePrintCPP);
} else {
Log.error(String.format("No implementation found for max operation: \"max(%s)\". Possible syntax is \"max( X )\", \"max(a,b)\"", mathExpressionSymbol.getTextualRepresentation()));
}
}
private void convertMaxAramadillo(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrint){
String valueListString = ExecuteMethodGenerator.generateExecuteCode(mathMatrixNameExpressionSymbol, new ArrayList<>());
MathStringExpression stringExpression = new MathStringExpression("max(max" + valueListString + ")", mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>(); List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("std::max"+valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression)); newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols); mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
}
private void convertMaxStd(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrint){
String valueListString = ExecuteMethodGenerator.generateExecuteCode(mathMatrixNameExpressionSymbol, new ArrayList<>());
MathStringExpression stringExpression = new MathStringExpression("std::max" + valueListString, mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
} }
} }
...@@ -57,24 +57,37 @@ public class MathMinCommand extends MathCommand { ...@@ -57,24 +57,37 @@ public class MathMinCommand extends MathCommand {
} }
public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) { public void convertUsingArmadilloBackend(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol; MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
mathMatrixNameExpressionSymbol.setNameToAccess(""); mathMatrixNameExpressionSymbol.setNameToAccess("");
BluePrintCPP bluePrintCPP = (BluePrintCPP) bluePrint;
int parametersNumber = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().size();
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols()) for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols())
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint); MathFunctionFixer.fixMathFunctions(accessSymbol,bluePrintCPP);
valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>()); if (parametersNumber == 1){
//OctaveHelper.getCallOctaveFunction(mathExpressionSymbol, "sum","Double", valueListString)); convertMinAramadillo(mathMatrixNameExpressionSymbol, bluePrintCPP);
}else if (parametersNumber == 2) {
convertMinStd(mathMatrixNameExpressionSymbol, bluePrintCPP);
} else {
Log.error(String.format("No implementation found for min operation: \"min(%s)\". Possible syntax is \"min( X )\", \"min(a,b)\"", mathExpressionSymbol.getTextualRepresentation()));
}
}
private void convertMinAramadillo(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrint){
String valueListString = ExecuteMethodGenerator.generateExecuteCode(mathMatrixNameExpressionSymbol, new ArrayList<>());
MathStringExpression stringExpression = new MathStringExpression("min(min" + valueListString + ")", mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>(); List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("std::min"+valueListString,mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression)); newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols); mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
}
private void convertMinStd(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrint) {
String valueListString = ExecuteMethodGenerator.generateExecuteCode(mathMatrixNameExpressionSymbol, new ArrayList<>());
MathStringExpression stringExpression = new MathStringExpression("std::min" + valueListString, mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
} }
} }
...@@ -196,8 +196,21 @@ public class ArmadilloFunctionTest extends AbstractSymtabTest { ...@@ -196,8 +196,21 @@ public class ArmadilloFunctionTest extends AbstractSymtabTest {
@Test @Test
public void testCeilCommand() throws IOException { public void testCeilCommand() throws IOException {
testMathCommand("ceil"); testMathCommand("ceil");
} }
@Test
public void testMaxCommand() throws IOException {
testMathCommand("max");
}
@Test
public void testMinCommand() throws IOException {
testMathCommand("min");
}
// Adding CV tests // Adding CV tests
@Test @Test
......
...@@ -9,12 +9,16 @@ using namespace arma; ...@@ -9,12 +9,16 @@ using namespace arma;
using namespace cv; using namespace cv;
class test_math_erodeCommandTest{ class test_math_erodeCommandTest{
public: public:
mat arrayIn;
mat arrayOut;
void init() void init()
{ {
arrayIn=mat(n,m);
arrayOut=mat(n,m);
} }
void execute() void execute()
{ {
double a = (erode(0, 0, 0, 0, 0)); arrayOut = (erode(arrayIn));
} }
}; };
......
/* (c) https://github.com/MontiCore/monticore */
#ifndef TEST_MATH_MAXCOMMANDTEST
#define TEST_MATH_MAXCOMMANDTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo"
using namespace arma;
class test_math_maxCommandTest{
public:
void init()
{
}
void execute()
{
double a = (std::max(15, 4));
}
};
#endif
/* (c) https://github.com/MontiCore/monticore */
#ifndef TEST_MATH_MINCOMMANDTEST
#define TEST_MATH_MINCOMMANDTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo"
using namespace arma;
class test_math_minCommandTest{
public:
void init()
{
}
void execute()
{
double a = (std::min(15, 4));
}
};
#endif
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
package test.math; package test.math;
component ErodeCommandTest{ component ErodeCommandTest{
port
in Q^{n,m} arrayIn,
out Q^{n,m} arrayOut;
implementation Math{ implementation Math{
Q a = erode(0,0,0,0,0); arrayOut = erode(arrayIn);
} }
} }
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