Skip to content

Commit 0c8fbe0

Browse files
authored
Merge pull request #1837 from Shaikh-Ubaid/print_error_on_assign_to_input_param
Print error on assign to input parameter
2 parents 8da8f21 + 20f04f2 commit 0c8fbe0

22 files changed

+97
-52
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ jobs:
227227
run: |
228228
# Package lpynn has lpython_emulation as dependency
229229
# Hence, it should by default install lpython_emulation
230-
python -m pip install lpython_emulation==0.0.1.8 lpynn==0.0.1.3 numpy==1.24.3
230+
python -m pip install lpython_emulation==0.0.1.9 lpynn==0.0.1.4 numpy==1.24.3
231231
232232
- name: PIP show installed packages
233233
shell: bash -l {0}

integration_tests/lnn/perceptron/perceptron_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import dataclass, i32, f64
1+
from lpython import dataclass, i32, f64, InOut
22
from sys import exit
33

44
@dataclass
@@ -27,7 +27,7 @@ def init_weights(size: i32) -> list[f64]:
2727
weights.append(0.0) # append bias
2828
return weights
2929

30-
def init_perceptron(p: Perceptron, n: i32, rate: f64, iterations_limit: i32, des_accuracy: f64):
30+
def init_perceptron(p: InOut[Perceptron], n: i32, rate: f64, iterations_limit: i32, des_accuracy: f64):
3131
if (n < 1 or n > 1000):
3232
print("no_of_inputs must be between [1, 1000]")
3333
exit(1)
@@ -39,7 +39,7 @@ def init_perceptron(p: Perceptron, n: i32, rate: f64, iterations_limit: i32, des
3939
p.cur_accuracy = 0.0
4040
p.epochs_cnt = 0
4141

42-
def train_perceptron(p: Perceptron, input_vector: list[f64], actual_output: i32):
42+
def train_perceptron(p: InOut[Perceptron], input_vector: list[f64], actual_output: i32):
4343
predicted_output: i32 = predict_perceptron(p, input_vector)
4444
error: i32 = actual_output - predicted_output
4545
i: i32
@@ -65,7 +65,7 @@ def train_epoch(p: Perceptron, input_vectors: list[list[f64]], outputs: list[i32
6565
if predict_perceptron(p, input_vector) != outputs[i]:
6666
train_perceptron(p, input_vector, outputs[i])
6767

68-
def train_dataset(p: Perceptron, input_vectors: list[list[f64]], outputs: list[i32]):
68+
def train_dataset(p: InOut[Perceptron], input_vectors: list[list[f64]], outputs: list[i32]):
6969
p.cur_accuracy = 0.0
7070
p.epochs_cnt = 0
7171
while p.cur_accuracy < p.des_accuracy and p.epochs_cnt < p.iterations_limit:

integration_tests/lnn/regression/regression_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import dataclass, i32, f64
1+
from lpython import dataclass, i32, f64, InOut
22
from sys import exit
33

44
@dataclass
@@ -27,7 +27,7 @@ def init_weights(size: i32) -> list[f64]:
2727
weights.append(0.0) # append bias
2828
return weights
2929

30-
def init_perceptron(p: Perceptron, n: i32, rate: f64, iterations_limit: i32, err_limit: f64):
30+
def init_perceptron(p: InOut[Perceptron], n: i32, rate: f64, iterations_limit: i32, err_limit: f64):
3131
p.no_of_inputs = n
3232
p.weights = init_weights(n)
3333
p.learn_rate = rate
@@ -36,7 +36,7 @@ def init_perceptron(p: Perceptron, n: i32, rate: f64, iterations_limit: i32, err
3636
p.err = 1.0
3737
p.epochs_cnt = 0
3838

39-
def train_perceptron(p: Perceptron, input_vector: list[f64], actual_output: f64):
39+
def train_perceptron(p: InOut[Perceptron], input_vector: list[f64], actual_output: f64):
4040
predicted_output: f64 = predict_perceptron(p, input_vector)
4141
error: f64 = actual_output - predicted_output
4242
i: i32
@@ -60,7 +60,7 @@ def train_epoch(p: Perceptron, input_vectors: list[list[f64]], outputs: list[f64
6060
if predict_perceptron(p, input_vector) != outputs[i]:
6161
train_perceptron(p, input_vector, outputs[i])
6262

63-
def train_dataset(p: Perceptron, input_vectors: list[list[f64]], outputs: list[f64]):
63+
def train_dataset(p: InOut[Perceptron], input_vectors: list[list[f64]], outputs: list[f64]):
6464
prev_err: f64 = 0.0
6565
p.err = 1.0
6666
p.epochs_cnt = 0

integration_tests/lnn/utils/utils_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import i32, f64
1+
from lpython import i32, f64, InOut
22

33
def normalize(value: f64, leftMin: f64, leftMax: f64, rightMin: f64, rightMax: f64) -> f64:
44
# Figure out how 'wide' each range is
@@ -11,7 +11,7 @@ def normalize(value: f64, leftMin: f64, leftMax: f64, rightMin: f64, rightMax: f
1111
# Convert the 0-1 range into a value in the right range.
1212
return rightMin + (valueScaled * rightSpan)
1313

14-
def normalize_input_vectors(input_vectors: list[list[f64]]):
14+
def normalize_input_vectors(input_vectors: InOut[list[list[f64]]]):
1515
rows: i32 = len(input_vectors)
1616
cols: i32 = len(input_vectors[0])
1717

@@ -29,7 +29,7 @@ def normalize_input_vectors(input_vectors: list[list[f64]]):
2929
for i in range(rows):
3030
input_vectors[i][j] = normalize(input_vectors[i][j], colMinVal, colMaxVal, -1.0, 1.0)
3131

32-
def normalize_output_vector(output_vector: list[f64]):
32+
def normalize_output_vector(output_vector: InOut[list[f64]]):
3333
rows: i32 = len(output_vector)
3434
colMinVal: f64 = output_vector[0]
3535
colMaxVal: f64 = output_vector[0]

integration_tests/print_list_tuple_01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import f64, i32, c64
1+
from lpython import f64, i32, c64, InOut
22

33

44
def test_print_list():
@@ -20,7 +20,7 @@ def test_print_list():
2020
print(x, y, z, t)
2121

2222

23-
def f(y: list[i32]) -> list[i32]:
23+
def f(y: InOut[list[i32]]) -> list[i32]:
2424
y.append(4)
2525
return y
2626

integration_tests/print_list_tuple_02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from lpython import i32, f64
1+
from lpython import i32, f64, InOut
22

3-
def insert_tuples_into_list(l: list[tuple[i32, f64, str]], size: i32) -> list[tuple[i32, f64, str]]:
3+
def insert_tuples_into_list(l: InOut[list[tuple[i32, f64, str]]], size: i32) -> list[tuple[i32, f64, str]]:
44
i: i32
55
string: str
66
t: tuple[i32, f64, str]

integration_tests/structs_01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import i32, f32, f64, dataclass
1+
from lpython import i32, f32, f64, dataclass, InOut
22

33
@dataclass
44
class A:
@@ -9,7 +9,7 @@ def f(a: A):
99
print(a.x)
1010
print(a.y)
1111

12-
def change_struct(a: A):
12+
def change_struct(a: InOut[A]):
1313
a.x = a.x + 1
1414
a.y = a.y + f32(1)
1515

integration_tests/structs_05.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import i32, f64, i64, i16, i8, f32, dataclass
1+
from lpython import i32, f64, i64, i16, i8, f32, dataclass, InOut
22
from numpy import empty
33

44
@dataclass
@@ -33,7 +33,7 @@ def verify(s: A[:], x1: i32, y1: f64, x2: i32, y2: f64):
3333
assert s1.c == i8(x2)
3434
assert s1.d
3535

36-
def update_1(s: A):
36+
def update_1(s: InOut[A]):
3737
s.x = 2
3838
s.y = 1.2
3939
s.z = i64(2)

integration_tests/test_list_03.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import i32
1+
from lpython import i32, InOut
22

33
def test_list_01(n: i32) -> i32:
44
a: list[i32] = []
@@ -10,7 +10,7 @@ def test_list_01(n: i32) -> i32:
1010
sum += a[i]
1111
return sum
1212

13-
def test_list_insert_02(x: list[i32], n: i32) -> list[i32]:
13+
def test_list_insert_02(x: InOut[list[i32]], n: i32) -> list[i32]:
1414
i: i32
1515
imod: i32
1616
for i in range(n):

integration_tests/test_list_05.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lpython import i32, f64
1+
from lpython import i32, f64, InOut
22

33
def check_list_of_tuples(l: list[tuple[i32, f64, str]], sign: i32):
44
size: i32 = len(l)
@@ -29,7 +29,7 @@ def fill_list_of_tuples(size: i32) -> list[tuple[i32, f64, str]]:
2929

3030
return l1
3131

32-
def insert_tuples_into_list(l: list[tuple[i32, f64, str]], size: i32) -> list[tuple[i32, f64, str]]:
32+
def insert_tuples_into_list(l: InOut[list[tuple[i32, f64, str]]], size: i32) -> list[tuple[i32, f64, str]]:
3333
i: i32
3434
string: str
3535
t: tuple[i32, f64, str]

0 commit comments

Comments
 (0)