From 67a6f7f26f092860a4e1b3f6ac0c2e5cde9bf685 Mon Sep 17 00:00:00 2001
From: Dominic Symes <dominic.symes@arm.com>
Date: Mon, 6 Mar 2023 17:14:15 +0000
Subject: Check the output shape of broadcast operations

For an operation that performs broadcast the
output shape size must be the maximum of the input shape
sizes in each dimension.

Additionally, the input dimension size must be 1 whenever
an input shape does not match the output shape size
in a dimension.

Signed-off-by: Dominic Symes <dominic.symes@arm.com>
Change-Id: I89492f4ef22da76f84f12e720c79634ea42545bc
---
 chapters/ewise_binary.adoc | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

(limited to 'chapters/ewise_binary.adoc')

diff --git a/chapters/ewise_binary.adoc b/chapters/ewise_binary.adoc
index 963d712..4af347a 100644
--- a/chapters/ewise_binary.adoc
+++ b/chapters/ewise_binary.adoc
@@ -18,6 +18,7 @@ include::{generated}/operators/ADD.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -37,6 +38,7 @@ include::{generated}/operators/ARITHMETIC_RIGHT_SHIFT.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -66,6 +68,7 @@ include::{generated}/operators/BITWISE_AND.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -85,6 +88,7 @@ include::{generated}/operators/BITWISE_OR.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -104,6 +108,7 @@ include::{generated}/operators/BITWISE_XOR.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -126,6 +131,7 @@ include::{generated}/operators/INTDIV.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -149,6 +155,7 @@ include::{generated}/operators/LOGICAL_AND.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -168,6 +175,7 @@ include::{generated}/operators/LOGICAL_LEFT_SHIFT.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -188,6 +196,7 @@ include::{generated}/operators/LOGICAL_RIGHT_SHIFT.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -208,6 +217,7 @@ include::{generated}/operators/LOGICAL_OR.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -227,6 +237,7 @@ include::{generated}/operators/LOGICAL_XOR.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -246,6 +257,7 @@ include::{generated}/operators/MAXIMUM.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -265,6 +277,7 @@ include::{generated}/operators/MINIMUM.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -284,6 +297,7 @@ include::{generated}/operators/MUL.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 ERROR_IF(in_t != int32_t && shift > 0);
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
@@ -313,6 +327,7 @@ include::{generated}/operators/POW.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
@@ -332,6 +347,7 @@ include::{generated}/operators/SUB.adoc[]
 
 [source,c++]
 ----
+ERROR_IF(shape != broadcast_shape(shape1, shape2));
 for_each(index in shape) {
     dim_t index1 = apply_broadcast(shape, shape1, index);
     dim_t index2 = apply_broadcast(shape, shape2, index);
-- 
cgit v1.2.1

