1#ifndef SIMPLELAPMATRIX_HH
2#define SIMPLELAPMATRIX_HH
5#include <dune/grid/config.h>
31 UNCMINVector(
double* start,
double* stop) {
for(
double* s=start; s<stop; ++s)
data.push_back(*s); };
60template<
class Num,
int offset=0>
70 data.reserve(col*row);
72 for(
int i=0; i<col; ++i)
73 for(
int j=0; j<row; ++j)
74 data.push_back(mat[j][i]);
95 data(std::
max(lda_,row_)*col_,0), col(col_), row(row_), lda(std::
max(lda_,row_))
97 assert(row>=0 && col>=0);
106 data.resize(col*row);
108 for(
int i=0; i<mat.
data.size(); ++i)
114 std::cout <<
"[" << std::endl;
115 for(
int i=0; i<
rows(); ++i)
117 for(
int j=0; j<
cols();++j)
118 std::cout << (*
this)(i,j) <<
",";
119 std::cout << std::endl;
121 std::cout <<
"]" << std::endl;
133 int LDA()
const {
return lda;}
138 for(
int i=0; i<
rows(); ++i)
139 for(
int k=0; k<
cols(); ++k)
140 M[i][k] = (*
this)(i,k);
146 for(
int i=0; i<
rows(); ++i)
147 for(
int k=0; k<
cols(); ++k)
151 M.
data.push_back((*
this)(k,i));
161 Num
const&
operator()(
int r,
int c)
const {
return data[lda*(c-offset)+(r-offset)]; }
162 Num&
operator()(
int r,
int c) {
return data[lda*(c-offset)+(r-offset)]; }
172 for(
int i=0; i<
rows(); ++i)
173 for(
int j=0; j<
cols(); ++j)
174 (*
this)(i,j) *= alpha;
180 for(
int i=0; i<
rows(); ++i)
181 for(
int j=0; j<
cols(); ++j)
182 (*
this)(i,j) *= scaling[j];
188 for(
int i=0; i<
rows(); ++i)
189 for(
int j=0; j<
cols(); ++j)
190 (*
this)(i,j) *= scaling[i];
195 std::vector<Num> data;
216template <
class Scalar>
SparseIndexInt nrows() const
Returns number of rows (computes them, if not known)
SparseIndexInt ncols() const
Returns number of cols (computes them, if not known)
std::vector< SparseIndexInt > ridx
row indices
std::vector< SparseIndexInt > cidx
column indices
std::vector< Scalar > data
data
Very simple dense matrix class for interfacing with LAPACK routines and the optimization tool uncmin.
void toTriplet(MatrixAsTriplet< RT > &M)
SLAPMatrix(MatrixAsTriplet< Num > const &mat)
SLAPMatrix(int row_, int col_, int lda_=-1)
Construction by specifying the size of the matrix directly.
SLAPMatrix< Num, offset > scaleCols(std::vector< Num > scaling)
int num_rows() const
Rows.
SLAPMatrix(Mat const &mat)
SLAPMatrix< Num, offset > scaleRows(std::vector< Num > scaling)
int LDA() const
Increment for row iteration.
Num & operator()(int r, int c)
Num const & operator()(int r, int c) const
Access to elements.
SLAPMatrix< Num, offset > operator*=(Num alpha)
SLAPMatrix(SLAPMatrix< Num, offset > const &mat)
Num * ptrToData()
Access to the raw data. This is needed by LAPACK routines.
Very simple vector wrapper for the use of the optimization tool uncmin, which is not capable of using...
double & operator()(int i)
UNCMINVector(int n, double v=0.0)
UNCMINVector(const std::vector< double > &v)
std::vector< double > data
UNCMINVector & operator=(const double &s)
UNCMINVector(double *start, double *stop)
UNCMINVector & operator=(const UNCMINVector &A)
UNCMINVector & operator*=(const double &s)
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
void MatrixMultiply(SLAPMatrix< double > A, std::vector< double > &in, std::vector< double > &out)
Matrix multiplication.
Dune::FieldVector< Scalar, d > eig(Dune::FieldMatrix< Scalar, d, d > &A, bool computeEigenvectors=true)
Computes the eigenvalues and eigenvectors of a symmetric matrix .
void MatrixKT_A_K(SLAPMatrix< double > A, SLAPMatrix< double > &K, SLAPMatrix< double > &out)
void LeastSquares(SLAPMatrix< double > a, std::vector< double > const &b, std::vector< double > &x)
Solve linear least squares problem, given by a*x=b.
void MatrixMultiplication(SLAPMatrix< double > A, SLAPMatrix< double > &B, SLAPMatrix< double > &AB)
void pseudoinverse(SLAPMatrix< Scalar > A, SLAPMatrix< Scalar > &Ainv)
void SymmetricEigenvalues(SLAPMatrix< double > a, std::vector< double > &eig)
void TransposedMatrixMultiply(SLAPMatrix< double > A, std::vector< double > &in, std::vector< double > &out)