Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/specs/stdlib_sparse.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,16 @@ If the `diagonal` array has not been previously allocated, the `diag` subroutine

### Syntax

`call ` [[stdlib_sparse_conversion(module):coo2csr(interface)]] `(coo,csr)`
`call ` [[stdlib_sparse_conversion(module):coo2csr(interface)]] `(coo,csr[,sort_data])`

### Arguments

`coo` : Shall be a `COO` type of `real` or `complex` type. It is an `intent(in)` argument.

`csr` : Shall be a `CSR` type of `real` or `complex` type. It is an `intent(out)` argument.

`sort_data`, `optional` : Shall be a `logical` argument to determine whether data in the COO graph should be sorted before obtaining the CSR representation. The transformation from COO to CSR depends on the former being sorted in row-major order and not having duplicate pairs. Using this boolean will call a sorting routine at the cost of extra runtime, default `.false.`. It is an `intent(in)` argument.

### Syntax

`call ` [[stdlib_sparse_conversion(module):coo2csc(interface)]] `(coo,csc)`
Expand Down
16 changes: 13 additions & 3 deletions src/sparse/stdlib_sparse_conversion.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
!!
! This code was modified from https://github.com/jalvesz/FSPARSE by its author: Alves Jose
module stdlib_sparse_conversion
use stdlib_optval, only: optval
use stdlib_sorting, only: sort
use stdlib_sparse_constants
use stdlib_sparse_kinds
Expand Down Expand Up @@ -215,11 +216,20 @@ contains
#:endfor

#:for k1, t1, s1 in (KINDS_TYPES)
subroutine coo2csr_${s1}$(COO,CSR)
type(COO_${s1}$_type), intent(in) :: COO
type(CSR_${s1}$_type), intent(out) :: CSR
subroutine coo2csr_${s1}$(COO, CSR, sort_data)
type(COO_${s1}$_type), intent(inout) :: COO
type(CSR_${s1}$_type), intent(out) :: CSR
logical, intent(in), optional :: sort_data
logical :: sort_data_
integer(ilp) :: i

sort_data_ = optval(x=sort_data, default=.false.)

if(sort_data_) then
call sort_coo_unique_${s1}$( COO%index, COO%data, COO%nnz, COO%nrows, COO%ncols )
COO%is_sorted = .true.
end if

CSR%nnz = COO%nnz; CSR%nrows = COO%nrows; CSR%ncols = COO%ncols
CSR%storage = COO%storage

Expand Down
Loading