This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 397 | Differences between
and this patch

Collapse All | Expand All

(-)a/CMakeLists.txt (-1 / +6 lines)
Lines 103-119 option(EIGEN_SPLIT_LARGE_TESTS "Split la Link Here
103
option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
103
option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
104
if(EIGEN_DEFAULT_TO_ROW_MAJOR)
104
if(EIGEN_DEFAULT_TO_ROW_MAJOR)
105
  add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
105
  add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
106
endif()
106
endif()
107
107
108
set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
108
set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320")
109
109
110
macro(ei_add_cxx_compiler_flag FLAG)
110
macro(ei_add_cxx_compiler_flag FLAG)
111
  string(REGEX REPLACE "-" "" SFLAG ${FLAG})
111
  string(REGEX REPLACE "-" "" SFLAG1 ${FLAG})
112
  string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1})
112
  check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
113
  check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG})
113
  if(COMPILER_SUPPORT_${SFLAG})
114
  if(COMPILER_SUPPORT_${SFLAG})
114
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
115
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
115
  endif()
116
  endif()
116
endmacro(ei_add_cxx_compiler_flag)
117
endmacro(ei_add_cxx_compiler_flag)
117
118
118
if(NOT MSVC)
119
if(NOT MSVC)
119
  # We assume that other compilers are partly compatible with GNUCC
120
  # We assume that other compilers are partly compatible with GNUCC
Lines 137-163 if(NOT MSVC) Link Here
137
  ei_add_cxx_compiler_flag("-Wundef")
138
  ei_add_cxx_compiler_flag("-Wundef")
138
  ei_add_cxx_compiler_flag("-Wcast-align")
139
  ei_add_cxx_compiler_flag("-Wcast-align")
139
  ei_add_cxx_compiler_flag("-Wchar-subscripts")
140
  ei_add_cxx_compiler_flag("-Wchar-subscripts")
140
  ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
141
  ei_add_cxx_compiler_flag("-Wnon-virtual-dtor")
141
  ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
142
  ei_add_cxx_compiler_flag("-Wunused-local-typedefs")
142
  ei_add_cxx_compiler_flag("-Wpointer-arith")
143
  ei_add_cxx_compiler_flag("-Wpointer-arith")
143
  ei_add_cxx_compiler_flag("-Wwrite-strings")
144
  ei_add_cxx_compiler_flag("-Wwrite-strings")
144
  ei_add_cxx_compiler_flag("-Wformat-security")
145
  ei_add_cxx_compiler_flag("-Wformat-security")
146
  ei_add_cxx_compiler_flag("-Wshorten-64-to-32")
147
  ei_add_cxx_compiler_flag("-Wenum-conversion")
148
  ei_add_cxx_compiler_flag("-Wc++11-extensions")
145
  
149
  
146
  ei_add_cxx_compiler_flag("-Wno-psabi")
150
  ei_add_cxx_compiler_flag("-Wno-psabi")
147
  ei_add_cxx_compiler_flag("-Wno-variadic-macros")
151
  ei_add_cxx_compiler_flag("-Wno-variadic-macros")
148
  ei_add_cxx_compiler_flag("-Wno-long-long")
152
  ei_add_cxx_compiler_flag("-Wno-long-long")
149
  
153
  
150
  ei_add_cxx_compiler_flag("-fno-check-new")
154
  ei_add_cxx_compiler_flag("-fno-check-new")
151
  ei_add_cxx_compiler_flag("-fno-common")
155
  ei_add_cxx_compiler_flag("-fno-common")
152
  ei_add_cxx_compiler_flag("-fstrict-aliasing")
156
  ei_add_cxx_compiler_flag("-fstrict-aliasing")
153
  ei_add_cxx_compiler_flag("-wd981")                    # disable ICC's "operands are evaluated in unspecified order" remark
157
  ei_add_cxx_compiler_flag("-wd981")                    # disable ICC's "operands are evaluated in unspecified order" remark
154
  ei_add_cxx_compiler_flag("-wd2304")                   # disbale ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor
158
  ei_add_cxx_compiler_flag("-wd2304")                   # disbale ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor
155
  
159
  
160
  
156
  # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
161
  # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails
157
  # Moreover we should not set both -strict-ansi and -ansi
162
  # Moreover we should not set both -strict-ansi and -ansi
158
  check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
163
  check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI)
159
  ei_add_cxx_compiler_flag("-Qunused-arguments")        # disable clang warning: argument unused during compilation: '-ansi'
164
  ei_add_cxx_compiler_flag("-Qunused-arguments")        # disable clang warning: argument unused during compilation: '-ansi'
160
  
165
  
161
  if(COMPILER_SUPPORT_STRICTANSI)
166
  if(COMPILER_SUPPORT_STRICTANSI)
162
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
167
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi")
163
  else()
168
  else()
(-)a/Eigen/src/Cholesky/LDLT.h (-3 / +5 lines)
Lines 241-256 template<> struct ldlt_inplace<Lower> Link Here
241
{
241
{
242
  template<typename MatrixType, typename TranspositionType, typename Workspace>
242
  template<typename MatrixType, typename TranspositionType, typename Workspace>
243
  static bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
243
  static bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign)
244
  {
244
  {
245
    using std::abs;
245
    using std::abs;
246
    typedef typename MatrixType::Scalar Scalar;
246
    typedef typename MatrixType::Scalar Scalar;
247
    typedef typename MatrixType::RealScalar RealScalar;
247
    typedef typename MatrixType::RealScalar RealScalar;
248
    typedef typename MatrixType::Index Index;
248
    typedef typename MatrixType::Index Index;
249
    typedef typename TranspositionType::IndexType IndexType;
249
    eigen_assert(mat.rows()==mat.cols());
250
    eigen_assert(mat.rows()==mat.cols());
250
    const Index size = mat.rows();
251
    const Index size = mat.rows();
251
252
252
    if (size <= 1)
253
    if (size <= 1)
253
    {
254
    {
254
      transpositions.setIdentity();
255
      transpositions.setIdentity();
255
      if (numext::real(mat.coeff(0,0)) > 0) sign = PositiveSemiDef;
256
      if (numext::real(mat.coeff(0,0)) > 0) sign = PositiveSemiDef;
256
      else if (numext::real(mat.coeff(0,0)) < 0) sign = NegativeSemiDef;
257
      else if (numext::real(mat.coeff(0,0)) < 0) sign = NegativeSemiDef;
Lines 260-285 template<> struct ldlt_inplace<Lower> Link Here
260
261
261
    for (Index k = 0; k < size; ++k)
262
    for (Index k = 0; k < size; ++k)
262
    {
263
    {
263
      // Find largest diagonal element
264
      // Find largest diagonal element
264
      Index index_of_biggest_in_corner;
265
      Index index_of_biggest_in_corner;
265
      mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
266
      mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
266
      index_of_biggest_in_corner += k;
267
      index_of_biggest_in_corner += k;
267
268
268
      transpositions.coeffRef(k) = index_of_biggest_in_corner;
269
      transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner);
269
      if(k != index_of_biggest_in_corner)
270
      if(k != index_of_biggest_in_corner)
270
      {
271
      {
271
        // apply the transposition while taking care to consider only
272
        // apply the transposition while taking care to consider only
272
        // the lower triangular part
273
        // the lower triangular part
273
        Index s = size-index_of_biggest_in_corner-1; // trailing size after the biggest element
274
        Index s = size-index_of_biggest_in_corner-1; // trailing size after the biggest element
274
        mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
275
        mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
275
        mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
276
        mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
276
        std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
277
        std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
277
        for(int i=k+1;i<index_of_biggest_in_corner;++i)
278
        for(Index i=k+1;i<index_of_biggest_in_corner;++i)
278
        {
279
        {
279
          Scalar tmp = mat.coeffRef(i,k);
280
          Scalar tmp = mat.coeffRef(i,k);
280
          mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i));
281
          mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i));
281
          mat.coeffRef(index_of_biggest_in_corner,i) = numext::conj(tmp);
282
          mat.coeffRef(index_of_biggest_in_corner,i) = numext::conj(tmp);
282
        }
283
        }
283
        if(NumTraits<Scalar>::IsComplex)
284
        if(NumTraits<Scalar>::IsComplex)
284
          mat.coeffRef(index_of_biggest_in_corner,k) = numext::conj(mat.coeff(index_of_biggest_in_corner,k));
285
          mat.coeffRef(index_of_biggest_in_corner,k) = numext::conj(mat.coeff(index_of_biggest_in_corner,k));
285
      }
286
      }
Lines 437-464 LDLT<MatrixType,_UpLo>& LDLT<MatrixType, Link Here
437
 * \param w a vector to be incorporated into the decomposition.
438
 * \param w a vector to be incorporated into the decomposition.
438
 * \param sigma a scalar, +1 for updates and -1 for "downdates," which correspond to removing previously-added column vectors. Optional; default value is +1.
439
 * \param sigma a scalar, +1 for updates and -1 for "downdates," which correspond to removing previously-added column vectors. Optional; default value is +1.
439
 * \sa setZero()
440
 * \sa setZero()
440
  */
441
  */
441
template<typename MatrixType, int _UpLo>
442
template<typename MatrixType, int _UpLo>
442
template<typename Derived>
443
template<typename Derived>
443
LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename NumTraits<typename MatrixType::Scalar>::Real& sigma)
444
LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename NumTraits<typename MatrixType::Scalar>::Real& sigma)
444
{
445
{
446
  typedef typename TranspositionType::IndexType IndexType;
445
  const Index size = w.rows();
447
  const Index size = w.rows();
446
  if (m_isInitialized)
448
  if (m_isInitialized)
447
  {
449
  {
448
    eigen_assert(m_matrix.rows()==size);
450
    eigen_assert(m_matrix.rows()==size);
449
  }
451
  }
450
  else
452
  else
451
  {    
453
  {    
452
    m_matrix.resize(size,size);
454
    m_matrix.resize(size,size);
453
    m_matrix.setZero();
455
    m_matrix.setZero();
454
    m_transpositions.resize(size);
456
    m_transpositions.resize(size);
455
    for (Index i = 0; i < size; i++)
457
    for (Index i = 0; i < size; i++)
456
      m_transpositions.coeffRef(i) = i;
458
      m_transpositions.coeffRef(i) = IndexType(i);
457
    m_temporary.resize(size);
459
    m_temporary.resize(size);
458
    m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
460
    m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
459
    m_isInitialized = true;
461
    m_isInitialized = true;
460
  }
462
  }
461
463
462
  internal::ldlt_inplace<UpLo>::update(m_matrix, m_transpositions, m_temporary, w, sigma);
464
  internal::ldlt_inplace<UpLo>::update(m_matrix, m_transpositions, m_temporary, w, sigma);
463
465
464
  return *this;
466
  return *this;
(-)a/Eigen/src/Core/PermutationMatrix.h (-26 / +32 lines)
Lines 61-81 class PermutationBase : public EigenBase Link Here
61
    enum {
61
    enum {
62
      Flags = Traits::Flags,
62
      Flags = Traits::Flags,
63
      CoeffReadCost = Traits::CoeffReadCost,
63
      CoeffReadCost = Traits::CoeffReadCost,
64
      RowsAtCompileTime = Traits::RowsAtCompileTime,
64
      RowsAtCompileTime = Traits::RowsAtCompileTime,
65
      ColsAtCompileTime = Traits::ColsAtCompileTime,
65
      ColsAtCompileTime = Traits::ColsAtCompileTime,
66
      MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
66
      MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
67
      MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
67
      MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
68
    };
68
    };
69
    typedef typename Traits::Scalar Scalar;
69
    typedef typename Traits::IndexType IndexType;
70
    typedef typename Traits::Index Index;
70
    typedef typename Traits::Index Index;
71
    typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime>
71
    typedef Matrix<IndexType,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime>
72
            DenseMatrixType;
72
            DenseMatrixType;
73
    typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,Index>
73
    typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,IndexType>
74
            PlainPermutationType;
74
            PlainPermutationType;
75
    using Base::derived;
75
    using Base::derived;
76
    #endif
76
    #endif
77
77
78
    /** Copies the other permutation into *this */
78
    /** Copies the other permutation into *this */
79
    template<typename OtherDerived>
79
    template<typename OtherDerived>
80
    Derived& operator=(const PermutationBase<OtherDerived>& other)
80
    Derived& operator=(const PermutationBase<OtherDerived>& other)
81
    {
81
    {
Lines 142-158 class PermutationBase : public EigenBase Link Here
142
    inline void resize(Index newSize)
142
    inline void resize(Index newSize)
143
    {
143
    {
144
      indices().resize(newSize);
144
      indices().resize(newSize);
145
    }
145
    }
146
146
147
    /** Sets *this to be the identity permutation matrix */
147
    /** Sets *this to be the identity permutation matrix */
148
    void setIdentity()
148
    void setIdentity()
149
    {
149
    {
150
      for(Index i = 0; i < size(); ++i)
150
      for(IndexType i = 0; i < size(); ++i)
151
        indices().coeffRef(i) = i;
151
        indices().coeffRef(i) = i;
152
    }
152
    }
153
153
154
    /** Sets *this to be the identity permutation matrix of given size.
154
    /** Sets *this to be the identity permutation matrix of given size.
155
      */
155
      */
156
    void setIdentity(Index newSize)
156
    void setIdentity(Index newSize)
157
    {
157
    {
158
      resize(newSize);
158
      resize(newSize);
Lines 168-185 class PermutationBase : public EigenBase Link Here
168
      *
168
      *
169
      * \sa applyTranspositionOnTheRight(int,int)
169
      * \sa applyTranspositionOnTheRight(int,int)
170
      */
170
      */
171
    Derived& applyTranspositionOnTheLeft(Index i, Index j)
171
    Derived& applyTranspositionOnTheLeft(Index i, Index j)
172
    {
172
    {
173
      eigen_assert(i>=0 && j>=0 && i<size() && j<size());
173
      eigen_assert(i>=0 && j>=0 && i<size() && j<size());
174
      for(Index k = 0; k < size(); ++k)
174
      for(Index k = 0; k < size(); ++k)
175
      {
175
      {
176
        if(indices().coeff(k) == i) indices().coeffRef(k) = j;
176
        if(indices().coeff(k) == i) indices().coeffRef(k) = IndexType(j);
177
        else if(indices().coeff(k) == j) indices().coeffRef(k) = i;
177
        else if(indices().coeff(k) == j) indices().coeffRef(k) = IndexType(i);
178
      }
178
      }
179
      return derived();
179
      return derived();
180
    }
180
    }
181
181
182
    /** Multiplies *this by the transposition \f$(ij)\f$ on the right.
182
    /** Multiplies *this by the transposition \f$(ij)\f$ on the right.
183
      *
183
      *
184
      * \returns a reference to *this.
184
      * \returns a reference to *this.
185
      *
185
      *
Lines 265-306 class PermutationBase : public EigenBase Link Here
265
  * \param IndexType the interger type of the indices
265
  * \param IndexType the interger type of the indices
266
  *
266
  *
267
  * This class represents a permutation matrix, internally stored as a vector of integers.
267
  * This class represents a permutation matrix, internally stored as a vector of integers.
268
  *
268
  *
269
  * \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix
269
  * \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix
270
  */
270
  */
271
271
272
namespace internal {
272
namespace internal {
273
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType>
273
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType>
274
struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType> >
274
struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _IndexType> >
275
 : traits<Matrix<IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
275
 : traits<Matrix<_IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
276
{
276
{
277
  typedef IndexType Index;
277
  typedef Matrix<_IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
278
  typedef Matrix<IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
278
  typedef typename IndicesType::Index Index;
279
  typedef _IndexType IndexType;
279
};
280
};
280
}
281
}
281
282
282
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType>
283
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType>
283
class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType> >
284
class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _IndexType> >
284
{
285
{
285
    typedef PermutationBase<PermutationMatrix> Base;
286
    typedef PermutationBase<PermutationMatrix> Base;
286
    typedef internal::traits<PermutationMatrix> Traits;
287
    typedef internal::traits<PermutationMatrix> Traits;
287
  public:
288
  public:
288
289
289
    #ifndef EIGEN_PARSED_BY_DOXYGEN
290
    #ifndef EIGEN_PARSED_BY_DOXYGEN
290
    typedef typename Traits::IndicesType IndicesType;
291
    typedef typename Traits::IndicesType IndicesType;
292
    typedef typename Traits::IndexType IndexType;
293
    typedef typename Traits::Index Index;
291
    #endif
294
    #endif
292
295
293
    inline PermutationMatrix()
296
    inline PermutationMatrix()
294
    {}
297
    {}
295
298
296
    /** Constructs an uninitialized permutation matrix of given size.
299
    /** Constructs an uninitialized permutation matrix of given size.
297
      */
300
      */
298
    inline PermutationMatrix(int size) : m_indices(size)
301
    inline PermutationMatrix(Index size) : m_indices(size)
299
    {}
302
    {}
300
303
301
    /** Copy constructor. */
304
    /** Copy constructor. */
302
    template<typename OtherDerived>
305
    template<typename OtherDerived>
303
    inline PermutationMatrix(const PermutationBase<OtherDerived>& other)
306
    inline PermutationMatrix(const PermutationBase<OtherDerived>& other)
304
      : m_indices(other.indices()) {}
307
      : m_indices(other.indices()) {}
305
308
306
    #ifndef EIGEN_PARSED_BY_DOXYGEN
309
    #ifndef EIGEN_PARSED_BY_DOXYGEN
Lines 379-421 class PermutationMatrix : public Permuta Link Here
379
382
380
  protected:
383
  protected:
381
384
382
    IndicesType m_indices;
385
    IndicesType m_indices;
383
};
386
};
384
387
385
388
386
namespace internal {
389
namespace internal {
387
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess>
390
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType, int _PacketAccess>
388
struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess> >
391
struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _IndexType>,_PacketAccess> >
389
 : traits<Matrix<IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
392
 : traits<Matrix<_IndexType,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
390
{
393
{
391
  typedef IndexType Index;
394
  typedef Map<const Matrix<_IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType;
392
  typedef Map<const Matrix<IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType;
395
  typedef typename IndicesType::Index Index;
396
  typedef _IndexType IndexType;
393
};
397
};
394
}
398
}
395
399
396
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess>
400
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType, int _PacketAccess>
397
class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess>
401
class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _IndexType>,_PacketAccess>
398
  : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, IndexType>,_PacketAccess> >
402
  : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _IndexType>,_PacketAccess> >
399
{
403
{
400
    typedef PermutationBase<Map> Base;
404
    typedef PermutationBase<Map> Base;
401
    typedef internal::traits<Map> Traits;
405
    typedef internal::traits<Map> Traits;
402
  public:
406
  public:
403
407
404
    #ifndef EIGEN_PARSED_BY_DOXYGEN
408
    #ifndef EIGEN_PARSED_BY_DOXYGEN
405
    typedef typename Traits::IndicesType IndicesType;
409
    typedef typename Traits::IndicesType IndicesType;
406
    typedef typename IndicesType::Scalar Index;
410
    typedef typename IndicesType::Scalar IndexType;
411
    typedef typename IndicesType::Index  Index;
407
    #endif
412
    #endif
408
413
409
    inline Map(const Index* indicesPtr)
414
    inline Map(const IndexType* indicesPtr)
410
      : m_indices(indicesPtr)
415
      : m_indices(indicesPtr)
411
    {}
416
    {}
412
417
413
    inline Map(const Index* indicesPtr, Index size)
418
    inline Map(const IndexType* indicesPtr, Index size)
414
      : m_indices(indicesPtr,size)
419
      : m_indices(indicesPtr,size)
415
    {}
420
    {}
416
421
417
    /** Copies the other permutation into *this */
422
    /** Copies the other permutation into *this */
418
    template<typename Other>
423
    template<typename Other>
419
    Map& operator=(const PermutationBase<Other>& other)
424
    Map& operator=(const PermutationBase<Other>& other)
420
    { return Base::operator=(other.derived()); }
425
    { return Base::operator=(other.derived()); }
421
426
Lines 461-477 struct PermutationStorage {}; Link Here
461
466
462
template<typename _IndicesType> class TranspositionsWrapper;
467
template<typename _IndicesType> class TranspositionsWrapper;
463
namespace internal {
468
namespace internal {
464
template<typename _IndicesType>
469
template<typename _IndicesType>
465
struct traits<PermutationWrapper<_IndicesType> >
470
struct traits<PermutationWrapper<_IndicesType> >
466
{
471
{
467
  typedef PermutationStorage StorageKind;
472
  typedef PermutationStorage StorageKind;
468
  typedef typename _IndicesType::Scalar Scalar;
473
  typedef typename _IndicesType::Scalar Scalar;
469
  typedef typename _IndicesType::Scalar Index;
474
  typedef typename _IndicesType::Scalar IndexType;
475
  typedef typename _IndicesType::Index Index;
470
  typedef _IndicesType IndicesType;
476
  typedef _IndicesType IndicesType;
471
  enum {
477
  enum {
472
    RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
478
    RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
473
    ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
479
    ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
474
    MaxRowsAtCompileTime = IndicesType::MaxRowsAtCompileTime,
480
    MaxRowsAtCompileTime = IndicesType::MaxRowsAtCompileTime,
475
    MaxColsAtCompileTime = IndicesType::MaxColsAtCompileTime,
481
    MaxColsAtCompileTime = IndicesType::MaxColsAtCompileTime,
476
    Flags = 0,
482
    Flags = 0,
477
    CoeffReadCost = _IndicesType::CoeffReadCost
483
    CoeffReadCost = _IndicesType::CoeffReadCost
(-)a/Eigen/src/Core/Transpositions.h (-34 / +43 lines)
Lines 48-64 template<typename TranspositionType, typ Link Here
48
template<typename Derived>
48
template<typename Derived>
49
class TranspositionsBase
49
class TranspositionsBase
50
{
50
{
51
    typedef internal::traits<Derived> Traits;
51
    typedef internal::traits<Derived> Traits;
52
    
52
    
53
  public:
53
  public:
54
54
55
    typedef typename Traits::IndicesType IndicesType;
55
    typedef typename Traits::IndicesType IndicesType;
56
    typedef typename IndicesType::Scalar Index;
56
    typedef typename IndicesType::Scalar IndexType;
57
    typedef typename IndicesType::Index  Index;
57
58
58
    Derived& derived() { return *static_cast<Derived*>(this); }
59
    Derived& derived() { return *static_cast<Derived*>(this); }
59
    const Derived& derived() const { return *static_cast<const Derived*>(this); }
60
    const Derived& derived() const { return *static_cast<const Derived*>(this); }
60
61
61
    /** Copies the \a other transpositions into \c *this */
62
    /** Copies the \a other transpositions into \c *this */
62
    template<typename OtherDerived>
63
    template<typename OtherDerived>
63
    Derived& operator=(const TranspositionsBase<OtherDerived>& other)
64
    Derived& operator=(const TranspositionsBase<OtherDerived>& other)
64
    {
65
    {
Lines 76-118 class TranspositionsBase Link Here
76
      return derived();
77
      return derived();
77
    }
78
    }
78
    #endif
79
    #endif
79
80
80
    /** \returns the number of transpositions */
81
    /** \returns the number of transpositions */
81
    inline Index size() const { return indices().size(); }
82
    inline Index size() const { return indices().size(); }
82
83
83
    /** Direct access to the underlying index vector */
84
    /** Direct access to the underlying index vector */
84
    inline const Index& coeff(Index i) const { return indices().coeff(i); }
85
    inline const IndexType& coeff(Index i) const { return indices().coeff(i); }
85
    /** Direct access to the underlying index vector */
86
    /** Direct access to the underlying index vector */
86
    inline Index& coeffRef(Index i) { return indices().coeffRef(i); }
87
    inline IndexType& coeffRef(Index i) { return indices().coeffRef(i); }
87
    /** Direct access to the underlying index vector */
88
    /** Direct access to the underlying index vector */
88
    inline const Index& operator()(Index i) const { return indices()(i); }
89
    inline const IndexType& operator()(Index i) const { return indices()(i); }
89
    /** Direct access to the underlying index vector */
90
    /** Direct access to the underlying index vector */
90
    inline Index& operator()(Index i) { return indices()(i); }
91
    inline IndexType& operator()(Index i) { return indices()(i); }
91
    /** Direct access to the underlying index vector */
92
    /** Direct access to the underlying index vector */
92
    inline const Index& operator[](Index i) const { return indices()(i); }
93
    inline const IndexType& operator[](Index i) const { return indices()(i); }
93
    /** Direct access to the underlying index vector */
94
    /** Direct access to the underlying index vector */
94
    inline Index& operator[](Index i) { return indices()(i); }
95
    inline IndexType& operator[](Index i) { return indices()(i); }
95
96
96
    /** const version of indices(). */
97
    /** const version of indices(). */
97
    const IndicesType& indices() const { return derived().indices(); }
98
    const IndicesType& indices() const { return derived().indices(); }
98
    /** \returns a reference to the stored array representing the transpositions. */
99
    /** \returns a reference to the stored array representing the transpositions. */
99
    IndicesType& indices() { return derived().indices(); }
100
    IndicesType& indices() { return derived().indices(); }
100
101
101
    /** Resizes to given size. */
102
    /** Resizes to given size. */
102
    inline void resize(int newSize)
103
    inline void resize(Index newSize)
103
    {
104
    {
104
      indices().resize(newSize);
105
      indices().resize(newSize);
105
    }
106
    }
106
107
107
    /** Sets \c *this to represents an identity transformation */
108
    /** Sets \c *this to represents an identity transformation */
108
    void setIdentity()
109
    void setIdentity()
109
    {
110
    {
110
      for(int i = 0; i < indices().size(); ++i)
111
      for(IndexType i = 0; i < indices().size(); ++i)
111
        coeffRef(i) = i;
112
        coeffRef(i) = i;
112
    }
113
    }
113
114
114
    // FIXME: do we want such methods ?
115
    // FIXME: do we want such methods ?
115
    // might be usefull when the target matrix expression is complex, e.g.:
116
    // might be usefull when the target matrix expression is complex, e.g.:
116
    // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
117
    // object.matrix().block(..,..,..,..) = trans * object.matrix().block(..,..,..,..);
117
    /*
118
    /*
118
    template<typename MatrixType>
119
    template<typename MatrixType>
Lines 139-171 class TranspositionsBase Link Here
139
    /** \returns the tranpose transformation */
140
    /** \returns the tranpose transformation */
140
    inline Transpose<TranspositionsBase> transpose() const
141
    inline Transpose<TranspositionsBase> transpose() const
141
    { return Transpose<TranspositionsBase>(derived()); }
142
    { return Transpose<TranspositionsBase>(derived()); }
142
143
143
  protected:
144
  protected:
144
};
145
};
145
146
146
namespace internal {
147
namespace internal {
147
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType>
148
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType>
148
struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> >
149
struct traits<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType> >
149
{
150
{
150
  typedef IndexType Index;
151
  typedef Matrix<_IndexType, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
151
  typedef Matrix<Index, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
152
  typedef typename IndicesType::Index Index;
153
  typedef _IndexType IndexType;
152
};
154
};
153
}
155
}
154
156
155
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType>
157
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType>
156
class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType> >
158
class Transpositions : public TranspositionsBase<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType> >
157
{
159
{
158
    typedef internal::traits<Transpositions> Traits;
160
    typedef internal::traits<Transpositions> Traits;
159
  public:
161
  public:
160
162
161
    typedef TranspositionsBase<Transpositions> Base;
163
    typedef TranspositionsBase<Transpositions> Base;
162
    typedef typename Traits::IndicesType IndicesType;
164
    typedef typename Traits::IndicesType IndicesType;
163
    typedef typename IndicesType::Scalar Index;
165
    typedef typename IndicesType::Scalar IndexType;
166
    typedef typename IndicesType::Index  Index;
167
    
164
168
165
    inline Transpositions() {}
169
    inline Transpositions() {}
166
170
167
    /** Copy constructor. */
171
    /** Copy constructor. */
168
    template<typename OtherDerived>
172
    template<typename OtherDerived>
169
    inline Transpositions(const TranspositionsBase<OtherDerived>& other)
173
    inline Transpositions(const TranspositionsBase<OtherDerived>& other)
170
      : m_indices(other.indices()) {}
174
      : m_indices(other.indices()) {}
171
175
Lines 210-249 class Transpositions : public Transposit Link Here
210
214
211
  protected:
215
  protected:
212
216
213
    IndicesType m_indices;
217
    IndicesType m_indices;
214
};
218
};
215
219
216
220
217
namespace internal {
221
namespace internal {
218
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int _PacketAccess>
222
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType, int _PacketAccess>
219
struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,_PacketAccess> >
223
struct traits<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType>,_PacketAccess> >
220
{
224
{
221
  typedef IndexType Index;
225
  typedef Map<const Matrix<_IndexType,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType;
222
  typedef Map<const Matrix<Index,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1>, _PacketAccess> IndicesType;
226
  typedef typename IndicesType::Index Index;
227
  typedef _IndexType IndexType;
223
};
228
};
224
}
229
}
225
230
226
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename IndexType, int PacketAccess>
231
template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _IndexType, int PacketAccess>
227
class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess>
232
class Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType>,PacketAccess>
228
 : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,IndexType>,PacketAccess> >
233
 : public TranspositionsBase<Map<Transpositions<SizeAtCompileTime,MaxSizeAtCompileTime,_IndexType>,PacketAccess> >
229
{
234
{
230
    typedef internal::traits<Map> Traits;
235
    typedef internal::traits<Map> Traits;
231
  public:
236
  public:
232
237
233
    typedef TranspositionsBase<Map> Base;
238
    typedef TranspositionsBase<Map> Base;
234
    typedef typename Traits::IndicesType IndicesType;
239
    typedef typename Traits::IndicesType IndicesType;
235
    typedef typename IndicesType::Scalar Index;
240
    typedef typename IndicesType::Scalar IndexType;
241
    typedef typename IndicesType::Index  Index;
236
242
237
    inline Map(const Index* indicesPtr)
243
    inline Map(const IndexType* indicesPtr)
238
      : m_indices(indicesPtr)
244
      : m_indices(indicesPtr)
239
    {}
245
    {}
240
246
241
    inline Map(const Index* indicesPtr, Index size)
247
    inline Map(const IndexType* indicesPtr, Index size)
242
      : m_indices(indicesPtr,size)
248
      : m_indices(indicesPtr,size)
243
    {}
249
    {}
244
250
245
    /** Copies the \a other transpositions into \c *this */
251
    /** Copies the \a other transpositions into \c *this */
246
    template<typename OtherDerived>
252
    template<typename OtherDerived>
247
    Map& operator=(const TranspositionsBase<OtherDerived>& other)
253
    Map& operator=(const TranspositionsBase<OtherDerived>& other)
248
    {
254
    {
249
      return Base::operator=(other);
255
      return Base::operator=(other);
Lines 270-300 class Map<Transpositions<SizeAtCompileTi Link Here
270
276
271
    IndicesType m_indices;
277
    IndicesType m_indices;
272
};
278
};
273
279
274
namespace internal {
280
namespace internal {
275
template<typename _IndicesType>
281
template<typename _IndicesType>
276
struct traits<TranspositionsWrapper<_IndicesType> >
282
struct traits<TranspositionsWrapper<_IndicesType> >
277
{
283
{
278
  typedef typename _IndicesType::Scalar Index;
284
  typedef typename _IndicesType::Scalar IndexType;
285
  typedef typename _IndicesType::Index Index;
279
  typedef _IndicesType IndicesType;
286
  typedef _IndicesType IndicesType;
280
};
287
};
281
}
288
}
282
289
283
template<typename _IndicesType>
290
template<typename _IndicesType>
284
class TranspositionsWrapper
291
class TranspositionsWrapper
285
 : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
292
 : public TranspositionsBase<TranspositionsWrapper<_IndicesType> >
286
{
293
{
287
    typedef internal::traits<TranspositionsWrapper> Traits;
294
    typedef internal::traits<TranspositionsWrapper> Traits;
288
  public:
295
  public:
289
296
290
    typedef TranspositionsBase<TranspositionsWrapper> Base;
297
    typedef TranspositionsBase<TranspositionsWrapper> Base;
291
    typedef typename Traits::IndicesType IndicesType;
298
    typedef typename Traits::IndicesType IndicesType;
292
    typedef typename IndicesType::Scalar Index;
299
    typedef typename IndicesType::Scalar IndexType;
300
    typedef typename IndicesType::Index  Index;
293
301
294
    inline TranspositionsWrapper(IndicesType& a_indices)
302
    inline TranspositionsWrapper(IndicesType& a_indices)
295
      : m_indices(a_indices)
303
      : m_indices(a_indices)
296
    {}
304
    {}
297
305
298
    /** Copies the \a other transpositions into \c *this */
306
    /** Copies the \a other transpositions into \c *this */
299
    template<typename OtherDerived>
307
    template<typename OtherDerived>
300
    TranspositionsWrapper& operator=(const TranspositionsBase<OtherDerived>& other)
308
    TranspositionsWrapper& operator=(const TranspositionsBase<OtherDerived>& other)
Lines 358-391 struct traits<transposition_matrix_produ Link Here
358
};
366
};
359
367
360
template<typename TranspositionType, typename MatrixType, int Side, bool Transposed>
368
template<typename TranspositionType, typename MatrixType, int Side, bool Transposed>
361
struct transposition_matrix_product_retval
369
struct transposition_matrix_product_retval
362
 : public ReturnByValue<transposition_matrix_product_retval<TranspositionType, MatrixType, Side, Transposed> >
370
 : public ReturnByValue<transposition_matrix_product_retval<TranspositionType, MatrixType, Side, Transposed> >
363
{
371
{
364
    typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned;
372
    typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned;
365
    typedef typename TranspositionType::Index Index;
373
    typedef typename TranspositionType::Index Index;
374
    typedef typename TranspositionType::IndexType IndexType;
366
375
367
    transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix)
376
    transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix)
368
      : m_transpositions(tr), m_matrix(matrix)
377
      : m_transpositions(tr), m_matrix(matrix)
369
    {}
378
    {}
370
379
371
    inline int rows() const { return m_matrix.rows(); }
380
    inline Index rows() const { return m_matrix.rows(); }
372
    inline int cols() const { return m_matrix.cols(); }
381
    inline Index cols() const { return m_matrix.cols(); }
373
382
374
    template<typename Dest> inline void evalTo(Dest& dst) const
383
    template<typename Dest> inline void evalTo(Dest& dst) const
375
    {
384
    {
376
      const int size = m_transpositions.size();
385
      const Index size = m_transpositions.size();
377
      Index j = 0;
386
      IndexType j = 0;
378
387
379
      if(!(is_same<MatrixTypeNestedCleaned,Dest>::value && extract_data(dst) == extract_data(m_matrix)))
388
      if(!(is_same<MatrixTypeNestedCleaned,Dest>::value && extract_data(dst) == extract_data(m_matrix)))
380
        dst = m_matrix;
389
        dst = m_matrix;
381
390
382
      for(int k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
391
      for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
383
        if((j=m_transpositions.coeff(k))!=k)
392
        if(Index(j=m_transpositions.coeff(k))!=k)
384
        {
393
        {
385
          if(Side==OnTheLeft)
394
          if(Side==OnTheLeft)
386
            dst.row(k).swap(dst.row(j));
395
            dst.row(k).swap(dst.row(j));
387
          else if(Side==OnTheRight)
396
          else if(Side==OnTheRight)
388
            dst.col(k).swap(dst.col(j));
397
            dst.col(k).swap(dst.col(j));
389
        }
398
        }
390
    }
399
    }
391
400
(-)a/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h (-1 / +1 lines)
Lines 26-42 namespace internal { Link Here
26
  **/ 
26
  **/ 
27
template <typename VectorV, typename VectorI, typename Index>
27
template <typename VectorV, typename VectorI, typename Index>
28
Index QuickSplit(VectorV &row, VectorI &ind, Index ncut)
28
Index QuickSplit(VectorV &row, VectorI &ind, Index ncut)
29
{
29
{
30
  typedef typename VectorV::RealScalar RealScalar;
30
  typedef typename VectorV::RealScalar RealScalar;
31
  using std::swap;
31
  using std::swap;
32
  using std::abs;
32
  using std::abs;
33
  Index mid;
33
  Index mid;
34
  Index n = row.size(); /* length of the vector */
34
  Index n = Index(row.size()); /* length of the vector */
35
  Index first, last ;
35
  Index first, last ;
36
  
36
  
37
  ncut--; /* to fit the zero-based indices */
37
  ncut--; /* to fit the zero-based indices */
38
  first = 0; 
38
  first = 0; 
39
  last = n-1; 
39
  last = n-1; 
40
  if (ncut < first || ncut > last ) return 0;
40
  if (ncut < first || ncut > last ) return 0;
41
  
41
  
42
  do {
42
  do {
(-)a/Eigen/src/LU/PartialPivLU.h (-3 / +3 lines)
Lines 366-388 struct partial_lu_impl Link Here
366
    }
366
    }
367
    return first_zero_pivot;
367
    return first_zero_pivot;
368
  }
368
  }
369
};
369
};
370
370
371
/** \internal performs the LU decomposition with partial pivoting in-place.
371
/** \internal performs the LU decomposition with partial pivoting in-place.
372
  */
372
  */
373
template<typename MatrixType, typename TranspositionType>
373
template<typename MatrixType, typename TranspositionType>
374
void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::Index& nb_transpositions)
374
void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::IndexType& nb_transpositions)
375
{
375
{
376
  eigen_assert(lu.cols() == row_transpositions.size());
376
  eigen_assert(lu.cols() == row_transpositions.size());
377
  eigen_assert((&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1);
377
  eigen_assert((&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1);
378
378
379
  partial_lu_impl
379
  partial_lu_impl
380
    <typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor, typename TranspositionType::Index>
380
    <typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor, typename TranspositionType::IndexType>
381
    ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions);
381
    ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions);
382
}
382
}
383
383
384
} // end namespace internal
384
} // end namespace internal
385
385
386
template<typename MatrixType>
386
template<typename MatrixType>
387
PartialPivLU<MatrixType>& PartialPivLU<MatrixType>::compute(const MatrixType& matrix)
387
PartialPivLU<MatrixType>& PartialPivLU<MatrixType>::compute(const MatrixType& matrix)
388
{
388
{
Lines 391-407 PartialPivLU<MatrixType>& PartialPivLU<M Link Here
391
  
391
  
392
  m_lu = matrix;
392
  m_lu = matrix;
393
393
394
  eigen_assert(matrix.rows() == matrix.cols() && "PartialPivLU is only for square (and moreover invertible) matrices");
394
  eigen_assert(matrix.rows() == matrix.cols() && "PartialPivLU is only for square (and moreover invertible) matrices");
395
  const Index size = matrix.rows();
395
  const Index size = matrix.rows();
396
396
397
  m_rowsTranspositions.resize(size);
397
  m_rowsTranspositions.resize(size);
398
398
399
  typename TranspositionType::Index nb_transpositions;
399
  typename TranspositionType::IndexType nb_transpositions;
400
  internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
400
  internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
401
  m_det_p = (nb_transpositions%2) ? -1 : 1;
401
  m_det_p = (nb_transpositions%2) ? -1 : 1;
402
402
403
  m_p = m_rowsTranspositions;
403
  m_p = m_rowsTranspositions;
404
404
405
  m_isInitialized = true;
405
  m_isInitialized = true;
406
  return *this;
406
  return *this;
407
}
407
}
(-)a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h (-6 / +5 lines)
Lines 64-80 class CwiseBinaryOpImpl<BinaryOp, Lhs, R Link Here
64
    }
64
    }
65
};
65
};
66
66
67
template<typename BinaryOp, typename Lhs, typename Rhs>
67
template<typename BinaryOp, typename Lhs, typename Rhs>
68
class CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator
68
class CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator
69
  : public internal::sparse_cwise_binary_op_inner_iterator_selector<BinaryOp,Lhs,Rhs,typename CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator>
69
  : public internal::sparse_cwise_binary_op_inner_iterator_selector<BinaryOp,Lhs,Rhs,typename CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Sparse>::InnerIterator>
70
{
70
{
71
  public:
71
  public:
72
    typedef typename Lhs::Index Index;
73
    typedef internal::sparse_cwise_binary_op_inner_iterator_selector<
72
    typedef internal::sparse_cwise_binary_op_inner_iterator_selector<
74
      BinaryOp,Lhs,Rhs, InnerIterator> Base;
73
      BinaryOp,Lhs,Rhs, InnerIterator> Base;
75
74
76
    EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, Index outer)
75
    EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, Index outer)
77
      : Base(binOp.derived(),outer)
76
      : Base(binOp.derived(),outer)
78
    {}
77
    {}
79
};
78
};
80
79
Lines 90-110 class CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs Link Here
90
namespace internal {
89
namespace internal {
91
90
92
// sparse - sparse  (generic)
91
// sparse - sparse  (generic)
93
template<typename BinaryOp, typename Lhs, typename Rhs, typename Derived>
92
template<typename BinaryOp, typename Lhs, typename Rhs, typename Derived>
94
class sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Derived, Sparse, Sparse>
93
class sparse_cwise_binary_op_inner_iterator_selector<BinaryOp, Lhs, Rhs, Derived, Sparse, Sparse>
95
{
94
{
96
    typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> CwiseBinaryXpr;
95
    typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> CwiseBinaryXpr;
97
    typedef typename traits<CwiseBinaryXpr>::Scalar Scalar;
96
    typedef typename traits<CwiseBinaryXpr>::Scalar Scalar;
97
    typedef typename traits<CwiseBinaryXpr>::Index Index;
98
    typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested;
98
    typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested;
99
    typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested;
99
    typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested;
100
    typedef typename _LhsNested::InnerIterator LhsIterator;
100
    typedef typename _LhsNested::InnerIterator LhsIterator;
101
    typedef typename _RhsNested::InnerIterator RhsIterator;
101
    typedef typename _RhsNested::InnerIterator RhsIterator;
102
    typedef typename Lhs::Index Index;
103
102
104
  public:
103
  public:
105
104
106
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
105
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
107
      : m_lhsIter(xpr.lhs(),outer), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor())
106
      : m_lhsIter(xpr.lhs(),outer), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor())
108
    {
107
    {
109
      this->operator++();
108
      this->operator++();
110
    }
109
    }
Lines 156-176 class sparse_cwise_binary_op_inner_itera Link Here
156
155
157
// sparse - sparse  (product)
156
// sparse - sparse  (product)
158
template<typename T, typename Lhs, typename Rhs, typename Derived>
157
template<typename T, typename Lhs, typename Rhs, typename Derived>
159
class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, Rhs, Derived, Sparse, Sparse>
158
class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, Rhs, Derived, Sparse, Sparse>
160
{
159
{
161
    typedef scalar_product_op<T> BinaryFunc;
160
    typedef scalar_product_op<T> BinaryFunc;
162
    typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
161
    typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
163
    typedef typename CwiseBinaryXpr::Scalar Scalar;
162
    typedef typename CwiseBinaryXpr::Scalar Scalar;
163
    typedef typename CwiseBinaryXpr::Index Index;
164
    typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested;
164
    typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested;
165
    typedef typename _LhsNested::InnerIterator LhsIterator;
165
    typedef typename _LhsNested::InnerIterator LhsIterator;
166
    typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested;
166
    typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested;
167
    typedef typename _RhsNested::InnerIterator RhsIterator;
167
    typedef typename _RhsNested::InnerIterator RhsIterator;
168
    typedef typename Lhs::Index Index;
169
  public:
168
  public:
170
169
171
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
170
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
172
      : m_lhsIter(xpr.lhs(),outer), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor())
171
      : m_lhsIter(xpr.lhs(),outer), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor())
173
    {
172
    {
174
      while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index()))
173
      while (m_lhsIter && m_rhsIter && (m_lhsIter.index() != m_rhsIter.index()))
175
      {
174
      {
176
        if (m_lhsIter.index() < m_rhsIter.index())
175
        if (m_lhsIter.index() < m_rhsIter.index())
Lines 210-234 class sparse_cwise_binary_op_inner_itera Link Here
210
209
211
// sparse - dense  (product)
210
// sparse - dense  (product)
212
template<typename T, typename Lhs, typename Rhs, typename Derived>
211
template<typename T, typename Lhs, typename Rhs, typename Derived>
213
class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, Rhs, Derived, Sparse, Dense>
212
class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, Rhs, Derived, Sparse, Dense>
214
{
213
{
215
    typedef scalar_product_op<T> BinaryFunc;
214
    typedef scalar_product_op<T> BinaryFunc;
216
    typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
215
    typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
217
    typedef typename CwiseBinaryXpr::Scalar Scalar;
216
    typedef typename CwiseBinaryXpr::Scalar Scalar;
217
    typedef typename CwiseBinaryXpr::Index Index;
218
    typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested;
218
    typedef typename traits<CwiseBinaryXpr>::_LhsNested _LhsNested;
219
    typedef typename traits<CwiseBinaryXpr>::RhsNested RhsNested;
219
    typedef typename traits<CwiseBinaryXpr>::RhsNested RhsNested;
220
    typedef typename _LhsNested::InnerIterator LhsIterator;
220
    typedef typename _LhsNested::InnerIterator LhsIterator;
221
    typedef typename Lhs::Index Index;
222
    enum { IsRowMajor = (int(Lhs::Flags)&RowMajorBit)==RowMajorBit };
221
    enum { IsRowMajor = (int(Lhs::Flags)&RowMajorBit)==RowMajorBit };
223
  public:
222
  public:
224
223
225
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
224
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
226
      : m_rhs(xpr.rhs()), m_lhsIter(xpr.lhs(),outer), m_functor(xpr.functor()), m_outer(outer)
225
      : m_rhs(xpr.rhs()), m_lhsIter(xpr.lhs(),typename _LhsNested::Index(outer)), m_functor(xpr.functor()), m_outer(outer)
227
    {}
226
    {}
228
227
229
    EIGEN_STRONG_INLINE Derived& operator++()
228
    EIGEN_STRONG_INLINE Derived& operator++()
230
    {
229
    {
231
      ++m_lhsIter;
230
      ++m_lhsIter;
232
      return *static_cast<Derived*>(this);
231
      return *static_cast<Derived*>(this);
233
    }
232
    }
234
233
Lines 251-269 class sparse_cwise_binary_op_inner_itera Link Here
251
250
252
// sparse - dense  (product)
251
// sparse - dense  (product)
253
template<typename T, typename Lhs, typename Rhs, typename Derived>
252
template<typename T, typename Lhs, typename Rhs, typename Derived>
254
class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, Rhs, Derived, Dense, Sparse>
253
class sparse_cwise_binary_op_inner_iterator_selector<scalar_product_op<T>, Lhs, Rhs, Derived, Dense, Sparse>
255
{
254
{
256
    typedef scalar_product_op<T> BinaryFunc;
255
    typedef scalar_product_op<T> BinaryFunc;
257
    typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
256
    typedef CwiseBinaryOp<BinaryFunc, Lhs, Rhs> CwiseBinaryXpr;
258
    typedef typename CwiseBinaryXpr::Scalar Scalar;
257
    typedef typename CwiseBinaryXpr::Scalar Scalar;
258
    typedef typename CwiseBinaryXpr::Index Index;
259
    typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested;
259
    typedef typename traits<CwiseBinaryXpr>::_RhsNested _RhsNested;
260
    typedef typename _RhsNested::InnerIterator RhsIterator;
260
    typedef typename _RhsNested::InnerIterator RhsIterator;
261
    typedef typename Lhs::Index Index;
262
261
263
    enum { IsRowMajor = (int(Rhs::Flags)&RowMajorBit)==RowMajorBit };
262
    enum { IsRowMajor = (int(Rhs::Flags)&RowMajorBit)==RowMajorBit };
264
  public:
263
  public:
265
264
266
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
265
    EIGEN_STRONG_INLINE sparse_cwise_binary_op_inner_iterator_selector(const CwiseBinaryXpr& xpr, Index outer)
267
      : m_xpr(xpr), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor()), m_outer(outer)
266
      : m_xpr(xpr), m_rhsIter(xpr.rhs(),outer), m_functor(xpr.functor()), m_outer(outer)
268
    {}
267
    {}
269
268
(-)a/Eigen/src/SparseCore/SparseDenseProduct.h (-2 / +2 lines)
Lines 91-108 class SparseDenseOuterProduct Link Here
91
    }
91
    }
92
92
93
    EIGEN_STRONG_INLINE SparseDenseOuterProduct(const Rhs& rhs, const Lhs& lhs)
93
    EIGEN_STRONG_INLINE SparseDenseOuterProduct(const Rhs& rhs, const Lhs& lhs)
94
      : m_lhs(lhs), m_rhs(rhs)
94
      : m_lhs(lhs), m_rhs(rhs)
95
    {
95
    {
96
      EIGEN_STATIC_ASSERT(Tr,YOU_MADE_A_PROGRAMMING_MISTAKE);
96
      EIGEN_STATIC_ASSERT(Tr,YOU_MADE_A_PROGRAMMING_MISTAKE);
97
    }
97
    }
98
98
99
    EIGEN_STRONG_INLINE Index rows() const { return Tr ? m_rhs.rows() : m_lhs.rows(); }
99
    EIGEN_STRONG_INLINE Index rows() const { return Tr ? Index(m_rhs.rows()) : m_lhs.rows(); }
100
    EIGEN_STRONG_INLINE Index cols() const { return Tr ? m_lhs.cols() : m_rhs.cols(); }
100
    EIGEN_STRONG_INLINE Index cols() const { return Tr ? m_lhs.cols() : Index(m_rhs.cols()); }
101
101
102
    EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
102
    EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
103
    EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
103
    EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
104
104
105
  protected:
105
  protected:
106
    LhsNested m_lhs;
106
    LhsNested m_lhs;
107
    RhsNested m_rhs;
107
    RhsNested m_rhs;
108
};
108
};
(-)a/Eigen/src/SparseCore/SparseDiagonalProduct.h (-6 / +8 lines)
Lines 27-44 namespace Eigen { Link Here
27
namespace internal {
27
namespace internal {
28
28
29
template<typename Lhs, typename Rhs>
29
template<typename Lhs, typename Rhs>
30
struct traits<SparseDiagonalProduct<Lhs, Rhs> >
30
struct traits<SparseDiagonalProduct<Lhs, Rhs> >
31
{
31
{
32
  typedef typename remove_all<Lhs>::type _Lhs;
32
  typedef typename remove_all<Lhs>::type _Lhs;
33
  typedef typename remove_all<Rhs>::type _Rhs;
33
  typedef typename remove_all<Rhs>::type _Rhs;
34
  typedef typename _Lhs::Scalar Scalar;
34
  typedef typename _Lhs::Scalar Scalar;
35
  typedef typename promote_index_type<typename traits<Lhs>::Index,
35
  // propagate the index type of the sparse matrix
36
                                         typename traits<Rhs>::Index>::type Index;
36
  typedef typename conditional< is_diagonal<_Lhs>::ret,
37
                                typename traits<Rhs>::Index,
38
                                typename traits<Lhs>::Index>::type Index;
37
  typedef Sparse StorageKind;
39
  typedef Sparse StorageKind;
38
  typedef MatrixXpr XprKind;
40
  typedef MatrixXpr XprKind;
39
  enum {
41
  enum {
40
    RowsAtCompileTime = _Lhs::RowsAtCompileTime,
42
    RowsAtCompileTime = _Lhs::RowsAtCompileTime,
41
    ColsAtCompileTime = _Rhs::ColsAtCompileTime,
43
    ColsAtCompileTime = _Rhs::ColsAtCompileTime,
42
44
43
    MaxRowsAtCompileTime = _Lhs::MaxRowsAtCompileTime,
45
    MaxRowsAtCompileTime = _Lhs::MaxRowsAtCompileTime,
44
    MaxColsAtCompileTime = _Rhs::MaxColsAtCompileTime,
46
    MaxColsAtCompileTime = _Rhs::MaxColsAtCompileTime,
Lines 85-102 class SparseDiagonalProduct Link Here
85
    class ReverseInnerIterator;
87
    class ReverseInnerIterator;
86
88
87
    EIGEN_STRONG_INLINE SparseDiagonalProduct(const Lhs& lhs, const Rhs& rhs)
89
    EIGEN_STRONG_INLINE SparseDiagonalProduct(const Lhs& lhs, const Rhs& rhs)
88
      : m_lhs(lhs), m_rhs(rhs)
90
      : m_lhs(lhs), m_rhs(rhs)
89
    {
91
    {
90
      eigen_assert(lhs.cols() == rhs.rows() && "invalid sparse matrix * diagonal matrix product");
92
      eigen_assert(lhs.cols() == rhs.rows() && "invalid sparse matrix * diagonal matrix product");
91
    }
93
    }
92
94
93
    EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); }
95
    EIGEN_STRONG_INLINE Index rows() const { return Index(m_lhs.rows()); }
94
    EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); }
96
    EIGEN_STRONG_INLINE Index cols() const { return Index(m_rhs.cols()); }
95
97
96
    EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
98
    EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
97
    EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
99
    EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
98
100
99
  protected:
101
  protected:
100
    LhsNested m_lhs;
102
    LhsNested m_lhs;
101
    RhsNested m_rhs;
103
    RhsNested m_rhs;
102
};
104
};
Lines 104-120 class SparseDiagonalProduct Link Here
104
namespace internal {
106
namespace internal {
105
107
106
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType>
108
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType>
107
class sparse_diagonal_product_inner_iterator_selector
109
class sparse_diagonal_product_inner_iterator_selector
108
<Lhs,Rhs,SparseDiagonalProductType,SDP_IsDiagonal,SDP_IsSparseRowMajor>
110
<Lhs,Rhs,SparseDiagonalProductType,SDP_IsDiagonal,SDP_IsSparseRowMajor>
109
  : public CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator
111
  : public CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator
110
{
112
{
111
    typedef typename CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator Base;
113
    typedef typename CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator Base;
112
    typedef typename Lhs::Index Index;
114
    typedef typename Rhs::Index Index;
113
  public:
115
  public:
114
    inline sparse_diagonal_product_inner_iterator_selector(
116
    inline sparse_diagonal_product_inner_iterator_selector(
115
              const SparseDiagonalProductType& expr, Index outer)
117
              const SparseDiagonalProductType& expr, Index outer)
116
      : Base(expr.rhs()*(expr.lhs().diagonal().coeff(outer)), outer)
118
      : Base(expr.rhs()*(expr.lhs().diagonal().coeff(outer)), outer)
117
    {}
119
    {}
118
};
120
};
119
121
120
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType>
122
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType>
Lines 124-140 class sparse_diagonal_product_inner_iter Link Here
124
      scalar_product_op<typename Lhs::Scalar>,
126
      scalar_product_op<typename Lhs::Scalar>,
125
      const typename Rhs::ConstInnerVectorReturnType,
127
      const typename Rhs::ConstInnerVectorReturnType,
126
      const typename Lhs::DiagonalVectorType>::InnerIterator
128
      const typename Lhs::DiagonalVectorType>::InnerIterator
127
{
129
{
128
    typedef typename CwiseBinaryOp<
130
    typedef typename CwiseBinaryOp<
129
      scalar_product_op<typename Lhs::Scalar>,
131
      scalar_product_op<typename Lhs::Scalar>,
130
      const typename Rhs::ConstInnerVectorReturnType,
132
      const typename Rhs::ConstInnerVectorReturnType,
131
      const typename Lhs::DiagonalVectorType>::InnerIterator Base;
133
      const typename Lhs::DiagonalVectorType>::InnerIterator Base;
132
    typedef typename Lhs::Index Index;
134
    typedef typename Rhs::Index Index;
133
    Index m_outer;
135
    Index m_outer;
134
  public:
136
  public:
135
    inline sparse_diagonal_product_inner_iterator_selector(
137
    inline sparse_diagonal_product_inner_iterator_selector(
136
              const SparseDiagonalProductType& expr, Index outer)
138
              const SparseDiagonalProductType& expr, Index outer)
137
      : Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0), m_outer(outer)
139
      : Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0), m_outer(outer)
138
    {}
140
    {}
139
    
141
    
140
    inline Index outer() const { return m_outer; }
142
    inline Index outer() const { return m_outer; }
(-)a/Eigen/src/SparseCore/SparseMatrix.h (-2 / +4 lines)
Lines 795-811 class SparseMatrix Link Here
795
#     include EIGEN_SPARSEMATRIX_PLUGIN
795
#     include EIGEN_SPARSEMATRIX_PLUGIN
796
#   endif
796
#   endif
797
797
798
protected:
798
protected:
799
799
800
    template<typename Other>
800
    template<typename Other>
801
    void initAssignment(const Other& other)
801
    void initAssignment(const Other& other)
802
    {
802
    {
803
      resize(other.rows(), other.cols());
803
      eigen_assert(     other.rows() == typename Other::Index(Index(other.rows()))
804
                    &&  other.cols() == typename Other::Index(Index(other.cols())) );
805
      resize(Index(other.rows()), Index(other.cols()));
804
      if(m_innerNonZeros)
806
      if(m_innerNonZeros)
805
      {
807
      {
806
        std::free(m_innerNonZeros);
808
        std::free(m_innerNonZeros);
807
        m_innerNonZeros = 0;
809
        m_innerNonZeros = 0;
808
      }
810
      }
809
    }
811
    }
810
812
811
    /** \internal
813
    /** \internal
Lines 935-951 namespace internal { Link Here
935
937
936
template<typename InputIterator, typename SparseMatrixType>
938
template<typename InputIterator, typename SparseMatrixType>
937
void set_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat, int Options = 0)
939
void set_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat, int Options = 0)
938
{
940
{
939
  EIGEN_UNUSED_VARIABLE(Options);
941
  EIGEN_UNUSED_VARIABLE(Options);
940
  enum { IsRowMajor = SparseMatrixType::IsRowMajor };
942
  enum { IsRowMajor = SparseMatrixType::IsRowMajor };
941
  typedef typename SparseMatrixType::Scalar Scalar;
943
  typedef typename SparseMatrixType::Scalar Scalar;
942
  typedef typename SparseMatrixType::Index Index;
944
  typedef typename SparseMatrixType::Index Index;
943
  SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor> trMat(mat.rows(),mat.cols());
945
  SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor,Index> trMat(mat.rows(),mat.cols());
944
946
945
  if(begin!=end)
947
  if(begin!=end)
946
  {
948
  {
947
    // pass 1: count the nnz per inner-vector
949
    // pass 1: count the nnz per inner-vector
948
    Matrix<Index,Dynamic,1> wi(trMat.outerSize());
950
    Matrix<Index,Dynamic,1> wi(trMat.outerSize());
949
    wi.setZero();
951
    wi.setZero();
950
    for(InputIterator it(begin); it!=end; ++it)
952
    for(InputIterator it(begin); it!=end; ++it)
951
    {
953
    {
(-)a/Eigen/src/SparseCore/SparseMatrixBase.h (-9 / +9 lines)
Lines 197-226 template<typename Derived> class SparseM Link Here
197
    }
197
    }
198
198
199
  protected:
199
  protected:
200
200
201
    template<typename OtherDerived>
201
    template<typename OtherDerived>
202
    inline Derived& assign(const OtherDerived& other)
202
    inline Derived& assign(const OtherDerived& other)
203
    {
203
    {
204
      const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
204
      const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
205
      const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols();
205
      const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? Index(other.rows()) : Index(other.cols());
206
      if ((!transpose) && other.isRValue())
206
      if ((!transpose) && other.isRValue())
207
      {
207
      {
208
        // eval without temporary
208
        // eval without temporary
209
        derived().resize(other.rows(), other.cols());
209
        derived().resize(Index(other.rows()), Index(other.cols()));
210
        derived().setZero();
210
        derived().setZero();
211
        derived().reserve((std::max)(this->rows(),this->cols())*2);
211
        derived().reserve((std::max)(this->rows(),this->cols())*2);
212
        for (Index j=0; j<outerSize; ++j)
212
        for (Index j=0; j<outerSize; ++j)
213
        {
213
        {
214
          derived().startVec(j);
214
          derived().startVec(j);
215
          for (typename OtherDerived::InnerIterator it(other, j); it; ++it)
215
          for (typename OtherDerived::InnerIterator it(other, typename OtherDerived::Index(j)); it; ++it)
216
          {
216
          {
217
            Scalar v = it.value();
217
            Scalar v = it.value();
218
            derived().insertBackByOuterInner(j,it.index()) = v;
218
            derived().insertBackByOuterInner(j,Index(it.index())) = v;
219
          }
219
          }
220
        }
220
        }
221
        derived().finalize();
221
        derived().finalize();
222
      }
222
      }
223
      else
223
      else
224
      {
224
      {
225
        assignGeneric(other);
225
        assignGeneric(other);
226
      }
226
      }
Lines 232-260 template<typename Derived> class SparseM Link Here
232
    {
232
    {
233
      //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
233
      //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
234
      eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
234
      eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) ||
235
                  (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) &&
235
                  (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) &&
236
                  "the transpose operation is supposed to be handled in SparseMatrix::operator=");
236
                  "the transpose operation is supposed to be handled in SparseMatrix::operator=");
237
237
238
      enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) };
238
      enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) };
239
239
240
      const Index outerSize = other.outerSize();
240
      const Index outerSize = Index(other.outerSize());
241
      //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType;
241
      //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType;
242
      // thanks to shallow copies, we always eval to a tempary
242
      // thanks to shallow copies, we always eval to a tempary
243
      Derived temp(other.rows(), other.cols());
243
      Derived temp(Index(other.rows()), Index(other.cols()));
244
244
245
      temp.reserve((std::max)(this->rows(),this->cols())*2);
245
      temp.reserve((std::max)(this->rows(),this->cols())*2);
246
      for (Index j=0; j<outerSize; ++j)
246
      for (Index j=0; j<outerSize; ++j)
247
      {
247
      {
248
        temp.startVec(j);
248
        temp.startVec(j);
249
        for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it)
249
        for (typename OtherDerived::InnerIterator it(other.derived(), typename OtherDerived::Index(j)); it; ++it)
250
        {
250
        {
251
          Scalar v = it.value();
251
          Scalar v = it.value();
252
          temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v;
252
          temp.insertBackByOuterInner(Flip?Index(it.index()):j,Flip?j:Index(it.index())) = v;
253
        }
253
        }
254
      }
254
      }
255
      temp.finalize();
255
      temp.finalize();
256
256
257
      derived() = temp.markAsRValue();
257
      derived() = temp.markAsRValue();
258
    }
258
    }
259
259
260
  public:
260
  public:
Lines 396-412 template<typename Derived> class SparseM Link Here
396
    const Block<const Derived,Dynamic,Dynamic,true> innerVectors(Index outerStart, Index outerSize) const;
396
    const Block<const Derived,Dynamic,Dynamic,true> innerVectors(Index outerStart, Index outerSize) const;
397
397
398
    /** \internal use operator= */
398
    /** \internal use operator= */
399
    template<typename DenseDerived>
399
    template<typename DenseDerived>
400
    void evalTo(MatrixBase<DenseDerived>& dst) const
400
    void evalTo(MatrixBase<DenseDerived>& dst) const
401
    {
401
    {
402
      dst.setZero();
402
      dst.setZero();
403
      for (Index j=0; j<outerSize(); ++j)
403
      for (Index j=0; j<outerSize(); ++j)
404
        for (typename Derived::InnerIterator i(derived(),j); i; ++i)
404
        for (typename Derived::InnerIterator i(derived(),typename Derived::Index(j)); i; ++i)
405
          dst.coeffRef(i.row(),i.col()) = i.value();
405
          dst.coeffRef(i.row(),i.col()) = i.value();
406
    }
406
    }
407
407
408
    Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> toDense() const
408
    Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> toDense() const
409
    {
409
    {
410
      return derived();
410
      return derived();
411
    }
411
    }
412
412
(-)a/Eigen/src/SparseCore/SparseSelfAdjointView.h (-1 / +1 lines)
Lines 241-257 class SparseSelfAdjointTimeDenseProduct Link Here
241
      enum {
241
      enum {
242
        LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit,
242
        LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit,
243
        ProcessFirstHalf =
243
        ProcessFirstHalf =
244
                 ((UpLo&(Upper|Lower))==(Upper|Lower))
244
                 ((UpLo&(Upper|Lower))==(Upper|Lower))
245
              || ( (UpLo&Upper) && !LhsIsRowMajor)
245
              || ( (UpLo&Upper) && !LhsIsRowMajor)
246
              || ( (UpLo&Lower) && LhsIsRowMajor),
246
              || ( (UpLo&Lower) && LhsIsRowMajor),
247
        ProcessSecondHalf = !ProcessFirstHalf
247
        ProcessSecondHalf = !ProcessFirstHalf
248
      };
248
      };
249
      for (Index j=0; j<m_lhs.outerSize(); ++j)
249
      for (typename _Lhs::Index j=0; j<m_lhs.outerSize(); ++j)
250
      {
250
      {
251
        LhsInnerIterator i(m_lhs,j);
251
        LhsInnerIterator i(m_lhs,j);
252
        if (ProcessSecondHalf)
252
        if (ProcessSecondHalf)
253
        {
253
        {
254
          while (i && i.index()<j) ++i;
254
          while (i && i.index()<j) ++i;
255
          if(i && i.index()==j)
255
          if(i && i.index()==j)
256
          {
256
          {
257
            dest.row(j) += i.value() * m_rhs.row(j);
257
            dest.row(j) += i.value() * m_rhs.row(j);
(-)a/Eigen/src/SparseQR/SparseQR.h (-1 / +1 lines)
Lines 576-592 struct SparseQR_QProduct : ReturnByValue Link Here
576
{
576
{
577
  typedef typename SparseQRType::QRMatrixType MatrixType;
577
  typedef typename SparseQRType::QRMatrixType MatrixType;
578
  typedef typename SparseQRType::Scalar Scalar;
578
  typedef typename SparseQRType::Scalar Scalar;
579
  typedef typename SparseQRType::Index Index;
579
  typedef typename SparseQRType::Index Index;
580
  // Get the references 
580
  // Get the references 
581
  SparseQR_QProduct(const SparseQRType& qr, const Derived& other, bool transpose) : 
581
  SparseQR_QProduct(const SparseQRType& qr, const Derived& other, bool transpose) : 
582
  m_qr(qr),m_other(other),m_transpose(transpose) {}
582
  m_qr(qr),m_other(other),m_transpose(transpose) {}
583
  inline Index rows() const { return m_transpose ? m_qr.rows() : m_qr.cols(); }
583
  inline Index rows() const { return m_transpose ? m_qr.rows() : m_qr.cols(); }
584
  inline Index cols() const { return m_other.cols(); }
584
  inline Index cols() const { return Index(m_other.cols()); }
585
  
585
  
586
  // Assign to a vector
586
  // Assign to a vector
587
  template<typename DesType>
587
  template<typename DesType>
588
  void evalTo(DesType& res) const
588
  void evalTo(DesType& res) const
589
  {
589
  {
590
    Index m = m_qr.rows();
590
    Index m = m_qr.rows();
591
    Index n = m_qr.cols();
591
    Index n = m_qr.cols();
592
    Index diagSize = (std::min)(m,n);
592
    Index diagSize = (std::min)(m,n);

Return to bug 397