mirror of https://github.com/Nonannet/copapy.git
floordiv added
This commit is contained in:
parent
3485584e5e
commit
3118826515
|
|
@ -0,0 +1,34 @@
|
|||
from copapy import CPVariable, Target
|
||||
from pytest import approx
|
||||
|
||||
|
||||
def function1(c1):
|
||||
return [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
|
||||
|
||||
def function2(c1):
|
||||
return [c1 / 4, c1 / -4, c1 / 4, c1 / -4, (c1 * -1) / 4]
|
||||
|
||||
def test_compile():
|
||||
|
||||
c1 = CPVariable(9)
|
||||
|
||||
ret = function1(c1)
|
||||
|
||||
tg = Target()
|
||||
print('* compile and copy ...')
|
||||
tg.compile(ret)
|
||||
#time.sleep(5)
|
||||
print('* run and copy ...')
|
||||
tg.run()
|
||||
#print('* finished')
|
||||
|
||||
ret_ref = function1(9)
|
||||
|
||||
for test, ref, name in zip(ret, ret_ref, ['r1', 'r2', 'r3', 'r4', 'r5']):
|
||||
val = tg.read_value(test)
|
||||
print('+', name, val, ref)
|
||||
assert val == approx(ref, 1e-5), name
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_compile()
|
||||
|
|
@ -2,7 +2,7 @@ from typing import Generator
|
|||
import argparse
|
||||
|
||||
|
||||
op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/',
|
||||
op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/', 'floordiv': '/',
|
||||
'gt': '>', 'eq': '==', 'mod': '%'}
|
||||
|
||||
entry_func_prefix = ''
|
||||
|
|
@ -123,9 +123,6 @@ if __name__ == "__main__":
|
|||
if args.abi:
|
||||
entry_func_prefix = f"__attribute__(({args.abi}_abi)) "
|
||||
|
||||
types = ['int', 'float']
|
||||
ops = ['add', 'sub', 'mul', 'div', 'gt', 'eq']
|
||||
|
||||
code = """
|
||||
// Auto-generated stencils for copapy
|
||||
// Do not edit manually
|
||||
|
|
@ -134,6 +131,10 @@ if __name__ == "__main__":
|
|||
volatile float dummy_float = 1337;
|
||||
"""
|
||||
|
||||
# Scalar arithmetic:
|
||||
types = ['int', 'float']
|
||||
ops = ['add', 'sub', 'mul', 'div', 'floordiv', 'gt', 'eq']
|
||||
|
||||
for t1 in types:
|
||||
code += get_result_stubs1(t1)
|
||||
|
||||
|
|
@ -143,9 +144,11 @@ if __name__ == "__main__":
|
|||
for op, t1, t2 in permutate(ops, types, types):
|
||||
t_out = t1 if t1 == t2 else 'float'
|
||||
if op == 'floordiv':
|
||||
code += get_op_code_int('div', t1, t2)
|
||||
code += get_op_code_int('floordiv', t1, t2)
|
||||
elif op == 'div':
|
||||
code += get_op_code_float(op, t1, t2)
|
||||
elif op == 'gt' or op == 'eq':
|
||||
code += get_op_code(op, t1, t2, 'int')
|
||||
else:
|
||||
code += get_op_code(op, t1, t2, t_out)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue