T
- Array typepublic abstract class BaseWorkspaceMgr<T extends Enum<T>> extends Object implements WorkspaceMgr<T>
WorkspaceMgr
implementationModifier and Type | Field and Description |
---|---|
protected Map<T,WorkspaceConfiguration> |
configMap |
protected Set<T> |
scopeOutOfWs |
protected Map<T,String> |
workspaceNames |
Modifier | Constructor and Description |
---|---|
protected |
BaseWorkspaceMgr() |
protected |
BaseWorkspaceMgr(Set<T> scopeOutOfWs,
Map<T,WorkspaceConfiguration> configMap,
Map<T,String> workspaceNames) |
Modifier and Type | Method and Description |
---|---|
void |
assertCurrentWorkspace(T arrayType,
String msg)
Assert that the current workspace is the one for the specified array type.
|
void |
assertNotOpen(T arrayType,
@NonNull 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 workspace |
INDArray |
create(T arrayType,
@NonNull DataType dataType,
long... shape)
Create an array in the specified array type's workspace (or detached if none is specified).
|
INDArray |
create(T arrayType,
@NonNull DataType dataType,
@NonNull long[] shape,
@NonNull char order)
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,
@NonNull DataType dataType,
@NonNull 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,
@NonNull 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 arrayType,
@NonNull 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 type
|
WorkspacesCloseable |
notifyScopeEntered(T... arrayTypes)
Open/enter multiple workspaces.
|
MemoryWorkspace |
notifyScopeEntered(T arrayType) |
void |
setConfiguration(T arrayType,
WorkspaceConfiguration configuration)
Set the workspace configuration for the specified array type
|
void |
setScopedOutFor(T arrayType)
Set arrays to be scoped out (not in any workspace) for the specified array type.
|
void |
setWorkspace(T forEnum,
@NonNull String wsName,
@NonNull WorkspaceConfiguration configuration)
Seth the workspace name and configuration for the specified array type
|
void |
setWorkspaceName(T arrayType,
@NonNull String name)
Set the workspace name for the specified array type
|
INDArray |
validateArrayLocation(T arrayType,
@NonNull INDArray array,
boolean migrateIfInvalid,
boolean exceptionIfDetached)
Validate that the specified array type is actually in the workspace it's supposed to be in
|
protected final Map<T extends Enum<T>,WorkspaceConfiguration> configMap
protected BaseWorkspaceMgr(Set<T> scopeOutOfWs, Map<T,WorkspaceConfiguration> configMap, Map<T,String> workspaceNames)
protected BaseWorkspaceMgr()
public void setConfiguration(@NonNull T arrayType, WorkspaceConfiguration configuration)
WorkspaceMgr
setConfiguration
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Type of array to set the configuration forconfiguration
- Configuration for the specified array typepublic WorkspaceConfiguration getConfiguration(@NonNull T arrayType)
getConfiguration
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to get the workspace configuration forpublic void setScopedOutFor(@NonNull T arrayType)
WorkspaceMgr
setScopedOutFor
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to set scoped out forpublic boolean isScopedOut(@NonNull T arrayType)
isScopedOut
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array typepublic boolean hasConfiguration(@NonNull T arrayType)
WorkspaceMgr
hasConfiguration
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to checkpublic MemoryWorkspace notifyScopeEntered(@NonNull T arrayType)
notifyScopeEntered
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to enter the scope forpublic WorkspacesCloseable notifyScopeEntered(@NonNull T... arrayTypes)
WorkspaceMgr
notifyScopeEntered
in interface WorkspaceMgr<T extends Enum<T>>
arrayTypes
- Open the specified workspacespublic MemoryWorkspace notifyScopeBorrowed(@NonNull T arrayType)
WorkspaceMgr
notifyScopeBorrowed
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to borrow the scope forpublic void setWorkspaceName(@NonNull T arrayType, @NonNull @NonNull String name)
WorkspaceMgr
setWorkspaceName
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to set the workspace name forname
- Workspace name to setpublic String getWorkspaceName(@NonNull T arrayType)
getWorkspaceName
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to get the workspace name for (if set)public void setWorkspace(@NonNull T forEnum, @NonNull @NonNull String wsName, @NonNull @NonNull WorkspaceConfiguration configuration)
WorkspaceMgr
setWorkspace
in interface WorkspaceMgr<T extends Enum<T>>
forEnum
- Array typewsName
- Workspace nameconfiguration
- Workspace configurationpublic boolean isWorkspaceOpen(@NonNull T arrayType)
WorkspaceMgr
isWorkspaceOpen
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array typepublic void assertOpen(T arrayType, String msg) throws ND4JWorkspaceException
WorkspaceMgr
assertOpen
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to checkmsg
- May be null. If non-null: include this in the exceptionND4JWorkspaceException
- If the specified workspace is not openpublic void assertNotOpen(@NonNull T arrayType, @NonNull @NonNull String msg)
WorkspaceMgr
assertNotOpen
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to checkmsg
- May be null. If non-null: include this in the exceptionpublic void assertCurrentWorkspace(@NonNull T arrayType, String msg)
WorkspaceMgr
WorkspaceMgr.isWorkspaceOpen(Enum)
scoped out array types are ignored here.assertCurrentWorkspace
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type to checkmsg
- May be null. Message to include in the exceptionpublic INDArray leverageTo(@NonNull T arrayType, @NonNull @NonNull INDArray array)
WorkspaceMgr
leverageTo
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type's workspace to move the array toarray
- Array to leveragepublic INDArray validateArrayLocation(@NonNull T arrayType, @NonNull @NonNull INDArray array, boolean migrateIfInvalid, boolean exceptionIfDetached)
WorkspaceMgr
validateArrayLocation
in interface WorkspaceMgr<T extends Enum<T>>
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?public INDArray create(@NonNull T arrayType, @NonNull @NonNull DataType dataType, @NonNull long... shape)
WorkspaceMgr
Nd4j.create(int...)
, other than the array locationcreate
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array typedataType
- Data type for the created arrayshape
- Shapepublic INDArray create(@NonNull T arrayType, @NonNull @NonNull DataType dataType, @NonNull @NonNull long[] shape, @NonNull @NonNull char order)
WorkspaceMgr
Nd4j.create(int[],char)
, other than the array locationcreate
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array typedataType
- Data type for the created arrayshape
- Shapeorder
- Order of the arraypublic INDArray createUninitialized(T arrayType, DataType dataType, long... shape)
WorkspaceMgr
org.nd4j.linalg.factory.Nd4j#createUninitialized(int)
(int...)}, other than the array locationcreateUninitialized
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array typedataType
- Data type of the created arrayshape
- Shapepublic INDArray createUninitialized(@NonNull T arrayType, @NonNull @NonNull DataType dataType, @NonNull @NonNull long[] shape, char order)
WorkspaceMgr
Nd4j.createUninitialized(int[], char)
}, other than the array locationcreateUninitialized
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array typedataType
- Data type of the returned arrayshape
- Shapeorder
- Order of the arraypublic INDArray dup(@NonNull T arrayType, @NonNull @NonNull INDArray toDup, char order)
WorkspaceMgr
dup
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type for the resulttoDup
- Array to duplicateorder
- Order for the duplicated arraypublic INDArray dup(@NonNull T arrayType, @NonNull @NonNull INDArray toDup)
WorkspaceMgr
dup
in interface WorkspaceMgr<T extends Enum<T>>
arrayType
- Array type for the resulttoDup
- Array to duplicatepublic INDArray castTo(@NonNull T arrayType, @NonNull @NonNull DataType dataType, @NonNull @NonNull INDArray toCast, boolean dupIfCorrectType)
WorkspaceMgr
castTo
in interface WorkspaceMgr<T extends Enum<T>>
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 typeCopyright © 2020. All rights reserved.