From f40b83d0ce903e429cec413ae9abb0e022820281 Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Fri, 7 Aug 2026 22:01:04 +0300 Subject: [PATCH] Simplify `GUFunc.ufunc_loop_inner_loop_body` The property could be simplified without causing any changes in the files `erfa_generator` creates. The `Argument.cast_pointer_if_needed` property was only called by `GUFunc.ufunc_loop_inner_loop_body` and has been inlined. --- erfa_generator.py | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/erfa_generator.py b/erfa_generator.py index 73432a7..a7d4325 100644 --- a/erfa_generator.py +++ b/erfa_generator.py @@ -203,16 +203,6 @@ def inner_loop_steps_and_copy(self, name_suffix: str = "") -> str | None: def cast_pointer(self) -> str: return f"_{self.name} = (({self.ctype} (*){self.cshape}){self.name});" - @functools.cached_property - def cast_pointer_if_needed(self) -> str: - return "\n".join( - [ - f"if (!copy_{self.name}) {{", - f" {self.cast_pointer}", - "}", - ] - ) - def copy_elements(self, direction: str, name_suffix: str = "") -> str: name = self.name + name_suffix shape_description = "".join(str(n) for n in self.shape if n is not None) @@ -581,26 +571,26 @@ def init_ufunc_loop_local_vars(self) -> str: @functools.cached_property def ufunc_loop_inner_loop_body(self) -> str: lines = [] - for arg in self.in_args: # copy input arguments to buffer if needed - if arg.signature_shape != "()": - lines.extend([ - arg.cast_pointer_if_needed, - "else {", - f" {arg.copy_elements('to')}", - "}", - ]) - # for inout arguments, set up output first, and then copy to it if needed - for arg in self.inout_args: + for arg in self.c_args: if arg.signature_shape != "()": lines.extend([ - arg.cast_pointer_if_needed, - f"if (copy_{arg.name}_in || {arg.name} != {arg.name}_in) {{", - f" {arg.copy_elements('to', '_in')}", + f"if (!copy_{arg.name}) {{", + f" {arg.cast_pointer}", "}", ]) - lines.extend([ # set up gufunc outputs - a.cast_pointer_if_needed for a in self.out_args if a.signature_shape != "()" - ]) + if arg in self.in_args: # copy input arguments to buffer if needed + lines.extend([ + "else {", + f" {arg.copy_elements('to')}", + "}", + ]) + elif arg in self.inout_args: + # for inout arguments copy to output if needed + lines.extend([ + f"if (copy_{arg.name}_in || {arg.name} != {arg.name}_in) {{", + f" {arg.copy_elements('to', '_in')}", + "}", + ]) lines.append(super().ufunc_loop_inner_loop_body) for arg in self.inout_or_out_args: if arg.signature_shape != "()":