Could someone please tell me how on earth I can iterate an Eigen::RowVectorXf?
I have looked for 3 hours through the web and documentation, and all I could find is from this link that I can access it by:
vector(i)
vector[i]
I have a:
auto vec = std::make_shared<Eigen::RowVectorXf>( rowIndex.size() );
Which I wanna populate with word frequencies.
Eigen::RowVectorXf::InnerIterator it(vec); it; ++it
Doesn't work, and
Eigen::RowVectorXf::Iterator it(vec); it; ++it
Doesn't exist.
The only thing that seems to work is:
for ( int i = 0; i < vec->row( 0 ).size(); i++ )
{
std::cout << vec->row( 0 )[i] << std::endl;
}
Which IMHO seems bizzare, as I shouldn't have to explicitly point to row( 0 ) since this is a RowVector.
Isn't there a cleaner, faster or more elegant way?
No need for the row(0), you can either use ->coeff(i) (not recommended because it skips the assertions, even in debug mode), or use operator* to dereference your shared_pointer
:
for(int i=0; i<vec->size(); ++i)
cout << (*vec)[i];
You can also use an InnerIterator, but you have to dereference your shared_pointer
:
RowVectorXf::InnerIterator it(*vec); it; ++it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With