38 #ifndef MAT_MATRIXTRIANGULAR 39 #define MAT_MATRIXTRIANGULAR 58 template<
typename Treal,
typename Tmatrix>
59 class MatrixTriangular :
public MatrixBase<Treal, 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,
162 Tmatrix::syInch(*SPD.
matrixPtr, *this->matrixPtr,
163 threshold, looking, version);
166 void thresh(Treal
const threshold,
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>&
231 MatrixTriangular<Treal, Tmatrix>::operator+=
234 Tmatrix::add(sm.A, *sm.B.matrixPtr, *this->matrixPtr);
239 template<
typename Treal,
typename Tmatrix>
245 this->frob_thresh(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,
266 maxIter = this->get_nrows() * 100;
269 lan(ztz, guess, maxIter);
270 lan.setRelTol( 100 * mat::getMachineEpsilon<Treal>() );
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 );
void thresh(Treal const threshold, normType const norm)
Definition: MatrixTriangular.h:241
MatrixTriangular< Treal, Tmatrix > & operator=(const MatrixTriangular< Treal, Tmatrix > &tri)
Definition: MatrixTriangular.h:70
Treal eucl_thresh(Treal const threshold)
Definition: MatrixTriangular.h:291
Normal matrix.
Definition: MatrixBase.h:49
mat::SizesAndBlocks cols
Definition: test.cc:52
MatrixBase< Treal, Tmatrix > & operator=(const MatrixBase< Treal, Tmatrix > &other)
Definition: MatrixBase.h:166
Treal low() const
Definition: Interval.h:144
inchversion
Definition: Matrix.h:76
void frob_thresh(Treal threshold)
Definition: MatrixTriangular.h:178
ValidPtr< Tmatrix > matrixPtr
Definition: MatrixBase.h:153
Definition: LanczosLargestMagnitudeEig.h:46
void read_from_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype)
Definition: MatrixBase.h:281
void inch(const MatrixGeneral< Treal, Tmatrix > &SPD, const Treal threshold, const side looking=left, const inchversion version=unstable)
Definition: MatrixTriangular.h:150
Truncation of general matrices.
Definition: truncation.h:272
Definition: MatrixBase.h:55
Treal real
Definition: MatrixTriangular.h:62
Definition: allocate.cc:39
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
MatrixTriangular()
Default constructor.
Definition: MatrixTriangular.h:64
Treal eucl(Treal const requestedAccuracy, int maxIter=-1) const
Definition: MatrixTriangular.h:257
Definition: Interval.h:46
VectorGeneral< Treal, typename Tmatrix::VectorType > VectorType
Definition: MatrixTriangular.h:61
void write_to_buffer(void *buffer, const int n_bytes) const
Definition: MatrixTriangular.h:189
void readFromFileBase(std::ifstream &file, matrix_type const mattype)
Definition: MatrixBase.h:236
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 writeToFileProt(std::ofstream &file) const
Write object to file.
Definition: MatrixTriangular.h:217
void write_to_buffer_base(void *buffer, const int n_bytes, const matrix_type mattype) const
Definition: MatrixBase.h:254
size_t nnz() const
Definition: MatrixTriangular.h:181
Upper non-unit triangular matrix.
Definition: MatrixBase.h:53
MatrixTriangular(const MatrixTriangular< Treal, Tmatrix > &tri)
Copy constructor.
Definition: MatrixTriangular.h:66
void readFromFileProt(std::ifstream &file)
Read object from file.
Definition: MatrixTriangular.h:220
Treal run(Treal const threshold)
Definition: truncation.h:80
void writeToFileBase(std::ofstream &file, matrix_type const mattype) const
Definition: MatrixBase.h:221
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
Treal midPoint() const
Definition: Interval.h:115
void rand()
Definition: VectorGeneral.h:102
void inch(const MatrixSymmetric< Treal, Tmatrix > &SPD, const Treal threshold, const side looking=left, const inchversion version=unstable)
Definition: MatrixTriangular.h:157
void resetSizesAndBlocks(SizesAndBlocks const &newRows, SizesAndBlocks const &newCols)
Definition: MatrixBase.h:76
size_t nvalues() const
Definition: MatrixTriangular.h:184
Treal eucl_thresh_congr_trans_measure(Treal const threshold, MatrixSymmetric< Treal, Tmatrix > &trA)
Definition: MatrixTriangular.h:300
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
void resetSizesAndBlocks(SizesAndBlocks const &newRows)
Definition: VectorGeneral.h:51
Treal frob() const
Definition: MatrixTriangular.h:169
Definition: mat_utils.h:78
void random()
Definition: MatrixTriangular.h:196
Base class for matrix API.
Definition: MatrixBase.h:69
void read_from_buffer(void *buffer, const int n_bytes)
Definition: MatrixTriangular.h:192
void getLargestMagnitudeEig(Treal &ev, Treal &accuracy)
Definition: LanczosLargestMagnitudeEig.h:58
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
side
Definition: Matrix.h:75
Base class for matrix API.
Treal length() const
Returns the length of the interval.
Definition: Interval.h:109
Definition: matInclude.h:139
This proxy expresses the result of multiplication of two objects, of possibly different types...
Definition: matrix_proxy.h:51
void haveDataStructureSet(bool val)
Definition: ValidPtr.h:99
Definition: MatrixBase.h:56
MatrixTriangular< Treal, Tmatrix > & operator=(int const k)
Set matrix to zero or identity: A = 0 or A = 1.
Definition: MatrixTriangular.h:75
Symmetric matrix.
Definition: MatrixBase.h:51
std::string obj_type_id() const
Definition: MatrixTriangular.h:215
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
Truncation of general matrices with impact on matrix triple multiply as error measure.
Definition: truncation.h:338
Treal template_blas_sqrt(Treal x)
normType
Definition: matInclude.h:139