Commit 0e5aa961 authored by Christoph Richter's avatar Christoph Richter
Browse files

Fixed generation of MathMatrixVectorExpressionSymbol (gitlab #14)

parent f8903b14
Pipeline #62239 passed with stage
in 2 minutes and 37 seconds
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator;
import de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol;
/**
* @author Sascha Schneiders
......@@ -52,4 +53,6 @@ public interface MathBackend {
String getWholeNumberMatrixTypeName();
String getWholeNumberCubeTypeName();
String getMathMatrixColonVectorString(MathMatrixVectorExpressionSymbol mathMatrixArithmeticExpressionSymbol);
}
......@@ -2,9 +2,9 @@ package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol;
import de.monticore.lang.monticar.generator.MathBackend;
import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
......@@ -134,4 +134,14 @@ public class ArmadilloBackend implements MathBackend {
public String getWholeNumberCubeTypeName() {
return "icube";
}
@Override
public String getMathMatrixColonVectorString(MathMatrixVectorExpressionSymbol symbol) {
String start = ExecuteMethodGenerator.generateExecuteCode(symbol.getStart(), new ArrayList<>());
String delta = "1";
if (symbol.getStep().isPresent())
delta = ExecuteMethodGenerator.generateExecuteCode(symbol.getStep().get(), new ArrayList<>());
String end = ExecuteMethodGenerator.generateExecuteCode(symbol.getEnd(), new ArrayList<>());
return String.format("regspace<rowvec>(%s, %s, %s)", start, delta, end);
}
}
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol;
import de.monticore.lang.monticar.generator.MathBackend;
import de.se_rwth.commons.logging.Log;
......@@ -124,4 +125,10 @@ public class LinalgBackend implements MathBackend {
Log.error("Not supported yet");
return null;
}
@Override
public String getMathMatrixColonVectorString(MathMatrixVectorExpressionSymbol mathMatrixArithmeticExpressionSymbol) {
Log.error("Not supported yet");
return null;
}
}
......@@ -3,6 +3,7 @@ package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.math._symboltable.expression.MathArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixVectorExpressionSymbol;
import de.monticore.lang.monticar.generator.MathBackend;
import de.se_rwth.commons.logging.Log;
......@@ -126,4 +127,10 @@ public class OctaveBackend implements MathBackend {
Log.warn("Octave does not support whole number matrices. Using real matrix instead!");
return getCubeTypeName();
}
@Override
public String getMathMatrixColonVectorString(MathMatrixVectorExpressionSymbol mathMatrixArithmeticExpressionSymbol) {
Log.warn("Not supported.", mathMatrixArithmeticExpressionSymbol.getSourcePosition());
return null;
}
}
......@@ -231,10 +231,12 @@ public class ExecuteMethodGeneratorMatrixExpressionHandler {
result = generateExecuteCode((MathMatrixNameExpressionSymbol) mathMatrixExpressionSymbol, includeStrings);
} else if (mathMatrixExpressionSymbol.isValueExpression()) {
result = generateExecuteCode((MathMatrixArithmeticValueSymbol) mathMatrixExpressionSymbol, includeStrings);
} else if (mathMatrixExpressionSymbol.isMatrixVectorExpression()) {
result = generateExecuteCode((MathMatrixVectorExpressionSymbol) mathMatrixExpressionSymbol, includeStrings);
} else {
Log.info(mathMatrixExpressionSymbol.getTextualRepresentation(), "Symbol:");
Log.info(mathMatrixExpressionSymbol.getClass().getName(), "Symbol Name:");
Log.debug("0xMAMAEXSY", "Case not handled");
Log.error("0xMAMAEXSY: Case not handled");
}
return result;
}
......@@ -253,4 +255,8 @@ public class ExecuteMethodGeneratorMatrixExpressionHandler {
}
return result;
}
public static String generateExecuteCode(MathMatrixVectorExpressionSymbol symbol, List<String> includeStrings) {
return MathConverter.curBackend.getMathMatrixColonVectorString(symbol);
}
}
......@@ -144,4 +144,18 @@ public class BasicMathGenerationArmadilloTest extends AbstractSymtabTest {
String restPath = "armadillo/testMath/l0/";
testFilesAreEqual(files, restPath);
}
@Test
public void vectorColonExpressionTest() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.math.vectorColonExpressionTest", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/testMath/l0");
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/testMath/l0/";
testFilesAreEqual(files, restPath);
}
}
#ifndef TEST_MATH_VECTORCOLONEXPRESSIONTEST
#define TEST_MATH_VECTORCOLONEXPRESSIONTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_math_vectorColonExpressionTest{
public:
void init()
{
}
void execute()
{
rowvec A = regspace<rowvec>(1, 1, 10);
rowvec B = regspace<rowvec>(1, 2, 10);
}
};
#endif
package test.math;
component VectorColonExpressionTest{
implementation Math{
Q^{1,10} A = 1:10;
Q^{1,5} B = 1:2:10;
}
}
\ 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