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

clamping matrixXvector without using temporary object?

Tags: None
(comma "," separated)
katakombi
Registered Member
Posts
18
Karma
0
Hi,

is there a way to optimize an expression like this:

Code: Select all
int gradient_cutoff = 15;
v1.noalias() = (m.block(i, j, a, b) * v2.segment(j, b)).array().max(-gradient_cutoff).min(gradient_cutoff).matrix();


NB: I need to clamp the range of the matrixXvector product in my NN training code...

thanks
Stefan
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes, split it in two:
Code: Select all
v1.noalias() = m.block(i, j, a, b) * v2.segment(j, b);
v1 = v1.array().max(-gradient_cutoff).min(gradient_cutoff);


(Eigen 3.3 should be able to do exactly that for you)
katakombi
Registered Member
Posts
18
Karma
0
ggael wrote:yes, split it in two:
Code: Select all
v1.noalias() = m.block(i, j, a, b) * v2.segment(j, b);
v1 = v1.array().max(-gradient_cutoff).min(gradient_cutoff);


(Eigen 3.3 should be able to do exactly that for you)


Thanks again, ggael, it seems to work. However, this will still force me to use temporaries anyways for expressions like that, right?

Code: Select all
v1.noalias() += m.block(...)*v2.segment(...).array.max(...).min(....);


Is there already a rough schedule for Eigen 3.3?

thanks a lot
Stefan
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes because this will be the most efficient solution. However, if the matrix m is pretty small or if you prefer to sacrifie performance for no temp, you can use A.lazyProduct(B) instead of operator*.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]