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 — ENH: Add templates for f2py c functions and handle more C types by Pranavchiku · Pull Request #25260 · numpy/numpy

Conversation

@Pranavchiku

@Pranavchiku Pranavchiku commented Nov 27, 2023

Copy link
Copy Markdown

Closes #25229.

This PR has commits from #25226, we'll wait till it gets merged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added the 01 - Enhancement label Nov 27, 2023
HaoZeke
HaoZeke reviewed Nov 28, 2023
View reviewed changes
Comment thread numpy/f2py/tests/src/isocintrin/isoCtests.f90 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Pranavchiku
Pranavchiku commented Nov 29, 2023
View reviewed changes
Comment thread numpy/f2py/tests/test_bindc.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Pranavchiku
Pranavchiku force-pushed the gh25229 branch from 65723cd to 4241bc8 Compare November 29, 2023 09:53
@Pranavchiku
Pranavchiku requested a review from HaoZeke November 29, 2023 10:46
@HaoZeke

HaoZeke commented Dec 19, 2023

Copy link
Copy Markdown
Member

@Pranavchiku now that #25226 is in, could you rebase this and address the test failures?

Pranavchiku reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pranavchiku
Pranavchiku force-pushed the gh25229 branch 2 times, most recently from 9b71de9 to 0170e08 Compare December 22, 2023 08:45
@HaoZeke

HaoZeke commented Dec 24, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@Pranavchiku, the problem is essentially in the way the c_double is being mapped. It is now incorrectly mapped to float somewhere instead of the correct double. Here are the changes from the older file (working) to the this one:

❯ diff meson_works/codditymodule.c meson_broken/codditymodule.c
2c2
<  * This file is auto-generated with f2py (version:2.0.0.dev0+git20231224.a43c068).
---
>  * This file is auto-generated with f2py (version:2.0.0.dev0+git20231222.94d21b0).
5c5
<  * Generation date: Sun Dec 24 18:19:50 2023
---
>  * Generation date: Sun Dec 24 18:24:33 2023
140a141,152
> static int
> float_from_pyobj(float* v, PyObject *obj, const char *errmess)
> {
>     double d=0.0;
>     if (double_from_pyobj(&d,obj,errmess)) {
>         *v = (float)d;
>         return 1;
>     }
>     return 0;
> }
> 
> 
170c182
<                            void (*f2py_func)(double*,double*,double*)) {
---
>                            void (*f2py_func)(float*,float*,float*)) {
175c187
<     double a = 0;
---
>     float a = 0;
177c189
<     double b = 0;
---
>     float b = 0;
179c191
<     double c = 0;
---
>     float c = 0;
192c204
<         f2py_success = double_from_pyobj(&a,a_capi,"coddity.coddity.c_add() 1st argument (a) can't be converted to double");
---
>         f2py_success = float_from_pyobj(&a,a_capi,"coddity.coddity.c_add() 1st argument (a) can't be converted to float");
195c207
<         f2py_success = double_from_pyobj(&b,b_capi,"coddity.coddity.c_add() 2nd argument (b) can't be converted to double");
---
>         f2py_success = float_from_pyobj(&b,b_capi,"coddity.coddity.c_add() 2nd argument (b) can't be converted to float");
214c226
<         capi_buildvalue = Py_BuildValue("d",c);
---
>         capi_buildvalue = Py_BuildValue("f",c);
298c310
<     s = PyUnicode_FromString("2.0.0.dev0+git20231224.a43c068");
---
>     s = PyUnicode_FromString("2.0.0.dev0+git20231222.94d21b0");
302c314
<         "This module 'coddity' is auto-generated with f2py (version:2.0.0.dev0+git20231224.a43c068).\nFunctions:\n"
---
>         "This module 'coddity' is auto-generated with f2py (version:2.0.0.dev0+git20231222.94d21b0).\nFunctions:\n"
306c318
<     s = PyUnicode_FromString("2.0.0.dev0+git20231224.a43c068");
---
>     s = PyUnicode_FromString("2.0.0.dev0+git20231222.94d21b0");

For this test case (extracted from the isoCtests.f90 file):

  module coddity
    use iso_c_binding, only: c_double, c_int, c_int64_t
    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
        c = a + b
      end subroutine c_add
  end module coddity

The steps to reproduce this (and other similar errors) is:

micromamba activate numpy-dev
spin run $SHELL
cd gh-25229 # or wherever the file is
f2py -m coddity -c coddity.f90 --build-dir blah --backend meson
# Modify the files after inspection

Another thing to do is to use meld to visually diff whole folders at once, between working and non-working variants.

Pranavchiku reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

HaoZeke
HaoZeke reviewed Dec 24, 2023
View reviewed changes
Comment thread numpy/f2py/_isocbind.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

HaoZeke
HaoZeke requested changes Dec 24, 2023
View reviewed changes

@HaoZeke HaoZeke left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku almost there :) looking good so far!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread numpy/f2py/cfuncs.py
Comment on lines +873 to +884
needs['int64_t_from_pyobj'] = ['long_from_pyobj']
cfuncs['int64_t_from_pyobj'] = """
static int
int64_t_from_pyobj(int64_t* v, PyObject *obj, const char *errmess) {
long i = 0;
if (long_from_pyobj(&i, obj, errmess)) {
*v = (int64_t)i;
return 1;
}
return 0;
}
"""

@HaoZeke HaoZeke Dec 24, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku could you check (in light of the previous comment) which of these need to be explicitly written out and which can be just type cast? I suppose it might be best to just have each one handled explicitly, if only to get the C++ types correct in the function signatures....

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Pranavchiku reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@Pranavchiku Pranavchiku Dec 25, 2023

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, on it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Pranavchiku Pranavchiku Dec 25, 2023

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, we already have ones for float/double_complex so I skipped both. I am not sure about how to add it for bool hence skipped it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Pranavchiku

Pranavchiku commented Dec 25, 2023

Copy link
Copy Markdown
Author

Thank you @HaoZeke, I'll apply code review by tonight.

HaoZeke reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Pranavchiku

Pranavchiku commented Dec 25, 2023

Copy link
Copy Markdown
Author

Tests pass locally for me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@HaoZeke HaoZeke added the component: numpy.f2py label Jan 30, 2024
Pranavchiku and others added 6 commits January 30, 2024 14:06
@Pranavchiku
fix: use value of v1 from c2py_map
03930e7
@Pranavchiku
fix: populate isoc_c2pycode_map and iso_c2py_map
e74fa38
@Pranavchiku
chore: add cfuncs for int64_t
6902675
@Pranavchiku
test: update assert statements
b6142d5
@HaoZeke @Pranavchiku
BUG: Fix type maps to keep numeric precision[f2py]
0b45c9b
@Pranavchiku
chore: add cfuncs
3597e45
@Pranavchiku
Pranavchiku force-pushed the gh25229 branch from 9c59241 to 3597e45 Compare January 30, 2024 08:36
@bmwoodruff

bmwoodruff commented Jun 11, 2025

Copy link
Copy Markdown
Member

Based on a discussion at the triage meeting, we decided to close inactive draft PRs that are more than 1 year old. Feel free to open a new PR to continue working on this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bmwoodruff bmwoodruff closed this Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@HaoZeke HaoZeke HaoZeke requested changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

01 - Enhancement component: numpy.f2py

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ENH: Add templates for f2py c functions and handle more C types

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Pranavchiku @HaoZeke @bmwoodruff
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — 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.