首页 > 解决方案 > 带参数的 f2py 转换子例程具有 inout 的意图

问题描述

通过f2py -c sorting.f90 -m sortF,我得到sortF.cpython-37m-x86_64-linux-gnu.so了很棒的东西。

sorting.f90

module sorting 
    use iso_fortran_env, only: i4 => int32, i8 => int64
    implicit none
contains
    subroutine bubbleSort(array)
        implicit none
        integer, dimension(:):: array
        integer :: i, j, tem
        i = size(array)
        do while (i > 1)
            do j = 1, i - 1 
                if (array(j) > array(j + 1)) then
                    tem = array(j)
                    array(j) = array(j + 1)
                    array(j + 1) = tem
                end if 
            end do
            i = i - 1
        end do 
    end subroutine bubbleSort
end module sorting 

在这个子程序中,输入array被改变了,因此,我希望在我执行之后sorting.bubblesort(x),我希望x变成[1, 2, 3, 5]

In [1]: from sortF import sorting                                                                                   

In [2]: x = [1, 2, 5, 3]                                                                                            

In [3]: print(sorting.bubblesort(x))                                                                                
None

In [4]: x                                                                                                           
Out[4]: [1, 2, 5, 3]

标签: fortranf2pypython-extensions

解决方案


推荐阅读