MCPcopy Index your code
hub / github.com/numpy/numpy / get_parameters

Function get_parameters

numpy/f2py/crackfortran.py:2447–2545  ·  view source on GitHub ↗
(vars, global_params={})

Source from the content-addressed store, hash-verified

2445
2446
2447def get_parameters(vars, global_params={}):
2448 params = copy.copy(global_params)
2449 g_params = copy.copy(global_params)
2450 for name, func in [('kind', _kind_func),
2451 ('selected_int_kind', _selected_int_kind_func),
2452 ('selected_real_kind', _selected_real_kind_func), ]:
2453 if name not in g_params:
2454 g_params[name] = func
2455 param_names = []
2456 for n in get_sorted_names(vars):
2457 if 'attrspec' in vars[n] and 'parameter' in vars[n]['attrspec']:
2458 param_names.append(n)
2459 kind_re = re.compile(r'\bkind\s*\(\s*(?P<value>.*)\s*\)', re.I)
2460 selected_int_kind_re = re.compile(
2461 r'\bselected_int_kind\s*\(\s*(?P<value>.*)\s*\)', re.I)
2462 selected_kind_re = re.compile(
2463 r'\bselected_(int|real)_kind\s*\(\s*(?P<value>.*)\s*\)', re.I)
2464 for n in param_names:
2465 if '=' in vars[n]:
2466 v = vars[n]['=']
2467 if islogical(vars[n]):
2468 v = v.lower()
2469 for repl in [
2470 ('.false.', 'False'),
2471 ('.true.', 'True'),
2472 # TODO: test .eq., .neq., etc replacements.
2473 ]:
2474 v = v.replace(*repl)
2475
2476 v = kind_re.sub(r'kind("\1")', v)
2477 v = selected_int_kind_re.sub(r'selected_int_kind(\1)', v)
2478
2479 # We need to act according to the data.
2480 # The easy case is if the data has a kind-specifier,
2481 # then we may easily remove those specifiers.
2482 # However, it may be that the user uses other specifiers...(!)
2483 is_replaced = False
2484
2485 if 'kindselector' in vars[n]:
2486 # Remove kind specifier (including those defined
2487 # by parameters)
2488 if 'kind' in vars[n]['kindselector']:
2489 orig_v_len = len(v)
2490 v = v.replace('_' + vars[n]['kindselector']['kind'], '')
2491 # Again, this will be true if even a single specifier
2492 # has been replaced, see comment above.
2493 is_replaced = len(v) < orig_v_len
2494
2495 if not is_replaced:
2496 if not selected_kind_re.match(v):
2497 v_ = v.split('_')
2498 # In case there are additive parameters
2499 if len(v_) > 1:
2500 v = ''.join(v_[:-1]).lower().replace(v_[-1].lower(), '')
2501
2502 # Currently this will not work for complex numbers.
2503 # There is missing code for extracting a complex number,
2504 # which may be defined in either of these:

Callers 3

analyzelineFunction · 0.85
get_useparametersFunction · 0.85
analyzevarsFunction · 0.85

Calls 15

get_sorted_namesFunction · 0.85
islogicalFunction · 0.85
isdoubleFunction · 0.85
param_evalFunction · 0.85
isstringFunction · 0.85
lowerMethod · 0.80
replaceMethod · 0.80
splitMethod · 0.80
joinMethod · 0.80
stripMethod · 0.80
startswithMethod · 0.80
iscomplexFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…