Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 从COO转换为CSR稀疏矩阵格式时求和重复值_Fortran_Sparse Matrix_Intel Mkl - Fatal编程技术网

Fortran 从COO转换为CSR稀疏矩阵格式时求和重复值

Fortran 从COO转换为CSR稀疏矩阵格式时求和重复值,fortran,sparse-matrix,intel-mkl,Fortran,Sparse Matrix,Intel Mkl,从COO格式转换为CSR格式时,如何有效地汇总重复值。执行类似于scipy实现的操作(http://docs.scipy.org/doc/scipy-0.9.0/reference/sparse.html)在fortran的子程序中是否存在?我正在使用Intel的MKL辅助例程将COO转换为CSR,但它似乎不适用于重复值。在我的代码中,我使用了我编写的以下子程序: subroutine csr_sum_duplicates(Ap, Aj, Ax) ! Sum together duplicate

从COO格式转换为CSR格式时,如何有效地汇总重复值。执行类似于scipy实现的操作(http://docs.scipy.org/doc/scipy-0.9.0/reference/sparse.html)在fortran的子程序中是否存在?我正在使用Intel的MKL辅助例程将COO转换为CSR,但它似乎不适用于重复值。

在我的代码中,我使用了我编写的以下子程序:

subroutine csr_sum_duplicates(Ap, Aj, Ax)
! Sum together duplicate column entries in each row of CSR matrix A
! The column indicies within each row must be in sorted order.
! Explicit zeros are retained.
! Ap, Aj, and Ax will be modified *inplace*
integer, intent(inout) :: Ap(:), Aj(:)
real(dp), intent(inout) :: Ax(:)
integer :: nnz, r1, r2, i, j, jj
real(dp) :: x
nnz = 1
r2 = 1
do i = 1, size(Ap) - 1
    r1 = r2
    r2 = Ap(i+1)
    jj = r1
    do while (jj < r2)
        j = Aj(jj)
        x = Ax(jj)
        jj = jj + 1
        do while (jj < r2)
            if (Aj(jj) == j) then
                x = x + Ax(jj)
                jj = jj + 1
            else
                exit
            end if
        end do
        Aj(nnz) = j
        Ax(nnz) = x
        nnz = nnz + 1
    end do
    Ap(i+1) = nnz
end do
end subroutine
其中
argsort

function iargsort(a) result(b)
! Returns the indices that would sort an array.
!
! Arguments
! ---------
!
integer, intent(in):: a(:)    ! array of numbers
integer :: b(size(a))         ! indices into the array 'a' that sort it
!
! Example
! -------
!
! iargsort([10, 9, 8, 7, 6])   ! Returns [5, 4, 3, 2, 1]

integer :: N                           ! number of numbers/vectors
integer :: i,imin,relimin(1)           ! indices: i, i of smallest, relative imin
integer :: temp                        ! temporary
integer :: a2(size(a))
a2 = a
N=size(a)
do i = 1, N
    b(i) = i
end do
do i = 1, N-1
    ! find ith smallest in 'a'
    relimin = minloc(a2(i:))
    imin = relimin(1) + i - 1
    ! swap to position i in 'a' and 'b', if not already there
    if (imin /= i) then
        temp = a2(i); a2(i) = a2(imin); a2(imin) = temp
        temp = b(i); b(i) = b(imin); b(imin) = temp
    end if
end do
end function
那应该是你想要的

function iargsort(a) result(b)
! Returns the indices that would sort an array.
!
! Arguments
! ---------
!
integer, intent(in):: a(:)    ! array of numbers
integer :: b(size(a))         ! indices into the array 'a' that sort it
!
! Example
! -------
!
! iargsort([10, 9, 8, 7, 6])   ! Returns [5, 4, 3, 2, 1]

integer :: N                           ! number of numbers/vectors
integer :: i,imin,relimin(1)           ! indices: i, i of smallest, relative imin
integer :: temp                        ! temporary
integer :: a2(size(a))
a2 = a
N=size(a)
do i = 1, N
    b(i) = i
end do
do i = 1, N-1
    ! find ith smallest in 'a'
    relimin = minloc(a2(i:))
    imin = relimin(1) + i - 1
    ! swap to position i in 'a' and 'b', if not already there
    if (imin /= i) then
        temp = a2(i); a2(i) = a2(imin); a2(imin) = temp
        temp = b(i); b(i) = b(imin); b(imin) = temp
    end if
end do
end function