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: Work with the ISOC_BINDINGS more consisently · charris/numpy@d7e78b6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • numpy/f2py
    • auxfuncs.py
    • capi_maps.py
    • tests
      • test_isoc.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎numpy/f2py/auxfuncs.py‎

Copy file name to clipboardExpand all lines: numpy/f2py/auxfuncs.py
+58-1Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'isunsigned_long_longarray', 'isunsigned_short',
5151
'isunsigned_shortarray', 'l_and', 'l_not', 'l_or', 'outmess',
5252
'replace', 'show', 'stripcomma', 'throw_error', 'isattr_value',
53-
'deep_merge', 'getuseblocks'
53+
'deep_merge', 'getuseblocks', 'process_f2cmap_dict'
5454
]
5555

5656

@@ -945,3 +945,60 @@ def getuseblocks(pymod):
945945
if modblock.get('use'):
946946
all_uses.extend([x for x in modblock.get("use").keys() if "__" not in x])
947947
return all_uses
948+
949+
def process_f2cmap_dict(f2cmap_all, new_map, c2py_map):
950+
"""
951+
Update the Fortran-to-C type mapping dictionary with new mappings.
952+
953+
This function integrates a new mapping dictionary into an existing
954+
Fortran-to-C type mapping dictionary. It ensures that all keys are in
955+
lowercase and validates new entries against a given C-to-Python mapping
956+
dictionary. Redefinitions and invalid entries are reported with a warning.
957+
958+
Parameters
959+
----------
960+
f2cmap_all : dict
961+
The existing Fortran-to-C type mapping dictionary that will be updated.
962+
It should be a dictionary of dictionaries where the main keys represent
963+
Fortran types and the nested dictionaries map Fortran type specifiers
964+
to corresponding C types.
965+
966+
new_map : dict
967+
A dictionary containing new type mappings to be added to `f2cmap_all`.
968+
The structure should be similar to `f2cmap_all`, with keys representing
969+
Fortran types and values being dictionaries of type specifiers and their
970+
C type equivalents.
971+
972+
c2py_map : dict
973+
A dictionary used for validating the C types in `new_map`. It maps C
974+
types to corresponding Python types and is used to ensure that the C
975+
types specified in `new_map` are valid.
976+
977+
Returns
978+
-------
979+
dict
980+
The updated Fortran-to-C type mapping dictionary.
981+
"""
982+
for k, d1 in new_map.items():
983+
for k1 in list(d1.keys()):
984+
d1[k1.lower()] = d1.pop(k1)
985+
k_lower = k.lower()
986+
987+
if k_lower not in f2cmap_all:
988+
f2cmap_all[k_lower] = {}
989+
for k1, v1 in d1.items():
990+
if v1 in c2py_map:
991+
if k1 in f2cmap_all[k_lower]:
992+
outmess(
993+
"\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n"
994+
% (k_lower, k1, f2cmap_all[k_lower][k1], v1)
995+
)
996+
f2cmap_all[k_lower][k1] = v1
997+
outmess('\tMapping "%s(kind=%s)" to "%s"\n' % (k_lower, k1, v1))
998+
else:
999+
errmess(
1000+
"\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n"
1001+
% (k_lower, k1, v1, v1, list(c2py_map.keys()))
1002+
)
1003+
1004+
return f2cmap_all
Collapse file

‎numpy/f2py/capi_maps.py‎

Copy file name to clipboardExpand all lines: numpy/f2py/capi_maps.py
+5-23Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
__all__ = [
3030
'getctype', 'getstrlength', 'getarrdims', 'getpydocsign',
3131
'getarrdocsign', 'getinit', 'sign2map', 'routsign2map', 'modsign2map',
32-
'cb_sign2map', 'cb_routsign2map', 'common_sign2map'
32+
'cb_sign2map', 'cb_routsign2map', 'common_sign2map', 'process_f2cmap_dict'
3333
]
3434

3535

@@ -131,7 +131,7 @@
131131
'byte': {'': 'char'},
132132
}
133133

134-
f2cmap_all = deep_merge(f2cmap_all, iso_c_binding_map)
134+
f2cmap_all = process_f2cmap_dict(f2cmap_all, iso_c_binding_map, c2py_map)
135135
f2cmap_default = copy.deepcopy(f2cmap_all)
136136

137137
f2cmap_mapped = []
@@ -156,29 +156,11 @@ def load_f2cmap_file(f2cmap_file):
156156
outmess('Reading f2cmap from {!r} ...\n'.format(f2cmap_file))
157157
with open(f2cmap_file) as f:
158158
d = eval(f.read().lower(), {}, {})
159-
for k, d1 in d.items():
160-
for k1 in d1.keys():
161-
d1[k1.lower()] = d1[k1]
162-
d[k.lower()] = d[k]
163-
for k in d.keys():
164-
if k not in f2cmap_all:
165-
f2cmap_all[k] = {}
166-
for k1 in d[k].keys():
167-
if d[k][k1] in c2py_map:
168-
if k1 in f2cmap_all[k]:
169-
outmess(
170-
"\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n" % (k, k1, f2cmap_all[k][k1], d[k][k1]))
171-
f2cmap_all[k][k1] = d[k][k1]
172-
outmess('\tMapping "%s(kind=%s)" to "%s"\n' %
173-
(k, k1, d[k][k1]))
174-
f2cmap_mapped.append(d[k][k1])
175-
else:
176-
errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n" % (
177-
k, k1, d[k][k1], d[k][k1], list(c2py_map.keys())))
159+
f2cmap_all = process_f2cmap_dict(f2cmap_all, d, c2py_map)
178160
outmess('Successfully applied user defined f2cmap changes\n')
179161
except Exception as msg:
180-
errmess(
181-
'Failed to apply user defined f2cmap changes: %s. Skipping.\n' % (msg))
162+
errmess('Failed to apply user defined f2cmap changes: %s. Skipping.\n' % (msg))
163+
182164

183165
cformat_map = {'double': '%g',
184166
'float': '%g',
Collapse file

‎numpy/f2py/tests/test_isoc.py‎

Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_isoc.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ def test_bindc_kinds(self):
2323
out = self.module.coddity.c_add_int64(1, 20)
2424
exp_out = 21
2525
assert out == exp_out
26+
27+
28+
def test_process_f2cmap_dict():
29+
from numpy.f2py.auxfuncs import process_f2cmap_dict
30+
f2cmap_all = {'integer': {'8': 'long_long'}}
31+
new_map = {'INTEGER': {'4': 'int'}}
32+
c2py_map = {'int': 'int', 'long_long': 'long'}
33+
34+
expected_result = {'integer': {'8': 'long_long', '4': 'int'}}
35+
36+
# Call the function
37+
result = process_f2cmap_dict(f2cmap_all, new_map, c2py_map)
38+
39+
# Assert the result is as expected
40+
assert result == expected_result

0 commit comments

Comments
0 (0)
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.