Commit 0a048ab4 authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

fixed some stuff

parent c481f475
......@@ -8,7 +8,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......@@ -20,10 +20,10 @@
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<SIUnit.version>0.0.7</SIUnit.version>
<Common-MontiCar.version>0.0.7</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.7</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.7</Embedded-MontiArc-Behaviour.version>
<Embedded-MontiArc.version>0.0.8</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.8</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.7.1</Math.version>
<Embedded-MontiArc-Math.version>0.0.7</Embedded-MontiArc-Math.version>
<Embedded-MontiArc-Math.version>0.0.8</Embedded-MontiArc-Math.version>
<tagging.version>0.0.1</tagging.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......
......@@ -12,10 +12,8 @@ import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
......@@ -134,6 +132,7 @@ public class GeneratorCPP implements Generator {
return fileContents;
}
//TODO add incremental generation based on described concept
public List<File> generateFiles(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol,
Scope symtab) throws IOException {
List<FileContent> fileContents = generateStrings(taggingResolver, componentSymbol, symtab);
......@@ -161,15 +160,26 @@ public class GeneratorCPP implements Generator {
public File generateFile(FileContent fileContent) throws IOException {
File f = new File(getGenerationTargetPath() + fileContent.getFileName());
Log.info(f.getName(), "FileCreation:");
boolean contentEqual = false;
//Actually slower than just saving and overwriting the file
/*if (f.exists()) {
String storedFileContent = new String(Files.readAllBytes(f.toPath()));
if (storedFileContent.equals(fileContent.getFileContent())) {
contentEqual = true;
}
} else*/
if (!f.exists()) {
f.getParentFile().mkdirs();
if (!f.createNewFile()) {
Log.error("File could not be created");
}
}
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(f));
bufferedWriter.write(fileContent.getFileContent(), 0, fileContent.getFileContent().length());
bufferedWriter.close();
if (!contentEqual) {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(f));
bufferedWriter.write(fileContent.getFileContent(), 0, fileContent.getFileContent().length());
bufferedWriter.close();
}
return f;
}
......
......@@ -23,6 +23,7 @@ public class MathCommandRegisterCPP extends MathCommandRegister {
registerMathCommand(new MathEigvecCommand());
registerMathCommand(new MathGcdCommand());
registerMathCommand(new MathInvCommand());
registerMathCommand(new MathInvDiagCommand());
registerMathCommand(new MathAbsCommand());
registerMathCommand(new MathAcosCommand());
registerMathCommand(new MathAcoshCommand());
......
......@@ -8,6 +8,7 @@ import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference;
import de.monticore.lang.monticar.types2._ast.ASTType;
import de.se_rwth.commons.logging.Log;
/**
* @author Sascha Schneiders
......@@ -54,9 +55,11 @@ public class PortConverter {
if (portSymbol.getTypeReference().getReferencedSymbol() instanceof MCASTTypeSymbolReference) {
MCASTTypeSymbolReference typeSymbolReference = (MCASTTypeSymbolReference) portSymbol.getTypeReference().getReferencedSymbol();
ASTType astType = typeSymbolReference.getAstType();
ASTAssignmentType astAssignmentType = (ASTAssignmentType) astType;
//if (astAssignmentType.getMatrixProperty().size() > 0) Log.error(astType.toString());
variable.addProperties(astAssignmentType.getMatrixProperty());
if (astType instanceof ASTAssignmentType) {
ASTAssignmentType astAssignmentType = (ASTAssignmentType) astType;
//if (astAssignmentType.getMatrixProperty().size() > 0) Log.error(astType.toString());
variable.addProperties(astAssignmentType.getMatrixProperty());
}
}
if (portSymbol.isIncoming())
......
......@@ -79,8 +79,9 @@ public class MathDiagonalMatrixInversionOptimization implements MathOptimization
String name = getMatrixName((MathMatrixAccessSymbol) mathExpressionSymbol.getAstMathMatrixNameExpression().getMathMatrixAccessExpression().get().getMathMatrixAccesss().get(0).getSymbol().get());//TODO handle all possible cases
invertsDiagonalMatrix = ComponentConverter.currentBluePrint.getMathInformationRegister().getVariable(name).getProperties().contains("diag");
}
if (invertsDiagonalMatrix)
if (invertsDiagonalMatrix) {
mathExpressionSymbol.setNameToAccess("invdiag");
}
Log.debug("Found inv and replaced with invdiag", "optimizeMathMatrixNameExp");
}
if (mathExpressionSymbol.getAstMathMatrixNameExpression().getMathMatrixAccessExpression().isPresent()) {
......
......@@ -40,12 +40,21 @@ public class MathMatrixMultiplicationOrder implements MathOptimizationRule {
} else if (((MathValueExpressionSymbol) mathExpressionSymbol).isNumberExpression()) {
//optimize((MathNumberExpressionSymbol)mathExpressionSymbol,precedingExpressions);
}
} else if (mathExpressionSymbol.isForLoopExpression()) {
optimize((MathForLoopExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else {
Log.info(mathExpressionSymbol.getClass().getName(), "Symbol name:");
Log.error("Optimizer Case not handled!");
}
}
public void optimize(MathForLoopExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
//TODO enable head optimization later
for (MathExpressionSymbol subExp : mathExpressionSymbol.getForLoopBody()) {
optimize(subExp, precedingExpressions);
}
}
@Override
public void optimize(MathExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions, MathStatementsSymbol mathStatementsSymbol) {
optimize(mathExpressionSymbol, precedingExpressions);
......@@ -87,6 +96,11 @@ public class MathMatrixMultiplicationOrder implements MathOptimizationRule {
}
}
public void optimize(MathMatrixArithmeticExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
optimize(mathExpressionSymbol.getLeftExpression(), precedingExpressions);
optimize(mathExpressionSymbol.getRightExpression(), precedingExpressions);
}
public void optimize(MathMatrixNameExpressionSymbol matrixNameExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
//nothing to do in this rule
}
......
......@@ -19,10 +19,9 @@ public class MathMultiplicationAddition implements MathOptimizationRule {
@Override
public void optimize(MathExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
if (mathExpressionSymbol == null){
if (mathExpressionSymbol == null) {
}
else if (mathExpressionSymbol.isMatrixExpression()) {
} else if (mathExpressionSymbol.isMatrixExpression()) {
optimize((MathMatrixExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else if (mathExpressionSymbol.isAssignmentExpression()) {
optimize((MathAssignmentExpressionSymbol) mathExpressionSymbol, precedingExpressions);
......@@ -39,12 +38,21 @@ public class MathMultiplicationAddition implements MathOptimizationRule {
} else if (((MathValueExpressionSymbol) mathExpressionSymbol).isNumberExpression()) {
//optimize((MathNumberExpressionSymbol)mathExpressionSymbol,precedingExpressions);
}
} else if (mathExpressionSymbol.isForLoopExpression()) {
optimize((MathForLoopExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else {
Log.info(mathExpressionSymbol.getClass().getName(), "Symbol name:");
Log.error("Optimizer Case not handled!");
}
}
public void optimize(MathForLoopExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
//TODO enable head optimization
for (MathExpressionSymbol subExp : mathExpressionSymbol.getForLoopBody()) {
optimize(subExp, precedingExpressions);
}
}
@Override
public void optimize(MathExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions, MathStatementsSymbol mathStatementsSymbol) {
optimize(mathExpressionSymbol, precedingExpressions);
......
......@@ -5,6 +5,7 @@ import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.monticar.generator.optimization.MathOptimizer;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
......@@ -308,6 +309,7 @@ public class MathOptimizerTest extends AbstractSymtabTest {
generatorCPP.generateFiles(componentSymbol, symtab);
}
@Ignore
@Test
public void testMathAssignmentOptimization1Octave() throws IOException{
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
......
......@@ -91,7 +91,65 @@ public class BasicGenerationArmadilloTest extends AbstractSymtabTest {
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector");
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector/l0");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
}
@Test
public void testAllObjectDetectorInstances() throws IOException{
for(int i=1;i<=9;++i){
testObjectDetectorInstancingL0(i);
testObjectDetectorInstancingL1(i);
testObjectDetectorInstancingL2(i);
testObjectDetectorInstancingL3(i);
}
}
private void testObjectDetectorInstancingL0(int number) throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("detection.objectDetector"+number, ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l0");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
}
private void testObjectDetectorInstancingL1(int number) throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("detection.objectDetector"+number, ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setUseAlgebraicOptimizations(true);
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l1");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
}
private void testObjectDetectorInstancingL2(int number) throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("detection.objectDetector"+number, ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setUseThreadingOptimization(true);
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l2");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
}
private void testObjectDetectorInstancingL3(int number) throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("detection.objectDetector"+number, ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setUseThreadingOptimization(true);
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l3");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
}
}
package a;
component Sub2 extends SuperComp{
component Sub2 implements SuperComp{
port in (-oo:oo) in1,
out B out1;
}
......@@ -9,7 +9,7 @@ component KMeansClustering<N1 n=1, N1 amountVectors=1, N1 maximumClusters=1>{
Q^{n,amountVectors} UMatrix;
for i=1:size(vectors,1)
Q^{1,amountVectors} target= vectors(i,:) .^ 2;
Q amount = sqrt(sum(target ));
Q amount = sqrt(sum(target));
UMatrix(i,:) = vectors(i,:) ./ amount;
end
......
......@@ -12,8 +12,11 @@ component NormalizedLaplacian<N1 n = 1>{
nLaplacian(i,j) = W(i,j) / (sqrt(degree(i,i)) * sqrt(degree(j,j)));
end
end*/
/*currently not working, this short notation will be automatically converted
* later on as it is equivalent to the expression below
*/
//nLaplacian = degree^(-0.5) * W * degree^(-0.5);
nLaplacian = sqrtm(inv(degree)) * W * sqrtm(inv(degree));
nLaplacian = sqrtm(inv(degree)*2) * W * sqrtm(inv(degree)*2 );
}
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector1{
ports in Q(0:255)^{2500, 3} imgFront,
out Q(-oo:oo)^{2500, 1} clusters;
instance SpectralClusterer<2500, 4, 4> spectralClusterer;
connect imgFront -> spectralClusterer.imgMatrix;
connect spectralClusterer.clusters -> clusters;
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector2{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
out Q(-oo:oo)^{2500, 1} clusters[2];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[2];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgBack -> spectralClusterer[2].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector3{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
in Q(0:255)^{2500, 3} imgLeft,
out Q(-oo:oo)^{2500, 1} clusters[3];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[3];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgBack -> spectralClusterer[2].imgMatrix;
connect imgLeft -> spectralClusterer[3].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector4{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
in Q(0:255)^{2500, 3} imgLeft,
in Q(0:255)^{2500, 3} imgRight,
out Q(-oo:oo)^{2500, 1} clusters[4];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[4];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgRight -> spectralClusterer[2].imgMatrix;
connect imgLeft -> spectralClusterer[3].imgMatrix;
connect imgBack -> spectralClusterer[4].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector5{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
in Q(0:255)^{2500, 3} imgLeft,
in Q(0:255)^{2500, 3} imgRight,
in Q(0:255)^{2500, 3} imgFront2,
out Q(-oo:oo)^{2500, 1} clusters[5];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[5];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgRight -> spectralClusterer[2].imgMatrix;
connect imgLeft -> spectralClusterer[3].imgMatrix;
connect imgBack -> spectralClusterer[4].imgMatrix;
connect imgFront2 -> spectralClusterer[5].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector6{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
in Q(0:255)^{2500, 3} imgLeft,
in Q(0:255)^{2500, 3} imgRight,
in Q(0:255)^{2500, 3} imgFront2,
in Q(0:255)^{2500, 3} imgBack2,
out Q(-oo:oo)^{2500, 1} clusters[6];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[6];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgRight -> spectralClusterer[2].imgMatrix;
connect imgLeft -> spectralClusterer[3].imgMatrix;
connect imgBack -> spectralClusterer[4].imgMatrix;
connect imgFront2 -> spectralClusterer[5].imgMatrix;
connect imgBack2 -> spectralClusterer[6].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector7{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
in Q(0:255)^{2500, 3} imgLeft,
in Q(0:255)^{2500, 3} imgRight,
in Q(0:255)^{2500, 3} imgFront2,
in Q(0:255)^{2500, 3} imgBack2,
in Q(0:255)^{2500, 3} imgLeft2,
out Q(-oo:oo)^{2500, 1} clusters[7];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[7];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgRight -> spectralClusterer[2].imgMatrix;
connect imgLeft -> spectralClusterer[3].imgMatrix;
connect imgBack -> spectralClusterer[4].imgMatrix;
connect imgFront2 -> spectralClusterer[5].imgMatrix;
connect imgBack2 -> spectralClusterer[6].imgMatrix;
connect imgLeft2 -> spectralClusterer[7].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ No newline at end of file
package detection;
import SpectralClusterer;
component ObjectDetector8{
ports in Q(0:255)^{2500, 3} imgFront,
in Q(0:255)^{2500, 3} imgBack,
in Q(0:255)^{2500, 3} imgLeft,
in Q(0:255)^{2500, 3} imgRight,
in Q(0:255)^{2500, 3} imgFront2,
in Q(0:255)^{2500, 3} imgBack2,
in Q(0:255)^{2500, 3} imgLeft2,
in Q(0:255)^{2500, 3} imgRight2,
out Q(-oo:oo)^{2500, 1} clusters[8];
instance SpectralClusterer<2500, 4, 4> spectralClusterer[8];
connect imgFront -> spectralClusterer[1].imgMatrix;
connect imgRight -> spectralClusterer[2].imgMatrix;
connect imgLeft -> spectralClusterer[3].imgMatrix;
connect imgBack -> spectralClusterer[4].imgMatrix;
connect imgFront2 -> spectralClusterer[5].imgMatrix;
connect imgRight2 -> spectralClusterer[6].imgMatrix;
connect imgLeft2 -> spectralClusterer[7].imgMatrix;
connect imgBack2 -> spectralClusterer[8].imgMatrix;
connect spectralClusterer[:].clusters -> clusters[:];
}
\ 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