From 2a3d560999c794e8faacefa93db23bf1e1714532 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Tue, 4 Jan 2022 11:20:44 -0800 Subject: Ensure ranks match in apply_broadcast ERROR_IF to make sure rank(index) == rank(out_shape) Also try to better explain what the expected value for index is. Change-Id: I0731324d33335cb1ffc0a6fbd153fbc8521ce2e9 Signed-off-by: Eric Kunze --- chapters/introduction.adoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/chapters/introduction.adoc b/chapters/introduction.adoc index 3fb5476..51d085d 100644 --- a/chapters/introduction.adoc +++ b/chapters/introduction.adoc @@ -304,8 +304,13 @@ The following function maps an index in the output tensor to an index in the inp [source,c++] ---- +// The index argument should be a valid location within out_shape. +// The function returns the location within in_shape that contributes +// to the output based on broadcasting rules. + dim_t apply_broadcast(dim_t out_shape, dim_t in_shape, dim_t index) { ERROR_IF(rank(out_shape) != rank(in_shape)); + ERROR_IF(rank(out_shape) != rank(index)); for (i = 0; i < rank(out_shape); i++) { if (out_shape[i] != in_shape[i]) { ERROR_IF(in_shape[i] != 1); -- cgit v1.2.1