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

Class FunctionApi

numpy/core/code_generators/genapi.py:403–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

401 return astr
402
403class FunctionApi:
404 def __init__(self, name, index, annotations, return_type, args, api_name):
405 self.name = name
406 self.index = index
407
408 self.min_version = None
409 self.annotations = []
410 for annotation in annotations:
411 # String checks, because manual import breaks isinstance
412 if type(annotation).__name__ == "StealRef":
413 self.annotations.append(annotation)
414 elif type(annotation).__name__ == "MinVersion":
415 if self.min_version is not None:
416 raise ValueError("Two minimum versions specified!")
417 self.min_version = annotation
418 else:
419 raise ValueError(f"unknown annotation {annotation}")
420
421 self.return_type = return_type
422 self.args = args
423 self.api_name = api_name
424
425 def _argtypes_string(self):
426 if not self.args:
427 return 'void'
428 argstr = ', '.join([_repl(a[0]) for a in self.args])
429 return argstr
430
431 def define_from_array_api_string(self):
432 arguments = self._argtypes_string()
433 define = textwrap.dedent(f"""\
434 #define {self.name} \\
435 (*({self.return_type} (*)({arguments})) \\
436 {self.api_name}[{self.index}])""")
437
438 if self.min_version is not None:
439 define = self.min_version.add_guard(self.name, define)
440 return define
441
442 def array_api_define(self):
443 return " (void *) %s" % self.name
444
445 def internal_define(self):
446 annstr = [str(a) for a in self.annotations]
447 annstr = ' '.join(annstr)
448 astr = """\
449NPY_NO_EXPORT %s %s %s \\\n (%s);""" % (annstr, self.return_type,
450 self.name,
451 self._argtypes_string())
452 return astr
453
454def order_dict(d):
455 """Order dict by its values."""

Callers 2

do_generate_apiFunction · 0.90
do_generate_apiFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected