Fixed object's removal in ArrayCacheMemoryMgr (#9155)

Signed-off-by: partarstu <partarstu@gmail.com>
master
partarstu 2021-01-18 06:52:42 +01:00 committed by GitHub
parent 95ca39bd21
commit 2ec24c762f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -252,11 +252,13 @@ public class ArrayCacheMemoryMgr extends AbstractMemoryMgr {
private void removeObject(INDArray array){ private void removeObject(INDArray array){
long length = array.data().length(); long length = array.data().length();
int idx = Arrays.binarySearch(lengths, 0, size, 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; boolean found = false;
int i = 0; int i = 0;
while(!found && i <= size && lengths[i] == length){ while (!found && i < size) {
found = sorted[i++] == array; //Object equality found = sorted[i] == array && lengths[i] == length; //Object and length equality
++i;
} }
Preconditions.checkState(found, "Cannot remove array: not found in ArrayCache"); Preconditions.checkState(found, "Cannot remove array: not found in ArrayCache");
removeIdx(i - 1); removeIdx(i - 1);