MCPcopy Create free account
hub / github.com/numpy/numpy / process_f2cmap_dict

Function process_f2cmap_dict

numpy/f2py/auxfuncs.py:921–988  ·  view source on GitHub ↗

Update the Fortran-to-C type mapping dictionary with new mappings and return a list of successfully mapped C types. This function integrates a new mapping dictionary into an existing Fortran-to-C type mapping dictionary. It ensures that all keys are in lowercase and validates n

(f2cmap_all, new_map, c2py_map, verbose = False)

Source from the content-addressed store, hash-verified

919 return all_uses
920
921def process_f2cmap_dict(f2cmap_all, new_map, c2py_map, verbose = False):
922 """
923 Update the Fortran-to-C type mapping dictionary with new mappings and
924 return a list of successfully mapped C types.
925
926 This function integrates a new mapping dictionary into an existing
927 Fortran-to-C type mapping dictionary. It ensures that all keys are in
928 lowercase and validates new entries against a given C-to-Python mapping
929 dictionary. Redefinitions and invalid entries are reported with a warning.
930
931 Parameters
932 ----------
933 f2cmap_all : dict
934 The existing Fortran-to-C type mapping dictionary that will be updated.
935 It should be a dictionary of dictionaries where the main keys represent
936 Fortran types and the nested dictionaries map Fortran type specifiers
937 to corresponding C types.
938
939 new_map : dict
940 A dictionary containing new type mappings to be added to `f2cmap_all`.
941 The structure should be similar to `f2cmap_all`, with keys representing
942 Fortran types and values being dictionaries of type specifiers and their
943 C type equivalents.
944
945 c2py_map : dict
946 A dictionary used for validating the C types in `new_map`. It maps C
947 types to corresponding Python types and is used to ensure that the C
948 types specified in `new_map` are valid.
949
950 verbose : boolean
951 A flag used to provide information about the types mapped
952
953 Returns
954 -------
955 tuple of (dict, list)
956 The updated Fortran-to-C type mapping dictionary and a list of
957 successfully mapped C types.
958 """
959 f2cmap_mapped = []
960
961 new_map_lower = {}
962 for k, d1 in new_map.items():
963 d1_lower = {k1.lower(): v1 for k1, v1 in d1.items()}
964 new_map_lower[k.lower()] = d1_lower
965
966 for k, d1 in new_map_lower.items():
967 if k not in f2cmap_all:
968 f2cmap_all[k] = {}
969
970 for k1, v1 in d1.items():
971 if v1 in c2py_map:
972 if k1 in f2cmap_all[k]:
973 outmess(
974 "\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n"
975 % (k, k1, f2cmap_all[k][k1], v1)
976 )
977 f2cmap_all[k][k1] = v1
978 if verbose:

Callers 3

test_process_f2cmap_dictFunction · 0.90
capi_maps.pyFile · 0.85
load_f2cmap_fileFunction · 0.85

Calls 3

lowerMethod · 0.80
keysMethod · 0.80
outmessFunction · 0.70

Tested by 1

test_process_f2cmap_dictFunction · 0.72