Commit 5378fd7d authored by Christoph Richter's avatar Christoph Richter
Browse files

Again fixed armadillo 0 based indexing (fixes #5)

parent b094a7a2
Pipeline #62354 passed with stage
in 2 minutes and 36 seconds
......@@ -228,14 +228,7 @@ public class ExecuteMethodGeneratorHandler {
result += ExecuteMethodGenerator.getCorrectAccessString(mathAssignmentExpressionSymbol.getNameOfMathValue(), mathAssignmentExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings);
result += mathAssignmentExpressionSymbol.getAssignmentOperator().getOperator() + " ";
String input = ExecuteMethodGenerator.generateExecuteCode(mathAssignmentExpressionSymbol.getExpressionSymbol(), includeStrings) + ";\n";
if (MathCommandRegisterCPP.containsCommandExpression(mathAssignmentExpressionSymbol.getExpressionSymbol(), input)) {
result += input;
} else {
if (!StringValueListExtractorUtil.containsPortName(input))
result += StringIndexHelper.modifyContentBetweenBracketsByAdding(input, "-1");
else
result += input;
}
result += input;
Log.info("result1: " + result, "MathAssignmentExpressionSymbol");
} else {
/*if (mathAssignmentExpressionSymbol.getNameOfMathValue().equals("eigenVectors")) {
......@@ -277,7 +270,6 @@ public class ExecuteMethodGeneratorHandler {
} else {
assignment = ExecuteMethodGenerator.generateExecuteCode(assignmentSymbol, includeStrings);
Log.info(assignment, "assignment3:");
}
String result = String.format("%s %s %s;\n", name, op, assignment.trim());
Log.info(name + " " + op + " " + assignment, "additionalInfo:");
......
......@@ -3,8 +3,10 @@ package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.math._symboltable.expression.IArithmeticExpression;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.*;
import de.monticore.lang.monticar.generator.cpp.MathCommandRegisterCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.OctaveHelper;
import de.monticore.lang.monticar.generator.cpp.StringValueListExtractorUtil;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
......@@ -251,7 +253,12 @@ public class ExecuteMethodGeneratorMatrixExpressionHandler {
result += mathMatrixNameExpressionSymbol.getNameToAccess();
if (mathMatrixNameExpressionSymbol.isMathMatrixAccessOperatorSymbolPresent()) {
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixNameExpressionSymbol(mathMatrixNameExpressionSymbol);
result += generateExecuteCode(mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings);
String input = generateExecuteCode(mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings);
// fix indexing
if (useZeroBasedIndexingForMatrixAccess(mathMatrixNameExpressionSymbol, input))
result += StringIndexHelper.modifyContentBetweenBracketsByAdding(input, "-1");
else
result += input;
}
return result;
}
......@@ -259,4 +266,13 @@ public class ExecuteMethodGeneratorMatrixExpressionHandler {
public static String generateExecuteCode(MathMatrixVectorExpressionSymbol symbol, List<String> includeStrings) {
return MathConverter.curBackend.getMathMatrixColonVectorString(symbol);
}
private static boolean useZeroBasedIndexingForMatrixAccess(MathMatrixNameExpressionSymbol symbol, String input) {
return MathConverter.curBackend.usesZeroBasedIndexing()
&& symbol.isMathMatrixAccessOperatorSymbolPresent()
&& (!symbol.getNameToAccess().isEmpty())
&& (!MathCommandRegisterCPP.containsCommandExpression(symbol, input))
&& (!MathFunctionFixer.fixForLoopAccess(symbol.getMathMatrixAccessOperatorSymbol().getMathMatrixNameExpressionSymbol(), ComponentConverter.currentBluePrint))
&& (!StringValueListExtractorUtil.containsPortName(symbol.getNameToAccess()));
}
}
......@@ -13,6 +13,7 @@ int inCol;
mat out1;
mat CONSTANTCONSTANTVECTOR0;
rowvec CONSTANTCONSTANTVECTOR1;
colvec CONSTANTCONSTANTVECTOR2;
void init()
{
in1=mat(2,2);
......@@ -25,6 +26,11 @@ CONSTANTCONSTANTVECTOR0(1,1) = 4;
CONSTANTCONSTANTVECTOR1 = rowvec(2);
CONSTANTCONSTANTVECTOR1(0,0) = 11;
CONSTANTCONSTANTVECTOR1(0,1) = 12;
CONSTANTCONSTANTVECTOR2 = colvec(4);
CONSTANTCONSTANTVECTOR2(0,0) = 1;
CONSTANTCONSTANTVECTOR2(1,0) = 1;
CONSTANTCONSTANTVECTOR2(2,0) = 1;
CONSTANTCONSTANTVECTOR2(3,0) = 1;
}
void execute()
{
......@@ -52,6 +58,8 @@ out1 = test;
out1(1-1) = test(1-1);
out1(2-1, 2-1) = A(2-1, 2-1);
double y = A(inRow-1, inCol-1);
colvec C = CONSTANTCONSTANTVECTOR2;
y = C(1-1)*C(4-1)*(C(1-1)+C(2-1)+C(3-1))+C(3-1);
}
};
......
......@@ -50,5 +50,9 @@ component ArmadilloIndexTest{
// test scalar port matrix access
Q y = A(inRow, inCol);
// test scalar matrix access
Q^{4} C = [1; 1; 1; 1];
y = C(1) * C(4) * (C(1) + C(2) + C(3)) + C(3);
}
}
\ 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