Skip to content

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

@inducer

Description

@inducer

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;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions