Commit 62f4551a authored by Christoph Richter's avatar Christoph Richter
Browse files

Fixed element-wise multiplication generation armadillo (gitlab #13)

parent bfdd83c3
......@@ -185,8 +185,13 @@ public class MathFunctionFixer extends BaseMathFunctionFixerHandler {
public static void fixMathFunctions(MathMatrixArithmeticExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
fixMathFunctions(mathExpressionSymbol.getLeftExpression(), bluePrintCPP);
if (mathExpressionSymbol.getRightExpression() != null)
if (mathExpressionSymbol.getRightExpression() != null) {
fixMathFunctions(mathExpressionSymbol.getRightExpression(), bluePrintCPP);
// fix element wise multiplication
if (mathExpressionSymbol.getOperator().contentEquals(".*")) {
mathExpressionSymbol.setOperator("%");
}
}
}
public static void fixMathFunctions(MathMatrixNameExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP) {
......
......@@ -130,4 +130,18 @@ public class BasicMathGenerationArmadilloTest extends AbstractSymtabTest {
String restPath = "armadillo/test/custom/l0/";
testFilesAreEqual(files, restPath);
}
@Test
public void elementwiseMultTest() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.math.elementwiseMultTest", 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_ELEMENTWISEMULTTEST
#define TEST_MATH_ELEMENTWISEMULTTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_math_elementwiseMultTest{
public:
mat CONSTANTCONSTANTVECTOR0;
mat CONSTANTCONSTANTVECTOR1;
void init()
{
CONSTANTCONSTANTVECTOR0 = mat(2,2);
CONSTANTCONSTANTVECTOR0(0,0) = 1;
CONSTANTCONSTANTVECTOR0(0,1) = 1;
CONSTANTCONSTANTVECTOR0(1,0) = 1;
CONSTANTCONSTANTVECTOR0(1,1) = 1;
CONSTANTCONSTANTVECTOR1 = mat(2,2);
CONSTANTCONSTANTVECTOR1(0,0) = 1;
CONSTANTCONSTANTVECTOR1(0,1) = 2;
CONSTANTCONSTANTVECTOR1(1,0) = 3;
CONSTANTCONSTANTVECTOR1(1,1) = 4;
}
void execute()
{
mat A = CONSTANTCONSTANTVECTOR0;
mat B = CONSTANTCONSTANTVECTOR1;
mat C = A % B;
}
};
#endif
package test.math;
component ElementwiseMultTest{
implementation Math{
Q^{2,2} A = [1,1;1,1];
Q^{2,2} B = [1,2;3,4];
Q^{2,2} C = A .* B;
}
}
\ 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