mirror of https://github.com/Nonannet/copapy.git
code style adjustments
This commit is contained in:
parent
ebb4abc5d3
commit
5daa54fafb
|
|
@ -77,7 +77,7 @@ class Target():
|
||||||
return [self.read_value(ni) if isinstance(ni, variable) else ni for ni in net]
|
return [self.read_value(ni) if isinstance(ni, variable) else ni for ni in net]
|
||||||
|
|
||||||
if isinstance(net, float | int):
|
if isinstance(net, float | int):
|
||||||
print(f"Warning: value is not a copypy value")
|
print("Warning: value is not a copypy value")
|
||||||
return net
|
return net
|
||||||
|
|
||||||
assert isinstance(net, Net), "Variable must be a copapy variable object"
|
assert isinstance(net, Net), "Variable must be a copapy variable object"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from . import variable, vector
|
from . import variable, vector
|
||||||
from ._basic_types import iif, unifloat, TNum
|
from ._basic_types import iif, unifloat
|
||||||
|
from._helper_types import TNum
|
||||||
from typing import Any, Iterable
|
from typing import Any, Iterable
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from copapy import variable
|
from copapy import variable
|
||||||
from copapy.backend import Write
|
from copapy.backend import Write
|
||||||
import copapy.backend as cpbe
|
import copapy.backend as cpb
|
||||||
|
|
||||||
|
|
||||||
def test_ast_generation():
|
def test_ast_generation():
|
||||||
|
|
@ -33,27 +33,27 @@ def test_ast_generation():
|
||||||
print(out)
|
print(out)
|
||||||
print('-- get_edges:')
|
print('-- get_edges:')
|
||||||
|
|
||||||
edges = list(cpbe.get_all_dag_edges(out))
|
edges = list(cpb.get_all_dag_edges(out))
|
||||||
for p in edges:
|
for p in edges:
|
||||||
print('#', p)
|
print('#', p)
|
||||||
|
|
||||||
print('-- get_ordered_ops:')
|
print('-- get_ordered_ops:')
|
||||||
ordered_ops = list(cpbe.stable_toposort(edges))
|
ordered_ops = cpb.stable_toposort(edges)
|
||||||
for p in ordered_ops:
|
for p in ordered_ops:
|
||||||
print('#', p)
|
print('#', p)
|
||||||
|
|
||||||
print('-- get_consts:')
|
print('-- get_consts:')
|
||||||
const_list = cpbe.get_const_nets(ordered_ops)
|
const_list = cpb.get_const_nets(ordered_ops)
|
||||||
for p in const_list:
|
for p in const_list:
|
||||||
print('#', p)
|
print('#', p)
|
||||||
|
|
||||||
print('-- add_read_ops:')
|
print('-- add_read_ops:')
|
||||||
output_ops = list(cpbe.add_read_ops(ordered_ops))
|
output_ops = list(cpb.add_read_ops(ordered_ops))
|
||||||
for p in output_ops:
|
for p in output_ops:
|
||||||
print('#', p)
|
print('#', p)
|
||||||
|
|
||||||
print('-- add_write_ops:')
|
print('-- add_write_ops:')
|
||||||
extended_output_ops = list(cpbe.add_write_ops(output_ops, const_list))
|
extended_output_ops = list(cpb.add_write_ops(output_ops, const_list))
|
||||||
for p in extended_output_ops:
|
for p in extended_output_ops:
|
||||||
print('#', p)
|
print('#', p)
|
||||||
print('--')
|
print('--')
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
import time
|
import time
|
||||||
from copapy import variable
|
|
||||||
from copapy import backend
|
from copapy import backend
|
||||||
from copapy.backend import Write, stencil_db_from_package
|
from copapy.backend import Write, stencil_db_from_package
|
||||||
import copapy.backend as cpbe
|
import copapy.backend as cpb
|
||||||
import copapy as cp
|
import copapy as cp
|
||||||
import copapy._binwrite as binw
|
import copapy._binwrite as binw
|
||||||
from copapy._compiler import get_nets, get_section_layout, get_data_layout
|
from copapy._compiler import get_nets, get_section_layout, get_data_layout
|
||||||
from copapy._compiler import patch_entry, CPConstant, get_aux_func_layout
|
from copapy._compiler import patch_entry, CPConstant, get_aux_func_layout
|
||||||
|
|
||||||
|
|
||||||
def test_timing_compiler():
|
def test_timing_compiler():
|
||||||
t1 = cp.vector([10, 11]*128) + cp.vector(cp.variable(v) for v in range(256))
|
t1 = cp.vector([10, 11]*128) + cp.vector(cp.variable(v) for v in range(256))
|
||||||
t2 = t1.sum()
|
#t2 = t1.sum()
|
||||||
t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(256))
|
t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(256))
|
||||||
t5 = ((t3 * t1) * 2).magnitude()
|
t5 = ((t3 * t1) * 2).magnitude()
|
||||||
out = [Write(t5)]
|
out = [Write(t5)]
|
||||||
|
|
@ -19,7 +19,7 @@ def test_timing_compiler():
|
||||||
|
|
||||||
print('-- get_edges:')
|
print('-- get_edges:')
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
edges = list(cpbe.get_all_dag_edges(out))
|
edges = list(cpb.get_all_dag_edges(out))
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
print(f' found {len(edges)} edges')
|
print(f' found {len(edges)} edges')
|
||||||
#for p in edges:
|
#for p in edges:
|
||||||
|
|
@ -28,7 +28,7 @@ def test_timing_compiler():
|
||||||
|
|
||||||
print('-- get_ordered_ops:')
|
print('-- get_ordered_ops:')
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
ordered_ops = list(cpbe.stable_toposort(edges))
|
ordered_ops = cpb.stable_toposort(edges)
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
print(f' found {len(ordered_ops)} ops')
|
print(f' found {len(ordered_ops)} ops')
|
||||||
#for p in ordered_ops:
|
#for p in ordered_ops:
|
||||||
|
|
@ -37,7 +37,7 @@ def test_timing_compiler():
|
||||||
|
|
||||||
print('-- get_consts:')
|
print('-- get_consts:')
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
const_net_list = cpbe.get_const_nets(ordered_ops)
|
const_net_list = cpb.get_const_nets(ordered_ops)
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
#for p in const_list:
|
#for p in const_list:
|
||||||
# print('#', p)
|
# print('#', p)
|
||||||
|
|
@ -45,7 +45,7 @@ def test_timing_compiler():
|
||||||
|
|
||||||
print('-- add_read_ops:')
|
print('-- add_read_ops:')
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
output_ops = list(cpbe.add_read_ops(ordered_ops))
|
output_ops = list(cpb.add_read_ops(ordered_ops))
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
#for p in output_ops:
|
#for p in output_ops:
|
||||||
# print('#', p)
|
# print('#', p)
|
||||||
|
|
@ -53,7 +53,7 @@ def test_timing_compiler():
|
||||||
|
|
||||||
print('-- add_write_ops:')
|
print('-- add_write_ops:')
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
extended_output_ops = list(cpbe.add_write_ops(output_ops, const_net_list))
|
extended_output_ops = list(cpb.add_write_ops(output_ops, const_net_list))
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
#for p in extended_output_ops:
|
#for p in extended_output_ops:
|
||||||
# print('#', p)
|
# print('#', p)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ def check_for_qemu() -> bool:
|
||||||
command = qemu_command + ['--version']
|
command = qemu_command + ['--version']
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
|
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
return result.returncode == 0
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ def check_for_qemu() -> bool:
|
||||||
command = qemu_command + ['--version']
|
command = qemu_command + ['--version']
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
|
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
return result.returncode == 0
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from copapy import NumLike, iif, variable, sin
|
from copapy import NumLike, iif, variable
|
||||||
from copapy.backend import Write, compile_to_dag, add_read_command
|
from copapy.backend import Write, compile_to_dag, add_read_command
|
||||||
import subprocess
|
import subprocess
|
||||||
from copapy import _binwrite
|
from copapy import _binwrite
|
||||||
|
|
@ -70,16 +70,16 @@ def iiftests(c1: NumLike) -> list[NumLike]:
|
||||||
|
|
||||||
@pytest.mark.runner
|
@pytest.mark.runner
|
||||||
def test_compile():
|
def test_compile():
|
||||||
t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
|
#t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
|
||||||
t2 = t1.sum()
|
#t2 = t1.sum()
|
||||||
|
|
||||||
t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(3))
|
#t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(3))
|
||||||
t4 = ((t3 * t1) * 2).sum()
|
#t4 = ((t3 * t1) * 2).sum()
|
||||||
t5 = ((t3 * t1) * 2).magnitude()
|
#t5 = ((t3 * t1) * 2).magnitude()
|
||||||
|
|
||||||
c_i = variable(9)
|
c_i = variable(9)
|
||||||
c_f = variable(1.111)
|
#c_f = variable(1.111)
|
||||||
c_b = variable(True)
|
#c_b = variable(True)
|
||||||
|
|
||||||
#ret_test = function1(c_i) + function1(c_f) + function2(c_i) + function2(c_f) + function3(c_i) + function4(c_i) + function5(c_b) + [c_i % 2, sin(c_f)] + iiftests(c_i) + iiftests(c_f)
|
#ret_test = function1(c_i) + function1(c_f) + function2(c_i) + function2(c_f) + function3(c_i) + function4(c_i) + function5(c_b) + [c_i % 2, sin(c_f)] + iiftests(c_i) + iiftests(c_f)
|
||||||
#ret_ref = function1(9) + function1(1.111) + function2(9) + function2(1.111) + function3(9) + function4(9) + function5(True) + [9 % 2, sin(1.111)] + iiftests(9) + iiftests(1.111)
|
#ret_ref = function1(9) + function1(1.111) + function2(9) + function2(1.111) + function3(9) + function4(9) + function5(True) + [9 % 2, sin(1.111)] + iiftests(9) + iiftests(1.111)
|
||||||
|
|
@ -143,7 +143,7 @@ def test_compile():
|
||||||
try:
|
try:
|
||||||
result = run_command(command)
|
result = run_command(command)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
warnings.warn(f"Test skipped, executable not found.", UserWarning)
|
warnings.warn("Test skipped, executable not found.", UserWarning)
|
||||||
return
|
return
|
||||||
|
|
||||||
print('* Output from runner:\n--')
|
print('* Output from runner:\n--')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue