Home » Community » Newbie corner » Eigen and UPP? (STL question?)
Re: Eigen and UPP? (STL question?) [message #32374 is a reply to message #32372] |
Fri, 13 May 2011 16:41   |
|
GaroRobe wrote on Fri, 13 May 2011 13:18 | It worked, but... hey, what did it do?
I mean... what does "NAMESPACE_UPP" means and why can't I define similar template for std::stringstream& instead of MatrixXd&?
| Well "NAMESPACE_UPP ... END_UPP_NAMESPACE" is just a fancy way to say "namespace Upp { ... }", it uses macro to allow compiling everything without namespace, when flag NONAMESPACE is used. Here it is necessary because AsString is templated function defined originally in Upp namespace.
Now what did it do Everything in Eigen uses this operator (defined in Core/IO.h in Eigen sources):template<typename Derived>
std::ostream & operator <<
(std::ostream & s,
const DenseBase<Derived> & m)
{
return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT);
} As you can see it uses std::ostream (and print_matrix() as well) which is not compatible with U++ streams. So we used this operator to output the matrix into stringstream (which inherits from ostream), then convert it to std::string by calling str() method and this string is then converted to Upp::String (using implicit conversion in the return statement). Now the whole machinery that lies behind the U++ operator<< can use the AsString specialization to convert the matrix to Upp::String, which can be used in the Cout << ... expression. I'm not sure if this is understandable, but looking at operator<<() definition (at Core/Stream.h:650) might help 
I'm 90% sure there is a better solution, I just didn't have time to investigate Eigen deep enough. I am quite interested in having nice algebra toolkit such as eigen available in U++. It would be great if you could make a package that would provide some of the basic functionality needed to better integrate eigen into U++, such as this << operator etc... Of course, I'll offer you help and advice on this 
GaroRobe wrote on Fri, 13 May 2011 13:18 | Well, anyway I'll have to do some serious learning on strings, values and containers in U++ (reading once obviously just wasn't enough )
Seems like I'll have quite a number of questions along the way
| Some parts of the U++ docs have to be read 10+ times to be fully understood It migh sound discouraging, but this forums members are very helpful and ready to answer the questions 
Honza
EDIT: I see mr_ped once again answered faster than me... Thankfully, the his answer is basicaly the same as mine
[Updated on: Fri, 13 May 2011 16:43] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Jul 08 23:16:46 CEST 2025
Total time taken to generate the page: 0.03909 seconds
|