GeezerVison is showing github.com — TST: Test the cracked intrinsic module · HaoZeke/numpy@0c4e6cc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/_isocbind.py +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Partially from: | | 2 | +# https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html | 1 | 3 | iso_c_binding_map = { | 2 | 4 | 'integer': { | 3 | 5 | 'c_int': 'int', | | 44 | 46 | for fortran_type, c_type_dict in iso_c_binding_map.items(): | 45 | 47 | for c_type in c_type_dict.keys(): | 46 | 48 | isoc_kindmap[c_type] = fortran_type | | 49 | + | | 50 | +# For derived type maps | | 51 | +flatisoc = { | | 52 | + c_type: ctype | | 53 | + for type_category in iso_c_binding_map.values() | | 54 | + for c_type, ctype in type_category.items() | | 55 | +} |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/capi_maps.py -38Lines changed: 0 additions & 38 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 132 | 132 | 'type': {'': 'struct'}, | 133 | 133 | 'character': {'': 'string'} | 134 | 134 | } | 135 | | -# From: | 136 | | -# https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html | 137 | | -iso_c_binding_map = { | 138 | | - # Integers | 139 | | - 'c_int': 'int', | 140 | | - 'c_short': 'short int', | 141 | | - 'c_long': 'long int', | 142 | | - 'c_long_long': 'long long int', | 143 | | - 'c_signed_char': 'signed char', | 144 | | - 'c_size_t': 'size_t', | 145 | | - 'c_int8_t': 'int8_t', | 146 | | - 'c_int16_t': 'int16_t', | 147 | | - 'c_int32_t': 'int32_t', | 148 | | - 'c_int64_t': 'int64_t', | 149 | | - 'c_int_least8_t': 'int_least8_t', | 150 | | - 'c_int_least16_t': 'int_least16_t', | 151 | | - 'c_int_least32_t': 'int_least32_t', | 152 | | - 'c_int_least64_t': 'int_least64_t', | 153 | | - 'c_int_fast8_t': 'int_fast8_t', | 154 | | - 'c_int_fast16_t': 'int_fast16_t', | 155 | | - 'c_int_fast32_t': 'int_fast32_t', | 156 | | - 'c_int_fast64_t': 'int_fast64_t', | 157 | | - 'c_intmax_t': 'intmax_t', | 158 | | - 'c_intptr_t': 'intptr_t', | 159 | | - 'c_ptrdiff_t': 'ptrdiff_t', | 160 | | - # Floating Point Numbers | 161 | | - 'c_float': 'float', | 162 | | - 'c_double': 'double', | 163 | | - 'c_long_double': 'long double', | 164 | | - # Complex Numbers | 165 | | - 'c_float_complex': 'float _Complex', | 166 | | - 'c_double_complex': 'double _Complex', | 167 | | - 'c_long_double_complex': 'long double _Complex', | 168 | | - # Logical | 169 | | - 'c_bool': '_Bool', | 170 | | - # Char | 171 | | - 'c_char': 'char', | 172 | | -} | 173 | 135 | # TODO:Support ["iso_fortran_env", "ieee_exceptions", "ieee_arithmetic", "ieee_features"] | 174 | 136 |
| 175 | 137 | f2cmap_all = deep_merge(f2cmap_all, iso_c_binding_map) | |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/crackfortran.py +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 162 | 162 | from . import auxfuncs as aux | 163 | 163 | from . import symbolic | 164 | 164 | from . import capi_maps as capim | | 165 | +from . import _isocbind as _isoc | 165 | 166 |
| 166 | 167 | f2py_version = __version__.version | 167 | 168 |
| @@ -1494,7 +1495,7 @@ def analyzeline(m, case, line): | 1494 | 1495 | else: | 1495 | 1496 | rl[l] = l | 1496 | 1497 | if name == "iso_c_binding": | 1497 | | - rl = {k:capim.iso_c_binding_map.get(k) for k,v in rl.items()} | | 1498 | + rl = {k:_isoc.flatisoc.get(k) for k,v in rl.items()} | 1498 | 1499 | groupcache[groupcounter]['use'][name]['map'] = rl | 1499 | 1500 | elif mintrin: | 1500 | 1501 | # Intrinsic check | |
Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +module vec | | 2 | + use, intrinsic :: iso_c_binding | | 3 | + implicit none | | 4 | + | | 5 | + type, bind(c) :: cartesian | | 6 | + real(c_float) :: x(2),y,z | | 7 | + end type cartesian | | 8 | + | | 9 | + type, bind(c) :: radial | | 10 | + real(c_double) :: rad, theta | | 11 | + end type radial | | 12 | + | | 13 | +end module vec |
Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +module vec | | 2 | + use iso_c_binding, only: c_float, c_double | | 3 | + implicit none | | 4 | + | | 5 | + type, bind(c) :: cartesian | | 6 | + real(c_float) :: x(2),y,z | | 7 | + end type cartesian | | 8 | + | | 9 | + type, bind(c) :: radial | | 10 | + real(c_double) :: rad, theta | | 11 | + end type radial | | 12 | + | | 13 | +end module vec |
Collapse file Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_crackfortran.py +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -323,7 +323,6 @@ def test_nameargspattern_backtracking(self, adversary): | 323 | 323 | good_version_of_adversary = repeated_adversary + '@)@' | 324 | 324 | assert nameargspattern.search(good_version_of_adversary) | 325 | 325 |
| 326 | | - | 327 | 326 | class TestFunctionReturn(util.F2PyTest): | 328 | 327 | sources = [util.getpath("tests", "src", "crackfortran", "gh23598.f90")] | 329 | 328 |
| @@ -348,3 +347,18 @@ def test_gh22648(self, tmp_path): | 348 | 347 | with contextlib.redirect_stdout(io.StringIO()) as stdout_f2py: | 349 | 348 | mod = crackfortran.crackfortran([str(fpath)]) | 350 | 349 | assert "Mismatch" not in stdout_f2py.getvalue() | | 350 | + | | 351 | + | | 352 | +class TestIntrinsicModule: | | 353 | + def test_dependencies_only(self, tmp_path): | | 354 | + fpath = util.getpath("tests", "src", "crackfortran", "isocbindonly.f90") | | 355 | + mod = crackfortran.crackfortran([str(fpath)]) | | 356 | + assert len(mod) == 1 | | 357 | + assert mod[0]["use"] == {'iso_c_binding': {'map': {'c_double': 'double', 'c_float': 'float'}, 'only': 1}} | | 358 | + | | 359 | + def test_dependencies(self, tmp_path): | | 360 | + fpath = util.getpath("tests", "src", "crackfortran", "isocbind.f90") | | 361 | + mod = crackfortran.crackfortran([str(fpath)]) | | 362 | + assert len(mod) == 1 | | 363 | + from numpy.f2py import capi_maps as capim | | 364 | + assert list(mod[0]["use"].values())[0] == capim.iso_c_binding_map |
|