bug #352:properly cast constants

This commit is contained in:
Igor Krivenko 2011-12-09 23:38:41 +01:00
parent d400a6245e
commit 36457178f9
17 changed files with 40 additions and 40 deletions

View File

@ -266,7 +266,7 @@ template<> struct ldlt_inplace<Lower>
return true; return true;
} }
RealScalar cutoff = 0, biggest_in_corner; RealScalar cutoff(0), biggest_in_corner;
for (Index k = 0; k < size; ++k) for (Index k = 0; k < size; ++k)
{ {

View File

@ -552,7 +552,7 @@ struct pow_default_impl<Scalar, true>
{ {
static inline Scalar run(Scalar x, Scalar y) static inline Scalar run(Scalar x, Scalar y)
{ {
Scalar res = 1; Scalar res(1);
eigen_assert(!NumTraits<Scalar>::IsSigned || y >= 0); eigen_assert(!NumTraits<Scalar>::IsSigned || y >= 0);
if(y & 1) res *= x; if(y & 1) res *= x;
y >>= 1; y >>= 1;

View File

@ -115,10 +115,10 @@ class ProductBase : public MatrixBase<Derived>
inline void evalTo(Dest& dst) const { dst.setZero(); scaleAndAddTo(dst,Scalar(1)); } inline void evalTo(Dest& dst) const { dst.setZero(); scaleAndAddTo(dst,Scalar(1)); }
template<typename Dest> template<typename Dest>
inline void addTo(Dest& dst) const { scaleAndAddTo(dst,1); } inline void addTo(Dest& dst) const { scaleAndAddTo(dst,Scalar(1)); }
template<typename Dest> template<typename Dest>
inline void subTo(Dest& dst) const { scaleAndAddTo(dst,-1); } inline void subTo(Dest& dst) const { scaleAndAddTo(dst,Scalar(-1)); }
template<typename Dest> template<typename Dest>
inline void scaleAndAddTo(Dest& dst,Scalar alpha) const { derived().scaleAndAddTo(dst,alpha); } inline void scaleAndAddTo(Dest& dst,Scalar alpha) const { derived().scaleAndAddTo(dst,alpha); }

View File

@ -58,9 +58,9 @@ MatrixBase<Derived>::stableNorm() const
{ {
using std::min; using std::min;
const Index blockSize = 4096; const Index blockSize = 4096;
RealScalar scale = 0; RealScalar scale(0);
RealScalar invScale = 1; RealScalar invScale(1);
RealScalar ssq = 0; // sum of square RealScalar ssq(0); // sum of square
enum { enum {
Alignment = (int(Flags)&DirectAccessBit) || (int(Flags)&AlignedBit) ? 1 : 0 Alignment = (int(Flags)&DirectAccessBit) || (int(Flags)&AlignedBit) ? 1 : 0
}; };

View File

@ -92,9 +92,9 @@ static EIGEN_DONT_INLINE void run(
Scalar t1 = cjAlpha * rhs[j+1]; Scalar t1 = cjAlpha * rhs[j+1];
Packet ptmp1 = pset1<Packet>(t1); Packet ptmp1 = pset1<Packet>(t1);
Scalar t2 = 0; Scalar t2(0);
Packet ptmp2 = pset1<Packet>(t2); Packet ptmp2 = pset1<Packet>(t2);
Scalar t3 = 0; Scalar t3(0);
Packet ptmp3 = pset1<Packet>(t3); Packet ptmp3 = pset1<Packet>(t3);
size_t starti = FirstTriangular ? 0 : j+2; size_t starti = FirstTriangular ? 0 : j+2;
@ -155,7 +155,7 @@ static EIGEN_DONT_INLINE void run(
register const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride; register const Scalar* EIGEN_RESTRICT A0 = lhs + j*lhsStride;
Scalar t1 = cjAlpha * rhs[j]; Scalar t1 = cjAlpha * rhs[j];
Scalar t2 = 0; Scalar t2(0);
// TODO make sure this product is a real * complex and that the rhs is properly conjugated if needed // TODO make sure this product is a real * complex and that the rhs is properly conjugated if needed
res[j] += cjd.pmul(internal::real(A0[j]), t1); res[j] += cjd.pmul(internal::real(A0[j]), t1);
for (Index i=FirstTriangular ? 0 : j+1; i<(FirstTriangular ? j : size); i++) for (Index i=FirstTriangular ? 0 : j+1; i<(FirstTriangular ? j : size); i++)

View File

@ -128,7 +128,7 @@ struct triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageO
{ {
if (TriStorageOrder==RowMajor) if (TriStorageOrder==RowMajor)
{ {
Scalar b = 0; Scalar b(0);
const Scalar* l = &tri(i,s); const Scalar* l = &tri(i,s);
Scalar* r = &other(s,j); Scalar* r = &other(s,j);
for (Index i3=0; i3<k; ++i3) for (Index i3=0; i3<k; ++i3)

View File

@ -157,13 +157,13 @@ protected:
template<typename Scalar,int AmbiantDim> template<typename Scalar,int AmbiantDim>
inline Scalar AlignedBox<Scalar,AmbiantDim>::squaredExteriorDistance(const VectorType& p) const inline Scalar AlignedBox<Scalar,AmbiantDim>::squaredExteriorDistance(const VectorType& p) const
{ {
Scalar dist2 = 0.; Scalar dist2(0);
Scalar aux; Scalar aux;
for (int k=0; k<dim(); ++k) for (int k=0; k<dim(); ++k)
{ {
if ((aux = (p[k]-m_min[k]))<0.) if ((aux = (p[k]-m_min[k]))<Scalar(0))
dist2 += aux*aux; dist2 += aux*aux;
else if ( (aux = (m_max[k]-p[k]))<0. ) else if ( (aux = (m_max[k]-p[k]))<Scalar(0))
dist2 += aux*aux; dist2 += aux*aux;
} }
return dist2; return dist2;

View File

@ -314,9 +314,9 @@ Quaternion<Scalar>::toRotationMatrix(void) const
// it has to be inlined, and so the return by value is not an issue // it has to be inlined, and so the return by value is not an issue
Matrix3 res; Matrix3 res;
const Scalar tx = 2*this->x(); const Scalar tx = Scalar(2)*this->x();
const Scalar ty = 2*this->y(); const Scalar ty = Scalar(2)*this->y();
const Scalar tz = 2*this->z(); const Scalar tz = Scalar(2)*this->z();
const Scalar twx = tx*this->w(); const Scalar twx = tx*this->w();
const Scalar twy = ty*this->w(); const Scalar twy = ty*this->w();
const Scalar twz = tz*this->w(); const Scalar twz = tz*this->w();
@ -327,15 +327,15 @@ Quaternion<Scalar>::toRotationMatrix(void) const
const Scalar tyz = tz*this->y(); const Scalar tyz = tz*this->y();
const Scalar tzz = tz*this->z(); const Scalar tzz = tz*this->z();
res.coeffRef(0,0) = 1-(tyy+tzz); res.coeffRef(0,0) = Scalar(1)-(tyy+tzz);
res.coeffRef(0,1) = txy-twz; res.coeffRef(0,1) = txy-twz;
res.coeffRef(0,2) = txz+twy; res.coeffRef(0,2) = txz+twy;
res.coeffRef(1,0) = txy+twz; res.coeffRef(1,0) = txy+twz;
res.coeffRef(1,1) = 1-(txx+tzz); res.coeffRef(1,1) = Scalar(1)-(txx+tzz);
res.coeffRef(1,2) = tyz-twx; res.coeffRef(1,2) = tyz-twx;
res.coeffRef(2,0) = txz-twy; res.coeffRef(2,0) = txz-twy;
res.coeffRef(2,1) = tyz+twx; res.coeffRef(2,1) = tyz+twx;
res.coeffRef(2,2) = 1-(txx+tyy); res.coeffRef(2,2) = Scalar(1)-(txx+tyy);
return res; return res;
} }

View File

@ -390,7 +390,7 @@ void SVD<MatrixType>::compute(const MatrixType& matrix)
Scalar ek = e[k]/scale; Scalar ek = e[k]/scale;
Scalar b = ((spm1 + sp)*(spm1 - sp) + epm1*epm1)/Scalar(2); Scalar b = ((spm1 + sp)*(spm1 - sp) + epm1*epm1)/Scalar(2);
Scalar c = (sp*epm1)*(sp*epm1); Scalar c = (sp*epm1)*(sp*epm1);
Scalar shift = 0.0; Scalar shift(0);
if ((b != 0.0) || (c != 0.0)) if ((b != 0.0) || (c != 0.0))
{ {
shift = ei_sqrt(b*b + c); shift = ei_sqrt(b*b + c);

View File

@ -432,7 +432,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
const Scalar eps = NumTraits<Scalar>::epsilon(); const Scalar eps = NumTraits<Scalar>::epsilon();
// inefficient! this is already computed in RealSchur // inefficient! this is already computed in RealSchur
Scalar norm = 0.0; Scalar norm(0);
for (Index j = 0; j < size; ++j) for (Index j = 0; j < size; ++j)
{ {
norm += m_matT.row(j).segment((std::max)(j-1,Index(0)), size-(std::max)(j-1,Index(0))).cwiseAbs().sum(); norm += m_matT.row(j).segment((std::max)(j-1,Index(0)), size-(std::max)(j-1,Index(0))).cwiseAbs().sum();
@ -452,7 +452,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
// Scalar vector // Scalar vector
if (q == Scalar(0)) if (q == Scalar(0))
{ {
Scalar lastr=0, lastw=0; Scalar lastr(0), lastw(0);
Index l = n; Index l = n;
m_matT.coeffRef(n,n) = 1.0; m_matT.coeffRef(n,n) = 1.0;
@ -498,7 +498,7 @@ void EigenSolver<MatrixType>::doComputeEigenvectors()
} }
else if (q < Scalar(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;
// Last vector component imaginary so matrix is triangular // Last vector component imaginary so matrix is triangular

View File

@ -235,7 +235,7 @@ RealSchur<MatrixType>& RealSchur<MatrixType>::compute(const MatrixType& matrix,
// Rows iu+1,...,end are already brought in triangular form. // Rows iu+1,...,end are already brought in triangular form.
Index iu = m_matT.cols() - 1; Index iu = m_matT.cols() - 1;
Index iter = 0; // iteration count Index iter = 0; // iteration count
Scalar exshift = 0.0; // sum of exceptional shifts Scalar exshift(0); // sum of exceptional shifts
Scalar norm = computeNormOfT(); Scalar norm = computeNormOfT();
while (iu >= 0) while (iu >= 0)
@ -288,7 +288,7 @@ inline typename MatrixType::Scalar RealSchur<MatrixType>::computeNormOfT()
// FIXME to be efficient the following would requires a triangular reduxion code // FIXME to be efficient the following would requires a triangular reduxion code
// Scalar norm = m_matT.upper().cwiseAbs().sum() // Scalar norm = m_matT.upper().cwiseAbs().sum()
// + m_matT.bottomLeftCorner(size-1,size-1).diagonal().cwiseAbs().sum(); // + m_matT.bottomLeftCorner(size-1,size-1).diagonal().cwiseAbs().sum();
Scalar norm = 0.0; Scalar norm(0);
for (Index j = 0; j < size; ++j) for (Index j = 0; j < size; ++j)
norm += m_matT.row(j).segment((std::max)(j-1,Index(0)), size-(std::max)(j-1,Index(0))).cwiseAbs().sum(); norm += m_matT.row(j).segment((std::max)(j-1,Index(0)), size-(std::max)(j-1,Index(0))).cwiseAbs().sum();
return norm; return norm;

View File

@ -427,7 +427,7 @@ SelfAdjointEigenSolver<MatrixType>& SelfAdjointEigenSolver<MatrixType>
// map the matrix coefficients to [-1:1] to avoid over- and underflow. // map the matrix coefficients to [-1:1] to avoid over- and underflow.
RealScalar scale = matrix.cwiseAbs().maxCoeff(); RealScalar scale = matrix.cwiseAbs().maxCoeff();
if(scale==Scalar(0)) scale = 1; if(scale==Scalar(0)) scale = Scalar(1);
mat = matrix / scale; mat = matrix / scale;
m_subdiag.resize(n-1); m_subdiag.resize(n-1);
internal::tridiagonalization_inplace(mat, diag, m_subdiag, computeEigenvectors); internal::tridiagonalization_inplace(mat, diag, m_subdiag, computeEigenvectors);
@ -513,7 +513,7 @@ template<typename SolverType> struct direct_selfadjoint_eigenvalues<SolverType,3
using std::atan2; using std::atan2;
using std::cos; using std::cos;
using std::sin; using std::sin;
const Scalar s_inv3 = 1.0/3.0; const Scalar s_inv3 = Scalar(1.0)/Scalar(3.0);
const Scalar s_sqrt3 = sqrt(Scalar(3.0)); const Scalar s_sqrt3 = sqrt(Scalar(3.0));
// The characteristic equation is x^3 - c2*x^2 + c1*x - c0 = 0. The // The characteristic equation is x^3 - c2*x^2 + c1*x - c0 = 0. The

View File

@ -310,7 +310,7 @@ template<typename Derived>
inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const MatrixBase<Derived>& a_p) const inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const MatrixBase<Derived>& a_p) const
{ {
const typename internal::nested<Derived,2*AmbientDim>::type p(a_p.derived()); const typename internal::nested<Derived,2*AmbientDim>::type p(a_p.derived());
Scalar dist2 = 0.; Scalar dist2(0);
Scalar aux; Scalar aux;
for (Index k=0; k<dim(); ++k) for (Index k=0; k<dim(); ++k)
{ {
@ -331,7 +331,7 @@ inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const Matri
template<typename Scalar,int AmbientDim> template<typename Scalar,int AmbientDim>
inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const AlignedBox& b) const inline Scalar AlignedBox<Scalar,AmbientDim>::squaredExteriorDistance(const AlignedBox& b) const
{ {
Scalar dist2 = 0.; Scalar dist2(0);
Scalar aux; Scalar aux;
for (Index k=0; k<dim(); ++k) for (Index k=0; k<dim(); ++k)
{ {

View File

@ -550,9 +550,9 @@ QuaternionBase<Derived>::toRotationMatrix(void) const
// it has to be inlined, and so the return by value is not an issue // it has to be inlined, and so the return by value is not an issue
Matrix3 res; Matrix3 res;
const Scalar tx = 2*this->x(); const Scalar tx = Scalar(2)*this->x();
const Scalar ty = 2*this->y(); const Scalar ty = Scalar(2)*this->y();
const Scalar tz = 2*this->z(); const Scalar tz = Scalar(2)*this->z();
const Scalar twx = tx*this->w(); const Scalar twx = tx*this->w();
const Scalar twy = ty*this->w(); const Scalar twy = ty*this->w();
const Scalar twz = tz*this->w(); const Scalar twz = tz*this->w();
@ -563,15 +563,15 @@ QuaternionBase<Derived>::toRotationMatrix(void) const
const Scalar tyz = tz*this->y(); const Scalar tyz = tz*this->y();
const Scalar tzz = tz*this->z(); const Scalar tzz = tz*this->z();
res.coeffRef(0,0) = 1-(tyy+tzz); res.coeffRef(0,0) = Scalar(1)-(tyy+tzz);
res.coeffRef(0,1) = txy-twz; res.coeffRef(0,1) = txy-twz;
res.coeffRef(0,2) = txz+twy; res.coeffRef(0,2) = txz+twy;
res.coeffRef(1,0) = txy+twz; res.coeffRef(1,0) = txy+twz;
res.coeffRef(1,1) = 1-(txx+tzz); res.coeffRef(1,1) = Scalar(1)-(txx+tzz);
res.coeffRef(1,2) = tyz-twx; res.coeffRef(1,2) = tyz-twx;
res.coeffRef(2,0) = txz-twy; res.coeffRef(2,0) = txz-twy;
res.coeffRef(2,1) = tyz+twx; res.coeffRef(2,1) = tyz+twx;
res.coeffRef(2,2) = 1-(txx+tyy); res.coeffRef(2,2) = Scalar(1)-(txx+tyy);
return res; return res;
} }

View File

@ -40,7 +40,7 @@ SparseMatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
eigen_assert(other.size()>0 && "you are using a non initialized vector"); eigen_assert(other.size()>0 && "you are using a non initialized vector");
typename Derived::InnerIterator i(derived(),0); typename Derived::InnerIterator i(derived(),0);
Scalar res = 0; Scalar res(0);
while (i) while (i)
{ {
res += internal::conj(i.value()) * other.coeff(i.index()); res += internal::conj(i.value()) * other.coeff(i.index());
@ -64,7 +64,7 @@ SparseMatrixBase<Derived>::dot(const SparseMatrixBase<OtherDerived>& other) cons
typename Derived::InnerIterator i(derived(),0); typename Derived::InnerIterator i(derived(),0);
typename OtherDerived::InnerIterator j(other.derived(),0); typename OtherDerived::InnerIterator j(other.derived(),0);
Scalar res = 0; Scalar res(0);
while (i && j) while (i && j)
{ {
if (i.index()==j.index()) if (i.index()==j.index())

View File

@ -30,7 +30,7 @@ typename internal::traits<Derived>::Scalar
SparseMatrixBase<Derived>::sum() const SparseMatrixBase<Derived>::sum() const
{ {
eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix");
Scalar res = 0; Scalar res(0);
for (Index j=0; j<outerSize(); ++j) for (Index j=0; j<outerSize(); ++j)
for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter) for (typename Derived::InnerIterator iter(derived(),j); iter; ++iter)
res += iter.value(); res += iter.value();

View File

@ -48,7 +48,7 @@ struct sparse_solve_triangular_selector<Lhs,Rhs,Mode,Lower,RowMajor>
for(int i=0; i<lhs.rows(); ++i) for(int i=0; i<lhs.rows(); ++i)
{ {
Scalar tmp = other.coeff(i,col); Scalar tmp = other.coeff(i,col);
Scalar lastVal = 0; Scalar lastVal(0);
int lastIndex = 0; int lastIndex = 0;
for(typename Lhs::InnerIterator it(lhs, i); it; ++it) for(typename Lhs::InnerIterator it(lhs, i); it; ++it)
{ {