Package org.nd4j.linalg.workspace
Interface WorkspaceMgr<T extends Enum<T>>
-
- All Known Implementing Classes:
BaseWorkspaceMgr
public interface WorkspaceMgr<T extends Enum<T>>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
assertCurrentWorkspace(T arrayType, String msg)
Assert that the current workspace is the one for the specified array type.void
assertNotOpen(T arrayType, String msg)
Assert thath the workspace for the specified array type is not open.void
assertOpen(T arrayType, String msg)
Assert thath the workspace for the specified array type is open.INDArray
castTo(T arrayType, @NonNull DataType dataType, @NonNull INDArray toCast, boolean dupIfCorrectType)
Cast the specified array to the specified datatype.
If the array is already the correct type, the bahaviour depends on the 'dupIfCorrectType' argument.
dupIfCorrectType = false && toCast.dataType() == dataType: return input array as-is (unless workspace is wrong)
dupIfCorrectType = true && toCast.dataType() == dataType: duplicate the array into the specified workspaceINDArray
create(T arrayType, DataType dataType, long... shape)
Create an array in the specified array type's workspace (or detached if none is specified).INDArray
create(T arrayType, DataType dataType, long[] shape, char ordering)
Create an array in the specified array type's workspace (or detached if none is specified).INDArray
createUninitialized(T arrayType, DataType dataType, long... shape)
Create an uninitialized array in the specified array type's workspace (or detached if none is specified).INDArray
createUninitialized(T arrayType, DataType dataType, long[] shape, char order)
Create an uninitialized array in the specified array type's workspace (or detached if none is specified).INDArray
dup(T arrayType, @NonNull INDArray toDup)
Duplicate the array, where the array is put into the specified array type's workspace (if applicable)INDArray
dup(T arrayType, INDArray toDup, char order)
Duplicate the array, where the array is put into the specified array type's workspace (if applicable)WorkspaceConfiguration
getConfiguration(T arrayType)
String
getWorkspaceName(T arrayType)
boolean
hasConfiguration(T arrayType)
Has the specified array type been configured in this workspace manager?boolean
isScopedOut(T arrayType)
boolean
isWorkspaceOpen(T arrayType)
Check if the workspace for the specified array type is open.INDArray
leverageTo(T toWorkspace, INDArray array)
Leverage the array to the specified array type's workspace (or detach if required).MemoryWorkspace
notifyScopeBorrowed(T arrayType)
Borrow the scope for the specified array typeMemoryWorkspace
notifyScopeEntered(T arrayType)
WorkspacesCloseable
notifyScopeEntered(T... arrayTypes)
Open/enter multiple workspaces.void
setConfiguration(T arrayType, WorkspaceConfiguration configuration)
Set the workspace configuration for the specified array typevoid
setScopedOutFor(T arrayType)
Set arrays to be scoped out (not in any workspace) for the specified array type.void
setWorkspace(T arrayType, String wsName, WorkspaceConfiguration configuration)
Seth the workspace name and configuration for the specified array typevoid
setWorkspaceName(T arrayType, String wsName)
Set the workspace name for the specified array typeINDArray
validateArrayLocation(T arrayType, INDArray array, boolean migrateIfInvalid, boolean exceptionIfDetached)
Validate that the specified array type is actually in the workspace it's supposed to be in
-
-
-
Method Detail
-
setWorkspaceName
void setWorkspaceName(T arrayType, String wsName)
Set the workspace name for the specified array type- Parameters:
arrayType
- Array type to set the workspace name forwsName
- Workspace name to set
-
getWorkspaceName
String getWorkspaceName(T arrayType)
- Parameters:
arrayType
- Array type to get the workspace name for (if set)- Returns:
- The workspace name for the specified array type (or null, if none has been set)
-
setWorkspace
void setWorkspace(T arrayType, String wsName, WorkspaceConfiguration configuration)
Seth the workspace name and configuration for the specified array type- Parameters:
arrayType
- Array typewsName
- Workspace nameconfiguration
- Workspace configuration
-
setConfiguration
void setConfiguration(T arrayType, WorkspaceConfiguration configuration)
Set the workspace configuration for the specified array type- Parameters:
arrayType
- Type of array to set the configuration forconfiguration
- Configuration for the specified array type
-
getConfiguration
WorkspaceConfiguration getConfiguration(T arrayType)
- Parameters:
arrayType
- Array type to get the workspace configuration for- Returns:
- Workspace configuration for the specified array type (or note, if no configuration has been set)
-
setScopedOutFor
void setScopedOutFor(T arrayType)
Set arrays to be scoped out (not in any workspace) for the specified array type. This means that create, dup, leverage etc methods will return result arrays that are not attached to any workspace- Parameters:
arrayType
- Array type to set scoped out for
-
isScopedOut
boolean isScopedOut(T arrayType)
- Parameters:
arrayType
- Array type- Returns:
- True if the specified array type is set to be scoped out
-
hasConfiguration
boolean hasConfiguration(T arrayType)
Has the specified array type been configured in this workspace manager?- Parameters:
arrayType
- Array type to check- Returns:
- True if the array type has been configured (either scoped out, or a workspace has been set for this array type)
-
notifyScopeEntered
MemoryWorkspace notifyScopeEntered(T arrayType)
- Parameters:
arrayType
- Array type to enter the scope for- Returns:
- Workspace for the specified array type
-
notifyScopeEntered
WorkspacesCloseable notifyScopeEntered(T... arrayTypes)
Open/enter multiple workspaces. This is equivalent to nested opening of the specified workspaces- Parameters:
arrayTypes
- Open the specified workspaces- Returns:
- Closeable for the specified workspaces
-
notifyScopeBorrowed
MemoryWorkspace notifyScopeBorrowed(T arrayType)
Borrow the scope for the specified array type- Parameters:
arrayType
- Array type to borrow the scope for- Returns:
- Workspace
-
isWorkspaceOpen
boolean isWorkspaceOpen(T arrayType)
Check if the workspace for the specified array type is open. If the array type is set to be scoped out, this will return true- Parameters:
arrayType
- Array type- Returns:
- True if the workspace is open (or array type is set to scoped out)
-
assertOpen
void assertOpen(T arrayType, String msg) throws ND4JWorkspaceException
Assert thath the workspace for the specified array type is open. For array types that are set to scoped out, this will be treated as a no-op- Parameters:
arrayType
- Array type to checkmsg
- May be null. If non-null: include this in the exception- Throws:
ND4JWorkspaceException
- If the specified workspace is not open
-
assertNotOpen
void assertNotOpen(T arrayType, String msg) throws ND4JWorkspaceException
Assert thath the workspace for the specified array type is not open. For array types that are set to scoped out, this will be treated as a no-op- Parameters:
arrayType
- Array type to checkmsg
- May be null. If non-null: include this in the exception- Throws:
ND4JWorkspaceException
- If the specified workspace is open
-
assertCurrentWorkspace
void assertCurrentWorkspace(T arrayType, String msg) throws ND4JWorkspaceException
Assert that the current workspace is the one for the specified array type. As perisWorkspaceOpen(Enum)
scoped out array types are ignored here.- Parameters:
arrayType
- Array type to checkmsg
- May be null. Message to include in the exception- Throws:
ND4JWorkspaceException
-
leverageTo
INDArray leverageTo(T toWorkspace, INDArray array)
Leverage the array to the specified array type's workspace (or detach if required). If the array is not attached (not defined in a workspace) - array is returned unmodified- Parameters:
toWorkspace
- Array type's workspace to move the array toarray
- Array to leverage- Returns:
- Leveraged array (if leveraged, or original array otherwise)
-
validateArrayLocation
INDArray validateArrayLocation(T arrayType, INDArray array, boolean migrateIfInvalid, boolean exceptionIfDetached) throws ND4JWorkspaceException
Validate that the specified array type is actually in the workspace it's supposed to be in- Parameters:
arrayType
- Array type of the arrayarray
- Array to checkmigrateIfInvalid
- if true, and array is in the wrong WS: migrate the array and return. If false and in the wrong WS: exceptionexceptionIfDetached
- If true: if the workspace is detached, but is expected to be in a workspace: should an exception be thrown?- Returns:
- The original array, or (if required, and if migrateIfInvalid == true) the migrated array
- Throws:
ND4JWorkspaceException
- If the array is in the incorrect workspace (and migrateIfInvalid == false)
-
create
INDArray create(T arrayType, DataType dataType, long... shape)
Create an array in the specified array type's workspace (or detached if none is specified). Equivalent toNd4j.create(int...)
, other than the array location- Parameters:
arrayType
- Array typedataType
- Data type for the created arrayshape
- Shape- Returns:
- Created arary
-
create
INDArray create(T arrayType, DataType dataType, long[] shape, char ordering)
Create an array in the specified array type's workspace (or detached if none is specified). Equivalent toNd4j.create(int[],char)
, other than the array location- Parameters:
arrayType
- Array typedataType
- Data type for the created arrayshape
- Shapeordering
- Order of the array- Returns:
- Created arary
-
createUninitialized
INDArray createUninitialized(T arrayType, DataType dataType, long... shape)
Create an uninitialized array in the specified array type's workspace (or detached if none is specified). Equivalent toorg.nd4j.linalg.factory.Nd4j#createUninitialized(int)
(int...)}, other than the array location- Parameters:
arrayType
- Array typedataType
- Data type of the created arrayshape
- Shape- Returns:
- Created array
-
createUninitialized
INDArray createUninitialized(T arrayType, DataType dataType, long[] shape, char order)
Create an uninitialized array in the specified array type's workspace (or detached if none is specified). Equivalent toNd4j.createUninitialized(int[], char)
}, other than the array location- Parameters:
arrayType
- Array typedataType
- Data type of the returned arrayshape
- Shapeorder
- Order of the array- Returns:
- Created array
-
dup
INDArray dup(@NonNull T arrayType, @NonNull @NonNull INDArray toDup)
Duplicate the array, where the array is put into the specified array type's workspace (if applicable)- Parameters:
arrayType
- Array type for the resulttoDup
- Array to duplicate- Returns:
- Duplicated array in the specified array type's workspace
-
dup
INDArray dup(T arrayType, INDArray toDup, char order)
Duplicate the array, where the array is put into the specified array type's workspace (if applicable)- Parameters:
arrayType
- Array type for the resulttoDup
- Array to duplicateorder
- Order for the duplicated array- Returns:
- Duplicated array in the specified array type's workspace
-
castTo
INDArray castTo(@NonNull T arrayType, @NonNull @NonNull DataType dataType, @NonNull @NonNull INDArray toCast, boolean dupIfCorrectType)
Cast the specified array to the specified datatype.
If the array is already the correct type, the bahaviour depends on the 'dupIfCorrectType' argument.
dupIfCorrectType = false && toCast.dataType() == dataType: return input array as-is (unless workspace is wrong)
dupIfCorrectType = true && toCast.dataType() == dataType: duplicate the array into the specified workspace- Parameters:
arrayType
- Array typedataType
- Data typetoCast
- Array to castdupIfCorrectType
- False: return array as-is if correct type and in the correct workspace. True: dup if already correct type- Returns:
- Cast (or duplicated) array
-
-