From 718ef8ef9054b68e2a30738d4a2b13794276b1bc Mon Sep 17 00:00:00 2001 From: Matthew Haddon Date: Tue, 12 Oct 2021 11:07:53 +0100 Subject: refactor SLICE error_if checks * refactored error_if checks to avoid logic overlap * Added check to ensure that size dimensions match output dimension * Defined the rank() function in pseudocode helpers Change-Id: I56bf06252d9149d449c984126e8f2025a07d6034 Signed-off-by: Matthew Haddon --- chapters/data_layout.adoc | 9 +++++---- chapters/pseudocode.adoc | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/chapters/data_layout.adoc b/chapters/data_layout.adoc index bc8d853..773e949 100644 --- a/chapters/data_layout.adoc +++ b/chapters/data_layout.adoc @@ -201,14 +201,15 @@ No data conversion happens during a slice operation. [source,c++] ---- +ERROR_IF(rank(input1) != length(start) || rank(input1) != length(size)); +ERROR_IF(rank(input1) != rank(output)) // Sanity check the given coordinates, ensure start and end are // within tensor bounds for_each(index in rank(input1)) { - ERROR_IF(start[index] < 0 || - start[index] >= shape1[index]); - ERROR_IF(start[index] + size[index] < 0 || - start[index] + size[index] >= shape1[index]); + ERROR_IF(start[index] < 0); ERROR_IF(size[index] <= 0); //Output must be positive size + ERROR_IF(start[index] + size[index] > shape1[index]); + ERROR_IF(shape[index] != size[index]); } for_each(index in shape) { diff --git a/chapters/pseudocode.adoc b/chapters/pseudocode.adoc index 5e6af5b..79ec190 100644 --- a/chapters/pseudocode.adoc +++ b/chapters/pseudocode.adoc @@ -151,4 +151,7 @@ int length(in_t input) int floor(in_t input) return input value rounded down to nearest integer + +int rank(in_t input) + return rank of an input tensor ---- \ No newline at end of file -- cgit v1.2.1