Class BaseWorkspaceMgr<T extends Enum<T>>

    • Constructor Detail

      • BaseWorkspaceMgr

        protected BaseWorkspaceMgr()
    • Method Detail

      • setConfiguration

        public void setConfiguration​(@NonNull
                                     T arrayType,
                                     WorkspaceConfiguration configuration)
        Description copied from interface: WorkspaceMgr
        Set the workspace configuration for the specified array type
        Specified by:
        setConfiguration in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Type of array to set the configuration for
        configuration - Configuration for the specified array type
      • getConfiguration

        public WorkspaceConfiguration getConfiguration​(@NonNull
                                                       T arrayType)
        Specified by:
        getConfiguration in interface WorkspaceMgr<T extends Enum<T>>
        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

        public void setScopedOutFor​(@NonNull
                                    T arrayType)
        Description copied from interface: WorkspaceMgr
        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
        Specified by:
        setScopedOutFor in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to set scoped out for
      • isScopedOut

        public boolean isScopedOut​(@NonNull
                                   T arrayType)
        Specified by:
        isScopedOut in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        Returns:
        True if the specified array type is set to be scoped out
      • hasConfiguration

        public boolean hasConfiguration​(@NonNull
                                        T arrayType)
        Description copied from interface: WorkspaceMgr
        Has the specified array type been configured in this workspace manager?
        Specified by:
        hasConfiguration in interface WorkspaceMgr<T extends Enum<T>>
        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

        public MemoryWorkspace notifyScopeEntered​(@NonNull
                                                  T arrayType)
        Specified by:
        notifyScopeEntered in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to enter the scope for
        Returns:
        Workspace for the specified array type
      • notifyScopeEntered

        public WorkspacesCloseable notifyScopeEntered​(@NonNull
                                                      @NonNull T... arrayTypes)
        Description copied from interface: WorkspaceMgr
        Open/enter multiple workspaces. This is equivalent to nested opening of the specified workspaces
        Specified by:
        notifyScopeEntered in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayTypes - Open the specified workspaces
        Returns:
        Closeable for the specified workspaces
      • notifyScopeBorrowed

        public MemoryWorkspace notifyScopeBorrowed​(@NonNull
                                                   T arrayType)
        Description copied from interface: WorkspaceMgr
        Borrow the scope for the specified array type
        Specified by:
        notifyScopeBorrowed in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to borrow the scope for
        Returns:
        Workspace
      • setWorkspaceName

        public void setWorkspaceName​(@NonNull
                                     T arrayType,
                                     @NonNull
                                     @NonNull String name)
        Description copied from interface: WorkspaceMgr
        Set the workspace name for the specified array type
        Specified by:
        setWorkspaceName in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to set the workspace name for
        name - Workspace name to set
      • getWorkspaceName

        public String getWorkspaceName​(@NonNull
                                       T arrayType)
        Specified by:
        getWorkspaceName in interface WorkspaceMgr<T extends Enum<T>>
        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

        public void setWorkspace​(@NonNull
                                 T forEnum,
                                 @NonNull
                                 @NonNull String wsName,
                                 @NonNull
                                 @NonNull WorkspaceConfiguration configuration)
        Description copied from interface: WorkspaceMgr
        Seth the workspace name and configuration for the specified array type
        Specified by:
        setWorkspace in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        forEnum - Array type
        wsName - Workspace name
        configuration - Workspace configuration
      • isWorkspaceOpen

        public boolean isWorkspaceOpen​(@NonNull
                                       T arrayType)
        Description copied from interface: WorkspaceMgr
        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
        Specified by:
        isWorkspaceOpen in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        Returns:
        True if the workspace is open (or array type is set to scoped out)
      • assertOpen

        public void assertOpen​(T arrayType,
                               String msg)
                        throws ND4JWorkspaceException
        Description copied from interface: WorkspaceMgr
        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
        Specified by:
        assertOpen in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to check
        msg - May be null. If non-null: include this in the exception
        Throws:
        ND4JWorkspaceException - If the specified workspace is not open
      • assertNotOpen

        public void assertNotOpen​(@NonNull
                                  T arrayType,
                                  @NonNull
                                  @NonNull String msg)
        Description copied from interface: WorkspaceMgr
        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
        Specified by:
        assertNotOpen in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to check
        msg - May be null. If non-null: include this in the exception
      • assertCurrentWorkspace

        public void assertCurrentWorkspace​(@NonNull
                                           T arrayType,
                                           String msg)
        Description copied from interface: WorkspaceMgr
        Assert that the current workspace is the one for the specified array type. As per WorkspaceMgr.isWorkspaceOpen(Enum) scoped out array types are ignored here.
        Specified by:
        assertCurrentWorkspace in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type to check
        msg - May be null. Message to include in the exception
      • leverageTo

        public INDArray leverageTo​(@NonNull
                                   T arrayType,
                                   @NonNull
                                   @NonNull INDArray array)
        Description copied from interface: WorkspaceMgr
        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
        Specified by:
        leverageTo in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type's workspace to move the array to
        array - Array to leverage
        Returns:
        Leveraged array (if leveraged, or original array otherwise)
      • validateArrayLocation

        public INDArray validateArrayLocation​(@NonNull
                                              T arrayType,
                                              @NonNull
                                              @NonNull INDArray array,
                                              boolean migrateIfInvalid,
                                              boolean exceptionIfDetached)
        Description copied from interface: WorkspaceMgr
        Validate that the specified array type is actually in the workspace it's supposed to be in
        Specified by:
        validateArrayLocation in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type of the array
        array - Array to check
        migrateIfInvalid - if true, and array is in the wrong WS: migrate the array and return. If false and in the wrong WS: exception
        exceptionIfDetached - 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
      • create

        public INDArray create​(@NonNull
                               T arrayType,
                               @NonNull
                               @NonNull DataType dataType,
                               @NonNull
                               @lombok.NonNull long... shape)
        Description copied from interface: WorkspaceMgr
        Create an array in the specified array type's workspace (or detached if none is specified). Equivalent to Nd4j.create(int...), other than the array location
        Specified by:
        create in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        dataType - Data type for the created array
        shape - Shape
        Returns:
        Created arary
      • create

        public INDArray create​(@NonNull
                               T arrayType,
                               @NonNull
                               @NonNull DataType dataType,
                               @NonNull
                               @lombok.NonNull long[] shape,
                               @NonNull
                               @lombok.NonNull char order)
        Description copied from interface: WorkspaceMgr
        Create an array in the specified array type's workspace (or detached if none is specified). Equivalent to Nd4j.create(int[],char), other than the array location
        Specified by:
        create in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        dataType - Data type for the created array
        shape - Shape
        order - Order of the array
        Returns:
        Created arary
      • createUninitialized

        public INDArray createUninitialized​(T arrayType,
                                            DataType dataType,
                                            long... shape)
        Description copied from interface: WorkspaceMgr
        Create an uninitialized array in the specified array type's workspace (or detached if none is specified). Equivalent to org.nd4j.linalg.factory.Nd4j#createUninitialized(int) (int...)}, other than the array location
        Specified by:
        createUninitialized in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        dataType - Data type of the created array
        shape - Shape
        Returns:
        Created array
      • createUninitialized

        public INDArray createUninitialized​(@NonNull
                                            T arrayType,
                                            @NonNull
                                            @NonNull DataType dataType,
                                            @NonNull
                                            @lombok.NonNull long[] shape,
                                            char order)
        Description copied from interface: WorkspaceMgr
        Create an uninitialized array in the specified array type's workspace (or detached if none is specified). Equivalent to Nd4j.createUninitialized(int[], char)}, other than the array location
        Specified by:
        createUninitialized in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        dataType - Data type of the returned array
        shape - Shape
        order - Order of the array
        Returns:
        Created array
      • dup

        public INDArray dup​(@NonNull
                            T arrayType,
                            @NonNull
                            @NonNull INDArray toDup,
                            char order)
        Description copied from interface: WorkspaceMgr
        Duplicate the array, where the array is put into the specified array type's workspace (if applicable)
        Specified by:
        dup in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type for the result
        toDup - Array to duplicate
        order - Order for the duplicated array
        Returns:
        Duplicated array in the specified array type's workspace
      • dup

        public INDArray dup​(@NonNull
                            T arrayType,
                            @NonNull
                            @NonNull INDArray toDup)
        Description copied from interface: WorkspaceMgr
        Duplicate the array, where the array is put into the specified array type's workspace (if applicable)
        Specified by:
        dup in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type for the result
        toDup - Array to duplicate
        Returns:
        Duplicated array in the specified array type's workspace
      • castTo

        public INDArray castTo​(@NonNull
                               T arrayType,
                               @NonNull
                               @NonNull DataType dataType,
                               @NonNull
                               @NonNull INDArray toCast,
                               boolean dupIfCorrectType)
        Description copied from interface: WorkspaceMgr
        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
        Specified by:
        castTo in interface WorkspaceMgr<T extends Enum<T>>
        Parameters:
        arrayType - Array type
        dataType - Data type
        toCast - Array to cast
        dupIfCorrectType - False: return array as-is if correct type and in the correct workspace. True: dup if already correct type
        Returns:
        Cast (or duplicated) array