Skip to content

BUG: [Regression 1.21.4 -> 1.22.0] f2py infers integers incorrectly from shape (-(nterms):nterms,nvcount) #20709

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

Closed
inducer opened this issue Jan 2, 2022 · 2 comments · Fixed by #20721

Comments

@inducer
Copy link
Contributor

inducer commented Jan 2, 2022

Describe the issue:

Consider the following F90 snippet, let's call that myext.f90.

subroutine h2dmpmp_vec(expn1, nterms, expn2, nvcount)
  implicit none
  integer, intent(in) :: nvcount
  complex*16, intent(in) :: expn1(-(nterms):nterms,nvcount)
  integer, intent(in) :: nterms
  complex*16, intent(out) :: expn2(-(nterms):nterms,nvcount)

  expn2 = expn1
end

(Excerpted and simplified from code generated by https://github.com/inducer/pyfmmlib/.)

Then run this line and get the following output:

$ f2py -c myext.f90; python -c "import untitled; print(untitled.h2dmpmp_vec.__doc__)"
# (SNIP gobs of compiler warnings)
expn2 = h2dmpmp_vec(expn1,[nterms,nvcount])

Wrapper for ``h2dmpmp_vec``.

Parameters
----------
expn1 : input rank-2 array('D') with bounds (1 + 2 * nterms,nvcount)

Other Parameters
----------------
nterms : input int, optional
    Default: shape(expn1, 0)
nvcount : input int, optional
    Default: shape(expn1, 1)

Returns
-------
expn2 : rank-2 array('D') with bounds (1 + 2 * nterms,nvcount)

Observe the default for nterms is given as shape(expn1, 0) when it should be (-1 + shape(expn1, 0)) / 2. If you remove nvcount from the shapes of expn1 and expn2, f2py will produce that.

Maybe this issue is related to #19805?

cc @pearu

NumPy/Python version information:

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.22.0 3.10.1 (main, Dec 16 2021, 23:04:04) [GCC 11.2.0]

Related CI failures;

@inducer inducer changed the title BUG: [Regression 1.21.4 -> 1.22] f2py infers integers incorrectly from shape (-(nterms):nterms,nvcount) BUG: [Regression 1.21.4 -> 1.22.0] f2py infers integers incorrectly from shape (-(nterms):nterms,nvcount) Jan 2, 2022
@pearu
Copy link
Contributor

pearu commented Jan 3, 2022

For the record, here is another way to reproduce the issue. First, the expected result is

$ f2py ~/test/numpy/gh20709.f90 -h stdout
subroutine h2dmpmp_vec(expn1,nterms,expn2,nvcount) ! in /home/pearu/test/numpy/gh20709.f90
    complex*16 dimension(2 * nterms + 1,nvcount),intent(in) :: expn1
    integer, optional,intent(in),check((shape(expn1,0)-1)/(2)==nterms),depend(expn1) :: nterms=(shape(expn1,0)-1)/(2)
    complex*16 dimension(2 * nterms + 1,nvcount),intent(out),depend(nterms,nvcount) :: expn2
    integer, optional,intent(in),check(shape(expn1,1)==nvcount),depend(expn1) :: nvcount=shape(expn1,1)
end subroutine h2dmpmp_vec

but the current numpy main branch gives:

subroutine h2dmpmp_vec(expn1,nterms,expn2,nvcount) ! in /home/pearu/test/numpy/gh20709.f90
    complex*16 dimension(1 + 2 * nterms,nvcount),intent(in) :: expn1
    integer, optional,intent(in),check(shape(expn1, 0) == 1 + 2 * nterms),depend(expn1) :: nterms=shape(expn1, 0)
    complex*16 dimension(1 + 2 * nterms,nvcount),intent(out),depend(nvcount,nterms) :: expn2
    integer, optional,intent(in),check(shape(expn1, 1) == nvcount),depend(expn1) :: nvcount=shape(expn1, 1)
end subroutine h2dmpmp_vec

I'll look into it..

pearu added a commit to pearu/numpy that referenced this issue Jan 3, 2022
@pearu pearu self-assigned this Jan 3, 2022
@charris charris added this to the 1.22.1 release milestone Jan 4, 2022
pearu added a commit that referenced this issue Jan 4, 2022
…py (#20721)

* BUG: Fix array dimensions solver for multidimensional arguments in f2py. See #20709
charris pushed a commit to charris/numpy that referenced this issue Jan 4, 2022
* BUG: Fix array dimensions solver for multidimensional arguments in f2py. See numpy#20709
@inducer
Copy link
Contributor Author

inducer commented Jan 7, 2022

Thanks for fixing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants