diff --git a/Eigen/Sparse b/Eigen/Sparse index 7425b3a41..8eb9d378c 100644 --- a/Eigen/Sparse +++ b/Eigen/Sparse @@ -40,7 +40,6 @@ struct Sparse {}; #include "src/Sparse/CompressedStorage.h" #include "src/Sparse/AmbiVector.h" #include "src/Sparse/SparseMatrix.h" -#include "src/Sparse/DynamicSparseMatrix.h" #include "src/Sparse/MappedSparseMatrix.h" #include "src/Sparse/SparseVector.h" #include "src/Sparse/CoreIterators.h" diff --git a/Eigen/src/Sparse/SparseBlock.h b/Eigen/src/Sparse/SparseBlock.h index b7bfa57e4..5054b9755 100644 --- a/Eigen/src/Sparse/SparseBlock.h +++ b/Eigen/src/Sparse/SparseBlock.h @@ -101,103 +101,6 @@ class SparseInnerVectorSet : internal::no_assignment_operator, const internal::variable_if_dynamic m_outerSize; }; -/*************************************************************************** -* specialisation for DynamicSparseMatrix -***************************************************************************/ - -template -class SparseInnerVectorSet, Size> - : public SparseMatrixBase, Size> > -{ - typedef DynamicSparseMatrix<_Scalar, _Options, _Index> MatrixType; - public: - - enum { IsRowMajor = internal::traits::IsRowMajor }; - - EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet) - class InnerIterator: public MatrixType::InnerIterator - { - public: - inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) - : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) - {} - inline Index row() const { return IsRowMajor ? m_outer : this->index(); } - inline Index col() const { return IsRowMajor ? this->index() : m_outer; } - protected: - Index m_outer; - }; - - inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) - : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) - { - eigen_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); - } - - inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) - : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) - { - eigen_assert(Size!=Dynamic); - eigen_assert( (outer>=0) && (outer - inline SparseInnerVectorSet& operator=(const SparseMatrixBase& other) - { - if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit)) - { - // need to transpose => perform a block evaluation followed by a big swap - DynamicSparseMatrix aux(other); - *this = aux.markAsRValue(); - } - else - { - // evaluate/copy vector per vector - for (Index j=0; j aux(other.innerVector(j)); - m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data()); - } - } - return *this; - } - - inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other) - { - return operator=(other); - } - - Index nonZeros() const - { - Index count = 0; - for (Index j=0; j0); - return m_matrix.data()[m_outerStart].vale(m_matrix.data()[m_outerStart].size()-1); - } - -// template -// inline SparseInnerVectorSet& operator=(const SparseMatrixBase& other) -// { -// return *this; -// } - - EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } - EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } - - protected: - - const typename MatrixType::Nested m_matrix; - Index m_outerStart; - const internal::variable_if_dynamic m_outerSize; - -}; - /*************************************************************************** * specialisation for SparseMatrix diff --git a/Eigen/src/Sparse/SparseDenseProduct.h b/Eigen/src/Sparse/SparseDenseProduct.h index 0f77aa5be..dda14bc13 100644 --- a/Eigen/src/Sparse/SparseDenseProduct.h +++ b/Eigen/src/Sparse/SparseDenseProduct.h @@ -167,8 +167,11 @@ class SparseTimeDenseProduct typedef typename internal::remove_all::type _Rhs; typedef typename _Lhs::InnerIterator LhsInnerIterator; enum { LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit }; - for(Index j=0; j + EIGEN_DONT_INLINE void kernel(Dest& dest, Scalar alpha, int j) const + { + typedef typename internal::remove_all::type _Lhs; + typedef typename internal::remove_all::type _Rhs; + typedef typename _Lhs::InnerIterator LhsInnerIterator; + enum { LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit }; + { + typename Rhs::Scalar rhs_j = alpha * m_rhs.coeff(LhsIsRowMajor ? 0 : j,0); + typename Dest::RowXpr dest_j(dest.row(LhsIsRowMajor ? j : 0)); + for(LhsInnerIterator it(m_lhs,j); it ;++it) + { + if(LhsIsRowMajor) dest_j += (alpha*it.value()) * m_rhs.row(it.index()); + else if(Rhs::ColsAtCompileTime==1) dest.coeffRef(it.index()) += it.value() * rhs_j; + else dest.row(it.index()) += (alpha*it.value()) * m_rhs.row(j); + } + } + } SparseTimeDenseProduct& operator=(const SparseTimeDenseProduct&); }; diff --git a/test/sparse.h b/test/sparse.h index 81ce82e16..4ca6b5aed 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -23,6 +23,7 @@ // Eigen. If not, see . #ifndef EIGEN_TESTSPARSE_H +#define EIGEN_TESTSPARSE_H #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index d4579e4c9..487e3c1c3 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -301,8 +301,5 @@ void test_sparse_basic() CALL_SUBTEST_2(( sparse_basic(SparseMatrix >(s, s)) )); CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); - - CALL_SUBTEST_3(( sparse_basic(DynamicSparseMatrix(s, s)) )); - CALL_SUBTEST_3(( sparse_basic(DynamicSparseMatrix(s, s)) )); } } diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 0082b56cd..ac1dac5f5 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -204,8 +204,6 @@ void test_sparse_product() CALL_SUBTEST_1( (sparse_product >()) ); CALL_SUBTEST_2( (sparse_product, ColMajor > >()) ); CALL_SUBTEST_2( (sparse_product, RowMajor > >()) ); - CALL_SUBTEST_3( (sparse_product >()) ); - CALL_SUBTEST_3( (sparse_product >()) ); CALL_SUBTEST_4( (sparse_product_regression_test, Matrix >()) ); } } diff --git a/unsupported/Eigen/SparseExtra b/unsupported/Eigen/SparseExtra index 443203c28..04f855a16 100644 --- a/unsupported/Eigen/SparseExtra +++ b/unsupported/Eigen/SparseExtra @@ -55,6 +55,8 @@ enum { #include "../../Eigen/src/misc/Solve.h" +#include "src/SparseExtra/DynamicSparseMatrix.h" +#include "src/SparseExtra/BlockOfDynamicSparseMatrix.h" #include "src/SparseExtra/RandomSetter.h" #include "src/SparseExtra/MarketIO.h" diff --git a/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h b/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h new file mode 100644 index 000000000..753643736 --- /dev/null +++ b/unsupported/Eigen/src/SparseExtra/BlockOfDynamicSparseMatrix.h @@ -0,0 +1,127 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2009 Gael Guennebaud +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#ifndef EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H +#define EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H + + +/*************************************************************************** +* specialisation for DynamicSparseMatrix +***************************************************************************/ + +template +class SparseInnerVectorSet, Size> + : public SparseMatrixBase, Size> > +{ + typedef DynamicSparseMatrix<_Scalar, _Options, _Index> MatrixType; + public: + + enum { IsRowMajor = internal::traits::IsRowMajor }; + + EIGEN_SPARSE_PUBLIC_INTERFACE(SparseInnerVectorSet) + class InnerIterator: public MatrixType::InnerIterator + { + public: + inline InnerIterator(const SparseInnerVectorSet& xpr, Index outer) + : MatrixType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) + {} + inline Index row() const { return IsRowMajor ? m_outer : this->index(); } + inline Index col() const { return IsRowMajor ? this->index() : m_outer; } + protected: + Index m_outer; + }; + + inline SparseInnerVectorSet(const MatrixType& matrix, Index outerStart, Index outerSize) + : m_matrix(matrix), m_outerStart(outerStart), m_outerSize(outerSize) + { + eigen_assert( (outerStart>=0) && ((outerStart+outerSize)<=matrix.outerSize()) ); + } + + inline SparseInnerVectorSet(const MatrixType& matrix, Index outer) + : m_matrix(matrix), m_outerStart(outer), m_outerSize(Size) + { + eigen_assert(Size!=Dynamic); + eigen_assert( (outer>=0) && (outer + inline SparseInnerVectorSet& operator=(const SparseMatrixBase& other) + { + if (IsRowMajor != ((OtherDerived::Flags&RowMajorBit)==RowMajorBit)) + { + // need to transpose => perform a block evaluation followed by a big swap + DynamicSparseMatrix aux(other); + *this = aux.markAsRValue(); + } + else + { + // evaluate/copy vector per vector + for (Index j=0; j aux(other.innerVector(j)); + m_matrix.const_cast_derived()._data()[m_outerStart+j].swap(aux._data()); + } + } + return *this; + } + + inline SparseInnerVectorSet& operator=(const SparseInnerVectorSet& other) + { + return operator=(other); + } + + Index nonZeros() const + { + Index count = 0; + for (Index j=0; j0); + return m_matrix.data()[m_outerStart].vale(m_matrix.data()[m_outerStart].size()-1); + } + +// template +// inline SparseInnerVectorSet& operator=(const SparseMatrixBase& other) +// { +// return *this; +// } + + EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); } + + protected: + + const typename MatrixType::Nested m_matrix; + Index m_outerStart; + const internal::variable_if_dynamic m_outerSize; + +}; + + +#endif // EIGEN_SPARSE_BLOCKFORDYNAMICMATRIX_H diff --git a/Eigen/src/Sparse/DynamicSparseMatrix.h b/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h similarity index 95% rename from Eigen/src/Sparse/DynamicSparseMatrix.h rename to unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h index 6ba55b58c..9a61ddb09 100644 --- a/Eigen/src/Sparse/DynamicSparseMatrix.h +++ b/unsupported/Eigen/src/SparseExtra/DynamicSparseMatrix.h @@ -25,7 +25,9 @@ #ifndef EIGEN_DYNAMIC_SPARSEMATRIX_H #define EIGEN_DYNAMIC_SPARSEMATRIX_H -/** \class DynamicSparseMatrix +/** \deprecated use a SparseMatrix in an uncompressed mode + * + * \class DynamicSparseMatrix * * \brief A sparse matrix class designed for matrix assembly purpose * @@ -64,7 +66,7 @@ struct traits > } template -class DynamicSparseMatrix + class DynamicSparseMatrix : public SparseMatrixBase > { public: @@ -232,20 +234,23 @@ class DynamicSparseMatrix } } - inline DynamicSparseMatrix() + /** The class DynamicSparseMatrix is deprectaed */ + EIGEN_DEPRECATED inline DynamicSparseMatrix() : m_innerSize(0), m_data(0) { eigen_assert(innerSize()==0 && outerSize()==0); } - inline DynamicSparseMatrix(Index rows, Index cols) + /** The class DynamicSparseMatrix is deprectaed */ + EIGEN_DEPRECATED inline DynamicSparseMatrix(Index rows, Index cols) : m_innerSize(0) { resize(rows, cols); } + /** The class DynamicSparseMatrix is deprectaed */ template - explicit inline DynamicSparseMatrix(const SparseMatrixBase& other) + EIGEN_DEPRECATED explicit inline DynamicSparseMatrix(const SparseMatrixBase& other) : m_innerSize(0) { Base::operator=(other.derived()); @@ -325,7 +330,7 @@ class DynamicSparseMatrix # ifdef EIGEN_DYNAMICSPARSEMATRIX_PLUGIN # include EIGEN_DYNAMICSPARSEMATRIX_PLUGIN # endif -}; + }; template class DynamicSparseMatrix::InnerIterator : public SparseVector::InnerIterator diff --git a/unsupported/test/sparse_extra.cpp b/unsupported/test/sparse_extra.cpp index b1fd481e8..e8c584640 100644 --- a/unsupported/test/sparse_extra.cpp +++ b/unsupported/test/sparse_extra.cpp @@ -22,7 +22,10 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#include "sparse.h" +//#include "sparse.h" +// import basic and product tests for deprectaed DynamicSparseMatrix +#include "sparse_basic.cpp" +#include "sparse_product.cpp" #include template @@ -145,10 +148,16 @@ template void sparse_extra(const SparseMatrixType& re void test_sparse_extra() { for(int i = 0; i < g_repeat; i++) { + int s = Eigen::internal::random(1,50); CALL_SUBTEST_1( sparse_extra(SparseMatrix(8, 8)) ); - CALL_SUBTEST_2( sparse_extra(SparseMatrix >(16, 16)) ); - CALL_SUBTEST_1( sparse_extra(SparseMatrix(33, 33)) ); + CALL_SUBTEST_2( sparse_extra(SparseMatrix >(s, s)) ); + CALL_SUBTEST_1( sparse_extra(SparseMatrix(s, s)) ); - CALL_SUBTEST_3( sparse_extra(DynamicSparseMatrix(8, 8)) ); + CALL_SUBTEST_3( sparse_extra(DynamicSparseMatrix(s, s)) ); +// CALL_SUBTEST_3(( sparse_basic(DynamicSparseMatrix(s, s)) )); +// CALL_SUBTEST_3(( sparse_basic(DynamicSparseMatrix(s, s)) )); + + CALL_SUBTEST_3( (sparse_product >()) ); + CALL_SUBTEST_3( (sparse_product >()) ); } }