|
|
◆ ZMMWrite()
| Sub ZMMWrite |
( |
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 Fchk As |
Long = 0, |
|
|
Optional Base As |
Long = -1, |
|
|
Optional Format As |
Long = 0 |
|
) |
| |
Write a matrix to the Matrix Market file (Complex matrix)
- Purpose
- This function writes a sparse (CSR, CSC oe COO format) or dense matrix to the Matrix Market file.
The data is written as it is without checking the contents.
- Parameters
-
| [in] | Fname | Output file name. |
| [in] | Nrow | Number of rows of the matrix. |
| [in] | Ncol | Number of columns of the matrix. |
| [in] | Nnz | Number of nonzero elements of the matrix. |
| [in] | 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). |
| [in] | 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). |
| [in] | 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). |
| [in] | DataType | Data type of the matrix.
= 1: Complex
= 2: Pattern. |
| [in] | MatShape | Matrix shape.
= 0: General.
= 1: Symmetric.
= 2: Skew-symmetric.
= 3: Hermitian. |
| [in] | 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.
= 2: File already exists.
= 4: Invalid type.
|
| [in] | Fchk | (Optional)
Flag to check if output file exists. (default = 0)
= 0: Overwrite without checking if the specified file already exists.
= 1: Return as error (Info = 2) if the specified file already exists.
(For other values, the default value will be used.) |
| [in] | Base | (Optional)
Index style of Ptr and Ind when COO format (Format = 2). (default = Ptr(0) if CSR or CSC (Format = 0 or 1), 0 if COO (Format = 2))
= 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. (default = 0)
= 0: CSR format.
= 1: CSC format.
= 2: COO format.
(For other values, the default value will be used.) |
- Example Program
- Writes the following matrix to the file (Test_ZMMWrite.mtx) in Matrix Market format.
( 0.78+0.16i -0.9-1.46i 0.48-1.08i )
A = ( 0.73+0.63i 1.58-1.24 -0.41-0.91i )
( 0.23-1.37i 0.79+0.64i -0.73-1.5i )
Sub Ex_ZMMWrite()
Const M = 3, N = 3, Nnz = M * N
Const DataType = 1, MatShape = 0, MatForm = 0
Dim A(Nnz - 1) As Complex, Ia(M) As Long, Ja(Nnz - 1) As Long
Dim Info As Long
A(0) = Cmplx(0.78, 0.16): A(1) = Cmplx(-0.9, -1.46): A(2) = Cmplx(0.48, -1.08): A(3) = Cmplx(0.73, 0.63): A(4) = Cmplx(1.58, -1.24): A(5) = Cmplx(-0.41, -0.91): A(6) = Cmplx(0.23, -1.37): A(7) = Cmplx(0.79, 0.64): A(8) = Cmplx(-0.73, -1.5)
Ia(0) = 0: Ia(1) = 3: Ia(2) = 6: Ia(3) = 9
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2: Ja(6) = 0: Ja(7) = 1: Ja(8) = 2
Call ZMMWrite("Test_ZMMWrite.mtx", M, N, Nnz, A(), Ia(), Ja(), DataType, MatShape, MatForm, Info)
Debug.Print " ZMMWrite: Info =" + Str(Info)
End Sub
Function Cmplx(R As Double, Optional I As Double=0) As Complex Building complex number
Sub ZMMWrite(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 Fchk As Long=0, Optional Base As Long=-1, Optional Format As Long=0) Write a matrix to the Matrix Market file (Complex matrix)
- Example Results
- Example Results (Test_ZMMWrite.mtx file)
%%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
|