From afaaa673e1620315e0d7d863d7bcef1a2dc54df9 Mon Sep 17 00:00:00 2001 From: Kevin Petit Date: Thu, 8 Feb 2024 11:03:31 +0000 Subject: pseudocode: a collection of variable declaration fixes Only cases where types are obvious. - Add missing types - Do not re-declare variables - Fix scope of declaration Signed-off-by: Kevin Petit Change-Id: I7d44d9adde606094e0a7910fb438649521ff3ec0 --- pseudocode/operators/COS.tosac | 2 +- pseudocode/operators/PAD.tosac | 4 ++-- pseudocode/operators/RESCALE.tosac | 13 +++++++------ pseudocode/operators/SIGMOID.tosac | 2 +- pseudocode/operators/SIN.tosac | 2 +- pseudocode/operators/SLICE.tosac | 2 +- pseudocode/operators/TANH.tosac | 2 +- pseudocode/operators/TILE.tosac | 2 +- pseudocode/operators/TRANSPOSE.tosac | 4 ++-- pseudocode/operators/VARIABLE.tosac | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pseudocode/operators/COS.tosac b/pseudocode/operators/COS.tosac index e1f1d91..afb9d14 100644 --- a/pseudocode/operators/COS.tosac +++ b/pseudocode/operators/COS.tosac @@ -9,6 +9,6 @@ for_each(index in shape) { in_out_t value1 = tensor_read(input, shape, index); - value = cos(value1); + in_out_t value = cos(value1); tensor_write(output, shape, index, value); } diff --git a/pseudocode/operators/PAD.tosac b/pseudocode/operators/PAD.tosac index 45ef674..b458170 100644 --- a/pseudocode/operators/PAD.tosac +++ b/pseudocode/operators/PAD.tosac @@ -9,14 +9,14 @@ // Check output shape matches the padded input shape ERROR_IF(rank(shape) != rank(shape1)); -for (i = 0; i < rank(shape); i++) { +for (int32_t i = 0; i < rank(shape); i++) { ERROR_IF(padding[i * 2] < 0 || padding[(i * 2) + 1] < 0); ERROR_IF(shape[i] != padding[i * 2] + shape1[i] + padding[(i * 2) + 1]); } for_each(index in shape) { shape_t index1 = index; bool_t is_pad = false; - for(i = 0; i < rank(shape); i++) { + for(int32_t i = 0; i < rank(shape); i++) { index1[i] = index1[i] - padding[i * 2]; if (index1[i] < 0 || index[i] >= length(shape[i])) { is_pad = true; diff --git a/pseudocode/operators/RESCALE.tosac b/pseudocode/operators/RESCALE.tosac index 0a3ce8d..555d4ca 100644 --- a/pseudocode/operators/RESCALE.tosac +++ b/pseudocode/operators/RESCALE.tosac @@ -42,19 +42,20 @@ for_each(index in shape) { apply_scale_32(value, multiplier[c], shift[c], double_round) : apply_scale_16(value, multiplier[c], shift[c]); + out_t out; if (output_unsigned) { int32_t extended_out_zp = zero_extend(output_zp); result = apply_add_s(result, extended_out_zp); - out_t out = static_cast(apply_clip_u(result, - minimum_u(), - maximum_u())); + out = static_cast(apply_clip_u(result, + minimum_u(), + maximum_u())); } else { int32_t extended_out_zp = sign_extend(output_zp); result = apply_add_s(result, extended_out_zp); - out_t out = static_cast(apply_clip_s(result, - minimum_s(), - maximum_s())); + out = static_cast(apply_clip_s(result, + minimum_s(), + maximum_s())); } tensor_write(output, shape, index, out); } diff --git a/pseudocode/operators/SIGMOID.tosac b/pseudocode/operators/SIGMOID.tosac index 048523e..fd9afc7 100644 --- a/pseudocode/operators/SIGMOID.tosac +++ b/pseudocode/operators/SIGMOID.tosac @@ -9,6 +9,6 @@ for_each(index in shape) { in_out_t value1 = tensor_read(input, shape, index); - value = sigmoid(value1); + in_out_t value = sigmoid(value1); tensor_write(output, shape, index, value); } diff --git a/pseudocode/operators/SIN.tosac b/pseudocode/operators/SIN.tosac index 9a24a00..82361a9 100644 --- a/pseudocode/operators/SIN.tosac +++ b/pseudocode/operators/SIN.tosac @@ -9,6 +9,6 @@ for_each(index in shape) { in_out_t value1 = tensor_read(input, shape, index); - value = sin(value1); + in_out_t value = sin(value1); tensor_write(output, shape, index, value); } diff --git a/pseudocode/operators/SLICE.tosac b/pseudocode/operators/SLICE.tosac index b6f70c5..b7b0680 100644 --- a/pseudocode/operators/SLICE.tosac +++ b/pseudocode/operators/SLICE.tosac @@ -20,7 +20,7 @@ for_each(index in rank(shape1)) { for_each(index in shape) { shape_t tmp_index = index; - for(i = 0; i < rank(shape); i++) { + for(int32_t i = 0; i < rank(shape); i++) { tmp_index[i] = index[i] + start[i]; } in_out_t value = tensor_read(input1, shape1, tmp_index); diff --git a/pseudocode/operators/TANH.tosac b/pseudocode/operators/TANH.tosac index 1b5edba..c0dccc1 100644 --- a/pseudocode/operators/TANH.tosac +++ b/pseudocode/operators/TANH.tosac @@ -9,6 +9,6 @@ for_each(index in shape) { in_out_t value1 = tensor_read(input, shape, index); - value = tanh(value1); + in_out_t value = tanh(value1); tensor_write(output, shape, index, value); } diff --git a/pseudocode/operators/TILE.tosac b/pseudocode/operators/TILE.tosac index be1cfee..5ebd1c1 100644 --- a/pseudocode/operators/TILE.tosac +++ b/pseudocode/operators/TILE.tosac @@ -11,7 +11,7 @@ ERROR_IF(rank(shape1) != rank(shape)); for_each(index in shape) { shape_t tmp_index = index; - for(i = 0; i < rank(shape); i++) { + for(int32_t i = 0; i < rank(shape); i++) { ERROR_IF(shape1[i] * multiples[i] != shape[i]); tmp_index[i] = index[i] % shape1[i]; } diff --git a/pseudocode/operators/TRANSPOSE.tosac b/pseudocode/operators/TRANSPOSE.tosac index 3981f54..09fea65 100644 --- a/pseudocode/operators/TRANSPOSE.tosac +++ b/pseudocode/operators/TRANSPOSE.tosac @@ -21,13 +21,13 @@ for_each(index in perms) { // Ensure that the output shapes have the properly // permuted shapes -for(i = 0; i < rank(shape); i++) { +for(int32_t i = 0; i < rank(shape); i++) { ERROR_IF(shape1[perms[i]] != shape[i]); } for_each(index in shape) { shape_t tmp_index = index; - for(i = 0; i < rank(shape); i++) { + for(int32_t i = 0; i < rank(shape); i++) { tmp_index[perms[i]] = index[i]; } in_out_t value = tensor_read(input1, shape1, tmp_index); diff --git a/pseudocode/operators/VARIABLE.tosac b/pseudocode/operators/VARIABLE.tosac index 4d2fce7..aaa2155 100644 --- a/pseudocode/operators/VARIABLE.tosac +++ b/pseudocode/operators/VARIABLE.tosac @@ -13,7 +13,7 @@ tensor_t var_tensor = variable_tensor_lookup(uid); // Invocation for the first time if (var_tensor == NULL) { // Allocate the persistent mutable memory for the variable tensor - tensor_t var_tensor = variable_tensor_allocate(var_shape, uid); + var_tensor = variable_tensor_allocate(var_shape, uid); if (initial_value != NULL) { REQUIRE(var_t == in_t); -- cgit v1.2.1