-
Notifications
You must be signed in to change notification settings - Fork 223
feat(io): Add support for the matrix market exchange format #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jalvesz
wants to merge
68
commits into
fortran-lang:master
Choose a base branch
from
jalvesz:matrix_market
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
9301ba1
draft implementation
jalvesz e1fbad1
manage symmetric storages
jalvesz f7b4700
Merge branch 'matrix_market' of https://github.com/jalvesz/stdlib int…
jalvesz b6ba5cd
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 34e5a3c
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 0ea33f7
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 32b1df1
add examples and test
jalvesz 08f8c6b
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 912f9ef
Merge branch 'matrix_market' of https://github.com/jalvesz/stdlib int…
jalvesz 6a21d2a
split mm_save into dense and coo
jalvesz eac6f6b
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 2fb010f
added temporary arrays to read from mtx file for coordinate matrices …
Mahmood-Sinan 621de46
fixed subroutine name typo, coordinate write format and store lower t…
Mahmood-Sinan 44c1a74
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 7b78c6d
added deallocation of temp arrays while reading mtx, calculation of n…
Mahmood-Sinan 7189b92
moved initialization of expand variable to a new line
Mahmood-Sinan 694c0f3
changed COMPLEX() to cmplx() inside load function
Mahmood-Sinan 3019722
Merge branch 'fortran-lang:master' into matrix_market
jalvesz a453ff3
Merge branch 'matrix_market' of https://github.com/jalvesz/stdlib int…
jalvesz 4aa2fad
move files according to new folder structure
jalvesz a8d988a
changed from COO sparse matrix to plain arrays
Mahmood-Sinan c0351f3
add format specifier and integer subroutines for saving and loading
Mahmood-Sinan 014b644
fix dependencies
jalvesz 90a3ba5
Merge branch 'matrix_market' of https://github.com/jalvesz/stdlib int…
jalvesz 8a9ffb9
Update src/io/stdlib_io_mm.fypp
jalvesz 0c33205
Update example/io/example_matrix_market.f90
jalvesz 53d3ac3
fix: filling of upper triangular half incase of loading dense symmtry…
Mahmood-Sinan a1ba8ac
add AUTO symmetry option for dense matrices
Mahmood-Sinan 7cf80fc
add: error handling
Mahmood-Sinan 2d02766
add: basic test_io_mm
Mahmood-Sinan 28db893
add: test array general
Mahmood-Sinan be4c498
test_io_mm_array implemented
Mahmood-Sinan 67a90c2
minor change
Mahmood-Sinan c736d41
add initialization of err variables to zero
Mahmood-Sinan 8d505bb
modify test
Mahmood-Sinan 63634be
minor changes
Mahmood-Sinan 0bf7170
remove: unused constants dependency
Mahmood-Sinan e8e7387
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 5abdabd
minor changes to write mm header call
Mahmood-Sinan 3113f13
add stat error check after each time reading an input value
Mahmood-Sinan c03119d
Merge remote-tracking branch 'upstream/master' into matrix_market
Mahmood-Sinan 91fbede
add zero length array save condition for COO type
Mahmood-Sinan 107ffda
added coo tests
Mahmood-Sinan 213bc2a
remove I and made R one more dimensional
Mahmood-Sinan c1a8c65
change fypp to subroutine: dense done
Mahmood-Sinan a4cb00e
change fypp to subroutine: complete
Mahmood-Sinan 4d220cc
modularized
Mahmood-Sinan 4b27f8c
minor changes
Mahmood-Sinan ad02254
minor improvements and updated fisher algorithm
Mahmood-Sinan 749b798
trim trailing whitespaces
Mahmood-Sinan 4a65054
add: pattern support and tests
Mahmood-Sinan 64456f5
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 3183c37
delet file
jalvesz 874bad2
modify: remove pattern test duplication
Mahmood-Sinan e00ee73
move optional arguments to last inside mm_fail_process declaration
Mahmood-Sinan 476cdf6
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 13df893
Merge branch 'fortran-lang:master' into matrix_market
jalvesz 9353e2e
Merge branch 'fortran-lang:master' into matrix_market
jalvesz bfd3bcc
fix: while loop in comments part
Mahmood-Sinan 37196b4
revert cmake and add fypp _FILE_ variable
Mahmood-Sinan af21a8d
add windows support, more mtx files
Mahmood-Sinan 516815e
fix windows bug
Mahmood-Sinan 0617db4
small change
Mahmood-Sinan 0901da1
remove: os check
Mahmood-Sinan 878eb91
Merge remote-tracking branch 'upstream/master' into matrix_market
Mahmood-Sinan 1fbd0bb
add README.md for data/matrix_market, remove the data file for ash85 …
Mahmood-Sinan 22ed21c
example modified
Mahmood-Sinan d6a4403
modified docs
Mahmood-Sinan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| program example_matrix_market | ||
| use stdlib_io_mm, only : load_mm, save_mm | ||
| use stdlib_kinds, only : dp | ||
| implicit none | ||
|
|
||
| real(dp), allocatable :: matrix(:,:), matrix2(:,:) | ||
| integer, allocatable :: index(:,:) | ||
| complex(dp), allocatable :: data(:) | ||
| character(len=*), parameter :: dense_filename = "example_dense.mtx" | ||
| character(len=*), parameter :: sparse_filename = "example_sparse.mtx" | ||
| integer :: iostat, i | ||
| character(len=:), allocatable :: iomsg | ||
|
|
||
| ! Create a test dense matrix | ||
| allocate(matrix(3,3)) | ||
| matrix = reshape([1.0_dp, 2.0_dp, 3.0_dp, & | ||
| 4.0_dp, 5.0_dp, 6.0_dp, & | ||
| 7.0_dp, 8.0_dp, 9.0_dp], [3,3]) | ||
|
|
||
| print *, "=== Dense Matrix Example ===" | ||
| print *, "Original dense matrix:" | ||
| call print_matrix(matrix) | ||
|
|
||
| ! Save dense matrix to Matrix Market file | ||
| call save_mm(dense_filename, matrix, format="ES24.15E2", symmetry="general", iostat=iostat, iomsg=iomsg) | ||
| if (iostat /= 0) then | ||
| print *, "Error saving dense matrix: ", iomsg | ||
| stop 1 | ||
| end if | ||
|
|
||
| print *, "Dense matrix saved to ", dense_filename | ||
|
|
||
| ! Load dense matrix from Matrix Market file | ||
| call load_mm(dense_filename, matrix2, iostat=iostat, iomsg=iomsg) | ||
| if (iostat /= 0) then | ||
| print *, "Error loading dense matrix: ", iomsg | ||
| stop 1 | ||
| end if | ||
|
|
||
| print *, "Loaded dense matrix:" | ||
| call print_matrix(matrix2) | ||
|
|
||
| print *, "=== Sparse Matrix Example ===" | ||
| ! Create a test sparse matrix | ||
| allocate(index(2,6)) | ||
| allocate(data(6)) | ||
| index(:,1) = [1,1]; data(1) = (10.0_dp, -1.5_dp) | ||
| index(:,2) = [2,2]; data(2) = (20.0_dp, 2.0_dp) | ||
| index(:,3) = [3,3]; data(3) = (30.0_dp, 3.0_dp) | ||
| index(:,4) = [4,4]; data(4) = (40.0_dp, -4.0_dp) | ||
| index(:,5) = [1,4]; data(5) = ( 5.0_dp, -7.5_dp) | ||
| index(:,6) = [3,1]; data(6) = (15.0_dp, 25.0_dp) | ||
|
|
||
| ! Save sparse matrix to Matrix Market file | ||
| call save_mm(sparse_filename, index, data, format="ES24.15E2", symmetry="general", iostat=iostat, iomsg=iomsg) | ||
| if (iostat /= 0) then | ||
| print *, "Error saving sparse matrix: ", iomsg | ||
| stop 1 | ||
| end if | ||
|
|
||
| print *, "Sparse matrix saved to ", sparse_filename | ||
|
|
||
| ! Load sparse matrix from Matrix Market file | ||
| call load_mm(sparse_filename, index, data, iostat=iostat, iomsg=iomsg) | ||
| if (iostat /= 0) then | ||
| print *, "Error loading sparse matrix: ", iomsg | ||
| stop 1 | ||
| end if | ||
|
|
||
| print *, "Loaded sparse matrix (COO format):" | ||
| print *, "Data (row, col, value):" | ||
| do i = 1, size(data) | ||
| print *, index(1,i), index(2,i), data(i) | ||
| end do | ||
|
|
||
| contains | ||
|
|
||
| subroutine print_matrix(mat) | ||
| real(dp), intent(in) :: mat(:,:) | ||
| integer :: i | ||
|
|
||
| do i = 1, size(mat, 1) | ||
| print *, mat(i, :) | ||
| end do | ||
| print * | ||
| end subroutine print_matrix | ||
|
|
||
| end program example_matrix_market | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| ! SPDX-Identifier: MIT | ||
|
|
||
| #:include "common.fypp" | ||
| #:set R_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_SUFFIX)) | ||
| #:set C_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES, CMPLX_SUFFIX)) | ||
| #:set I_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES, INT_KINDS)) | ||
| #:set RCI_KINDS_TYPES = R_KINDS_TYPES + C_KINDS_TYPES + I_KINDS_TYPES | ||
|
|
||
| !> The Matrix Market (MM) format is a simple, human-readable, ASCII format for sparse | ||
| !> and dense matrices. The format was developed at NIST (National Institute of Standards | ||
| !> and Technology) for the Matrix Market, a repository of test matrices for use in | ||
| !> comparative studies of algorithms for numerical linear algebra. | ||
| !> | ||
| !> For more information, see: https://math.nist.gov/MatrixMarket/formats.html | ||
| module stdlib_io_mm | ||
| use stdlib_kinds, only : int8, int16, int32, int64, sp, dp, xdp, qp | ||
| implicit none | ||
| private | ||
|
|
||
| type, public :: mm_header_type | ||
| integer :: object | ||
| integer :: format | ||
| integer :: qualifier | ||
| integer :: symmetry | ||
| character(len=1024), allocatable :: comments(:) | ||
| end type mm_header_type | ||
|
|
||
| !> Version: experimental | ||
| !> | ||
| !> Load a matrix from a Matrix Market file | ||
| !> ([Specification](../page/specs/stdlib_io.html#load_mm)) | ||
| interface load_mm | ||
| #:for k, t, s in RCI_KINDS_TYPES | ||
| module subroutine load_mm_dense_${s}$(filename, matrix, iostat, iomsg) | ||
| !> Name of the Matrix Market file to load from | ||
| character(len=*), intent(in) :: filename | ||
| !> Matrix to be loaded from the Matrix Market file | ||
| ${t}$, allocatable, intent(out) :: matrix(:,:) | ||
| !> Error status of loading, zero on success | ||
| integer, intent(out), optional :: iostat | ||
| !> Associated error message in case of non-zero status code | ||
| character(len=:), allocatable, intent(out), optional :: iomsg | ||
| end subroutine | ||
| #:endfor | ||
| #:for k, t, s in RCI_KINDS_TYPES | ||
| module subroutine load_mm_coo_${s}$(filename, index, data, iostat, iomsg) | ||
| !> Name of the Matrix Market file to load from | ||
| character(len=*), intent(in) :: filename | ||
| !> Matrix indices to be read from the Matrix Market file | ||
| integer, allocatable, intent(out) :: index(:,:) | ||
| !> Matrix data to be read from the Matrix Market file | ||
| ${t}$, allocatable, intent(out) :: data(:) | ||
| !> Error status of loading, zero on success | ||
| integer, intent(out), optional :: iostat | ||
| !> Associated error message in case of non-zero status code | ||
| character(len=:), allocatable, intent(out), optional :: iomsg | ||
| end subroutine | ||
| #:endfor | ||
| end interface | ||
| public :: load_mm | ||
|
|
||
| !> Version: experimental | ||
| !> | ||
| !> Save a matrix to a Matrix Market file | ||
| !> ([Specification](../page/specs/stdlib_io.html#save_mm)) | ||
| interface save_mm | ||
| #:for k, t, s in RCI_KINDS_TYPES | ||
| module subroutine save_mm_dense_${s}$(filename, matrix, comment, format, symmetry, iostat, iomsg) | ||
| character(len=*), intent(in) :: filename | ||
| ${t}$, intent(in) :: matrix(:,:) | ||
| character(len=*), intent(in), optional :: comment | ||
| character(len=*), intent(in), optional :: format | ||
| character(len=*), intent(in), optional :: symmetry | ||
| integer, intent(out), optional :: iostat | ||
| character(len=:), allocatable, intent(out), optional :: iomsg | ||
| end subroutine | ||
| #:endfor | ||
|
|
||
| #:for k, t, s in RCI_KINDS_TYPES | ||
| module subroutine save_mm_coo_${s}$(filename, index, data, comment, format, symmetry, iostat, iomsg) | ||
| character(len=*), intent(in) :: filename | ||
| integer, intent(in) :: index(:,:) | ||
| ${t}$, intent(in) :: data(:) | ||
| character(len=*), intent(in), optional :: comment | ||
| character(len=*), intent(in), optional :: format | ||
| character(len=*), intent(in), optional :: symmetry | ||
| integer, intent(out), optional :: iostat | ||
| character(len=:), allocatable, intent(out), optional :: iomsg | ||
| end subroutine | ||
| #:endfor | ||
| end interface save_mm | ||
| public :: save_mm | ||
|
|
||
| end module stdlib_io_mm |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly cosmetic, but I guess you could
error stop "your message"rather than a combination ofprintandstop.