From f63e09fb99f9f52a475862affc2036525cc5dac9 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Sun, 29 Mar 2026 14:56:05 +0200 Subject: [PATCH] code style fixed --- src/copapy/_compiler.py | 6 +++--- src/copapy/_stencils.py | 2 +- src/coparun_module.pyi | 2 +- stencils/generate_stencils.py | 2 +- tests/benchmark.py | 4 +--- tests/test_dag_optimization.py | 2 +- tests/test_ops_armv7thumb.py | 2 +- tests/test_rev_kinematics.py | 4 ++-- tests/test_tensor_basic.py | 14 +++++++------- tools/make_example.py | 2 +- 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/copapy/_compiler.py b/src/copapy/_compiler.py index 4f71d73..e2ffe0a 100644 --- a/src/copapy/_compiler.py +++ b/src/copapy/_compiler.py @@ -79,7 +79,7 @@ def get_all_dag_edges_between(roots: Iterable[Node], leaves: Iterable[Node]) -> # Walk the DAG in reverse direction starting from given leaves to given roots emitted_edges: set[tuple[Node, Node]] = set() - node_list = [n for n in leaves] + node_list = list(leaves) while(node_list): child_node = node_list.pop() if child_node in parent_lookup: @@ -104,13 +104,13 @@ def get_all_dag_edges(nodes: Iterable[Node]) -> Generator[tuple[Node, Node], Non """ emitted_edges: set[tuple[Node, Node]] = set() used_nets: dict[Net, Net] = {} - node_list: list[Node] = [n for n in nodes] + node_list: list[Node] = list(nodes) while(node_list): node = node_list.pop() for net in node.args: - # In case there is already net with equivalent value use this + # In case there is already net with equivalent value use this if net in used_nets: net = used_nets[net] else: diff --git a/src/copapy/_stencils.py b/src/copapy/_stencils.py index 7ac84e5..dcee2a2 100644 --- a/src/copapy/_stencils.py +++ b/src/copapy/_stencils.py @@ -362,7 +362,7 @@ class stencil_database(): patch_value = symbol_address + pr.fields['r_addend'] symbol_type = symbol_type + 0x06 # PATCH_OBJECT_ARM32_ABS_THM #print(f" *> {pr.type} {patch_value=} {symbol_address=}, {function_offset=}, {pr.fields['r_addend']=}") - + elif pr.type == 'R_ARM_THM_MOVT_ABS': # (S + A) & 0xFFFF0000 mask = 0xFFFF0000 diff --git a/src/coparun_module.pyi b/src/coparun_module.pyi index 5a1a5aa..ab3f1fa 100644 --- a/src/coparun_module.pyi +++ b/src/coparun_module.pyi @@ -1,4 +1,4 @@ def coparun(context: int, data: bytes) -> int: ... def read_data_mem(context: int, rel_addr: int, length: int) -> bytes: ... def create_target() -> int: ... -def clear_target(context: int) -> None: ... \ No newline at end of file +def clear_target(context: int) -> None: ... diff --git a/stencils/generate_stencils.py b/stencils/generate_stencils.py index 307db55..5fc9a2f 100644 --- a/stencils/generate_stencils.py +++ b/stencils/generate_stencils.py @@ -303,7 +303,7 @@ if __name__ == "__main__": code += get_custom_stencil('abs_int(int arg1)', 'result_int(__builtin_abs(arg1));') for t in types: - code += get_custom_stencil(f"sign_{t}({t} arg1)", f"result_int((arg1 > 0) - (arg1 < 0));") + code += get_custom_stencil(f"sign_{t}({t} arg1)", "result_int((arg1 > 0) - (arg1 < 0));") fnames = ['atan2', 'pow'] for fn, t1, t2 in permutate(fnames, types, types): diff --git a/tests/benchmark.py b/tests/benchmark.py index 6eb2c12..bad4f0c 100644 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -7,8 +7,6 @@ import sys import numpy as np from numpy.core._multiarray_umath import __cpu_features__ -from copapy._matrices import diagonal - CPU_SIMD_FEATURES = "SSE SSE2 SSE3 SSSE3 SSE41 SSE42 AVX AVX2 AVX512F FMA3" @@ -217,7 +215,7 @@ def save_svg_with_theme_styles(pyplot_obj, path): # --- Step 1: Capture SVG to memory --- buf = io.StringIO() - + # pyplot_obj can be a module (plt) or a Figure instance if hasattr(pyplot_obj, "gcf"): fig = pyplot_obj.gcf() diff --git a/tests/test_dag_optimization.py b/tests/test_dag_optimization.py index b381c70..ab79038 100644 --- a/tests/test_dag_optimization.py +++ b/tests/test_dag_optimization.py @@ -70,4 +70,4 @@ def test_dag_reduction(): if __name__ == "__main__": test_get_dag_stats() - test_dag_reduction() \ No newline at end of file + test_dag_reduction() diff --git a/tests/test_ops_armv7thumb.py b/tests/test_ops_armv7thumb.py index 997f1cd..85cd1f9 100644 --- a/tests/test_ops_armv7thumb.py +++ b/tests/test_ops_armv7thumb.py @@ -181,4 +181,4 @@ qemu-arm -d in_asm,exec -D qemu_trace.log \ -global driver=pl011.audiomaddr,property=addr,value=0xff7ec000 \ -global driver=pl011.audiomaddr,property=size,value=0x100000 \ your_binary -""" \ No newline at end of file +""" diff --git a/tests/test_rev_kinematics.py b/tests/test_rev_kinematics.py index 8eeac3f..d42c6b7 100644 --- a/tests/test_rev_kinematics.py +++ b/tests/test_rev_kinematics.py @@ -18,7 +18,7 @@ def forward_kinematics(theta1: cp.value[float] | float, theta2: cp.value[float] return joint, end_effector -def test_two_arms(): +def test_two_arms(): target_vec = cp.vector(target) theta = cp.vector([cp.value(0.0), cp.value(0.0)]) @@ -47,4 +47,4 @@ def test_two_arms(): if __name__ == '__main__': - test_two_arms() \ No newline at end of file + test_two_arms() diff --git a/tests/test_tensor_basic.py b/tests/test_tensor_basic.py index 9683d5d..9ddf85e 100644 --- a/tests/test_tensor_basic.py +++ b/tests/test_tensor_basic.py @@ -68,7 +68,7 @@ def test_tensor_basic(): assert result_2d_1d.shape == (2, 3) assert result_2d_1d[0, 0] == 11.0 assert result_2d_1d[1, 2] == 36.0 - + # 3D tensor + 2D tensor t3d = cp.tensor([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) t2d_broadcast = cp.tensor([[100.0, 200.0], [300.0, 400.0]]) @@ -77,7 +77,7 @@ def test_tensor_basic(): assert result_3d_2d.shape == (2, 2, 2) assert result_3d_2d[0, 0, 0] == 101.0 assert result_3d_2d[1, 1, 1] == 408.0 - + # 3D tensor + 1D tensor t1d_broadcast = cp.tensor([1.0, 2.0]) result_3d_1d = t3d + t1d_broadcast @@ -106,7 +106,7 @@ def test_tensor_basic(): assert c2d.shape == (2, 2) assert c2d[0, 0] == 2.0 assert c2d[1, 1] == 20.0 - + # 3D - 2D t3d_sub = cp.tensor([[[10.0, 20.0], [30.0, 40.0]], [[50.0, 60.0], [70.0, 80.0]]]) t2d_sub = cp.tensor([[1.0, 2.0], [3.0, 4.0]]) @@ -173,7 +173,7 @@ def test_tensor_basic(): print("Test 10b: Sum with multiple axes and keepdims") t3d = cp.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) print(f"Original 3D tensor: shape={t3d.shape}") - + # Sum along multiple axes sum_axes_0_2 = t3d.sum(axis=(0, 2)) print(f"Sum along axes (0, 2): shape={sum_axes_0_2.shape}") @@ -181,17 +181,17 @@ def test_tensor_basic(): assert sum_axes_0_2[0] == 1 + 2 + 5 + 6 # Elements from [0,:,*] and [1,:,*] assert sum_axes_0_2[1] == 3 + 4 + 7 + 8 print(f"Values: {[sum_axes_0_2[i] for i in range(len(sum_axes_0_2))]}") - + # Sum with keepdims sum_keepdims = t3d.sum(axis=1, keepdims=True) print(f"Sum along axis 1 with keepdims: shape={sum_keepdims.shape}") assert sum_keepdims.shape == (2, 1, 2), f"Expected (2, 1, 2), got {sum_keepdims.shape}" - + # Sum multiple axes with keepdims sum_multi_keepdims = t3d.sum(axis=(0, 2), keepdims=True) print(f"Sum along axes (0, 2) with keepdims: shape={sum_multi_keepdims.shape}") assert sum_multi_keepdims.shape == (1, 2, 1), f"Expected (1, 2, 1), got {sum_multi_keepdims.shape}" - + # Sum all axes with keepdims sum_all_keepdims = t3d.sum(keepdims=True) print(f"Sum all with keepdims: shape={sum_all_keepdims.shape}") diff --git a/tools/make_example.py b/tools/make_example.py index abac7ff..03c3c84 100644 --- a/tools/make_example.py +++ b/tools/make_example.py @@ -13,4 +13,4 @@ dw, _ = compile_to_dag([Store(result)], sdb) # Instruct runner to dump patched code to a file: dw.write_com(Command.DUMP_CODE) -dw.to_file('build/runner/test.copapy') \ No newline at end of file +dw.to_file('build/runner/test.copapy')