GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG,MAINT: `f2py` doesn't map `iso_c_binding` values by default · Issue #24553 · numpy/numpy

BUG,MAINT: f2py doesn't map iso_c_binding values by default #24553

New issue
Copy link
New issue
Copy link
Closed
#24555
Closed
BUG,MAINT: f2py doesn't map iso_c_binding values by default#24553
#24555
Copy link
Labels
00 - Bugcomponent: numpy.f2py

Description

@HaoZeke
HaoZeke
opened on Aug 26, 2023
Issue body actions

Reproducer

Consider:

! isoc_oddity.f90
  module coddity
    use iso_c_binding, only: c_double
    implicit none
    contains
      subroutine c_add(a, b, c) bind(c, name="c_add")
        real(c_double), intent(in) :: a, b
        real(c_double), intent(out) :: c
        print*, "a is", a
        print*, "b is", b
        c = a + b
      end subroutine c_add
  end module coddity

Which compiles fine but doesn't do what one might expect:

python -m numpy.f2py -c isoc_oddity.f90 -m buggy
python -c 'import buggy;res=buggy.coddity.c_add(1, 2); print(f"res: {res}, exp: 3, eq: {res==3}")'
 a is   2.0000004731118679     
 b is   5.3049894774131808E-315
res: 1.0, exp: 3, eq: False

Clearly, c_double is not being interpreted correctly. This has an easy user-land fix though, adding an .f2py_f2cmap file to the directory (or passing a named file in via the command line) with the following:

# isoc_f2cmap
dict(
    real=dict(c_double="double"),
)

Will work correctly:

python -m numpy.f2py -c isoc_oddity.f90 -m buggy --f2cmap isoc_f2cmap
python -c 'import buggy;res=buggy.coddity.c_add(1, 2); print(f"res: {res}, exp: 3, eq: {res==3}")'
 a is   1.0000000000000000     
 b is   2.0000000000000000     
res: 3.0, exp: 3, eq: True

Suggestion

This is definitely unexpected behavior, iso_c_binding values should be mapped correctly by default, or atleast loaded in when the iso_c_binding module is used.

Reacted by Ralf Gommers

Activity

  1. HaoZeke
    added
    component: numpy.f2py
    on Aug 26, 2023
  2. HaoZeke
    changed the title [-]BUG,MAINT: f2py doesn't map iso_c_environment variables by default[/-] [+]BUG,MAINT: `f2py` doesn't map `iso_c_binding` values by default[/+] on Aug 26, 2023
  3. HaoZeke
    added
    00 - Bug
    on Aug 26, 2023
  4. HaoZeke
    added a commit that references this issue on Aug 26, 2023

    TST: Add a test for numpygh-24553

    a34d2bc
  5. charris
    closed this as completedin #24555on Sep 2, 2023
  6. charris
    added a commit that references this issue on Sep 2, 2023

    TST: Add a test for numpygh-24553

    d3cd409
  7. charris
    added a commit that references this issue on Nov 11, 2023

    TST: Add a test for numpygh-24553

    0230426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bugcomponent: numpy.f2py

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.