forked from M-Labs/nac3
standalone/demo: numpy2 compatibility
This commit is contained in:
parent
e480081e4b
commit
8322d457c6
@ -67,7 +67,7 @@ def _bool(x):
|
|||||||
|
|
||||||
def _float(x):
|
def _float(x):
|
||||||
if isinstance(x, np.ndarray):
|
if isinstance(x, np.ndarray):
|
||||||
return np.float_(x)
|
return np.float64(x)
|
||||||
else:
|
else:
|
||||||
return float(x)
|
return float(x)
|
||||||
|
|
||||||
@ -111,6 +111,9 @@ def patch(module):
|
|||||||
def output_strln(x):
|
def output_strln(x):
|
||||||
print(x, end='')
|
print(x, end='')
|
||||||
|
|
||||||
|
def output_int32_list(x):
|
||||||
|
print([int(e) for e in x])
|
||||||
|
|
||||||
def dbg_stack_address(_):
|
def dbg_stack_address(_):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -126,11 +129,12 @@ def patch(module):
|
|||||||
return output_float
|
return output_float
|
||||||
elif name == "output_str":
|
elif name == "output_str":
|
||||||
return output_strln
|
return output_strln
|
||||||
|
elif name == "output_int32_list":
|
||||||
|
return output_int32_list
|
||||||
elif name in {
|
elif name in {
|
||||||
"output_bool",
|
"output_bool",
|
||||||
"output_int32",
|
"output_int32",
|
||||||
"output_int64",
|
"output_int64",
|
||||||
"output_int32_list",
|
|
||||||
"output_uint32",
|
"output_uint32",
|
||||||
"output_uint64",
|
"output_uint64",
|
||||||
"output_strln",
|
"output_strln",
|
||||||
|
@ -29,10 +29,10 @@ def u32_max() -> uint32:
|
|||||||
return ~uint32(0)
|
return ~uint32(0)
|
||||||
|
|
||||||
def i32_min() -> int32:
|
def i32_min() -> int32:
|
||||||
return int32(1 << 31)
|
return int32(-(1 << 31))
|
||||||
|
|
||||||
def i32_max() -> int32:
|
def i32_max() -> int32:
|
||||||
return int32(~(1 << 31))
|
return int32((1 << 31)-1)
|
||||||
|
|
||||||
def u64_min() -> uint64:
|
def u64_min() -> uint64:
|
||||||
return uint64(0)
|
return uint64(0)
|
||||||
@ -63,8 +63,9 @@ def test_conv_from_i32():
|
|||||||
i32_max()
|
i32_max()
|
||||||
]:
|
]:
|
||||||
output_int64(int64(x))
|
output_int64(int64(x))
|
||||||
output_uint32(uint32(x))
|
if x >= 0:
|
||||||
output_uint64(uint64(x))
|
output_uint32(uint32(x))
|
||||||
|
output_uint64(uint64(x))
|
||||||
output_float64(float(x))
|
output_float64(float(x))
|
||||||
|
|
||||||
def test_conv_from_u32():
|
def test_conv_from_u32():
|
||||||
@ -108,7 +109,6 @@ def test_conv_from_u64():
|
|||||||
|
|
||||||
def test_f64toi32():
|
def test_f64toi32():
|
||||||
for x in [
|
for x in [
|
||||||
float(i32_min()) - 1.0,
|
|
||||||
float(i32_min()),
|
float(i32_min()),
|
||||||
float(i32_min()) + 1.0,
|
float(i32_min()) + 1.0,
|
||||||
-1.5,
|
-1.5,
|
||||||
@ -117,7 +117,6 @@ def test_f64toi32():
|
|||||||
1.5,
|
1.5,
|
||||||
float(i32_max()) - 1.0,
|
float(i32_max()) - 1.0,
|
||||||
float(i32_max()),
|
float(i32_max()),
|
||||||
float(i32_max()) + 1.0
|
|
||||||
]:
|
]:
|
||||||
output_int32(int32(x))
|
output_int32(int32(x))
|
||||||
|
|
||||||
@ -138,24 +137,17 @@ def test_f64toi64():
|
|||||||
|
|
||||||
def test_f64tou32():
|
def test_f64tou32():
|
||||||
for x in [
|
for x in [
|
||||||
-1.5,
|
|
||||||
float(u32_min()) - 1.0,
|
|
||||||
-0.5,
|
|
||||||
float(u32_min()),
|
float(u32_min()),
|
||||||
0.5,
|
0.5,
|
||||||
float(u32_min()) + 1.0,
|
float(u32_min()) + 1.0,
|
||||||
1.5,
|
1.5,
|
||||||
float(u32_max()) - 1.0,
|
float(u32_max()) - 1.0,
|
||||||
float(u32_max()),
|
float(u32_max()),
|
||||||
float(u32_max()) + 1.0
|
|
||||||
]:
|
]:
|
||||||
output_uint32(uint32(x))
|
output_uint32(uint32(x))
|
||||||
|
|
||||||
def test_f64tou64():
|
def test_f64tou64():
|
||||||
for x in [
|
for x in [
|
||||||
-1.5,
|
|
||||||
float(u64_min()) - 1.0,
|
|
||||||
-0.5,
|
|
||||||
float(u64_min()),
|
float(u64_min()),
|
||||||
0.5,
|
0.5,
|
||||||
float(u64_min()) + 1.0,
|
float(u64_min()) + 1.0,
|
||||||
@ -181,4 +173,4 @@ def run() -> int32:
|
|||||||
test_f64tou32()
|
test_f64tou32()
|
||||||
test_f64tou64()
|
test_f64tou64()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user