Skip to content

Commit bfafccb

Browse files
Rohan Budhirajaolivier-stasse
authored andcommitted
[eigen] Replace jrl-mal with eigen
1 parent a2473cd commit bfafccb

15 files changed

+173
-49
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "jrl-cmakemodules"]
2-
path = jrl-cmakemodules
3-
url = git://github.com/jrl-umi3218/jrl-cmakemodules.git
2+
path = jrl-cmakemodules
3+
url = git://github.com/jrl-umi3218/jrl-cmakemodules.git
44
[submodule "cmake"]
55
path = cmake
66
url = git://github.com/jrl-umi3218/jrl-cmakemodules.git

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: cpp
2+
sudo: required
23
compiler:
34
- gcc
45
- clang

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
1717

1818
INCLUDE(cmake/base.cmake)
1919
INCLUDE(cmake/boost.cmake)
20+
INCLUDE(cmake/eigen.cmake)
2021
INCLUDE(cmake/pthread.cmake)
2122
INCLUDE(cmake/cpack.cmake)
2223

@@ -31,9 +32,6 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
3132

3233
SETUP_PROJECT()
3334

34-
# Trigger dependency to jrl-mal
35-
ADD_REQUIRED_DEPENDENCY("jrl-mal >= 1.8.0")
36-
3735
# Add configuration headers for plug-ins.
3836
GENERATE_CONFIGURATION_HEADER(
3937
${HEADER_DIR} config-tracer.hh DG_TRACER tracer_EXPORTS)
@@ -62,6 +60,9 @@ PKG_CONFIG_APPEND_LIBS("dynamic-graph")
6260
SEARCH_FOR_BOOST()
6361
SEARCH_FOR_PTHREAD()
6462

63+
# Search for Boost.
64+
SEARCH_FOR_EIGEN()
65+
6566
ADD_SUBDIRECTORY(src)
6667
ADD_SUBDIRECTORY(include)
6768
ADD_SUBDIRECTORY(doc)

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ tracer.h
6767
tracer-real-time.h
6868

6969
command.h
70+
eigen-io.h
7071
linear-algebra.h
7172
value.h
7273

include/dynamic-graph/eigen-io.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
//
2+
// Copyright 2010 CNRS
3+
//
4+
// Author: Rohan Budhiraja
5+
//
6+
// This file is part of dynamic-graph.
7+
// dynamic-graph is free software: you can redistribute it and/or
8+
// modify it under the terms of the GNU Lesser General Public License
9+
// as published by the Free Software Foundation, either version 3 of
10+
// the License, or (at your option) any later version.
11+
// dynamic-graph is distributed in the hope that it will be
12+
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13+
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU Lesser General Public License for more details. You should
15+
// have received a copy of the GNU Lesser General Public License along
16+
// with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#ifndef DYNAMIC_GRAPH_EIGEN_IO_H
19+
#define DYNAMIC_GRAPH_EIGEN_IO_H
20+
21+
#include <iostream>
22+
#include <boost/format.hpp>
23+
#include <boost/numeric/conversion/cast.hpp>
24+
25+
#include <dynamic-graph/exception-signal.h>
26+
#include <dynamic-graph/linear-algebra.h>
27+
#include <Eigen/Geometry>
28+
29+
using dynamicgraph::ExceptionSignal;
30+
31+
//TODO: Eigen 3.3 onwards has a global Eigen::Index definition.
32+
//If Eigen version is updated, use Eigen::Index instead of this macro.
33+
34+
35+
/* \brief Eigen Vector input from istream
36+
*
37+
* Input Vector format: val1 val2 val3 ... valN
38+
* e.g. 1 23 32.2 12.12 32
39+
*/
40+
namespace Eigen {
41+
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE eigen_index;
42+
inline std::istringstream& operator >> (std::istringstream &iss,
43+
dynamicgraph::Vector &inst)
44+
{
45+
std::vector<double> _stdvec;
46+
double _dbl_val;
47+
48+
boost::format fmt ("Failed to enter %s as vector. Reenter as [val1 val2 ... valN]");
49+
fmt %iss.str();
50+
51+
while(iss >> _dbl_val && !iss.fail()) {
52+
_stdvec.push_back(_dbl_val);
53+
}
54+
try {
55+
inst = Eigen::VectorXd::Map (_stdvec.data(),
56+
boost::numeric_cast<eigen_index> (_stdvec.size()) );
57+
}
58+
catch (boost::bad_numeric_cast&) {
59+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str() );
60+
}
61+
62+
return iss;
63+
}
64+
65+
/* \brief Eigen Matrix input from istream
66+
*
67+
* Matrix format: [[val11 val12 val13 ... val1N] ... [valM1 valM2 ... valMN]]
68+
* e.g. [[1 23 32.2 12.12 32][2 32 23 92.01 19.2]]
69+
*/
70+
71+
template<typename Derived>
72+
inline std::istringstream& operator >> (std::istringstream &iss,
73+
DenseBase<Derived> &inst)
74+
{
75+
std::vector<dynamicgraph::Vector> _stdmat;
76+
char _ch;
77+
int _vec_size;
78+
bool _vec_size_set = false;
79+
80+
boost::format fmt
81+
("Failed to enter %s as matrix. Reenter as [[val11 val12 ... val1N]...[valM1 valM2 ... valMN]]. Check that vector sizes are consistent.");
82+
fmt %iss.str();
83+
84+
if(iss>> _ch && _ch != '['){
85+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
86+
}
87+
else{
88+
dynamicgraph::Vector _eigvec;
89+
while(iss >> _eigvec && !iss.fail()){
90+
if (!_vec_size_set) {
91+
try {
92+
_vec_size = boost::numeric_cast <int> (_eigvec.size());
93+
}
94+
catch (boost::bad_numeric_cast&) {
95+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
96+
}
97+
_vec_size_set = true;
98+
}
99+
else {
100+
if (_eigvec.size() != _vec_size) {
101+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
102+
}
103+
}
104+
_stdmat.push_back(_eigvec);
105+
}
106+
if(iss>> _ch && _ch != ']'){
107+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
108+
}
109+
else {
110+
try {
111+
inst.resize(boost::numeric_cast<eigen_index> (_stdmat.size()), _vec_size);
112+
}
113+
catch (boost::bad_numeric_cast&) {
114+
throw ExceptionSignal(ExceptionSignal::GENERIC, fmt.str());
115+
}
116+
for (unsigned int i =0;i<_stdmat.size(); i++) {
117+
inst.row(i) = _stdmat[i];
118+
}
119+
}
120+
}
121+
return iss;
122+
}
123+
}
124+
125+
126+
#endif //DYNAMIC_GRAPH_EIGEN_IO_H

include/dynamic-graph/linear-algebra.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717

1818
#ifndef DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
1919
#define DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
20-
21-
#include <jrl/mal/boost.hh>
22-
#include <boost/numeric/ublas/matrix.hpp>
20+
#include <Eigen/Core>
2321

2422
namespace dynamicgraph {
25-
typedef maal::boost::Vector Vector;
26-
typedef maal::boost::Matrix Matrix;
23+
typedef Eigen::MatrixXd Matrix;
24+
typedef Eigen::VectorXd Vector;
2725
}
2826

29-
#endif //DYNAMIC_GRAPH_LINEAR_ALGEBRA_H
30-
3127

28+
#endif //DYNAMIC_GRAPH_LINEAR_ALGEBRA_H

include/dynamic-graph/signal-cast-helper.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
# include <boost/lexical_cast.hpp>
2929
# include <boost/tuple/tuple.hpp>
3030

31+
#include <dynamic-graph/eigen-io.h>
32+
3133
# include <dynamic-graph/dynamic-graph-api.h>
3234
# include "dynamic-graph/exception-signal.h"
3335
# include "dynamic-graph/signal-caster.h"
@@ -99,8 +101,8 @@ namespace dynamicgraph
99101
class SignalCast
100102
{
101103
public:
102-
static T cast( std::istringstream& stringValue ) { throw 1;}
103-
static void disp( const T& t,std::ostream& os ) { throw 1; }
104+
static T cast( std::istringstream& ) { throw 1;}
105+
static void disp( const T&,std::ostream&) { throw 1; }
104106
static void trace( const T& t,std::ostream& os ) { disp(t,os); }
105107
public:
106108
// adapter functions for SignalCast

include/dynamic-graph/value.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
#include <cassert>
2424
#include <typeinfo>
2525
#include "dynamic-graph/dynamic-graph-api.h"
26-
#include "dynamic-graph/linear-algebra.h"
26+
#include <dynamic-graph/linear-algebra.h>
2727

2828
namespace dynamicgraph {
2929
namespace command {
3030
class Value;
3131
class DYNAMIC_GRAPH_DLLAPI EitherType {
3232
public:
33+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34+
3335
EitherType(const Value& value);
3436
~EitherType();
3537
operator bool () const;
@@ -46,6 +48,9 @@ namespace dynamicgraph {
4648

4749
class DYNAMIC_GRAPH_DLLAPI Value {
4850
public:
51+
52+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
53+
4954
enum Type {
5055
NONE,
5156
BOOL,

src/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,16 @@ ADD_LIBRARY(${LIBRARY_NAME}
5050
5151
SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
5252
53-
PKG_CONFIG_USE_DEPENDENCY(${LIBRARY_NAME} jrl-mal)
5453
5554
IF (UNIX)
5655
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${CMAKE_DL_LIBS} pthread)
5756
ENDIF (UNIX)
5857
5958
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${Boost_LIBRARIES})
6059
61-
IF (UNIX AND NOT APPLE)
62-
TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${JRL_MAL_LDFLAGS_OTHER})
63-
ENDIF (UNIX AND NOT APPLE)
60+
#IF (UNIX AND NOT APPLE)
61+
# TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${JRL_MAL_LDFLAGS_OTHER})
62+
#ENDIF (UNIX AND NOT APPLE)
6463
6564
INSTALL(TARGETS ${LIBRARY_NAME}
6665
DESTINATION ${CMAKE_INSTALL_LIBDIR})

src/command/value.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// have received a copy of the GNU Lesser General Public License along
1616
// with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
1717

18-
#include <boost/numeric/ublas/io.hpp>
1918
#include "dynamic-graph/value.h"
2019
#include "dynamic-graph/exception-abstract.h"
2120

0 commit comments

Comments
 (0)