Class BaseNDManager
- All Implemented Interfaces:
- NDManager,- AutoCloseable
BaseNDManager is the default implementation of NDManager.- 
Nested Class SummaryNested ClassesNested classes/interfaces inherited from interface ai.djl.ndarray.NDManagerNDManager.SystemNDManager
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected NDManagerprotected AtomicBooleanprotected AtomicBooleanprotected Deviceprotected Stringprotected NDManagerprotected ConcurrentHashMap<String,AutoCloseable> protected ConcurrentHashMap<String,BaseNDManager.TempResource> protected String
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionReturns evenly spaced values within a given interval.voidattachInternal(String resourceId, AutoCloseable... resources) Attaches a resource to thisNDManager.voidattachUncappedInternal(String resourceId, AutoCloseable resource) Attaches a resource to thisNDManagercircumventing any cap protection.voidcap()Caps this manager to prevent unintentional attachment of resources.voidclose()static voidcopyBuffer(Buffer src, ByteBuffer target) Copies data from the sourceBufferto the targetByteBuffer.Creates a StringNDArraybased on the provided shape.Creates a Coordinate Format (COO) Matrix.Creates a Compressed Sparse Row Storage (CSR) Format Matrix.createRowSparse(Buffer data, Shape dataShape, long[] indices, Shape shape) Stores the matrix in row sparse format.voiddebugDump(int level) Prints information about thisNDManagerand all sub-managers to the console.final DeviceReturns the default context used in Engine.voiddetachInternal(String resourceId) Detaches aNDArrayfrom thisNDManager's lifecycle.Returns a 2-D array with ones on the diagonal and zeros elsewhere.Return a newNDArrayof given shape, filled with value.Returns the defaultDeviceof thisNDManager.Returns allNDArrays managed by this manager (including recursively).getName()Gets the name of the NDManager.Returns the parentNDManager.voidAn engine specific generic invocation to native operation.An engine specific generic invocation to native operation.booleanisOpen()Check if the manager is still valid.linspace(float start, float stop, int num, boolean endpoint) Returns evenly spaced numbers over a specified interval.Loads the NDArrays saved to a file.Creates a childNDManager.randomInteger(long low, long high, Shape shape, DataType dataType) Returns random integer values from low (inclusive) to high (exclusive).randomMultinomial(int n, NDArray pValues) Draw samples from a multinomial distribution.randomMultinomial(int n, NDArray pValues, Shape shape) Draw samples from a multinomial distribution.randomNormal(float loc, float scale, Shape shape, DataType dataType) Draws random samples from a normal (Gaussian) distribution.randomPermutation(long n) Returns a random permutation of integers from 0 to n - 1.randomUniform(float low, float high, Shape shape, DataType dataType) Draws samples from a uniform distribution.sampleGamma(NDArray alpha, NDArray beta) Draw random samples from a gamma distribution.sampleGamma(NDArray alpha, NDArray beta, Shape shape) Draw random samples from a gamma distribution.sampleNormal(NDArray mu, NDArray sigma) Concurrent sampling from multiple normal distributions with parameters *mu* (mean) and *sigma* (standard deviation).sampleNormal(NDArray mu, NDArray sigma, Shape shape) Concurrent sampling from multiple normal distributions with parameters *mu* (mean) and *sigma* (standard deviation).samplePoisson(NDArray lam) Draw random samples from a Poisson distribution.samplePoisson(NDArray lam, Shape shape) Draw random samples from a Poisson distribution.voidSets the name for the NDManager.voidtempAttachInternal(NDManager originalManager, String resourceId, NDResource resource) Temporarily attaches a resource to thisNDManagerto be returned when this is closed.toString()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 voidvalidateBuffer(Buffer buffer, DataType dataType, int expected) Checks if the input buffer size is match expected data type.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ai.djl.ndarray.NDManagerallocateDirect, 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, hanningWindow, linspace, linspace, linspace, linspace, load, newSubManager, ones, ones, ones, randomNormal, randomNormal, randomNormal, randomUniform, randomUniform, ret, tempAttachAll, truncatedNormal, truncatedNormal, truncatedNormal, zeros, zeros, zeros
- 
Field Details- 
parent
- 
alternativeManager
- 
uid
- 
name
- 
device
- 
resources
- 
tempResources
- 
closed
- 
capped
 
- 
- 
Constructor Details- 
BaseNDManager
 
- 
- 
Method Details- 
defaultDeviceReturns the default context used in Engine.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. - Specified by:
- defaultDevicein interface- NDManager
- Returns:
- a Device
 
- 
createCreates a StringNDArraybased on the provided shape.
- 
create
- 
createCSRCreates a Compressed Sparse Row Storage (CSR) Format Matrix.- Specified by:
- createCSRin interface- NDManager
- Parameters:
- data- the data to set for the CSR Matrix
- indptr- the indptr array is what will help identify the rows where the data appears
- indices- the indices array stores the column index for each non-zero element in data
- shape- the- Shapeof the- NDArray
- Returns:
- a new instance of NDArray
 
- 
createRowSparseStores the matrix in row sparse format.
- 
createCooCreates a Coordinate Format (COO) Matrix.
- 
loadLoads the NDArrays saved to a file.
- 
setNameSets the name for the NDManager.
- 
getNameGets the name of the NDManager.
- 
fullReturn a newNDArrayof given shape, filled with value.
- 
arangeReturns evenly spaced values within a given interval.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 NDArrayrather than a list.
- 
eyeReturns a 2-D array with ones on the diagonal and zeros elsewhere.- Specified by:
- eyein interface- NDManager
- Parameters:
- rows- the number of rows int the output
- cols- the number of columns in the output
- k- the index of the diagonal: a positive value refers to an upper diagonal, and a negative value to a lower diagonal
- dataType- the- DataTypeof the- NDArray
- Returns:
- a NDArraywhere all elements are equal to zero, except for the k-th diagonal, whose values are equal to one
 
- 
linspaceReturns evenly spaced numbers over a specified interval.Returns num evenly spaced samples, calculated over the interval [start, stop].The endpoint of the interval can optionally be excluded. 
- 
randomIntegerReturns random integer values from low (inclusive) to high (exclusive).- Specified by:
- randomIntegerin interface- NDManager
- Parameters:
- low- Lowest (signed) longs to be drawn from the distribution
- high- one above the largest (signed) long to be drawn from the distribution
- shape- the- Shapeof the- NDArray
- dataType- the- DataTypeof the- NDArray
- Returns:
- the drawn samples NDArray
 
- 
randomPermutationReturns a random permutation of integers from 0 to n - 1.- Specified by:
- randomPermutationin interface- NDManager
- Parameters:
- n- (int) – the upper bound (exclusive)
- Returns:
- a random permutation of integers from 0 to n - 1.
 
- 
randomUniformDraws samples from a uniform distribution.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. - Specified by:
- randomUniformin interface- NDManager
- Parameters:
- 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- Shapeof the- NDArray
- dataType- the- DataTypeof the- NDArray
- Returns:
- the drawn samples NDArray
 
- 
randomNormalDraws random samples from a normal (Gaussian) distribution.
- 
truncatedNormalDraws random samples from a normal (Gaussian) distribution, discarding and re-drawing any samples that are more than two standard deviations from the mean.
- 
randomMultinomialDraw samples from a multinomial distribution.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. - Specified by:
- randomMultinomialin interface- NDManager
- Parameters:
- n- the number of experiments
- pValues- 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)
- Returns:
- the drawn samples NDArray
 
- 
randomMultinomialDraw samples from a multinomial distribution.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. - Specified by:
- randomMultinomialin interface- NDManager
- Parameters:
- n- the number of experiments
- pValues- 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
- Returns:
- the drawn samples NDArray
 
- 
sampleNormalConcurrent sampling from multiple normal distributions with parameters *mu* (mean) and *sigma* (standard deviation).- Specified by:
- sampleNormalin interface- NDManager
- Parameters:
- mu- Means of the distributions
- sigma- Standard deviations of the distributions
- Returns:
- the drawn samples NDArray
 
- 
sampleNormalConcurrent sampling from multiple normal distributions with parameters *mu* (mean) and *sigma* (standard deviation).- Specified by:
- sampleNormalin interface- NDManager
- Parameters:
- mu- Means of the distributions
- sigma- Standard deviations of the distributions
- shape- Shape to be sampled from each random distribution
- Returns:
- the drawn samples NDArray
 
- 
samplePoissonDraw random samples from a Poisson distribution.Samples are distributed according to a Poisson distribution parametrized by *lambda* (rate). Samples will always be returned as a floating point data type. - Specified by:
- samplePoissonin interface- NDManager
- Parameters:
- lam- Lambda (rate) parameters of the distributions
- Returns:
- the drawn samples NDArray
 
- 
samplePoissonDraw random samples from a Poisson distribution.Samples are distributed according to a Poisson distribution parametrized by *lambda* (rate). Samples will always be returned as a floating point data type. - Specified by:
- samplePoissonin interface- NDManager
- Parameters:
- lam- Lambda (rate) parameters of the distributions
- shape- Shape to be sampled from each random distribution
- Returns:
- the drawn samples NDArray
 
- 
sampleGammaDraw random samples from a gamma distribution.Samples are distributed according to a gamma distribution parametrized by *alpha* (shape) and *beta* (scale). - Specified by:
- sampleGammain interface- NDManager
- Parameters:
- alpha- The shape of the gamma distribution
- beta- The scale of the gamma distribution
- Returns:
- the drawn samples NDArray
 
- 
sampleGammaDraw random samples from a gamma distribution.Samples are distributed according to a gamma distribution parametrized by *alpha* (shape) and *beta* (scale). - Specified by:
- sampleGammain interface- NDManager
- Parameters:
- alpha- The shape of the gamma distribution
- beta- The scale of the gamma distribution
- shape- Shape to be sampled from each random distribution
- Returns:
- the drawn samples NDArray
 
- 
isOpenpublic boolean isOpen()Check if the manager is still valid.
- 
cappublic void cap()Caps this manager to prevent unintentional attachment of resources. This is useful to detect memory leaks at an early point in time. The attachment of sub managers is still allowed after this method has been called.
- 
getParentManagerReturns the parentNDManager.- Specified by:
- getParentManagerin interface- NDManager
- Returns:
- the parent NDManager
 
- 
newSubManagerCreates a childNDManager.Child NDManagerwill inherit defaultDevicefrom thisNDManager.- Specified by:
- newSubManagerin interface- NDManager
- Returns:
- a child NDManager
 
- 
getDeviceReturns the defaultDeviceof thisNDManager.
- 
getManagedArraysReturns allNDArrays managed by this manager (including recursively).- Specified by:
- getManagedArraysin interface- NDManager
- Returns:
- all NDArrays managed by this manager (including recursively)
 
- 
toString
- 
attachInternalAttaches a resource to thisNDManager.The attached resource will be closed when this NDManageris 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.- Specified by:
- attachInternalin interface- NDManager
- Parameters:
- resourceId- the unique resourceId
- resources- the- AutoCloseableresource to be attached
 
- 
attachUncappedInternalAttaches a resource to thisNDManagercircumventing any cap protection.The attached resource will be closed when this NDManageris 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.- Specified by:
- attachUncappedInternalin interface- NDManager
- Parameters:
- resourceId- the unique resourceId
- resource- the- AutoCloseableresource to be attached
 
- 
tempAttachInternalTemporarily attaches a resource to thisNDManagerto be returned when this is closed.The attached resource will be returned to it's original manager when this NDManageris 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.- Specified by:
- tempAttachInternalin interface- NDManager
- Parameters:
- originalManager- the original manager to return the resource to
- resourceId- the unique resourceId
- resource- the- AutoCloseableresource to be attached
 
- 
detachInternalDetaches aNDArrayfrom thisNDManager's lifecycle.The detached NDArraybecome 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.- Specified by:
- detachInternalin interface- NDManager
- Parameters:
- resourceId- the resourceId to be removed from this- NDManager's lifecycle
 
- 
invokepublic void invoke(String operation, NDArray[] src, NDArray[] dest, ai.djl.util.PairList<String, ?> params) An engine specific generic invocation to native operation.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. 
- 
invokeAn engine specific generic invocation to native operation.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. 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- NDManager
 
- 
debugDumppublic void debugDump(int level) Prints information about thisNDManagerand all sub-managers to the console.- Parameters:
- level- the level of this- NDManagerin the hierarchy
 
- 
validateBufferChecks if the input buffer size is match expected data type.- Parameters:
- buffer- the input buffer
- dataType- the desired- DataType
- expected- the expected size
- Throws:
- IllegalArgumentException- if buffer size is invalid
 
- 
copyBufferCopies data from the sourceBufferto the targetByteBuffer.- Parameters:
- src- the source- Buffer
- target- the target- ByteBuffer
 
 
-