Home » Community » Newbie corner » Eigen and UPP? (STL question?)
Re: Eigen and UPP? (STL question?) [message #32362 is a reply to message #32360] |
Fri, 13 May 2011 08:43   |
|
Hi GaroRobe!
Welcome to U++ Forum! 
First, regarding your remark: Not using STL in past will actually make it simpler for you to get familiar with U++, since you won't have to get rid of the old habbits 
Now to the code: Simply put, the operator<< in U++ uses by default function AsString(), which transform the given object to Upp::String. This is in most cases done by just calling the objects ToString() method, but in cases of foreign types, like those from Eigen, you have to make a specialization of AsString, which would understand it. The simplest posible code to make this work (altough not the best, but I didn't have much time to study Eigen internals ) can be this: #include <Core/Core.h>
#include <Eigen/Dense>
using namespace Upp;
using Eigen::MatrixXd;
NAMESPACE_UPP
template<>
String AsString(const MatrixXd& m) {
std::stringstream tmp;
tmp << m; // we just use eigen classes capability to write to std::ostream
return tmp.str(); // here the std::string is 'magicaly' converted to Upp::String
}
END_UPP_NAMESPACE
CONSOLE_APP_MAIN
{
MatrixXd m ( 2, 2 );
m ( 0, 0 ) = 3;
m ( 1, 0 ) = 2.5;
m ( 0, 1 ) = -1;
m ( 1, 1 ) = m ( 1, 0 ) + m ( 0, 1 );
Cout() << m << '\n';
}
Hopefully this will give you an idea 
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Sun Aug 24 14:35:15 CEST 2025
Total time taken to generate the page: 0.04554 seconds
|