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

conversion of matrix double into matrix long double

Tags: None
(comma "," separated)
theokoles
Registered Member
Posts
6
Karma
0
OS
hi,

I wrote a algorithm of minimization (UZAWA) thanks to Eigen.
Using Eigen::VectorXd, and Eigen::MatrixXd.

My problem is actually realy simple :

Sometimes, checking the convergence, my variable "double test" exceeds the max double value.
test = vector_1.dot(vector_2); // test = nan or inf
Is there any method witch can convert a VectorXd or MatrixXd into
<long double, Dynamic, Dynamic > ? Because all my prog is written with double, and I really don't want to redefine all my VectorXd and MatrixXd...
I tried a loop :

v(i)= (long double) V(i);

that's efficient but some kind of dirty

Thanks a lot !
manuels
Registered Member
Posts
47
Karma
0
I'm not sure, but you could try
Code: Select all
test = vector_1.dot(vector_2).cast<long double>();

or
Code: Select all
test = vector_1.cast<long double>().dot(vector_2.cast<long double>())


(untested code)
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
The second version manuels proposed is correct. But you won't get much higher precision, 80 bits instead of 64... Cannot you write your condition as a vector norm instead of a inner product of two different vectors? In this case you can use a stable norm, e.g., vec.stableNorm() which avoids under/overflows.
theokoles
Registered Member
Posts
6
Karma
0
OS
thks for the advices both manuels and ggael,

Actually, my test checks the karush kuhn tucker condition,

test = (lagrange multipliers).dot(constraint) < tolerance

so, I don't see how to use the stable norm instead :/
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I see, I'm also using the same test in my iterative solvers. There exists other solution than extending the precision. For instance, if you need the value of the dot product only for this test, then overflow is not a big deal since in this case you know that it is greater than tolerance. Another solution is to apply appropriate scaling, e.g:

double maxL = lm.cwiseAbs().max();
double maxR = res.cwiseAbs().max();

(lm/maxL).dot(res/maxR) < tolerance


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar