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

Function getinit

numpy/f2py/capi_maps.py:430–462  ·  view source on GitHub ↗
(a, var)

Source from the content-addressed store, hash-verified

428
429
430def getinit(a, var):
431 if isstring(var):
432 init, showinit = '""', "''"
433 else:
434 init, showinit = '', ''
435 if hasinitvalue(var):
436 init = var['=']
437 showinit = init
438 if iscomplex(var) or iscomplexarray(var):
439 ret = {}
440
441 try:
442 v = var["="]
443 if ',' in v:
444 ret['init.r'], ret['init.i'] = markoutercomma(
445 v[1:-1]).split('@,@')
446 else:
447 v = eval(v, {}, {})
448 ret['init.r'], ret['init.i'] = str(v.real), str(v.imag)
449 except Exception:
450 raise ValueError(
451 f'getinit: expected complex number `(r,i)\' but got `{init}\' as initial value of {a!r}.')
452 if isarray(var):
453 init = f"(capi_c.r={ret['init.r']},capi_c.i={ret['init.i']},capi_c)"
454 elif isstring(var):
455 if not init:
456 init, showinit = '""', "''"
457 if init[0] == "'":
458 escaped_init = init[1:-1].replace('"', '\\"')
459 init = f'"{escaped_init}"'
460 if init[0] == '"':
461 showinit = f"'{init[1:-1]}'"
462 return init, showinit
463
464
465def get_elsize(var):

Callers 2

getpydocsignFunction · 0.85
sign2mapFunction · 0.85

Calls 8

isstringFunction · 0.85
hasinitvalueFunction · 0.85
iscomplexarrayFunction · 0.85
markoutercommaFunction · 0.85
isarrayFunction · 0.85
splitMethod · 0.80
replaceMethod · 0.80
iscomplexFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…