From 82f19e2ad25bcbdde8e7f8b6bd6a6064a207fe36 Mon Sep 17 00:00:00 2001
From: Eric Kunze <eric.kunze@arm.com>
Date: Mon, 25 Oct 2021 16:13:22 -0700
Subject: Readability fixes for pseudocode

Avoid use of acc for variables when they are not convolution
accumulators.

Use argument types appropriately.
Add missing pseudocode for some MI operators

Change-Id: I9113f9228dbcafb85206bcc39310e9599cb12c08
---
 chapters/reduction.adoc | 76 ++++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 36 deletions(-)

(limited to 'chapters/reduction.adoc')

diff --git a/chapters/reduction.adoc b/chapters/reduction.adoc
index b687896..11db960 100644
--- a/chapters/reduction.adoc
+++ b/chapters/reduction.adoc
@@ -29,16 +29,18 @@ Reduce a tensor along the given axis with a logical AND operation
 ----
 ERROR_IF(axis < 0  || axis >= rank(shape1));
 ERROR_IF(shape[axis] != 1);
+
+// Initialize output state to true
 for_each(index in shape) {
     tensor_write<in_t>(output, shape, index, true);
 }
 for_each(index in shape1) {
-    tmp_index = index;
-    tmp_index[axis]=0;
-    value = tensor_read<in_t>(input, shape1, index);
-    acc   = tensor_read<in_t>(output, shape, tmp_index);
-    acc   = acc && value;
-    tensor_write<in_t>(output, shape, tmp_index, acc);
+    out_index = index;
+    out_index[axis] = 0;
+    in_t value = tensor_read<in_t>(input, shape1, index);
+    in_t state = tensor_read<in_t>(output, shape, out_index);
+    state      = state && value;
+    tensor_write<in_t>(output, shape, out_index, state);
 }
 ----
 
@@ -70,16 +72,18 @@ Reduce a tensor along the given axis with a logical OR operation
 ----
 ERROR_IF(axis < 0  || axis >= rank(shape1));
 ERROR_IF(shape[axis] != 1);
+
+// Initialize output state to false
 for_each(index in shape) {
     tensor_write<in_t>(output, shape, index, false);
 }
 for_each(index in shape1) {
-    tmp_index = index;
-    tmp_index[axis]=0;
-    value = tensor_read<in_t>(input, shape1, index);
-    acc   = tensor_read<in_t>(output, shape, tmp_index);
-    acc   = acc || value;
-    tensor_write<in_t>(output, shape, tmp_index, acc);
+    out_index = index;
+    out_index[axis] = 0;
+    in_t value = tensor_read<in_t>(input, shape1, index);
+    in_t state = tensor_read<in_t>(output, shape, out_index);
+    state      = state || value;
+    tensor_write<in_t>(output, shape, out_index, state);
 }
 ----
 
@@ -115,12 +119,12 @@ for_each(index in shape) {
     tensor_write<in_t>(output, shape, index, minimum<in_t>);
 }
 for_each(index in shape1) {
-    tmp_index = index;
-    tmp_index[axis]=0;
-    value = tensor_read<in_t>(input, shape1, index);
-    acc   = tensor_read<in_t>(output, shape, tmp_index);
-    acc   = apply_max<in_t>(acc, value);
-    tensor_write<in_t>(output, shape, tmp_index, acc);
+    out_index = index;
+    out_index[axis] = 0;
+    in_t value = tensor_read<in_t>(input, shape1, index);
+    in_t state = tensor_read<in_t>(output, shape, out_index);
+    state      = apply_max<in_t>(state, value);
+    tensor_write<in_t>(output, shape, out_index, state);
 }
 ----
 
@@ -158,12 +162,12 @@ for_each(index in shape) {
     tensor_write<in_t>(output, shape, index, maximum<in_t>);
 }
 for_each(index in shape1) {
-    tmp_index = index;
-    tmp_index[axis]=0;
-    value = tensor_read<in_t>(input, shape1, index);
-    acc   = tensor_read<in_t>(output, shape, tmp_index);
-    acc   = apply_min<in_t>(acc, value);
-    tensor_write<in_t>(output, shape, tmp_index, acc);
+    out_index = index;
+    out_index[axis] = 0;
+    in_t value = tensor_read<in_t>(input, shape1, index);
+    in_t state = tensor_read<in_t>(output, shape, out_index);
+    state      = apply_min<in_t>(state, value);
+    tensor_write<in_t>(output, shape, out_index, state);
 }
 ----
 
@@ -202,12 +206,12 @@ for_each(index in shape) {
     tensor_write<in_t>(output, shape, index, 1.0);
 }
 for_each(index in shape1) {
-    tmp_index = index;
-    tmp_index[axis]=0;
-    value = tensor_read<in_t>(input, shape1, index);
-    acc   = tensor_read<in_t>(output, shape, tmp_index);
-    acc   = acc * value;
-    tensor_write<in_t>(output, shape, tmp_index, acc);
+    out_index = index;
+    out_index[axis] = 0;
+    in_t value = tensor_read<in_t>(input, shape1, index);
+    in_t state = tensor_read<in_t>(output, shape, out_index);
+    state      = state * value;
+    tensor_write<in_t>(output, shape, out_index, state);
 }
 ----
 
@@ -243,12 +247,12 @@ for_each(index in shape) {
     tensor_write<in_t>(output, shape, index, 0);
 }
 for_each(index in shape1) {
-    tmp_index = index;
-    tmp_index[axis]=0;
-    value = tensor_read<in_t>(input, shape1, index);
-    acc   = tensor_read<in_t>(output, shape, tmp_index);
-    acc   = apply_add<in_t>(acc, value);
-    tensor_write<in_t>(output, shape, tmp_index, acc);
+    out_index = index;
+    out_index[axis] = 0;
+    in_t value = tensor_read<in_t>(input, shape1, index);
+    in_t state = tensor_read<in_t>(output, shape, out_index);
+    state      = apply_add<in_t>(state, value);
+    tensor_write<in_t>(output, shape, out_index, state);
 }
 ----
 
-- 
cgit v1.2.1

