Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions erfa_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 != "()":
Expand Down
Loading