GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — BUG: Handle ``iso_c_type`` mappings more consistently by HaoZeke · Pull Request #25226 · numpy/numpy Conversation
|
|
I'm not sure I can review this without some context. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, so the reported issue is that as currently implemented, the I will leave comments in the code. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def deep_merge(dict1, dict2): | ||
| """Recursively merge two dictionaries into a new dictionary. | ||
|
|
||
| Parameters: | ||
| - dict1: The base dictionary. | ||
| - dict2: The dictionary to merge into a copy of dict1. | ||
| If a key exists in both, the dict2 value will take precedence. | ||
|
|
||
| Returns: | ||
| - A new merged dictionary. | ||
| """ | ||
| merged_dict = deepcopy(dict1) | ||
| for key, value in dict2.items(): | ||
| if key in merged_dict: | ||
| if isinstance(merged_dict[key], dict) and isinstance(value, dict): | ||
| merged_dict[key] = deep_merge(merged_dict[key], value) | ||
| else: | ||
| merged_dict[key] = value | ||
| else: | ||
| merged_dict[key] = value | ||
| return merged_dict | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No longer required since it is handled in process_f2cmap_dict
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for k, d1 in d.items(): | ||
| for k1 in d1.keys(): | ||
| d1[k1.lower()] = d1[k1] | ||
| d[k.lower()] = d[k] | ||
| for k in d.keys(): | ||
| if k not in f2cmap_all: | ||
| f2cmap_all[k] = {} | ||
| for k1 in d[k].keys(): | ||
| if d[k][k1] in c2py_map: | ||
| if k1 in f2cmap_all[k]: | ||
| outmess( | ||
| "\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n" % (k, k1, f2cmap_all[k][k1], d[k][k1])) | ||
| f2cmap_all[k][k1] = d[k][k1] | ||
| outmess('\tMapping "%s(kind=%s)" to "%s"\n' % | ||
| (k, k1, d[k][k1])) | ||
| f2cmap_mapped.append(d[k][k1]) | ||
| else: | ||
| errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n" % ( | ||
| k, k1, d[k][k1], d[k][k1], list(c2py_map.keys()))) | ||
| f2cmap_all, f2cmap_mapped = process_f2cmap_dict(f2cmap_all, d, c2py_map, True) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This section is used to handle user provided f2cmap files, now refactored into a function, process_f2cmap_dict which is also used for the iso_c_binding types.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Essentially, the bug in #24555 was that I didn't update f2cmap_mapped.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| f2cmap_all = deep_merge(f2cmap_all, iso_c_binding_map) | ||
| # Add ISO_C handling | ||
| c2pycode_map.update(isoc_c2pycode_map) | ||
| c2py_map.update(iso_c2py_map) | ||
| f2cmap_all, _ = process_f2cmap_dict(f2cmap_all, iso_c_binding_map, c2py_map) | ||
| # End ISO_C handling | ||
| f2cmap_default = copy.deepcopy(f2cmap_all) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The problem with the old handling is that updating the f2cmap_all doesn't preserve / update the mapping basically.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| return f2cmap_all, f2cmap_mapped |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The return here is key, previously only the f2cmap dictionary was being updated, now we ensure the mapped types are tracked as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@mattip I rescoped this into a smaller minimal fix and added comments now, the long and short of it is I forgot to consider propagating the kind map for variables my older PR (#25226 (comment)). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Actually making this a draft to check the subroutine mentioned in the original issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Fixes numpygh-25226 MAINT: Cleanup and scope fix better [f2py]
| 'c_short': 'short int', | ||
| 'c_long': 'long int', | ||
| 'c_long_long': 'long long int', | ||
| 'c_signed_char': 'signed char', | ||
| 'c_size_t': 'size_t', | ||
| 'c_int8_t': 'int8_t', | ||
| 'c_int16_t': 'int16_t', | ||
| 'c_int32_t': 'int32_t', | ||
| 'c_int64_t': 'int64_t', | ||
| 'c_int_least8_t': 'int_least8_t', | ||
| 'c_int_least16_t': 'int_least16_t', | ||
| 'c_int_least32_t': 'int_least32_t', | ||
| 'c_int_least64_t': 'int_least64_t', | ||
| 'c_int_fast8_t': 'int_fast8_t', | ||
| 'c_int_fast16_t': 'int_fast16_t', | ||
| 'c_int_fast32_t': 'int_fast32_t', | ||
| 'c_int_fast64_t': 'int_fast64_t', | ||
| 'c_intmax_t': 'intmax_t', | ||
| 'c_intptr_t': 'intptr_t', | ||
| 'c_ptrdiff_t': 'intptr_t', | ||
| 'c_short': 'short', # 'short' <=> 'int' for now | ||
| 'c_long': 'long', # 'long' <=> 'int' for now | ||
| 'c_long_long': 'long_long', | ||
| 'c_signed_char': 'signed_char', | ||
| 'c_size_t': 'unsigned', # size_t <=> 'unsigned' for now |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What's going on here is that the original PR for ISO_C_BINDINGS was overly optimistic. F2PY can only support maps which are defined as part of the c2py keys, and then those need to have corresponding cfuncs snippets to generate binding code. For now, this performs forced casting to known types to get around that.
Eventually, the various maps in capi_maps will be updated to get more correct bindings #25229. However, for now this is exactly the handling done typically at the user end via the f2cmap files.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@mattip, let me know if this is clearer now :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have a potential fix for #25229 ready, do you wish me to open a PR or wait to get this merged? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
We should wait for this to get merged, but feel free to open a draft PR, we can start iterating over it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@mattip does the extended rationale make sense? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Let's try this, hoepfully we will get some end-user feedback before the release. Thanks @HaoZeke |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Fixes numpygh-25226 MAINT: Cleanup and scope fix better [f2py]
iso_c_type mappings more consistentlyiso_c_type mappings more consistently
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
BUG: c2capi_map entries missing for iso_c_binding in f2py
There was an error while loading. Please reload this page.