wrapper class for numpy functions Same as method, but the name is used for referencing numpy functions
| 348 | |
| 349 | |
| 350 | class function: |
| 351 | """wrapper class for numpy functions |
| 352 | |
| 353 | Same as method, but the name is used for referencing numpy functions |
| 354 | """ |
| 355 | |
| 356 | def __init__(self, name_or_function, *args, function_label=None, **kwargs): |
| 357 | if callable(name_or_function): |
| 358 | self.name = ( |
| 359 | function_label |
| 360 | if function_label is not None |
| 361 | else name_or_function.__name__ |
| 362 | ) |
| 363 | self.func = name_or_function |
| 364 | else: |
| 365 | self.name = name_or_function if function_label is None else function_label |
| 366 | self.func = getattr(np, name_or_function) |
| 367 | if self.func is None: |
| 368 | raise AttributeError( |
| 369 | f"module 'numpy' has no attribute named '{self.name}'" |
| 370 | ) |
| 371 | |
| 372 | self.args = args |
| 373 | self.kwargs = kwargs |
| 374 | |
| 375 | def __call__(self, *args, **kwargs): |
| 376 | all_args = merge_args(self.args, args) |
| 377 | all_kwargs = {**self.kwargs, **kwargs} |
| 378 | |
| 379 | return self.func(*all_args, **all_kwargs) |
| 380 | |
| 381 | def __repr__(self): |
| 382 | return f"function_{self.name}" |
| 383 | |
| 384 | |
| 385 | @pytest.mark.parametrize( |
no outgoing calls
searching dependent graphs…