From 2ec24c762feadfcd12f580e43326af5d387abf05 Mon Sep 17 00:00:00 2001 From: partarstu <67119045+partarstu@users.noreply.github.com> Date: Mon, 18 Jan 2021 06:52:42 +0100 Subject: [PATCH] Fixed object's removal in ArrayCacheMemoryMgr (#9155) Signed-off-by: partarstu --- .../samediff/internal/memory/ArrayCacheMemoryMgr.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/internal/memory/ArrayCacheMemoryMgr.java b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/internal/memory/ArrayCacheMemoryMgr.java index 6fb12b826..69db24f03 100644 --- a/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/internal/memory/ArrayCacheMemoryMgr.java +++ b/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/internal/memory/ArrayCacheMemoryMgr.java @@ -252,11 +252,13 @@ public class ArrayCacheMemoryMgr extends AbstractMemoryMgr { private void removeObject(INDArray array){ long length = array.data().length(); int idx = Arrays.binarySearch(lengths, 0, size, length); - Preconditions.checkState(idx > 0, "Cannot remove array from ArrayStore: no array with this length exists in the cache"); + Preconditions.checkState(idx >= 0, + "Cannot remove array from ArrayStore: no array with this length exists in the cache"); boolean found = false; int i = 0; - while(!found && i <= size && lengths[i] == length){ - found = sorted[i++] == array; //Object equality + while (!found && i < size) { + found = sorted[i] == array && lengths[i] == length; //Object and length equality + ++i; } Preconditions.checkState(found, "Cannot remove array: not found in ArrayCache"); removeIdx(i - 1);