code clean up

This commit is contained in:
Nicolas Kruse 2025-10-18 23:21:31 +02:00
parent c2d51c6c39
commit 140d1f0f9f
2 changed files with 3 additions and 12 deletions

View File

@ -9,7 +9,6 @@ from coparun_module import coparun, read_data_mem
import struct import struct
import platform import platform
#CPNumLike: TypeAlias = 'cpint | cpfloat | cpbool'
NumLike: TypeAlias = 'cpint | cpfloat | cpbool | int | float| bool' NumLike: TypeAlias = 'cpint | cpfloat | cpbool | int | float| bool'
NumLikeAndNet: TypeAlias = 'cpint | cpfloat | cpbool | int | float | bool | Net' NumLikeAndNet: TypeAlias = 'cpint | cpfloat | cpbool | int | float | bool | Net'
NetAndNum: TypeAlias = 'Net | int | float' NetAndNum: TypeAlias = 'Net | int | float'
@ -46,7 +45,6 @@ class Node:
self.name: str = '' self.name: str = ''
def __repr__(self) -> str: def __repr__(self) -> str:
#return f"Node:{self.name}({', '.join(str(a) for a in self.args) if self.args else self.value})"
return f"Node:{self.name}({', '.join(str(a) for a in self.args) if self.args else (self.value if isinstance(self, InitVar) else '')})" return f"Node:{self.name}({', '.join(str(a) for a in self.args) if self.args else (self.value if isinstance(self, InitVar) else '')})"
@ -364,23 +362,14 @@ def _add_op(op: str, args: list[CPNumber | int | float], commutative: bool = Fal
typed_op = '_'.join([op] + [transl_type(a.dtype) for a in arg_nets]) typed_op = '_'.join([op] + [transl_type(a.dtype) for a in arg_nets])
if typed_op not in generic_sdb.stencil_definitions: if typed_op not in generic_sdb.stencil_definitions:
#raise ValueError(f"Unsupported operand type(s) for {op}: {' and '.join([a.dtype for a in arg_nets])}")
raise NotImplementedError(f"Operation {op} not implemented for {' and '.join([a.dtype for a in arg_nets])}") raise NotImplementedError(f"Operation {op} not implemented for {' and '.join([a.dtype for a in arg_nets])}")
result_type = generic_sdb.stencil_definitions[typed_op].split('_')[0] result_type = generic_sdb.stencil_definitions[typed_op].split('_')[0]
#if op in {'eq', 'ne', 'gt'}:
# assert result_type == 'int'
# result_type = 'bool'
if result_type == 'int': if result_type == 'int':
return cpint(Op(typed_op, arg_nets)) return cpint(Op(typed_op, arg_nets))
#elif result_type == 'float':
else: else:
return cpfloat(Op(typed_op, arg_nets)) return cpfloat(Op(typed_op, arg_nets))
#else:
# return cpbool(result_type, Op(typed_op, arg_nets))
#return CPNumber(result_type, Op(typed_op, arg_nets))
@overload @overload

View File

@ -1,6 +1,7 @@
import argparse import argparse
import re import re
def main() -> None: def main() -> None:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("path", type=str, help="Input file path") parser.add_argument("path", type=str, help="Input file path")
@ -32,5 +33,6 @@ def main() -> None:
print('</code>') print('</code>')
if __name__ == "__main__": if __name__ == "__main__":
main() main()