This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Truncated output

Tags: None
(comma "," separated)
nickray
Registered Member
Posts
1
Karma
0

Truncated output

Mon Jan 14, 2013 4:47 pm
Hi

I'm trying to add a generic way to output truncated versions of large row and column vectors.
If such a vector is very large,
Code: Select all
cout << v << endl;
is not very useful...

Matlab and NumPy etc. all have such implementations, I'm wondering if there exists one for
Eigen as well. For a given Matrix type it's easy to do, e.g.
Code: Select all
string repr(const VectorXd & v) {
    stringstream stream;
    if (v.size() > 2*HEAD_TAIL_LEN)
        stream << v.topRows<HEAD_TAIL_LEN>() << "\n(...)\n" << v.bottomRows<HEAD_TAIL_LEN>();
    else
        stream << v;
    return stream.str();
}
std::ostream& operator<< (std::ostream& o, const VectorXd & v) {
    o << repr(v);
    return o;
}
However, I'm at a loss on how to do this generically, and find myself adding implementations
as they arise for say const Transpose<VectorXd const> & and const Transpose<VectorXd> &

Seems to me this would be a good addition to the library itself?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Truncated output

Mon Jan 14, 2013 9:02 pm
Make repr a template function like:
Code: Select all
template<typename Derived>
string repr(const DenseBase<Derived>& mat) {
...
}


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]