[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [analitza/aucahuasi/matrixeigen] /: Resolve conflict.
From: Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date: 2014-06-04 5:04:49
Message-ID: E1Ws3NZ-0002VM-43 () scm ! kde ! org
[Download RAW message or body]
Git commit 28537992f4895d692e01173e7dc1fa2667274be7 by Percy Camilo Triveño \
Aucahuasi. Committed on 04/06/2014 at 05:01.
Pushed by aucahuasi into branch 'aucahuasi/matrixeigen'.
Resolve conflict.
M +1 -4 CMakeLists.txt
M +1 -2 analitza/CMakeLists.txt
M +4 -0 analitza/analyzer.cpp
M +65 -2 analitza/commands/eigencommands.cpp
M +9 -0 analitza/commands/eigencommands.h
M +11 -3 analitza/tests/commandstest.cpp
http://commits.kde.org/analitza/28537992f4895d692e01173e7dc1fa2667274be7
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3e3205b..8435c96 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,11 +35,8 @@ set(HAVE_OPENGL ${OPENGL_FOUND})
find_package(Eigen3) # find and setup Eigen3 if available
set(HAVE_EIGEN3 ${EIGEN3_FOUND})
-if(NOT EIGEN3_FOUND)
- message(STATUS "Cannot find Eigen3, some analitza commands will be disabled.")
-endif()
-include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
+include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${EIGEN3_INCLUDE_DIR})
remove_definitions(-DQT_NO_CAST_TO_ASCII)
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
diff --git a/analitza/CMakeLists.txt b/analitza/CMakeLists.txt
index b145119..3787d84 100644
--- a/analitza/CMakeLists.txt
+++ b/analitza/CMakeLists.txt
@@ -48,8 +48,7 @@ set(analitza_SRCS
commands/matrixqueries.cpp
)
-if(OPENGL_FOUND)
- include_directories ( ${EIGEN3_INCLUDE_DIR} )
+if(EIGEN3_FOUND)
list(APPEND analitza_SRCS commands/eigencommands.cpp)
endif()
diff --git a/analitza/analyzer.cpp b/analitza/analyzer.cpp
index fbe15eb..5e08461 100644
--- a/analitza/analyzer.cpp
+++ b/analitza/analyzer.cpp
@@ -42,6 +42,7 @@
#include "commands/matrixcommands.h"
#include "commands/blockmatrixcommands.h"
#include "commands/matrixqueries.h"
+#include "commands/eigencommands.h"
// #define SCRIPT_PROFILER
@@ -168,6 +169,9 @@ void Analyzer::registerBuiltinMethods()
m_builtin.insertFunction(IsZeroMatrixCommand::id, IsZeroMatrixCommand::type, new \
IsZeroMatrixCommand); m_builtin.insertFunction(IsIdentityMatrixCommand::id, \
IsIdentityMatrixCommand::type, new IsIdentityMatrixCommand); \
m_builtin.insertFunction(IsDiagonalMatrixCommand::id, IsDiagonalMatrixCommand::type, \
new IsDiagonalMatrixCommand); +#ifdef HAVE_EIGEN3
+ m_builtin.insertFunction(EigenTestCommand::id, EigenTestCommand::type, new \
EigenTestCommand); +#endif
}
void Analyzer::setExpression(const Expression & e)
diff --git a/analitza/commands/eigencommands.cpp \
b/analitza/commands/eigencommands.cpp index 0b12b18..9392cb9 100644
--- a/analitza/commands/eigencommands.cpp
+++ b/analitza/commands/eigencommands.cpp
@@ -20,9 +20,72 @@
#include <QCoreApplication>
-#include "analitzautils.h"
+#include <Eigen/Dense>
+
#include "expression.h"
#include "value.h"
#include "matrix.h"
-#include "operations.h"
+using Analitza::Expression;
+using Analitza::ExpressionType;
+
+const QString EigenTestCommand::id = QString("eigentest");
+const ExpressionType EigenTestCommand::type = ExpressionType(ExpressionType::Lambda)
+.addParameter(ExpressionType(ExpressionType::Any,
+ ExpressionType(ExpressionType::Matrix, \
ExpressionType(ExpressionType::Vector, ExpressionType(ExpressionType::Value), -2), \
-1))) +.addParameter(ExpressionType(ExpressionType::List, \
ExpressionType(ExpressionType::Value))); +
+Expression EigenTestCommand::operator()(const QList< Analitza::Expression >& args)
+{
+ Expression ret;
+
+ const int nargs = args.size();
+
+ if (nargs != 1) {
+ ret.addError(QCoreApplication::tr("Invalid parameter count for '%1'. Should have 1 \
parameter.").arg(EigenTestCommand::id)); +
+ return ret;
+ }
+
+ const Analitza::Matrix *matrix = static_cast<const \
Analitza::Matrix*>(args.first().tree()); + const int m = matrix->rowCount();
+ const int n = matrix->columnCount();
+
+ Eigen::MatrixXd scalarmatrix(m, n);
+
+ for (int i = 0; i < m; ++i)
+ for (int j = 0; j < n; ++j)
+ if (matrix->at(i,j)->type() == Analitza::Object::value) {
+ const Analitza::Cn *entry = static_cast<const Analitza::Cn*>(matrix->at(i,j));
+ const Analitza::Cn::ValueFormat entryformat = entry->format();
+
+ //Don't allow complex numbers
+ if (entryformat == Analitza::Cn::Char || entryformat == Analitza::Cn::Real ||
+ entryformat == Analitza::Cn::Integer || entryformat == Analitza::Cn::Boolean) {
+ scalarmatrix(i,j) = entry->value();
+ } else {
+ ret.addError(QCoreApplication::tr("Invalid parameter type in matrix entry \
(%1,%2) for '%3', it must be a number value.") + \
.arg(i).arg(j).arg(EigenTestCommand::id)); +
+ return ret;
+ }
+ } else {
+ ret.addError(QCoreApplication::tr("Invalid parameter type in matrix entry \
(%1,%2) for '%3', it must be a number value.") \
+ .arg(i).arg(j).arg(EigenTestCommand::id)); +
+ return ret;
+ }
+
+ Q_ASSERT(nargs > 0);
+ Q_ASSERT(ret.toString().isEmpty());
+ Q_ASSERT(ret.isCorrect());
+
+ Eigen::EigenSolver<Eigen::MatrixXd> eigensolver;
+ eigensolver.compute(scalarmatrix, /* computeEigenvectors = */ false);
+
+
+
+ return ret;
+}
+
+//E
\ No newline at end of file
diff --git a/analitza/commands/eigencommands.h b/analitza/commands/eigencommands.h
index 2d517c4..8ef05b6 100644
--- a/analitza/commands/eigencommands.h
+++ b/analitza/commands/eigencommands.h
@@ -20,10 +20,19 @@
#define EIGENCOMMANDS_H
#include "builtinmethods.h"
+#include "config-analitza.h"
namespace Analitza {
class Expression;
};
+class EigenTestCommand: public Analitza::FunctionDefinition
+{
+public:
+ virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args);
+
+ static const QString id;
+ static const Analitza::ExpressionType type;
+};
#endif // EIGENCOMMANDS_H
diff --git a/analitza/tests/commandstest.cpp b/analitza/tests/commandstest.cpp
index d469894..07bb828 100644
--- a/analitza/tests/commandstest.cpp
+++ b/analitza/tests/commandstest.cpp
@@ -21,9 +21,7 @@
#include <QtTest/QTest>
#include "analyzer.h"
-#include <matrix.h>
-#include <container.h>
-#include <apply.h>
+#include "config-analitza.h"
using Analitza::Expression;
@@ -491,6 +489,16 @@ void CommandsTest::testIncorrect_data()
QTest::newRow("bad dimensions:2x2identitymatrix and 2x1zeromatrix") << \
"2*(identitymatrix(2) + matrix(2,1))"; QTest::newRow("bad \
dimensions:2x2identitymatrix and -2x2matrix") << "2*(identitymatrix(2) + matrix(-2, \
2,1))"; +
+#ifdef HAVE_EIGEN3
+ QTest::newRow("bad eigen 1") << "eigentest(list{23},4)";
+ QTest::newRow("bad eigen 2") << "eigentest(list{23})";
+ QTest::newRow("bad eigen 3") << "eigentest(matrix{})";
+ QTest::newRow("bad eigen 4") << "eigentest(matrix{1}, matrix{})";
+ QTest::newRow("bad eigen 5") << "eigentest(matrix{matrixrow{1,2}}, matrix{})";
+ QTest::newRow("bad eigen 6") << "eigentest(matrix{matrixrow{1,2}}, \
matrix{matrixrow{list{5},6}})"; + QTest::newRow("bad eigen 7") << \
"eigentest(matrix{matrixrow{1,list{2}}})"; +#endif
}
void CommandsTest::testIncorrect()
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic