Skip to content

Commit bc01cbf

Browse files
committed
TEST: Add for numpy dtypes
1 parent d6034a1 commit bc01cbf

File tree

6 files changed

+127
-0
lines changed

6 files changed

+127
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ RUN(NAME variable_decl_03 LABELS cpython llvm c)
413413
RUN(NAME array_expr_01 LABELS cpython llvm c)
414414
RUN(NAME array_expr_02 LABELS cpython llvm c NOFAST)
415415
RUN(NAME array_expr_03 LABELS cpython llvm c)
416+
RUN(NAME array_expr_04 LABELS cpython llvm c)
417+
RUN(NAME array_expr_05 LABELS cpython llvm c)
418+
RUN(NAME array_expr_06 LABELS cpython llvm c)
419+
RUN(NAME array_expr_07 LABELS cpython llvm c)
420+
RUN(NAME array_expr_08 LABELS cpython llvm c)
416421
RUN(NAME array_size_01 LABELS cpython llvm c)
417422
RUN(NAME array_size_02 LABELS cpython llvm c)
418423
RUN(NAME array_01 LABELS cpython llvm wasm c)

integration_tests/array_expr_04.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from lpython import i8, i16, i32, i64
2+
from numpy import int8, int16, int32, int64, array
3+
4+
def g():
5+
a8: i8[4] = array([127, -127, 3, 111], dtype=int8)
6+
a16: i16[4] = array([127, -127, 3, 111], dtype=int16)
7+
a32: i32[4] = array([127, -127, 3, 111], dtype=int32)
8+
a64: i64[4] = array([127, -127, 3, 111], dtype=int64)
9+
10+
print(a8)
11+
print(a16)
12+
print(a32)
13+
print(a64)
14+
15+
assert (a8[0] == i8(127))
16+
assert (a8[1] == i8(-127))
17+
assert (a8[2] == i8(3))
18+
assert (a8[3] == i8(111))
19+
20+
assert (a16[0] == i16(127))
21+
assert (a16[1] == i16(-127))
22+
assert (a16[2] == i16(3))
23+
assert (a16[3] == i16(111))
24+
25+
assert (a32[0] == i32(127))
26+
assert (a32[1] == i32(-127))
27+
assert (a32[2] == i32(3))
28+
assert (a32[3] == i32(111))
29+
30+
assert (a64[0] == i64(127))
31+
assert (a64[1] == i64(-127))
32+
assert (a64[2] == i64(3))
33+
assert (a64[3] == i64(111))
34+
35+
g()

integration_tests/array_expr_05.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from lpython import u8, u16, u32, u64
2+
from numpy import uint8, uint16, uint32, uint64, array
3+
4+
def g():
5+
a8: u8[3] = array([127, 3, 111], dtype=uint8)
6+
a16: u16[3] = array([127, 3, 111], dtype=uint16)
7+
a32: u32[3] = array([127, 3, 111], dtype=uint32)
8+
a64: u64[3] = array([127, 3, 111], dtype=uint64)
9+
10+
print(a8)
11+
print(a16)
12+
print(a32)
13+
print(a64)
14+
15+
assert (a8[0] == u8(127))
16+
assert (a8[1] == u8(3))
17+
assert (a8[2] == u8(111))
18+
19+
assert (a16[0] == u16(127))
20+
assert (a16[1] == u16(3))
21+
assert (a16[2] == u16(111))
22+
23+
assert (a32[0] == u32(127))
24+
assert (a32[1] == u32(3))
25+
assert (a32[2] == u32(111))
26+
27+
assert (a64[0] == u64(127))
28+
assert (a64[1] == u64(3))
29+
assert (a64[2] == u64(111))
30+
31+
g()

integration_tests/array_expr_06.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from lpython import f32, f64
2+
from numpy import float32, float64, array
3+
4+
def g():
5+
a32: f32[4] = array([127, -127, 3, 111], dtype=float32)
6+
a64: f64[4] = array([127, -127, 3, 111], dtype=float64)
7+
8+
print(a32)
9+
print(a64)
10+
11+
assert (abs(a32[0] - f32(127)) <= f32(1e-5))
12+
assert (abs(a32[1] - f32(-127)) <= f32(1e-5))
13+
assert (abs(a32[2] - f32(3)) <= f32(1e-5))
14+
assert (abs(a32[3] - f32(111)) <= f32(1e-5))
15+
16+
assert (abs(a64[0] - f64(127)) <= 1e-5)
17+
assert (abs(a64[1] - f64(-127)) <= 1e-5)
18+
assert (abs(a64[2] - f64(3)) <= 1e-5)
19+
assert (abs(a64[3] - f64(111)) <= 1e-5)
20+
21+
g()

integration_tests/array_expr_07.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from lpython import c32, c64, f32
2+
from numpy import complex64, complex128, array
3+
4+
def g():
5+
a32: c32[4] = array([127, -127, 3, 111], dtype=complex64)
6+
a64: c64[4] = array([127, -127, 3, 111], dtype=complex128)
7+
8+
print(a32)
9+
print(a64)
10+
11+
assert (abs(a32[0] - c32(127)) <= f32(1e-5))
12+
assert (abs(a32[1] - c32(-127)) <= f32(1e-5))
13+
assert (abs(a32[2] - c32(3)) <= f32(1e-5))
14+
assert (abs(a32[3] - c32(111)) <= f32(1e-5))
15+
16+
assert (abs(a64[0] - c64(127)) <= 1e-5)
17+
assert (abs(a64[1] - c64(-127)) <= 1e-5)
18+
assert (abs(a64[2] - c64(3)) <= 1e-5)
19+
assert (abs(a64[3] - c64(111)) <= 1e-5)
20+
21+
g()

integration_tests/array_expr_08.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from lpython import i1
2+
from numpy import bool_, array
3+
4+
def g():
5+
a1: i1[4] = array([0, -127, 0, 111], dtype=bool_)
6+
7+
print(a1)
8+
9+
assert not a1[0]
10+
assert a1[1]
11+
assert not a1[2]
12+
assert a1[3]
13+
14+
g()

0 commit comments

Comments
 (0)