38#ifndef MAT_MATRIXTRIANGULAR
39#define MAT_MATRIXTRIANGULAR
58 template<
typename Treal,
typename Tmatrix>
86 (std::vector<int>
const & rowind,
87 std::vector<int>
const & colind,
88 std::vector<Treal>
const & values,
92 this->
matrixPtr->syAssignFromSparse(rowind, colind, values);
107 (std::vector<int>
const & rowind,
108 std::vector<int>
const & colind,
109 std::vector<Treal>
const & values) {
110 this->
matrixPtr->syAddValues(rowind, colind, values);
115 (std::vector<int>
const & rowind,
116 std::vector<int>
const & colind,
117 std::vector<Treal> & values)
const {
118 this->
matrixPtr->syGetValues(rowind, colind, values);
128 (std::vector<int> & rowind,
129 std::vector<int> & colind,
130 std::vector<Treal> & values)
const {
134 rowind.reserve(
nnz());
135 colind.reserve(
nnz());
136 values.reserve(
nnz());
137 this->
matrixPtr->syGetAllValues(rowind, colind, values);
145 inline void fullmatrix(Treal*
const full,
int const size)
const {
146 this->
matrixPtr->fullmatrix(full, size, size);
151 const Treal threshold,
154 Tmatrix::inch(*SPD.
matrixPtr, *this->matrixPtr,
155 threshold, looking, version);
158 const Treal threshold,
161 this->
matrixPtr.haveDataStructureSet(
true);
162 Tmatrix::syInch(*SPD.
matrixPtr, *this->matrixPtr,
163 threshold, looking, version);
172 Treal
eucl(Treal
const requestedAccuracy,
173 int maxIter = -1)
const;
181 inline size_t nnz()
const {
204 template<
typename TRule>
206 this->
matrixPtr->trSetElementsByRule(rule);
229 template<
typename Treal,
typename Tmatrix>
230 inline MatrixTriangular<Treal, Tmatrix>&
234 Tmatrix::add(sm.A, *sm.B.matrixPtr, *this->matrixPtr);
239 template<
typename Treal,
typename Tmatrix>
241 thresh(Treal
const threshold,
248 throw Failure(
"MatrixTriangular<Treal, Tmatrix>::"
249 "thresh(Treal const, "
251 "Thresholding not imlpemented for selected norm");
255 template<
typename Treal,
typename Tmatrix>
257 eucl(Treal
const requestedAccuracy,
269 lan(ztz, guess, maxIter);
277 if ( euclInt.
low() < 0 )
279 if ( euclInt.
length() / 2.0 > requestedAccuracy ) {
280 std::cout <<
"req: " << (double)requestedAccuracy
281 <<
" obt: " << (
double)(euclInt.
length() / 2.0) << std::endl;
282 throw std::runtime_error(
"Desired accuracy not obtained in Lanczos.");
289 template<
typename Treal,
typename Tmatrix>
293 return TruncObj.
run( threshold );
298 template<
typename Treal,
typename Tmatrix>
303 return TruncObj.
run( threshold );
Base class for matrix API.
Treal run(Treal const threshold)
Definition truncation.h:80
Truncation of general matrices with impact on matrix triple multiply as error measure.
Definition truncation.h:338
Truncation of general matrices.
Definition truncation.h:272
Treal low() const
Definition Interval.h:144
Treal midPoint() const
Definition Interval.h:115
Treal length() const
Returns the length of the interval.
Definition Interval.h:109
void getCols(SizesAndBlocks &colsCopy) const
Definition MatrixBase.h:85
void read_from_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype)
Definition MatrixBase.h:281
int get_nrows() const
Definition MatrixBase.h:138
void writeToFileBase(std::ofstream &file, matrix_type const mattype) const
Definition MatrixBase.h:221
MatrixBase< Treal, Tmatrix > & operator=(const MatrixBase< Treal, Tmatrix > &other)
Definition MatrixBase.h:166
void resetSizesAndBlocks(SizesAndBlocks const &newRows, SizesAndBlocks const &newCols)
Definition MatrixBase.h:76
void write_to_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype) const
Definition MatrixBase.h:254
ValidPtr< Tmatrix > matrixPtr
Definition MatrixBase.h:153
void readFromFileBase(std::ifstream &file, matrix_type const mattype)
Definition MatrixBase.h:236
MatrixBase()
Definition MatrixBase.h:155
Normal matrix.
Definition MatrixGeneral.h:59
Symmetric matrix.
Definition MatrixSymmetric.h:68
Upper non-unit triangular matrix.
Definition MatrixTriangular.h:59
void assign_from_sparse(std::vector< int > const &rowind, std::vector< int > const &colind, std::vector< Treal > const &values, SizesAndBlocks const &newRows, SizesAndBlocks const &newCols)
Assign from sparse matrix given by three vectors.
Definition MatrixTriangular.h:86
void frob_thresh(Treal threshold)
Definition MatrixTriangular.h:178
void setElementsByRule(TRule &rule)
Uses rule depending on the row and column indexes to set matrix elements The Trule class should have ...
Definition MatrixTriangular.h:205
void readFromFileProt(std::ifstream &file)
Read object from file.
Definition MatrixTriangular.h:220
MatrixTriangular< Treal, Tmatrix > & operator=(const MatrixTriangular< Treal, Tmatrix > &tri)
Definition MatrixTriangular.h:70
void random()
Definition MatrixTriangular.h:196
void add_values(std::vector< int > const &rowind, std::vector< int > const &colind, std::vector< Treal > const &values)
Add given set of values to the matrix (+=).
Definition MatrixTriangular.h:107
std::string obj_type_id() const
Definition MatrixTriangular.h:215
VectorGeneral< Treal, typename Tmatrix::VectorType > VectorType
Definition MatrixTriangular.h:61
void inch(const MatrixGeneral< Treal, Tmatrix > &SPD, const Treal threshold, const side looking=left, const inchversion version=unstable)
Definition MatrixTriangular.h:150
Treal frob() const
Definition MatrixTriangular.h:169
void inch(const MatrixSymmetric< Treal, Tmatrix > &SPD, const Treal threshold, const side looking=left, const inchversion version=unstable)
Definition MatrixTriangular.h:157
void get_values(std::vector< int > const &rowind, std::vector< int > const &colind, std::vector< Treal > &values) const
Get values given by row and column index lists.
Definition MatrixTriangular.h:115
Treal eucl_thresh_congr_trans_measure(Treal const threshold, MatrixSymmetric< Treal, Tmatrix > &trA)
Definition MatrixTriangular.h:300
Treal real
Definition MatrixTriangular.h:62
void thresh(Treal const threshold, normType const norm)
Definition MatrixTriangular.h:241
Treal eucl_thresh(Treal const threshold)
Definition MatrixTriangular.h:291
void get_all_values(std::vector< int > &rowind, std::vector< int > &colind, std::vector< Treal > &values) const
Get all values and corresponding row and column index lists, in matrix.
Definition MatrixTriangular.h:128
MatrixTriangular()
Default constructor.
Definition MatrixTriangular.h:64
MatrixTriangular(const MatrixTriangular< Treal, Tmatrix > &tri)
Copy constructor.
Definition MatrixTriangular.h:66
MatrixTriangular< Treal, Tmatrix > & operator=(int const k)
Set matrix to zero or identity: A = 0 or A = 1.
Definition MatrixTriangular.h:75
size_t nvalues() const
Definition MatrixTriangular.h:184
void write_to_buffer(void *buffer, const int n_bytes) const
Definition MatrixTriangular.h:189
size_t nnz() const
Definition MatrixTriangular.h:181
Treal eucl(Treal const requestedAccuracy, int maxIter=-1) const
Definition MatrixTriangular.h:257
void read_from_buffer(void *buffer, const int n_bytes)
Definition MatrixTriangular.h:192
void writeToFileProt(std::ofstream &file) const
Write object to file.
Definition MatrixTriangular.h:217
Describes dimensions of matrix and its blocks on all levels.
Definition SizesAndBlocks.h:45
Definition VectorGeneral.h:48
void resetSizesAndBlocks(SizesAndBlocks const &newRows)
Definition VectorGeneral.h:51
void rand()
Definition VectorGeneral.h:108
Definition LanczosLargestMagnitudeEig.h:47
void getLargestMagnitudeEig(Treal &ev, Treal &accuracy)
Definition LanczosLargestMagnitudeEig.h:58
mat::SizesAndBlocks cols
Definition test.cc:52
Definition allocate.cc:39
side
Definition Matrix.h:75
@ left
Definition Matrix.h:75
@ matrix_triang
Definition MatrixBase.h:56
normType
Definition matInclude.h:139
@ frobNorm
Definition matInclude.h:139
static Treal getMachineEpsilon()
Definition matInclude.h:147
inchversion
Definition Matrix.h:76
@ unstable
Definition Matrix.h:76
Definition mat_utils.h:95
This proxy expresses the result of multiplication of two objects, of possibly different types,...
Definition matrix_proxy.h:51
Treal template_blas_sqrt(Treal x)