Skip to content

Commit f011dbe

Browse files
authored
Merge pull request #2294 from Shaikh-Ubaid/dtype_for_empty
Support/Enforce dtype for empty()
2 parents 621ffc0 + d0b31d5 commit f011dbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1407
-400
lines changed

integration_tests/array_01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from lpython import i32
2-
from numpy import empty
2+
from numpy import empty, int32
33

44
def main0():
55
Nx: i32 = 600; Ny: i32 = 450
6-
arr: i32[450, 600] = empty([Ny, Nx])
6+
arr: i32[450, 600] = empty([450, 600], dtype=int32)
77
i: i32
88
j: i32
99
for i in range(Ny):

integration_tests/array_02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from lpython import i32
2-
from numpy import empty
2+
from numpy import empty, int32
33

44
def main0():
55
Nx: i32 = 60; Ny: i32 = 45; Nz: i32 = 20
6-
arr: i32[45, 60, 20] = empty([Ny, Nx, Nz])
6+
arr: i32[45, 60, 20] = empty([45, 60, 20], dtype=int32)
77
i: i32
88
j: i32
99
k: i32

integration_tests/array_02_decl.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from lpython import i32, i64, f32, f64, c32, c64
2-
from numpy import empty
2+
from numpy import empty, int32, int64, float32, float64, complex64, complex128
33

44
def accept_multidim_i32_array(xi32: i32[:, :]) -> i32:
55
return xi32[0, 0]
@@ -14,12 +14,12 @@ def accept_multidim_f64_array(xf64: f64[:, :]) -> f64:
1414
return xf64[0, 1]
1515

1616
def declare_arrays():
17-
ai32: i32[3, 3] = empty([3, 3])
18-
ai64: i64[10, 10, 10] = empty([10, 10, 10])
19-
af32: f32[3] = empty(3)
20-
af64: f64[10, 4] = empty([10, 4])
21-
ac32: c32[3, 5, 99] = empty([3, 5, 99])
22-
ac64: c64[10, 13, 11, 16] = empty([10, 13, 11, 16])
17+
ai32: i32[3, 3] = empty([3, 3], dtype=int32)
18+
ai64: i64[10, 10, 10] = empty([10, 10, 10], dtype=int64)
19+
af32: f32[3] = empty(3, dtype=float32)
20+
af64: f64[10, 4] = empty([10, 4], dtype=float64)
21+
ac32: c32[3, 5, 99] = empty([3, 5, 99], dtype=complex64)
22+
ac64: c64[10, 13, 11, 16] = empty([10, 13, 11, 16], dtype=complex128)
2323
print(accept_multidim_i32_array(ai32))
2424
print(accept_multidim_i64_array(ai64))
2525
print(accept_multidim_f32_array(af32))

integration_tests/array_03_decl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class Truck:
1212
wheels: i32
1313

1414
def declare_struct_array():
15-
cars: Car[1] = empty(10, dtype=Car)
16-
trucks: Truck[2] = empty(20, dtype=Truck)
15+
cars: Car[1] = empty(1, dtype=Car)
16+
trucks: Truck[2] = empty(2, dtype=Truck)
1717
cars[0] = Car(100000, 800.0)
1818
trucks[0] = Truck(1000000, 8)
1919
trucks[1] = Truck(5000000, 12)

integration_tests/array_expr_01.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
from lpython import i32, f32, f64
1+
from lpython import Const, i32, f32, f64
22
from numpy import empty, reshape, int32, float64
33

44
def array_expr_01():
5-
dim1: i32
6-
dim2: i32
7-
dim3: i32
8-
dim1d: i32
5+
dim1: Const[i32] = 10
6+
dim2: Const[i32] = 10
7+
dim3: Const[i32] = 5
8+
dim1d: Const[i32] = dim1 * dim2 * dim3
9+
910
i: i32
1011
shape1d: i32[1] = empty(1, dtype=int32)
1112
shape3d: i32[3] = empty(3, dtype=int32)
1213
eps: f64
1314
eps = 1e-12
1415

15-
dim1 = 10
16-
dim2 = 10
17-
dim3 = 5
18-
dim1d = dim1 * dim2 * dim3
19-
2016
e: f64[10, 10, 5] = empty((dim1, dim2, dim3), dtype=float64)
2117
f: f64[10, 10, 5] = empty((dim1, dim2, dim3), dtype=float64)
2218
g: f64[500] = empty(dim1d, dtype=float64)

integration_tests/array_size_01.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from lpython import i32, f64, c32, c64
2-
from numpy import empty
2+
from numpy import empty, int32, float64, complex64, complex128
33

44
def main0():
5-
x: i32[4, 5, 2] = empty([4, 5, 2])
6-
y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5])
5+
x: i32[4, 5, 2] = empty([4, 5, 2], dtype=int32)
6+
y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5], dtype=float64)
77
print(x.size)
88
print(y.size)
99

1010
assert x.size == 40
1111
assert y.size == 24000
1212

1313
def main1():
14-
a: c32[12] = empty([12])
15-
b: c64[15, 15, 10] = empty([15, 15, 10])
14+
a: c32[12] = empty([12], dtype=complex64)
15+
b: c64[15, 15, 10] = empty([15, 15, 10], dtype=complex128)
1616
print(a.size)
1717
print(b.size)
1818

integration_tests/array_size_02.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from lpython import i32, f64, c32, c64, u32
2-
from numpy import empty, size
1+
from lpython import i32, f64, c32, c64, u32, u64
2+
from numpy import empty, size, int32, uint32, uint64, float64, complex64, complex128
33

44
def main0():
5-
x: i32[4, 5, 2] = empty([4, 5, 2])
6-
y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5])
5+
x: i32[4, 5, 2] = empty([4, 5, 2], dtype=int32)
6+
y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5], dtype=float64)
77
z: i32
88
w: i32
99
z = 2
@@ -29,8 +29,8 @@ def main0():
2929
assert size(y, w) == 5
3030

3131
def main1():
32-
a: c32[12] = empty([12])
33-
b: c64[15, 15, 10] = empty([15, 15, 10])
32+
a: c32[12] = empty([12], dtype=complex64)
33+
b: c64[15, 15, 10] = empty([15, 15, 10], dtype=complex128)
3434
c: i32
3535
d: i32
3636
c = 1
@@ -50,7 +50,7 @@ def main1():
5050
assert size(b, d) == 10
5151

5252
def main2():
53-
a: i32[2, 3] = empty([2, 3])
53+
a: i32[2, 3] = empty([2, 3], dtype=int32)
5454
print(size(a))
5555
print(size(a, 0))
5656
print(size(a, 1))
@@ -60,8 +60,8 @@ def main2():
6060
assert size(a, 1) == 3
6161

6262
def main3():
63-
a: u32[2, 3, 4] = empty([2, 3, 4])
64-
b: u64[10, 5] = empty([10, 5])
63+
a: u32[2, 3, 4] = empty([2, 3, 4], dtype=uint32)
64+
b: u64[10, 5] = empty([10, 5], dtype=uint64)
6565
c: i32
6666
d: i32
6767
c = 1

integration_tests/bindpy_02.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from lpython import i32, f64, pythoncall, Const
2-
from numpy import empty
2+
from numpy import empty, int32, float64
33

44
@pythoncall(module = "bindpy_02_module")
55
def get_cpython_version() -> str:
@@ -28,7 +28,7 @@ def show_array_dot_product(a: i32[:], b: f64[:]):
2828
# Integers:
2929
def test_array_ints():
3030
n: Const[i32] = 5
31-
a: i32[n] = empty([n], dtype=int)
31+
a: i32[n] = empty([n], dtype=int32)
3232

3333
i: i32
3434
for i in range(n):
@@ -41,7 +41,7 @@ def test_array_ints():
4141
def test_array_floats():
4242
n: Const[i32] = 3
4343
m: Const[i32] = 5
44-
b: f64[n, m] = empty([n, m], dtype=float)
44+
b: f64[n, m] = empty([n, m], dtype=float64)
4545

4646
i: i32
4747
j: i32
@@ -56,8 +56,8 @@ def test_array_floats():
5656
def test_array_broadcast():
5757
n: Const[i32] = 3
5858
m: Const[i32] = 5
59-
a: i32[n] = empty([n], dtype=int)
60-
b: f64[n, m] = empty([n, m], dtype=float)
59+
a: i32[n] = empty([n], dtype=int32)
60+
b: f64[n, m] = empty([n, m], dtype=float64)
6161

6262
i: i32
6363
j: i32

integration_tests/bindpy_04.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from lpython import i1, i32, u32, f64, c64, pythoncall, Const, TypeVar
2-
from numpy import empty, uint32, complex64
2+
from numpy import empty, uint32, complex128
33

44
n = TypeVar("n")
55
m = TypeVar("m")
@@ -102,8 +102,8 @@ def test_2D_array_bools():
102102
# Complex
103103
def test_array_complexes():
104104
n: Const[i32] = 5
105-
a: c64[n] = empty([n], dtype=complex64)
106-
b: c64[n] = empty([n], dtype=complex64)
105+
a: c64[n] = empty([n], dtype=complex128)
106+
b: c64[n] = empty([n], dtype=complex128)
107107

108108
i: i32
109109
for i in range(n):
@@ -122,8 +122,8 @@ def test_array_complexes():
122122
def test_2D_array_complexes():
123123
n: Const[i32] = 3
124124
m: Const[i32] = 4
125-
a: c64[n, m] = empty([n, m], dtype=complex64)
126-
b: c64[n, m] = empty([n, m], dtype=complex64)
125+
a: c64[n, m] = empty([n, m], dtype=complex128)
126+
b: c64[n, m] = empty([n, m], dtype=complex128)
127127

128128
i: i32
129129
j: i32

integration_tests/elemental_01.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from lpython import i32, f64, f32
2-
from numpy import empty, sin, cos, reshape
2+
from numpy import empty, sin, cos, reshape, int32, float32, float64
33

44
def verify1d(array: f32[:], result: f32[:], size: i32):
55
i: i32
@@ -55,9 +55,9 @@ def elemental_sum():
5555
j: i32
5656
k: i32
5757

58-
array_a: f64[100] = empty(100)
59-
array_b: f64[100] = empty(100)
60-
array_c: f64[100] = empty(100)
58+
array_a: f64[100] = empty(100, dtype=float64)
59+
array_b: f64[100] = empty(100, dtype=float64)
60+
array_c: f64[100] = empty(100, dtype=float64)
6161

6262
for i in range(100):
6363
array_a[i] = float(i)
@@ -74,9 +74,9 @@ def elemental_mul():
7474
j: i32
7575
k: i32
7676

77-
array_a: f64[100] = empty(100)
78-
array_b: f64[100] = empty(100)
79-
array_c: f64[100] = empty(100)
77+
array_a: f64[100] = empty(100, dtype=float64)
78+
array_b: f64[100] = empty(100, dtype=float64)
79+
array_c: f64[100] = empty(100, dtype=float64)
8080

8181
for i in range(100):
8282
array_a[i] = float(i)
@@ -93,8 +93,8 @@ def elemental_sin():
9393
j: i32
9494
k: i32
9595

96-
array1d: f32[256] = empty(256)
97-
sin1d: f32[256] = empty(256)
96+
array1d: f32[256] = empty(256, dtype=float32)
97+
sin1d: f32[256] = empty(256, dtype=float32)
9898

9999
for i in range(256):
100100
array1d[i] = f32(i)
@@ -103,8 +103,8 @@ def elemental_sin():
103103

104104
verify1d(array1d, sin1d, 256)
105105

106-
arraynd: f64[256, 64, 16] = empty((256, 64, 16))
107-
sinnd: f64[256, 64, 16] = empty((256, 64, 16))
106+
arraynd: f64[256, 64, 16] = empty((256, 64, 16), dtype=float64)
107+
sinnd: f64[256, 64, 16] = empty((256, 64, 16), dtype=float64)
108108

109109
for i in range(256):
110110
for j in range(64):
@@ -119,8 +119,8 @@ def elemental_cos():
119119
i: i32
120120
j: i32
121121

122-
array2d: f64[256, 64] = empty((256, 64))
123-
cos2d: f64[256, 64] = empty((256, 64))
122+
array2d: f64[256, 64] = empty((256, 64), dtype=float64)
123+
cos2d: f64[256, 64] = empty((256, 64), dtype=float64)
124124

125125
for i in range(256):
126126
for j in range(64):
@@ -138,9 +138,9 @@ def elemental_trig_identity():
138138
eps: f32
139139
eps = f32(1e-6)
140140

141-
arraynd: f32[64, 32, 8, 4] = empty((64, 32, 8, 4))
142-
observed: f32[64, 32, 8, 4] = empty((64, 32, 8, 4))
143-
observed1d: f32[65536] = empty(65536)
141+
arraynd: f32[64, 32, 8, 4] = empty((64, 32, 8, 4), dtype=float32)
142+
observed: f32[64, 32, 8, 4] = empty((64, 32, 8, 4), dtype=float32)
143+
observed1d: f32[65536] = empty(65536, dtype=float32)
144144

145145
for i in range(64):
146146
for j in range(32):
@@ -150,7 +150,7 @@ def elemental_trig_identity():
150150

151151
observed = sin(arraynd)**f32(2) + cos(arraynd)**f32(2)
152152

153-
newshape: i32[1] = empty(1, dtype=int)
153+
newshape: i32[1] = empty(1, dtype=int32)
154154
newshape[0] = 65536
155155
observed1d = reshape(observed, newshape)
156156

0 commit comments

Comments
 (0)