HOLDER_PAC
 All Classes Functions Modules
matrixIO.hpp
1 #ifndef MATRIXIO_HPP
2 #define MATRIXIO_HPP
3 
4 #include <string>
5 #include <fstream>
6 #include <iostream>
7 #include <Eigen/Sparse>
8 #include <Eigen/Dense>
9 #include <vector>
10 
11 /* Function: readTxtIntoMatrix
12  * ---------------------------
13  * This function reads a text file and outputs a dense matrix (Eigen's MatrixXd) on return.
14  * The text file format is as follows:
15  * Fisrt line : nRows nCols
16  * All other lines: i j value(i,j)
17  * This function is very slow for large matrices. Use the binary format instead.
18  * inputFileName : Path of the input text file.
19  */
20 Eigen::MatrixXd readTxtIntoMatrix(const std::string inputFileName);
21 
22 
23 
24 /* Function : readMtxIntoSparseMatrix
25  *-------------------------------------
26  * This function reads a sparse matrix market format (*.mmx) file and returns an Eigen sparse matrix object.
27  * Currently it only supports matrix object type with coordinate format. Only real or double data types are acceptable at this time.
28  * The symmetricity can only be general or symmetric.
29  * inputFileName : The path of the input matrix market file.
30  */
31 Eigen::SparseMatrix<double> readMtxIntoSparseMatrix(const std::string inputFileName);
32 
33 
34 
35 void saveSparseMatrixIntoMtx(const Eigen::SparseMatrix<double> &inputMatrix,const std::string outputFileName);
36 
37 
38 /* Function: saveMatrixXdToBinary
39  * ------------------------------
40  * This function saves a dense matrix (Eigen's MatrixXd) as a binary file (SVD_F_DB) file format.
41  * inputMatrix : The dense matrix being saved.
42  * outputFileName : Path of the output file.
43  */
44 void saveMatrixXdToBinary(const Eigen::MatrixXd& inputMatrix, const std::string outputFileName);
45 
46 
47 
48 /* Function: readBinaryIntoMatrixXd
49  * -------------------------------
50  * This function reads a dense matrix binary file (SVD_F_DB) and outputs on return, a dense matrix (Eigen's MatrixXd).
51  * inputFileName : Path of the input file.
52  */
53 Eigen::MatrixXd readBinaryIntoMatrixXd(const std::string inputFileName);
54 
55 
56 void saveVectorAsText(const std::string outputFileName, const std::vector<double> & inputVector);
57 
58 #endif
59