Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
TEST: Add for numpy dtypes
  • Loading branch information
ubaidsk committed Aug 15, 2023
commit bc01cbf71633dd64e6dc882fe54a5d96051c4ba3
5 changes: 5 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ RUN(NAME variable_decl_03 LABELS cpython llvm c)
RUN(NAME array_expr_01 LABELS cpython llvm c)
RUN(NAME array_expr_02 LABELS cpython llvm c NOFAST)
RUN(NAME array_expr_03 LABELS cpython llvm c)
RUN(NAME array_expr_04 LABELS cpython llvm c)
RUN(NAME array_expr_05 LABELS cpython llvm c)
RUN(NAME array_expr_06 LABELS cpython llvm c)
RUN(NAME array_expr_07 LABELS cpython llvm c)
RUN(NAME array_expr_08 LABELS cpython llvm c)
RUN(NAME array_size_01 LABELS cpython llvm c)
RUN(NAME array_size_02 LABELS cpython llvm c)
RUN(NAME array_01 LABELS cpython llvm wasm c)
Expand Down
35 changes: 35 additions & 0 deletions integration_tests/array_expr_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from lpython import i8, i16, i32, i64
from numpy import int8, int16, int32, int64, array

def g():
a8: i8[4] = array([127, -127, 3, 111], dtype=int8)
a16: i16[4] = array([127, -127, 3, 111], dtype=int16)
a32: i32[4] = array([127, -127, 3, 111], dtype=int32)
a64: i64[4] = array([127, -127, 3, 111], dtype=int64)

print(a8)
print(a16)
print(a32)
print(a64)

assert (a8[0] == i8(127))
assert (a8[1] == i8(-127))
assert (a8[2] == i8(3))
assert (a8[3] == i8(111))

assert (a16[0] == i16(127))
assert (a16[1] == i16(-127))
assert (a16[2] == i16(3))
assert (a16[3] == i16(111))

assert (a32[0] == i32(127))
assert (a32[1] == i32(-127))
assert (a32[2] == i32(3))
assert (a32[3] == i32(111))

assert (a64[0] == i64(127))
assert (a64[1] == i64(-127))
assert (a64[2] == i64(3))
assert (a64[3] == i64(111))

g()
31 changes: 31 additions & 0 deletions integration_tests/array_expr_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from lpython import u8, u16, u32, u64
from numpy import uint8, uint16, uint32, uint64, array

def g():
a8: u8[3] = array([127, 3, 111], dtype=uint8)
a16: u16[3] = array([127, 3, 111], dtype=uint16)
a32: u32[3] = array([127, 3, 111], dtype=uint32)
a64: u64[3] = array([127, 3, 111], dtype=uint64)

print(a8)
print(a16)
print(a32)
print(a64)

assert (a8[0] == u8(127))
assert (a8[1] == u8(3))
assert (a8[2] == u8(111))

assert (a16[0] == u16(127))
assert (a16[1] == u16(3))
assert (a16[2] == u16(111))

assert (a32[0] == u32(127))
assert (a32[1] == u32(3))
assert (a32[2] == u32(111))

assert (a64[0] == u64(127))
assert (a64[1] == u64(3))
assert (a64[2] == u64(111))

g()
21 changes: 21 additions & 0 deletions integration_tests/array_expr_06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from lpython import f32, f64
from numpy import float32, float64, array

def g():
a32: f32[4] = array([127, -127, 3, 111], dtype=float32)
a64: f64[4] = array([127, -127, 3, 111], dtype=float64)

print(a32)
print(a64)

assert (abs(a32[0] - f32(127)) <= f32(1e-5))
assert (abs(a32[1] - f32(-127)) <= f32(1e-5))
assert (abs(a32[2] - f32(3)) <= f32(1e-5))
assert (abs(a32[3] - f32(111)) <= f32(1e-5))

assert (abs(a64[0] - f64(127)) <= 1e-5)
assert (abs(a64[1] - f64(-127)) <= 1e-5)
assert (abs(a64[2] - f64(3)) <= 1e-5)
assert (abs(a64[3] - f64(111)) <= 1e-5)

g()
21 changes: 21 additions & 0 deletions integration_tests/array_expr_07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from lpython import c32, c64, f32
from numpy import complex64, complex128, array

def g():
a32: c32[4] = array([127, -127, 3, 111], dtype=complex64)
a64: c64[4] = array([127, -127, 3, 111], dtype=complex128)

print(a32)
print(a64)

assert (abs(a32[0] - c32(127)) <= f32(1e-5))
assert (abs(a32[1] - c32(-127)) <= f32(1e-5))
assert (abs(a32[2] - c32(3)) <= f32(1e-5))
assert (abs(a32[3] - c32(111)) <= f32(1e-5))

assert (abs(a64[0] - c64(127)) <= 1e-5)
assert (abs(a64[1] - c64(-127)) <= 1e-5)
assert (abs(a64[2] - c64(3)) <= 1e-5)
assert (abs(a64[3] - c64(111)) <= 1e-5)

g()
14 changes: 14 additions & 0 deletions integration_tests/array_expr_08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from lpython import i1
from numpy import bool_, array

def g():
a1: i1[4] = array([0, -127, 0, 111], dtype=bool_)

print(a1)

assert not a1[0]
assert a1[1]
assert not a1[2]
assert a1[3]

g()