ergo
random_matrices.h
Go to the documentation of this file.
1/* Ergo, version 3.8.2, a program for linear scaling electronic structure
2 * calculations.
3 * Copyright (C) 2023 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4 * and Anastasia Kruchinina.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Primary academic reference:
20 * Ergo: An open-source program for linear-scaling electronic structure
21 * calculations,
22 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23 * Kruchinina,
24 * SoftwareX 7, 107 (2018),
25 * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26 *
27 * For further information about Ergo, see <http://www.ergoscf.org>.
28 */
29
41#ifndef HEADER_RANDOM_MATRICES
42#define HEADER_RANDOM_MATRICES
43
44
45#include "matrix_typedefs.h" // definitions of matrix types and interval type (source)
46#include "realtype.h" // definitions of types (utilities_basic)
47#include "matrix_utilities.h"
49#include "SizesAndBlocks.h"
50#include "Matrix.h"
51#include "Vector.h"
52#include "MatrixSymmetric.h"
53#include "MatrixTriangular.h"
54#include "MatrixGeneral.h"
55#include "VectorGeneral.h"
56#include "output.h"
57
58#include "files_dense.h"
59#include "files_sparse.h"
60
61#include <iostream>
62#include <fstream>
63#include <sstream>
64#include <string.h>
65
66
67using namespace std;
68
69
70
75
76typedef std::vector<int> VectorTypeInt;
77
78#ifdef PRECISION_QUAD_FLT128
79#define MAX_DOUBLE FLT128_MAX
80#define MIN_DOUBLE FLT128_MIN
81#else
82#define MAX_DOUBLE std::numeric_limits<ergo_real>::max()
83#define MIN_DOUBLE std::numeric_limits<ergo_real>::min()
84#endif
85
86
87#define PI 3.14159265 // needed for sprandsym
88
89
91void print_matrix(std::vector<ergo_real> const &A);
92template<typename Matrix>
93void init_matrix(Matrix &X, const int N, int blockSizesMultuple = 4);
94void get_random_symm_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple = 4);
95void get_random_sparse_blocks_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple = 4, ergo_real probabilityBeingZero = 0);
96void get_all_eigenvalues_of_matrix(std::vector<ergo_real> & eigvalList, const MatrixTypeInner & M);
97void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector<ergo_real> &D, const double MATRIX_SPARSITY);
98int get_matrix_from_sparse(char *filename, MatrixTypeInner &X);
99int get_matrix_from_sparse_vec(char *filename, std::vector<int> &I, std::vector<int> &J, std::vector<ergo_real> &val);
100int get_matrix_from_binary(char *filename, MatrixTypeInner &X);
101int get_matrix_from_binary_vec(char *filename, std::vector<int> &I, std::vector<int> &J, std::vector<ergo_real> &val, int &N);
102int get_matrix_from_full(char * filename, MatrixTypeInner &X);
103
104
110template<typename Matrix>
111void init_matrix(Matrix &X, const int N, int blockSizesMultuple /*=4*/)
112{
113 /********** Initialization of SizesAndBlocks */
114 int size = N;
115 int nlevels = 5;
116 std::vector<int> blockSizes(nlevels);
117 blockSizes[nlevels - 1] = 1; // should always be one
118 for (int ind = nlevels - 2; ind >= 0; ind--)
119 blockSizes[ind] = blockSizes[ind + 1] * blockSizesMultuple;
120 mat::SizesAndBlocks rows(blockSizes, size);
121 mat::SizesAndBlocks cols(blockSizes, size);
122 /********************************************/
123 X.resetSizesAndBlocks(rows,cols);
124}
125
126
127#endif // HEADER_RANDOM_MATRICES
General matrix class.
Symmetric matrix class.
Triangular matrix class.
The heart of the matrix library.
Class used to keep track of the block sizes used at different levels in the hierarchical matrix data ...
General vector class.
Copyright(c) Emanuel Rubensson 2006.
Describes dimensions of matrix and its blocks on all levels.
Definition SizesAndBlocks.h:45
mat::SizesAndBlocks rows
Definition test.cc:51
mat::SizesAndBlocks cols
Definition test.cc:52
File containing declaration of functions for reading/writing dense matrices and vectors.
File containing declarations of functions for reading/writing sparse matrices from/to mtx (MatrixMark...
Wrapper routines for different parts of the integral code, including conversion of matrices from/to t...
#define A
Header file with typedefs for matrix and vector types.
Utilities related to the hierarchical matrix library (HML), including functions for setting up permut...
Functionality for writing output messages to a text file.
void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector< ergo_real > &D, const double MATRIX_SPARSITY)
Definition random_matrices.cc:129
symmMatrix MatrixTypeInner
Definition random_matrices.h:72
intervalType IntervalType
Definition random_matrices.h:71
void get_random_symm_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple=4)
Definition random_matrices.cc:65
int get_matrix_from_sparse_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< ergo_real > &val)
Definition random_matrices.cc:421
std::vector< int > VectorTypeInt
Definition random_matrices.h:76
int get_matrix_from_full(char *filename, MatrixTypeInner &X)
Definition random_matrices.cc:480
void print_matrix(std::vector< ergo_real > const &A)
Definition random_matrices.cc:52
void init_matrix(Matrix &X, const int N, int blockSizesMultuple=4)
Create hierarchical matrix structure.
Definition random_matrices.h:111
void print_ergo_matrix(const MatrixTypeInner &F)
Definition random_matrices.cc:45
int get_matrix_from_binary(char *filename, MatrixTypeInner &X)
Definition random_matrices.cc:437
void get_all_eigenvalues_of_matrix(std::vector< ergo_real > &eigvalList, const MatrixTypeInner &M)
Definition random_matrices.cc:105
triangMatrix TriangMatrixType
Definition random_matrices.h:73
int get_matrix_from_sparse(char *filename, MatrixTypeInner &X)
Definition random_matrices.cc:405
normalMatrix MatrixGeneral
Definition random_matrices.h:74
void get_random_sparse_blocks_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple=4, ergo_real probabilityBeingZero=0)
Definition random_matrices.cc:95
int get_matrix_from_binary_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< ergo_real > &val, int &N)
Definition random_matrices.cc:456
Definition of the main floating-point datatype used; the ergo_real type.
double ergo_real
Definition realtype.h:69
MatrixSymmetric< real, matri > symmMatrix
Definition test_LanczosSeveralLargestEig.cc:69
MatrixTriangular< real, matri > triangMatrix
Definition test_LanczosSeveralLargestEig.cc:70
MatrixGeneral< real, matri > normalMatrix
Definition test_LanczosSeveralLargestEig.cc:71