Modifier and Type | Class and Description |
---|---|
protected static class |
BaseNDManager.TempResource |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.atomic.AtomicBoolean |
closed |
protected Device |
device |
protected java.lang.String |
name |
protected NDManager |
parent |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.AutoCloseable> |
resources |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,BaseNDManager.TempResource> |
tempResources |
protected java.lang.String |
uid |
Modifier | Constructor and Description |
---|---|
protected |
BaseNDManager(NDManager parent,
Device device) |
Modifier and Type | Method and Description |
---|---|
NDArray |
arange(float start,
float stop,
float step,
DataType dataType)
Returns evenly spaced values within a given interval.
|
void |
attachInternal(java.lang.String resourceId,
java.lang.AutoCloseable resource)
Attaches a resource to this
NDManager . |
void |
close() |
static void |
copyBuffer(java.nio.Buffer src,
java.nio.ByteBuffer target)
Copies data from the source
Buffer to the target ByteBuffer . |
NDArray |
create(Shape shape,
DataType dataType)
|
NDArray |
create(java.lang.String[] data,
java.nio.charset.Charset charset,
Shape shape)
Creates a String
NDArray based on the provided shape. |
NDArray |
createCoo(java.nio.Buffer data,
long[][] indices,
Shape shape)
Creates a Coordinate Format (COO) Matrix.
|
NDArray |
createCSR(java.nio.Buffer data,
long[] indptr,
long[] indices,
Shape shape)
Creates a Compressed Sparse Row Storage (CSR) Format Matrix.
|
NDArray |
createRowSparse(java.nio.Buffer data,
Shape dataShape,
long[] indices,
Shape shape)
Stores the matrix in row sparse format.
|
void |
debugDump(int level)
Prints information about this
NDManager and all sub-managers to the console. |
Device |
defaultDevice()
Returns the default context used in Engine.
|
void |
detachInternal(java.lang.String resourceId)
Detaches a
NDArray from this NDManager 's lifecycle. |
NDArray |
eye(int rows,
int cols,
int k,
DataType dataType)
Returns a 2-D array with ones on the diagonal and zeros elsewhere.
|
NDArray |
full(Shape shape,
float value,
DataType dataType)
Return a new
NDArray of given shape, filled with value. |
protected NDManager |
getAlternativeManager() |
Device |
getDevice()
Returns the default
Device of this NDManager . |
java.lang.String |
getName()
Gets the name of the NDManager.
|
NDManager |
getParentManager()
Returns the parent
NDManager . |
void |
invoke(java.lang.String operation,
NDArray[] src,
NDArray[] dest,
ai.djl.util.PairList<java.lang.String,?> params)
An engine specific generic invocation to native operation.
|
NDList |
invoke(java.lang.String operation,
NDList src,
ai.djl.util.PairList<java.lang.String,?> params)
An engine specific generic invocation to native operation.
|
boolean |
isOpen()
Check if the manager is still valid.
|
NDArray |
linspace(float start,
float stop,
int num,
boolean endpoint)
Returns evenly spaced numbers over a specified interval.
|
NDList |
load(java.nio.file.Path path)
Loads the NDArrays saved to a file.
|
NDManager |
newSubManager()
Creates a child
NDManager . |
NDArray |
ones(Shape shape,
DataType dataType)
|
NDArray |
randomInteger(long low,
long high,
Shape shape,
DataType dataType)
Returns random integer values from low (inclusive) to high (exclusive).
|
NDArray |
randomMultinomial(int n,
NDArray pValues)
Draw samples from a multinomial distribution.
|
NDArray |
randomMultinomial(int n,
NDArray pValues,
Shape shape)
Draw samples from a multinomial distribution.
|
NDArray |
randomNormal(float loc,
float scale,
Shape shape,
DataType dataType)
Draws random samples from a normal (Gaussian) distribution.
|
NDArray |
randomUniform(float low,
float high,
Shape shape,
DataType dataType)
Draws samples from a uniform distribution.
|
void |
setName(java.lang.String name)
Sets the name for the NDManager.
|
void |
tempAttachInternal(NDManager originalManager,
java.lang.String resourceId,
NDResource resource)
Temporarily attaches a resource to this
NDManager to be returned when this is closed. |
java.lang.String |
toString() |
NDArray |
truncatedNormal(float loc,
float scale,
Shape shape,
DataType dataType)
Draws random samples from a normal (Gaussian) distribution, discarding and re-drawing any
samples that are more than two standard deviations from the mean.
|
static void |
validateBufferSize(java.nio.Buffer buffer,
DataType dataType,
int expected)
Checks if the input buffer size is match expected data type.
|
NDArray |
zeros(Shape shape,
DataType dataType)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
allocateDirect, arange, arange, arange, arange, arange, arange, arange, arange, attachAll, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, createCSR, createCSR, createRowSparse, decode, decode, eye, eye, eye, eye, from, full, full, full, getEngine, linspace, linspace, linspace, linspace, load, newBaseManager, newBaseManager, newBaseManager, newSubManager, ones, ones, randomNormal, randomNormal, randomNormal, randomUniform, randomUniform, ret, subManagerOf, tempAttachAll, truncatedNormal, truncatedNormal, truncatedNormal, zeros, zeros
protected NDManager parent
protected java.lang.String uid
protected java.lang.String name
protected Device device
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.AutoCloseable> resources
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,BaseNDManager.TempResource> tempResources
protected java.util.concurrent.atomic.AtomicBoolean closed
public final Device defaultDevice()
The default type is defined by whether the deep learning engine is recognizing GPUs available on your machine. If there is no GPU available, CPU will be used.
defaultDevice
in interface NDManager
Device
public NDArray create(java.lang.String[] data, java.nio.charset.Charset charset, Shape shape)
NDArray
based on the provided shape.public NDArray createCSR(java.nio.Buffer data, long[] indptr, long[] indices, Shape shape)
createCSR
in interface NDManager
data
- the data to set for the CSR Matrixindptr
- the indptr array is what will help identify the rows where the data appearsindices
- the indices array stores the column index for each non-zero element in datashape
- the Shape
of the NDArray
NDArray
public NDArray createRowSparse(java.nio.Buffer data, Shape dataShape, long[] indices, Shape shape)
public NDArray createCoo(java.nio.Buffer data, long[][] indices, Shape shape)
public NDList load(java.nio.file.Path path)
public void setName(java.lang.String name)
public java.lang.String getName()
public NDArray full(Shape shape, float value, DataType dataType)
NDArray
of given shape, filled with value.public NDArray arange(float start, float stop, float step, DataType dataType)
Values are generated within the half-open interval [start, stop) (in other words, the
interval including start but excluding stop). For integer arguments, the function is
equivalent to the Python built-in range function, but returns an instance of NDArray
rather than a list.
public NDArray eye(int rows, int cols, int k, DataType dataType)
eye
in interface NDManager
rows
- the number of rows int the outputcols
- the number of columns in the outputk
- the index of the diagonal: a positive value refers to an upper diagonal, and a
negative value to a lower diagonaldataType
- the DataType
of the NDArray
NDArray
where all elements are equal to zero, except for the k-th diagonal,
whose values are equal to onepublic NDArray linspace(float start, float stop, int num, boolean endpoint)
Returns num evenly spaced samples, calculated over the interval [start, stop].The endpoint of the interval can optionally be excluded.
public NDArray randomInteger(long low, long high, Shape shape, DataType dataType)
randomInteger
in interface NDManager
low
- Lowest (signed) longs to be drawn from the distributionhigh
- one above the largest (signed) long to be drawn from the distributionshape
- the Shape
of the NDArray
dataType
- the DataType
of the NDArray
NDArray
public NDArray randomUniform(float low, float high, Shape shape, DataType dataType)
Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.
randomUniform
in interface NDManager
low
- the lower boundary of the output interval. All values generated will be greater
than or equal to low.high
- the upper boundary of the output interval. All values generated will be less than
high.shape
- the Shape
of the NDArray
dataType
- the DataType
of the NDArray
NDArray
public NDArray randomNormal(float loc, float scale, Shape shape, DataType dataType)
public NDArray truncatedNormal(float loc, float scale, Shape shape, DataType dataType)
public NDArray randomMultinomial(int n, NDArray pValues)
The multinomial distribution is a multivariate generalization of the binomial distribution. Take an experiment with one of p possible outcomes. An example of such an experiment is throwing a dice, where the outcome can be 1 through 6. Each sample drawn from the distribution represents n such experiments. Its values, X_i = [X_0, X_1, ..., X_p], represent the number of times the outcome was i.
randomMultinomial
in interface NDManager
n
- the number of experimentspValues
- the probabilities of each of the p different outcomes. These should sum to 1
The last element is always assumed to account for the remaining probability, as long as
pValues.sum().getFloat() <= 1)NDArray
public NDArray randomMultinomial(int n, NDArray pValues, Shape shape)
The multinomial distribution is a multivariate generalization of the binomial distribution. Take an experiment with one of p possible outcomes. An example of such an experiment is throwing a dice, where the outcome can be 1 through 6. Each sample drawn from the distribution represents n such experiments. Its values, X_i = [X_0, X_1, ..., X_p], represent the number of times the outcome was i.
randomMultinomial
in interface NDManager
n
- the number of experimentspValues
- the probabilities of each of the p different outcomes. These should sum to 1
The last element is always assumed to account for the remaining probability, as long as
pValues.sum().getFloat() <= 1)shape
- the output Shape
NDArray
public boolean isOpen()
public NDManager getParentManager()
NDManager
.getParentManager
in interface NDManager
NDManager
public NDManager newSubManager()
NDManager
.
Child NDManager
will inherit default Device
from this NDManager
.
newSubManager
in interface NDManager
NDManager
public java.lang.String toString()
toString
in class java.lang.Object
public void attachInternal(java.lang.String resourceId, java.lang.AutoCloseable resource)
NDManager
.
The attached resource will be closed when this NDManager
is closed.
This attachment is internal. Many resources will internally track which manager they are
attached to. In that case, you should call NDResource.attach(NDManager)
instead and
that should then call attachInternal.
attachInternal
in interface NDManager
resourceId
- the unique resourceIdresource
- the AutoCloseable
resource to be attachedpublic void tempAttachInternal(NDManager originalManager, java.lang.String resourceId, NDResource resource)
NDManager
to be returned when this is closed.
The attached resource will be returned to it's original manager when this NDManager
is closed.
This attachment is internal. Many resources will internally track which manager they are
attached to. In that case, you should call NDResource.attach(NDManager)
instead and
that should then call tempAttachInternal.
tempAttachInternal
in interface NDManager
originalManager
- the original manager to return the resource toresourceId
- the unique resourceIdresource
- the AutoCloseable
resource to be attachedpublic void detachInternal(java.lang.String resourceId)
NDArray
from this NDManager
's lifecycle.
The detached NDArray
become un-managed, it's user's responsibility to close the
resource. Failed to close the resource has to wait on GC to be freed, and might cause out of
native memory.
This detach is internal. Many resources will internally track which manager they are
attached to. In that case, you should call NDResource.detach()
instead and that
should then call detachInternal.
detachInternal
in interface NDManager
resourceId
- the resourceId to be removed from this NDManager
's lifecyclepublic void invoke(java.lang.String operation, NDArray[] src, NDArray[] dest, ai.djl.util.PairList<java.lang.String,?> params)
You should avoid using this function if possible. Since this function is engine specific, using this API may cause a portability issue. Native operation may not be compatible between each version.
public NDList invoke(java.lang.String operation, NDList src, ai.djl.util.PairList<java.lang.String,?> params)
You should avoid using this function if possible. Since this function is engine specific, using this API may cause a portability issue. Native operation may not compatible between each version.
public void close()
public void debugDump(int level)
NDManager
and all sub-managers to the console.level
- the level of this NDManager
in the hierarchyprotected NDManager getAlternativeManager()
public static void validateBufferSize(java.nio.Buffer buffer, DataType dataType, int expected)
buffer
- the input bufferdataType
- the desired DataType
expected
- the expected sizejava.lang.IllegalArgumentException
- if buffer size is invalidpublic static void copyBuffer(java.nio.Buffer src, java.nio.ByteBuffer target)
Buffer
to the target ByteBuffer
.src
- the source Buffer
target
- the target ByteBuffer