8000 BUG, ENH: Fix ``iso_c_binding`` type maps and fix ``bind(c)`` support by charris · Pull Request #24622 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG, ENH: Fix iso_c_binding type maps and fix bind(c) support #24622

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

Merged
merged 17 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MAINT: fix ISO_C type maps in f2py
  • Loading branch information
HaoZeke authored and charris committed Sep 2, 2023
commit 091e89510200a84c16799154bdf79a0b9694c362
26 changes: 25 additions & 1 deletion numpy/f2py/auxfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sys
import types
from functools import reduce
from copy import deepcopy

from . import __version__
from . import cfuncs
Expand Down Expand Up @@ -47,7 +48,8 @@
'isunsigned_chararray', 'isunsigned_long_long',
'isunsigned_long_longarray', 'isunsigned_short',
'isunsigned_shortarray', 'l_and', 'l_not', 'l_or', 'outmess',
'replace', 'show', 'stripcomma', 'throw_error', 'isattr_value'
'replace', 'show', 'stripcomma', 'throw_error', 'isattr_value',
'deep_merge'
]


Expand Down Expand Up @@ -888,3 +890,25 @@ def applyrules(rules, d, var={}):
if ret[k] == []:
del ret[k]
return ret

def deep_merge(dict1, dict2):
"""Deep merge two dictionaries and return 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
44 changes: 43 additions & 1 deletion numpy/f2py/capi_maps.py
60D8
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,49 @@
'byte': {'': 'char'},
}

f2cmap_default = copy.deepcopy(f2cmap_all)
iso_c_binding_map = {
'integer': {
'c_int': 'int',
'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',
},
'real': {
'c_float': 'float',
'c_double': 'double',
'c_long_double': 'long double'
},
'complex': {
'c_float_complex': 'float _Complex',
'c_double_complex': 'double _Complex',
'c_long_double_complex': 'long double _Complex'
},
'logical': {
'c_bool': '_Bool'
},
'character': {
'c_char': 'char'
}
}

f2cmap_default = deep_merge(f2cmap_all, iso_c_binding_map)

f2cmap_mapped = []

Expand Down
0