Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
c54e58c9
Commit
c54e58c9
authored
Jan 23, 2019
by
Alexander David Hellwig
Browse files
Fix: remove REQUIRE macro use from HelperA.h if no tests are generated
parent
fef3de38
Pipeline
#99560
passed with stages
in 40 minutes and 6 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
c54e58c9
...
...
@@ -30,7 +30,7 @@
<groupId>
de.monticore.lang.monticar
</groupId>
<artifactId>
embedded-montiarc-math-generator
</artifactId>
<version>
0.1.
4
-SNAPSHOT
</version>
<version>
0.1.
5
-SNAPSHOT
</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/ArmadilloHelper.java
View file @
c54e58c9
...
...
@@ -28,10 +28,10 @@ import de.monticore.lang.monticar.generator.FileContent;
public
class
ArmadilloHelper
{
public
static
String
fileName
=
"HelperA"
;
public
static
FileContent
getArmadilloHelperFileContent
()
{
public
static
FileContent
getArmadilloHelperFileContent
(
boolean
generateTests
)
{
FileContent
fileContent
=
new
FileContent
();
fileContent
.
setFileName
(
fileName
+
".h"
);
String
fileContentString
=
ArmadilloHelperSource
.
armadilloHelperSourceCode
;
String
fileContentString
=
generateTests
?
ArmadilloHelperSource
.
armadilloHelperSourceCodeWithTests
:
ArmadilloHelperSource
.
armadilloHelperSourceCode
;
fileContent
.
setFileContent
(
fileContentString
);
return
fileContent
;
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/ArmadilloHelperSource.java
View file @
c54e58c9
...
...
@@ -24,7 +24,7 @@ package de.monticore.lang.monticar.generator.cpp;
* @author Sascha Schneiders
*/
public
class
ArmadilloHelperSource
{
public
static
String
armadilloHelperSourceCode
=
"#ifndef HELPERA_H\n"
+
public
static
String
armadilloHelperSourceCode
WithTests
=
"#ifndef HELPERA_H\n"
+
"#define HELPERA_H\n"
+
"#include <iostream>\n"
+
"#include \"armadillo.h\"\n"
+
...
...
@@ -180,4 +180,146 @@ public class ArmadilloHelperSource {
"}\n"
+
"};\n"
+
"#endif\n"
;
public
static
String
armadilloHelperSourceCode
=
"#ifndef HELPERA_H\n"
+
"#define HELPERA_H\n"
+
"#include <iostream>\n"
+
"#include \"armadillo.h\"\n"
+
"#include <stdarg.h>\n"
+
"#include <initializer_list>\n"
+
"#include <fstream>\n"
+
"using namespace arma;\n"
+
"#ifndef _FILESTRING_CONVERSION___A\n"
+
"#define _FILESTRING_CONVERSION___A\n"
+
"void toFileString(std::ofstream& myfile, mat A){\n"
+
" myfile << \"[\";\n"
+
" for (int i = 0; i < A.n_rows; i++){\n"
+
" for (int j = 0; j < A.n_cols; j++){\n"
+
" myfile << A(i,j);\n"
+
" if(j + 1 < A.n_cols){\n"
+
" myfile << \", \";\n"
+
" }\n"
+
" }\n"
+
" if(i + 1 < A.n_rows){\n"
+
" myfile << \";\";\n"
+
" }\n"
+
" }\n"
+
" myfile << \"]\";\n"
+
"}\n"
+
"void toFileString(std::ofstream& myfile, double A){\n"
+
" myfile << A;\n"
+
"}\n"
+
"void toFileString(std::ofstream& myfile, float A){\n"
+
" myfile << A;\n"
+
"}\n"
+
"void toFileString(std::ofstream& myfile, int A){\n"
+
" myfile << A;\n"
+
"}\n"
+
"void toFileString(std::ofstream& myfile, bool A){\n"
+
" myfile << A;\n"
+
"}\n"
+
"bool Is_close(mat& X, mat& Y, double tol)\n"
+
"{\n"
+
" // abs returns a mat type then max checks columns and returns a row_vec\n"
+
" // max used again will return the biggest element in the row_vec\n"
+
" bool close(false);\n"
+
" if(arma::max(arma::max(arma::abs(X-Y))) < tol)\n"
+
" {\n"
+
" close = true;\n"
+
" }\n"
+
" return close;\n"
+
"}\n"
+
"#endif\n"
+
"class HelperA{\n"
+
"public:\n"
+
"static mat getEigenVectors(mat A){\n"
+
"vec eigenValues;\n"
+
"mat eigenVectors;\n"
+
"eig_sym(eigenValues,eigenVectors,A);\n"
+
"return eigenVectors;\n"
+
"}\n"
+
"static vec getEigenValues(mat A){\n"
+
"vec eigenValues;\n"
+
"mat eigenVectors;\n"
+
"eig_sym(eigenValues,eigenVectors,A);\n"
+
"return eigenValues;\n"
+
"}\n"
+
"\n"
+
"static mat getKMeansClusters(mat A, int k){\n"
+
"mat clusters;\n"
+
"kmeans(clusters,A.t(),k,random_subset,20,true);\n"
+
"/*printf(\"cluster centroid calculation done\\n\");\n"
+
"std::ofstream myfile;\n"
+
" myfile.open(\"data after cluster.txt\");\n"
+
" myfile << A;\n"
+
" myfile.close();\n"
+
"\t \n"
+
"\t std::ofstream myfile2;\n"
+
" myfile2.open(\"cluster centroids.txt\");\n"
+
" myfile2 << clusters;\n"
+
" myfile2.close();*/\n"
+
"mat indexedData=getKMeansClustersIndexData(A.t(), clusters);\n"
+
"\n"
+
"/*std::ofstream myfile3;\n"
+
" myfile3.open(\"data after index.txt\");\n"
+
" myfile3 << indexedData;\n"
+
" myfile3.close();\n"
+
"\t */\n"
+
"return indexedData;\n"
+
"}\n"
+
"\n"
+
"static mat getKMeansClustersIndexData(mat A, mat centroids){\n"
+
"\tmat result=mat(A.n_cols, 1);\n"
+
"\tfor(int i=0;i<A.n_cols;++i){\n"
+
"\t\tresult(i, 0) = getIndexForClusterCentroids(A, i, centroids);\n"
+
"\t}\n"
+
"\treturn result;\n"
+
"}\n"
+
"\n"
+
"static int getIndexForClusterCentroids(mat A, int colIndex, mat centroids){\n"
+
"\tint index=1;\n"
+
"\tdouble lowestDistance=getEuclideanDistance(A, colIndex, centroids, 0);\n"
+
"\tfor(int i=1;i<centroids.n_cols;++i){\n"
+
"\t\tdouble curDistance=getEuclideanDistance(A, colIndex, centroids, i);\n"
+
"\t\tif(curDistance<lowestDistance){\n"
+
"\t\t\tlowestDistance=curDistance;\n"
+
"\t\t\tindex=i+1;\n"
+
"\t\t}\n"
+
"\t}\n"
+
"\treturn index;\n"
+
"}\n"
+
"\n"
+
"static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){\n"
+
"\tdouble distance=0;\n"
+
"\tfor(int i=0;i<A.n_rows;++i){\n"
+
"\t\tdouble elementA=A(i,colIndexA);\n"
+
"\t\tdouble elementB=B(i,colIndexB);\n"
+
"\t\tdouble diff=elementA-elementB;\n"
+
"\t\tdistance+=diff*diff;\n"
+
"\t}\n"
+
"\treturn sqrt(distance);\n"
+
"}\n"
+
"\n"
+
"static mat getSqrtMat(mat A){\n"
+
" cx_mat result=sqrtmat(A);\n"
+
" return real(result);\n"
+
"}\n"
+
"\n"
+
"static mat getSqrtMatDiag(mat A){\n"
+
"for(int i=0;i<A.n_rows;++i){\n"
+
" double curVal = A(i,i);\n"
+
" A(i,i) = sqrt(curVal);\n"
+
"}\n"
+
"return A;\n"
+
"}\n"
+
"\n"
+
"static mat invertDiagMatrix(mat A){\n"
+
"for(int i=0;i<A.n_rows;++i){\n"
+
" double curVal = A(i,i);\n"
+
" A(i,i) = 1/curVal;\n"
+
"}\n"
+
"return A;\n"
+
"}\n"
+
"};\n"
+
"#endif\n"
;
}
src/main/java/de/monticore/lang/monticar/generator/cpp/GeneratorCPP.java
View file @
c54e58c9
...
...
@@ -224,7 +224,7 @@ public class GeneratorCPP implements Generator {
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"OctaveBackend"
))
fileContents
.
add
(
OctaveHelper
.
getOctaveHelperFileContent
());
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"ArmadilloBackend"
))
fileContents
.
add
(
ArmadilloHelper
.
getArmadilloHelperFileContent
());
fileContents
.
add
(
ArmadilloHelper
.
getArmadilloHelperFileContent
(
isGenerateTests
));
if
(
shouldGenerateMainClass
())
{
//fileContents.add(getMainClassFileContent(componentInstanceSymbol, fileContents.get(0)));
...
...
@@ -235,7 +235,7 @@ public class GeneratorCPP implements Generator {
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"OctaveBackend"
))
fileContents
.
add
(
OctaveHelper
.
getOctaveHelperFileContent
());
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"ArmadilloBackend"
))
fileContents
.
add
(
ArmadilloHelper
.
getArmadilloHelperFileContent
());
fileContents
.
add
(
ArmadilloHelper
.
getArmadilloHelperFileContent
(
isGenerateTests
));
if
(
componentInstanceSymbol
instanceof
EMADynamicComponentInstanceSymbol
){
//TODO: add Events Value Helper
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment