OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

f2py - understanding how to pass an integer (and avoiding message Deprecated NumPy 1.25.)

  • Thread starter Thread starter user3749165
  • Start date Start date
U

user3749165

Guest
I am using f2py to link my old Fortran codes to Python. Although I did not have much trouble doing it, I still don't know how to handle integers. For instance, below is a piece of Fortran code where some integers are used with intent(inout) (mlag, nyt, nut, and net).

Code:
subroutine maxlags(iext, nump, degree, nsuby, mlag, npt, nnt, nyt, nut, net)
implicit none
integer, intent(in) :: nump, degree, nsuby
integer, intent(in) :: iext(nump, degree, nsuby)
integer, intent(inout) :: mlag, npt(nsuby), nnt(nsuby), nyt, nut, net
...
end subroutine maxlags

In python, if I define them as

Code:
nst = np.array([0])
nyt = np.array([0])
nut = np.array([0])
net = np.array([0])

calling the subroutine works, the values of mlag, nyt, nut and net are updated, but a warning msg comes out

/var/folders/sj/q_5xy_n50ps10lg75p99wbw80000gn/T/ipykernel_87520/378702212.py:18: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

If I define them as

Code:
nst = np.int32(0)
nyt = np.int32(0)
nut = np.int32(0)
net = np.int32(0)

there is no warning msg anymore, however the values of mlag, nyt, nut and net are longer updated.

How do I get rid of the warning msg? Or is there another to define integers to avoid the warning msg and get their values updated?

Many thanks.
<p>I am using <strong>f2py</strong> to link my old Fortran codes to Python. Although I did not have much trouble doing it, I still don't know how to handle integers. For instance, below is a piece of Fortran code where some integers are used with <em>intent(inout)</em> (mlag, nyt, nut, and net).</p>
<pre><code>subroutine maxlags(iext, nump, degree, nsuby, mlag, npt, nnt, nyt, nut, net)
implicit none
integer, intent(in) :: nump, degree, nsuby
integer, intent(in) :: iext(nump, degree, nsuby)
integer, intent(inout) :: mlag, npt(nsuby), nnt(nsuby), nyt, nut, net
...
end subroutine maxlags
</code></pre>
<p>In python, if I define them as</p>
<pre><code>nst = np.array([0])
nyt = np.array([0])
nut = np.array([0])
net = np.array([0])
</code></pre>
<p>calling the subroutine works, the values of mlag, nyt, nut and net are updated, but a warning msg comes out</p>
<blockquote>
<p>/var/folders/sj/q_5xy_n50ps10lg75p99wbw80000gn/T/ipykernel_87520/378702212.py:18: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)</p>
</blockquote>
<p>If I define them as</p>
<pre><code>nst = np.int32(0)
nyt = np.int32(0)
nut = np.int32(0)
net = np.int32(0)
</code></pre>
<p>there is no warning msg anymore, however the values of mlag, nyt, nut and net are longer updated.</p>
<p>How do I get rid of the warning msg? Or is there another to define integers to avoid the warning msg and get their values updated?</p>
<p>Many thanks.</p>
 
Top