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

[SOLVED] Fastest way to copy large number of elements?

Tags: None
(comma "," separated)
stair314
Registered Member
Posts
8
Karma
0
Is the fastest way to copy a large number of elements from one location to another to use block assignment?

For example, if I want to copy the contents of matrix m into vector v, is the best way to do this

for (int i = 0; i < m.rows(); i++)
v.block(i*m.cols(),0,m.cols(),1).transpose() = m.rows(i)?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
In this case I'd suggest to re-map your data like this:

Matrix::Map(v.data(),m.rows(),m.cols()) = m;

if m is row-major then the copy will be automatically vectorized.
stair314
Registered Member
Posts
8
Karma
0
ggael wrote:In this case I'd suggest to re-map your data like this:

Matrix::Map(v.data(),m.rows(),m.cols()) = m;

if m is row-major then the copy will be automatically vectorized.


Thanks!


Bookmarks



Who is online

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