mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-28 14:54:11 +08:00

* rename Cholesky to LLT * rename CholeskyWithoutSquareRoot to LDLT * rename MatrixBase::cholesky() to llt() * rename MatrixBase::choleskyNoSqrt() to ldlt() * make {LLT,LDLT}::solve() API consistent with other modules Note that we are going to keep a source compatibility untill the next beta release. E.g., the "old" Cholesky* classes, etc are still available for some time. To be clear, Eigen beta2 should be (hopefully) source compatible with beta1, and so beta2 will contain all the deprecated API of beta1. Those features marked as deprecated will be removed in beta3 (or in the final 2.0 if there is no beta 3 !). Also includes various updated in sparse Cholesky.
75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
|
|
#include <Eigen/Array>
|
|
#include <Eigen/Sparse>
|
|
#include <bench/BenchTimer.h>
|
|
|
|
using namespace std;
|
|
using namespace Eigen;
|
|
USING_PART_OF_NAMESPACE_EIGEN
|
|
|
|
#ifndef SIZE
|
|
#define SIZE 1024
|
|
#endif
|
|
|
|
#ifndef DENSITY
|
|
#define DENSITY 0.01
|
|
#endif
|
|
|
|
#ifndef SCALAR
|
|
#define SCALAR double
|
|
#endif
|
|
|
|
typedef SCALAR Scalar;
|
|
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
|
|
typedef SparseMatrix<Scalar> EigenSparseMatrix;
|
|
|
|
void fillMatrix(float density, int rows, int cols, EigenSparseMatrix& dst)
|
|
{
|
|
dst.startFill(rows*cols*density);
|
|
for(int j = 0; j < cols; j++)
|
|
{
|
|
for(int i = 0; i < rows; i++)
|
|
{
|
|
Scalar v = (ei_random<float>(0,1) < density) ? ei_random<Scalar>() : 0;
|
|
if (v!=0)
|
|
dst.fill(i,j) = v;
|
|
}
|
|
}
|
|
dst.endFill();
|
|
}
|
|
|
|
void eiToDense(const EigenSparseMatrix& src, DenseMatrix& dst)
|
|
{
|
|
dst.setZero();
|
|
for (int j=0; j<src.cols(); ++j)
|
|
for (EigenSparseMatrix::InnerIterator it(src.derived(), j); it; ++it)
|
|
dst(it.index(),j) = it.value();
|
|
}
|
|
|
|
#ifndef NOGMM
|
|
#include "gmm/gmm.h"
|
|
typedef gmm::csc_matrix<Scalar> GmmSparse;
|
|
typedef gmm::col_matrix< gmm::wsvector<Scalar> > GmmDynSparse;
|
|
void eiToGmm(const EigenSparseMatrix& src, GmmSparse& dst)
|
|
{
|
|
GmmDynSparse tmp(src.rows(), src.cols());
|
|
for (int j=0; j<src.cols(); ++j)
|
|
for (EigenSparseMatrix::InnerIterator it(src.derived(), j); it; ++it)
|
|
tmp(it.index(),j) = it.value();
|
|
gmm::copy(tmp, dst);
|
|
}
|
|
#endif
|
|
|
|
#ifndef NOMTL
|
|
#include <boost/numeric/mtl/mtl.hpp>
|
|
typedef mtl::compressed2D<Scalar, mtl::matrix::parameters<mtl::tag::col_major> > MtlSparse;
|
|
typedef mtl::compressed2D<Scalar, mtl::matrix::parameters<mtl::tag::row_major> > MtlSparseRowMajor;
|
|
void eiToMtl(const EigenSparseMatrix& src, MtlSparse& dst)
|
|
{
|
|
mtl::matrix::inserter<MtlSparse> ins(dst);
|
|
for (int j=0; j<src.cols(); ++j)
|
|
for (EigenSparseMatrix::InnerIterator it(src.derived(), j); it; ++it)
|
|
ins[it.index()][j] = it.value();
|
|
}
|
|
#endif
|