clean a bit previous patch (ctor vs static_cast and a few bits)

This commit is contained in:
Gael Guennebaud 2011-05-23 13:34:04 +02:00
parent 074b067624
commit 46bee5682f
7 changed files with 24 additions and 21 deletions

View File

@ -449,6 +449,8 @@ struct triangular_assignment_selector
row = (UnrollCount-1) % Derived1::RowsAtCompileTime row = (UnrollCount-1) % Derived1::RowsAtCompileTime
}; };
typedef typename Derived1::Scalar Scalar;
inline static void run(Derived1 &dst, const Derived2 &src) inline static void run(Derived1 &dst, const Derived2 &src)
{ {
triangular_assignment_selector<Derived1, Derived2, Mode, UnrollCount-1, ClearOpposite>::run(dst, src); triangular_assignment_selector<Derived1, Derived2, Mode, UnrollCount-1, ClearOpposite>::run(dst, src);
@ -466,9 +468,9 @@ struct triangular_assignment_selector
else if(ClearOpposite) else if(ClearOpposite)
{ {
if (Mode&UnitDiag && row==col) if (Mode&UnitDiag && row==col)
dst.coeffRef(row, col) = 1; dst.coeffRef(row, col) = Scalar(1);
else else
dst.coeffRef(row, col) = static_cast<typename Derived1::Scalar>(0); dst.coeffRef(row, col) = Scalar(0);
} }
} }
}; };
@ -484,6 +486,7 @@ template<typename Derived1, typename Derived2, bool ClearOpposite>
struct triangular_assignment_selector<Derived1, Derived2, Upper, Dynamic, ClearOpposite> struct triangular_assignment_selector<Derived1, Derived2, Upper, Dynamic, ClearOpposite>
{ {
typedef typename Derived1::Index Index; typedef typename Derived1::Index Index;
typedef typename Derived1::Scalar Scalar;
inline static void run(Derived1 &dst, const Derived2 &src) inline static void run(Derived1 &dst, const Derived2 &src)
{ {
for(Index j = 0; j < dst.cols(); ++j) for(Index j = 0; j < dst.cols(); ++j)
@ -493,7 +496,7 @@ struct triangular_assignment_selector<Derived1, Derived2, Upper, Dynamic, ClearO
dst.copyCoeff(i, j, src); dst.copyCoeff(i, j, src);
if (ClearOpposite) if (ClearOpposite)
for(Index i = maxi+1; i < dst.rows(); ++i) for(Index i = maxi+1; i < dst.rows(); ++i)
dst.coeffRef(i, j) = static_cast<typename Derived1::Scalar>(0); dst.coeffRef(i, j) = Scalar(0);
} }
} }
}; };

View File

@ -450,7 +450,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
Scalar q = m_eivalues.coeff(n).imag(); Scalar q = m_eivalues.coeff(n).imag();
// Scalar vector // Scalar vector
if (q == static_cast<Scalar>(0)) if (q == Scalar(0))
{ {
Scalar lastr=0, lastw=0; Scalar lastr=0, lastw=0;
Index l = n; Index l = n;
@ -530,7 +530,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
else else
{ {
l = i; l = i;
if (m_eivalues.coeff(i).imag() == static_cast<Scalar>(0)) if (m_eivalues.coeff(i).imag() == RealScalar(0))
{ {
std::complex<Scalar> cc = cdiv(-ra,-sa,w,q); std::complex<Scalar> cc = cdiv(-ra,-sa,w,q);
m_matT.coeffRef(i,n-1) = internal::real(cc); m_matT.coeffRef(i,n-1) = internal::real(cc);
@ -564,7 +564,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
// Overflow control // Overflow control
Scalar t = std::max(internal::abs(m_matT.coeff(i,n-1)),internal::abs(m_matT.coeff(i,n))); Scalar t = std::max(internal::abs(m_matT.coeff(i,n-1)),internal::abs(m_matT.coeff(i,n)));
if ((eps * t) * t > static_cast<Scalar>(1)) if ((eps * t) * t > Scalar(1))
m_matT.block(i, n-1, size-i, 2) /= t; m_matT.block(i, n-1, size-i, 2) /= t;
} }

View File

@ -324,11 +324,11 @@ inline void RealSchur<MatrixType>::splitOffTwoRows(Index iu, bool computeU, Scal
m_matT.coeffRef(iu,iu) += exshift; m_matT.coeffRef(iu,iu) += exshift;
m_matT.coeffRef(iu-1,iu-1) += exshift; m_matT.coeffRef(iu-1,iu-1) += exshift;
if (q >= static_cast<Scalar>(0)) // Two real eigenvalues if (q >= Scalar(0)) // Two real eigenvalues
{ {
Scalar z = internal::sqrt(internal::abs(q)); Scalar z = internal::sqrt(internal::abs(q));
JacobiRotation<Scalar> rot; JacobiRotation<Scalar> rot;
if (p >= static_cast<Scalar>(0)) if (p >= Scalar(0))
rot.makeGivens(p + z, m_matT.coeff(iu, iu-1)); rot.makeGivens(p + z, m_matT.coeff(iu, iu-1));
else else
rot.makeGivens(p - z, m_matT.coeff(iu, iu-1)); rot.makeGivens(p - z, m_matT.coeff(iu, iu-1));
@ -369,7 +369,7 @@ inline void RealSchur<MatrixType>::computeShift(Index iu, Index iter, Scalar& ex
{ {
Scalar s = (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0); Scalar s = (shiftInfo.coeff(1) - shiftInfo.coeff(0)) / Scalar(2.0);
s = s * s + shiftInfo.coeff(2); s = s * s + shiftInfo.coeff(2);
if (s > static_cast<Scalar>(0)) if (s > Scalar(0))
{ {
s = internal::sqrt(s); s = internal::sqrt(s);
if (shiftInfo.coeff(1) < shiftInfo.coeff(0)) if (shiftInfo.coeff(1) < shiftInfo.coeff(0))

View File

@ -104,9 +104,9 @@ bool JacobiRotation<Scalar>::makeJacobi(RealScalar x, Scalar y, RealScalar z)
else else
{ {
RealScalar tau = (x-z)/(RealScalar(2)*internal::abs(y)); RealScalar tau = (x-z)/(RealScalar(2)*internal::abs(y));
RealScalar w = internal::sqrt(internal::abs2(tau) + static_cast<RealScalar>(1)); RealScalar w = internal::sqrt(internal::abs2(tau) + RealScalar(1));
RealScalar t; RealScalar t;
if(tau>static_cast<RealScalar>(0)) if(tau>RealScalar(0))
{ {
t = RealScalar(1) / (tau + w); t = RealScalar(1) / (tau + w);
} }
@ -114,8 +114,8 @@ bool JacobiRotation<Scalar>::makeJacobi(RealScalar x, Scalar y, RealScalar z)
{ {
t = RealScalar(1) / (tau - w); t = RealScalar(1) / (tau - w);
} }
RealScalar sign_t = t > static_cast<RealScalar>(0) ? static_cast<RealScalar>(1) : static_cast<RealScalar>(-1); RealScalar sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1);
RealScalar n = RealScalar(1) / internal::sqrt(internal::abs2(t)+static_cast<RealScalar>(1)); RealScalar n = RealScalar(1) / internal::sqrt(internal::abs2(t)+RealScalar(1));
m_s = - sign_t * (internal::conj(y) / internal::abs(y)) * internal::abs(t) * n; m_s = - sign_t * (internal::conj(y) / internal::abs(y)) * internal::abs(t) * n;
m_c = n; m_c = n;
return true; return true;
@ -221,13 +221,13 @@ template<typename Scalar>
void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::false_type) void JacobiRotation<Scalar>::makeGivens(const Scalar& p, const Scalar& q, Scalar* r, internal::false_type)
{ {
if(q==static_cast<Scalar>(0)) if(q==Scalar(0))
{ {
m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1); m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
m_s = Scalar(0); m_s = Scalar(0);
if(r) *r = internal::abs(p); if(r) *r = internal::abs(p);
} }
else if(p==static_cast<Scalar>(0)) else if(p==Scalar(0))
{ {
m_c = Scalar(0); m_c = Scalar(0);
m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1); m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);

View File

@ -268,7 +268,7 @@ struct partial_lu_impl
row_transpositions[k] = row_of_biggest_in_col; row_transpositions[k] = row_of_biggest_in_col;
if(biggest_in_corner != static_cast<RealScalar>(0)) if(biggest_in_corner != RealScalar(0))
{ {
if(k != row_of_biggest_in_col) if(k != row_of_biggest_in_col)
{ {

View File

@ -387,7 +387,7 @@ ColPivHouseholderQR<MatrixType>& ColPivHouseholderQR<MatrixType>::compute(const
for(Index k = 0; k < cols; ++k) for(Index k = 0; k < cols; ++k)
m_colSqNorms.coeffRef(k) = m_qr.col(k).squaredNorm(); m_colSqNorms.coeffRef(k) = m_qr.col(k).squaredNorm();
RealScalar threshold_helper = m_colSqNorms.maxCoeff() * internal::abs2(NumTraits<Scalar>::epsilon()) / static_cast<double>(rows); RealScalar threshold_helper = m_colSqNorms.maxCoeff() * internal::abs2(NumTraits<Scalar>::epsilon()) / RealScalar(rows);
m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case) m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case)
m_maxpivot = RealScalar(0); m_maxpivot = RealScalar(0);
@ -413,7 +413,7 @@ ColPivHouseholderQR<MatrixType>& ColPivHouseholderQR<MatrixType>::compute(const
// Note that here, if we test instead for "biggest == 0", we get a failure every 1000 (or so) // Note that here, if we test instead for "biggest == 0", we get a failure every 1000 (or so)
// repetitions of the unit test, with the result of solve() filled with large values of the order // repetitions of the unit test, with the result of solve() filled with large values of the order
// of 1/(size*epsilon). // of 1/(size*epsilon).
if(biggest_col_sq_norm < threshold_helper * static_cast<double>(rows-k)) if(biggest_col_sq_norm < threshold_helper * RealScalar(rows-k))
{ {
m_nonzero_pivots = k; m_nonzero_pivots = k;
m_hCoeffs.tail(size-k).setZero(); m_hCoeffs.tail(size-k).setZero();

View File

@ -271,13 +271,13 @@ void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q,
RealScalar d = m.coeff(1,0) - m.coeff(0,1); RealScalar d = m.coeff(1,0) - m.coeff(0,1);
if(t == RealScalar(0)) if(t == RealScalar(0))
{ {
rot1.c() = static_cast<RealScalar>(0); rot1.c() = RealScalar(0);
rot1.s() = d > static_cast<RealScalar>(0) ? static_cast<RealScalar>(1) : static_cast<RealScalar>(-1); rot1.s() = d > RealScalar(0) ? RealScalar(1) : RealScalar(-1);
} }
else else
{ {
RealScalar u = d / t; RealScalar u = d / t;
rot1.c() = RealScalar(1) / sqrt(static_cast<RealScalar>(1) + abs2(u)); rot1.c() = RealScalar(1) / sqrt(RealScalar(1) + abs2(u));
rot1.s() = rot1.c() * u; rot1.s() = rot1.c() * u;
} }
m.applyOnTheLeft(0,1,rot1); m.applyOnTheLeft(0,1,rot1);