From 018ee3203be88e30a97346fad5f2fb9e48c7c9a9 Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Thu, 10 Mar 2022 10:31:31 -0800 Subject: [PATCH] Chunks: Add check that chunk size is positive Fixes #538. --- Standard/src/Arrays/Arrays.qs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Standard/src/Arrays/Arrays.qs b/Standard/src/Arrays/Arrays.qs index 23d4d4e5668..7506b9efcbd 100644 --- a/Standard/src/Arrays/Arrays.qs +++ b/Standard/src/Arrays/Arrays.qs @@ -283,7 +283,7 @@ namespace Microsoft.Quantum.Arrays { /// /// # Input /// ## nElements - /// The length of each chunk. + /// The length of each chunk. Must be positive. /// ## arr /// The array to be split. /// @@ -294,6 +294,7 @@ namespace Microsoft.Quantum.Arrays { /// Note that the last element of the output may be shorter /// than `nElements` if `Length(arr)` is not divisible by `nElements`. function Chunks<'T>(nElements : Int, arr : 'T[]) : 'T[][] { + Fact(nElements > 0, "nElements must be positive"); mutable output = []; mutable remaining = arr; while (not IsEmpty(remaining)) {