protected void checkWorkspace(String opName, INDArray array) { if (array.isAttached()) { val ws = array.data().getParentWorkspace(); if (ws.getWorkspaceType() != MemoryWorkspace.Type.CIRCULAR) { if (!ws.isScopeActive()) { throw new ND4JIllegalStateException("Op [" + opName + "] X argument uses leaked workspace pointer from workspace [" + ws.getId() + "]\nAll open workspaces: " + allOpenWorkspaces() + "\n" + SCOPE_PANIC_MSG); } if (ws.getGenerationId() != array.data().getGenerationId()) throw new ND4JIllegalStateException("Op [" + opName + "] X argument uses outdated workspace pointer from workspace [" + ws.getId() + "]\nAll open workspaces: " + allOpenWorkspaces() + "\n" + SCOPE_PANIC_MSG); } } }
/** * Assert that the specified array is valid, in terms of workspaces: i.e., if it is attached (and not in a circular * workspace), assert that the workspace is open, and that the data is not from an old generation. * @param array Array to check * @param msg Message (prefix) to include in the exception, if required. May be null */ public static void assertValidArray(INDArray array, String msg){ if(array == null || !array.isAttached()){ return; } val ws = array.data().getParentWorkspace(); if (ws.getWorkspaceType() != MemoryWorkspace.Type.CIRCULAR) { if (!ws.isScopeActive()) { throw new ND4JWorkspaceException( (msg == null ? "" : msg + ": ") + "Array uses leaked workspace pointer " + "from workspace " + ws.getId() + "\nAll open workspaces: " + allOpenWorkspaces()); } if (ws.getGenerationId() != array.data().getGenerationId()) { throw new ND4JWorkspaceException( (msg == null ? "" : msg + ": ") + "Array outdated workspace pointer " + "from workspace " + ws.getId() + " (array generation " + array.data().getGenerationId() + ", current workspace generation " + ws.getGenerationId() + ")\nAll open workspaces: " + allOpenWorkspaces()); } } }