|
|
◆ ZMMRead()
| Sub ZMMRead |
( |
Fname As |
String, |
|
|
Nrow As |
Long, |
|
|
Ncol As |
Long, |
|
|
Nnz As |
Long, |
|
|
Val() As |
Complex, |
|
|
Ptr() As |
Long, |
|
|
Ind() As |
Long, |
|
|
DataType As |
Long, |
|
|
MatShape As |
Long, |
|
|
MatForm As |
Long, |
|
|
Optional Info As |
Long, |
|
|
Optional Skip As |
Long = 0, |
|
|
Optional Base As |
Long = 0, |
|
|
Optional Format As |
Long = 0, |
|
|
Optional Sort As |
Long = 0 |
|
) |
| |
Read a matrix from the Matrix Market file (Complex matrix)
- Purpose
- This routine reads a sparse or dense matrix from the Matrix Market file. A sparse matrix is stored in CSR, CSC or COO format.
- Parameters
-
| [in] | Fname | Input file name. |
| [out] | Nrow | Number of rows of the matrix. |
| [out] | Ncol | Number of columns of the matrix. |
| [out] | Nnz | Number of nonzero elements of the matrix. |
| [out] | Val() | Array Val(LVal - 1) (LVal is as follows)
Storage Matrix shape LVal (min. value)
---------- -------------- -----------------
0 (sparse) Nnz
1 (dense) 0 (gegeral) Nrow*Ncol
1 (symmetric) Ncol*(Ncol + 1)/2
2 (skew) Ncol*(Ncol - 1)/2
3 (Hermitian) Ncol*(Ncol + 1)/2
Nonzero elements of sparse matrix, or, all elements of dense matrix.
Not referenced if data type = 2 (pattern). |
| [out] | Ptr() | Array Ptr(LPtr - 1) (LPtr >= Ncol + 1 (if matrix is stored in CSC format), LPtr >= Nrow + 1 (if matrix is stored in CSR format) or LPtr >= Nnz (if matrix is stored in COO format))
Row pointers (if matrix is stored in CSR format), column pointers (if matrix is stored in CSC format) or row indices (if matrix is stored in COO format) of nonzero elements.
Not referenced if storage format = 1 (dense). |
| [out] | Ind() | Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if matrix is stored in CSC format) or column indices (if matrix is stored in CSR or COO format) of nonzero elements.
Not referenced if storage format = 1 (dense). |
| [out] | DataType | Data type of the matrix.
= 1: Complex
= 2: Pattern. |
| [out] | MatShape | Matrix shape.
= 0: General.
= 1: Symmetric.
= 2: Skew-symmetric.
= 3: Hermitian. |
| [out] | MatForm | Storage format of the matrix.
= 0: Sparse.
= 1: Dense. |
| [out] | Info | (Optional)
= 0: Successful exit.
= i < 0: The (-i)-th argument is invalid.
= 1: Failed to open file.
= 3: File read error.
= 4: Invalid type. |
| [in] | Skip | (Optional)
Flag to skip to read data. (default = 0)
= 0: Read all data.
= 1: Read header and size only (matrix data is not read). |
| [in] | Base | (Optional)
Index style of Ptr and Ind. (default = 0)
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1. |
| [in] | Format | (Optional)
Sparse matrix format when stored. (default = 0)
= 0: CSR format.
= 1: CSC format.
= 2: COO format. |
| [in] | Sort | (Optional)
Specify whether to sort elements of sparse matrix in ascending order of column number within each row (if CSR) or row number within each column (if CSC). (default = 0)
= 0: Do not sort elements.
= 1: Sort elements. |
- Example Program
- Reads the following file (Test_ZMMWrite.mtx) in Matrix Market format.
%%MatrixMarket matrix coordinate complex general
3 3 9
1 1 7.800000000000000e-01 1.600000000000000e-01
1 2 -9.000000000000000e-01 -1.460000000000000e+00
1 3 4.800000000000000e-01 -1.080000000000000e+00
2 1 7.300000000000000e-01 6.300000000000000e-01
2 2 1.580000000000000e+00 -1.240000000000000e+00
2 3 -4.100000000000000e-01 -9.100000000000000e-01
3 1 2.300000000000000e-01 -1.370000000000000e+00
3 2 7.900000000000000e-01 6.400000000000000e-01
3 3 -7.300000000000000e-01 -1.500000000000000e+00
Sub Ex_ZMMRead()
Dim M As Long, N As Long, Nnz As Long, DataType As Long, MatShape As Long, MatForm As Long
Dim A(8) As Complex, Ia(3) As Long, Ja(8) As Long
Dim Info As Long
Call ZMMRead("Test_ZMMWrite.mtx", M, N, Nnz, A(), Ia(), Ja(), DataType, MatShape, MatForm, Info)
Debug.Print " ZMMRead: Info =" + Str(Info)
Debug.Print "M =" + Str(M) + ", N =" + Str(N) + ", Nnz =" + Str(Nnz)
Debug.Print "DataType =" + Str(DataType) + ", MatShape =" + Str(MatShape) + ", MatForm =" + Str(MatForm)
Debug.Print "(" + Str( Creal(A(0))) + "," + Str( Cimag(A(0))) + ")", "(" + Str( Creal(A(1))) + "," + Str( Cimag(A(1))) + ")", "(" + Str( Creal(A(2))) + "," + Str( Cimag(A(2))) + ")"
Debug.Print "(" + Str( Creal(A(3))) + "," + Str( Cimag(A(3))) + ")", "(" + Str( Creal(A(4))) + "," + Str( Cimag(A(4))) + ")", "(" + Str( Creal(A(5))) + "," + Str( Cimag(A(5))) + ")"
Debug.Print "(" + Str( Creal(A(6))) + "," + Str( Cimag(A(6))) + ")", "(" + Str( Creal(A(7))) + "," + Str( Cimag(A(7))) + ")", "(" + Str( Creal(A(8))) + "," + Str( Cimag(A(8))) + ")"
Debug.Print Ia(0), Ia(1), Ia(2), Ia(3)
Debug.Print Ja(0), Ja(1), Ja(2), Ja(3), Ja(4), Ja(5), Ja(6), Ja(7), Ja(8)
End Sub
Function Cimag(A As Complex) As Double Imaginary part of complex number
Function Creal(A As Complex) As Double Real part of complex number
Sub ZMMRead(Fname As String, Nrow As Long, Ncol As Long, Nnz As Long, Val() As Complex, Ptr() As Long, Ind() As Long, DataType As Long, MatShape As Long, MatForm As Long, Optional Info As Long, Optional Skip As Long=0, Optional Base As Long=0, Optional Format As Long=0, Optional Sort As Long=0) Read a matrix from the Matrix Market file (Complex matrix)
- Example Results
M = 3, N = 3, Nnz = 9
DataType = 1, MatShape = 0, MatForm = 0
( .78, .16) (-.9,-1.46) ( .48,-1.08)
( .73, .63) ( 1.58,-1.24) (-.41,-.91)
( .23,-1.37) ( .79, .64) (-.73,-1.5)
0 3 6 9
0 1 2 0 1 2 0 1 2
|