mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-23 18:20:47 +08:00
fix implicit scalar conversions (needed to support fancy scalar types, see bug #276)
This commit is contained in:
parent
7209d6a126
commit
074b067624
@ -468,7 +468,7 @@ struct triangular_assignment_selector
|
|||||||
if (Mode&UnitDiag && row==col)
|
if (Mode&UnitDiag && row==col)
|
||||||
dst.coeffRef(row, col) = 1;
|
dst.coeffRef(row, col) = 1;
|
||||||
else
|
else
|
||||||
dst.coeffRef(row, col) = 0;
|
dst.coeffRef(row, col) = static_cast<typename Derived1::Scalar>(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -493,7 +493,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) = 0;
|
dst.coeffRef(i, j) = static_cast<typename Derived1::Scalar>(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -511,7 +511,7 @@ struct triangular_assignment_selector<Derived1, Derived2, Lower, Dynamic, ClearO
|
|||||||
Index maxi = std::min(j, dst.rows());
|
Index maxi = std::min(j, dst.rows());
|
||||||
if (ClearOpposite)
|
if (ClearOpposite)
|
||||||
for(Index i = 0; i < maxi; ++i)
|
for(Index i = 0; i < maxi; ++i)
|
||||||
dst.coeffRef(i, j) = 0;
|
dst.coeffRef(i, j) = static_cast<typename Derived1::Scalar>(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -547,7 +547,7 @@ struct triangular_assignment_selector<Derived1, Derived2, StrictlyLower, Dynamic
|
|||||||
Index maxi = std::min(j, dst.rows()-1);
|
Index maxi = std::min(j, dst.rows()-1);
|
||||||
if (ClearOpposite)
|
if (ClearOpposite)
|
||||||
for(Index i = 0; i <= maxi; ++i)
|
for(Index i = 0; i <= maxi; ++i)
|
||||||
dst.coeffRef(i, j) = 0;
|
dst.coeffRef(i, j) = static_cast<typename Derived1::Scalar>(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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 == 0)
|
if (q == static_cast<Scalar>(0))
|
||||||
{
|
{
|
||||||
Scalar lastr=0, lastw=0;
|
Scalar lastr=0, lastw=0;
|
||||||
Index l = n;
|
Index l = n;
|
||||||
@ -491,12 +491,12 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
|
|||||||
|
|
||||||
// Overflow control
|
// Overflow control
|
||||||
Scalar t = internal::abs(m_matT.coeff(i,n));
|
Scalar t = internal::abs(m_matT.coeff(i,n));
|
||||||
if ((eps * t) * t > 1)
|
if ((eps * t) * t > Scalar(1))
|
||||||
m_matT.col(n).tail(size-i) /= t;
|
m_matT.col(n).tail(size-i) /= t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (q < 0 && n > 0) // Complex vector
|
else if (q < Scalar(0) && n > 0) // Complex vector
|
||||||
{
|
{
|
||||||
Scalar lastra=0, lastsa=0, lastw=0;
|
Scalar lastra=0, lastsa=0, lastw=0;
|
||||||
Index l = n-1;
|
Index l = n-1;
|
||||||
@ -530,7 +530,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
l = i;
|
l = i;
|
||||||
if (m_eivalues.coeff(i).imag() == 0)
|
if (m_eivalues.coeff(i).imag() == static_cast<Scalar>(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 > 1)
|
if ((eps * t) * t > static_cast<Scalar>(1))
|
||||||
m_matT.block(i, n-1, size-i, 2) /= t;
|
m_matT.block(i, n-1, size-i, 2) /= t;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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 >= 0) // Two real eigenvalues
|
if (q >= static_cast<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 >= 0)
|
if (p >= static_cast<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 > 0)
|
if (s > static_cast<Scalar>(0))
|
||||||
{
|
{
|
||||||
s = internal::sqrt(s);
|
s = internal::sqrt(s);
|
||||||
if (shiftInfo.coeff(1) < shiftInfo.coeff(0))
|
if (shiftInfo.coeff(1) < shiftInfo.coeff(0))
|
||||||
|
@ -72,7 +72,7 @@ void MatrixBase<Derived>::makeHouseholder(
|
|||||||
|
|
||||||
if(tailSqNorm == RealScalar(0) && internal::imag(c0)==RealScalar(0))
|
if(tailSqNorm == RealScalar(0) && internal::imag(c0)==RealScalar(0))
|
||||||
{
|
{
|
||||||
tau = 0;
|
tau = RealScalar(0);
|
||||||
beta = internal::real(c0);
|
beta = internal::real(c0);
|
||||||
essential.setZero();
|
essential.setZero();
|
||||||
}
|
}
|
||||||
|
@ -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) + 1);
|
RealScalar w = internal::sqrt(internal::abs2(tau) + static_cast<RealScalar>(1));
|
||||||
RealScalar t;
|
RealScalar t;
|
||||||
if(tau>0)
|
if(tau>static_cast<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 > 0 ? 1 : -1;
|
RealScalar sign_t = t > static_cast<RealScalar>(0) ? static_cast<RealScalar>(1) : static_cast<RealScalar>(-1);
|
||||||
RealScalar n = RealScalar(1) / internal::sqrt(internal::abs2(t)+1);
|
RealScalar n = RealScalar(1) / internal::sqrt(internal::abs2(t)+static_cast<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,15 +221,15 @@ 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==0)
|
if(q==static_cast<Scalar>(0))
|
||||||
{
|
{
|
||||||
m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
|
m_c = p<Scalar(0) ? Scalar(-1) : Scalar(1);
|
||||||
m_s = 0;
|
m_s = Scalar(0);
|
||||||
if(r) *r = internal::abs(p);
|
if(r) *r = internal::abs(p);
|
||||||
}
|
}
|
||||||
else if(p==0)
|
else if(p==static_cast<Scalar>(0))
|
||||||
{
|
{
|
||||||
m_c = 0;
|
m_c = Scalar(0);
|
||||||
m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
|
m_s = q<Scalar(0) ? Scalar(1) : Scalar(-1);
|
||||||
if(r) *r = internal::abs(q);
|
if(r) *r = internal::abs(q);
|
||||||
}
|
}
|
||||||
|
@ -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 != 0)
|
if(biggest_in_corner != static_cast<RealScalar>(0))
|
||||||
{
|
{
|
||||||
if(k != row_of_biggest_in_col)
|
if(k != row_of_biggest_in_col)
|
||||||
{
|
{
|
||||||
|
@ -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()) / rows;
|
RealScalar threshold_helper = m_colSqNorms.maxCoeff() * internal::abs2(NumTraits<Scalar>::epsilon()) / static_cast<double>(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 * (rows-k))
|
if(biggest_col_sq_norm < threshold_helper * static_cast<double>(rows-k))
|
||||||
{
|
{
|
||||||
m_nonzero_pivots = k;
|
m_nonzero_pivots = k;
|
||||||
m_hCoeffs.tail(size-k).setZero();
|
m_hCoeffs.tail(size-k).setZero();
|
||||||
|
@ -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() = 0;
|
rot1.c() = static_cast<RealScalar>(0);
|
||||||
rot1.s() = d > 0 ? 1 : -1;
|
rot1.s() = d > static_cast<RealScalar>(0) ? static_cast<RealScalar>(1) : static_cast<RealScalar>(-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RealScalar u = d / t;
|
RealScalar u = d / t;
|
||||||
rot1.c() = RealScalar(1) / sqrt(1 + abs2(u));
|
rot1.c() = RealScalar(1) / sqrt(static_cast<RealScalar>(1) + abs2(u));
|
||||||
rot1.s() = rot1.c() * u;
|
rot1.s() = rot1.c() * u;
|
||||||
}
|
}
|
||||||
m.applyOnTheLeft(0,1,rot1);
|
m.applyOnTheLeft(0,1,rot1);
|
||||||
|
Loading…
Reference in New Issue
Block a user