public class NDList extends java.util.ArrayList<NDArray> implements NDResource, BytesSupplier
NDList represents a sequence of NDArrays with names.
Each NDArray in this list can optionally have a name. You can use the name to look up
an NDArray in the NDList.
NDArray,
Serialized Form| Constructor and Description |
|---|
NDList()
Constructs an empty NDList.
|
NDList(java.util.Collection<NDArray> other)
Constructs and initiates an NDList with the specified
NDArrays. |
NDList(int initialCapacity)
Constructs an empty NDList with the specified initial capacity.
|
NDList(NDArray... arrays)
Constructs and initiates an NDList with the specified
NDArrays. |
| Modifier and Type | Method and Description |
|---|---|
NDList |
addAll(NDList other)
Appends all of the NDArrays in the specified NDList to the end of this NDList, in the order
that they are returned by the specified NDList's iterator.
|
void |
attach(NDManager manager)
Attaches this
NDResource to the specified NDManager. |
void |
close() |
boolean |
contains(java.lang.String name)
Returns
true if this NDList contains an NDArray with the specified name. |
static NDList |
decode(NDManager manager,
byte[] byteArray)
Decodes NDList from byte array.
|
static NDList |
decode(NDManager manager,
java.io.InputStream is)
Decodes NDList from
InputStream. |
void |
detach()
Detaches the
NDResource from current NDManager's lifecycle. |
byte[] |
encode()
Encodes the NDList to byte array.
|
void |
encode(java.io.OutputStream os)
Writes the encoded NDList to
OutputStream. |
void |
encode(java.io.OutputStream os,
boolean numpy)
Writes the encoded NDList to
OutputStream. |
NDArray |
get(java.lang.String name)
Returns the first occurrence of the specified element from this NDList if it is present.
|
byte[] |
getAsBytes()
Returns the
byte[] presentation of the object. |
NDManager |
getManager()
Returns the
NDManager that manages this. |
Shape[] |
getShapes()
Gets all of shapes in the
NDList. |
NDArray |
head()
Returns the head index of the NDList.
|
NDArray |
remove(java.lang.String name)
Removes the first occurrence of the specified element from this NDList if it is present.
|
NDArray |
singletonOrThrow()
Returns the only element if this is a singleton NDList or throws an exception if multiple
elements.
|
NDList |
subNDList(int fromIndex)
Returns a view of the portion of this NDList between the specified fromIndex, inclusive, and
to the end.
|
void |
tempAttach(NDManager manager)
Temporarily attaches this
NDResource to the specified NDManager. |
java.nio.ByteBuffer |
toByteBuffer()
Returns the
ByteBuffer presentation of the object. |
NDList |
toDevice(Device device,
boolean copy)
|
java.lang.String |
toString() |
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizefinalize, getClass, notify, notifyAll, wait, wait, waitgetAsObject, getAsString, wrap, wrap, wrapAsJsonpublic NDList()
public NDList(int initialCapacity)
initialCapacity - the initial capacity of the listjava.lang.IllegalArgumentException - if the specified initial capacity is negativepublic NDList(NDArray... arrays)
NDArrays.arrays - the NDArrayspublic static NDList decode(NDManager manager, byte[] byteArray)
manager - manager assigned to NDArraybyteArray - byte array to load fromNDListpublic static NDList decode(NDManager manager, java.io.InputStream is)
InputStream.manager - manager assigned to NDArrayis - input stream contains the ndlist informationNDListpublic NDArray get(java.lang.String name)
name - the name of the NDArraypublic NDArray remove(java.lang.String name)
If this list does not contain the element, it is unchanged. More formally, removes the
element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists).
name - the name of the NDArray to be removed from this NDList, if presentpublic boolean contains(java.lang.String name)
true if this NDList contains an NDArray with the specified name.name - the name of the NDArray to be removed from this NDList, if presenttrue if this list contains the specified elementpublic NDArray head()
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index
>= size())public NDArray singletonOrThrow()
java.lang.IndexOutOfBoundsException - if the list does not contain exactly one elementpublic NDList addAll(NDList other)
other - the NDList containing NDArray to be added to this listpublic NDList subNDList(int fromIndex)
fromIndex - the start index (inclusive)public NDManager getManager()
NDManager that manages this.getManager in interface NDResourceNDManager that manages this.public void attach(NDManager manager)
NDResource to the specified NDManager.
Attached resource will be closed when the NDManager is closed.
attach in interface NDResourcemanager - the NDManager to be attached topublic void tempAttach(NDManager manager)
NDResource to the specified NDManager.
Attached resource will be returned to the original manager when the NDManager is
closed.
tempAttach in interface NDResourcemanager - the NDManager to be attached topublic void detach()
NDResource from current NDManager's lifecycle.
This becomes un-managed and it is the user's responsibility to close this. Failure to close the resource might cause your machine to run out of native memory.
detach in interface NDResourceNDManagerpublic byte[] encode()
public void encode(java.io.OutputStream os)
throws java.io.IOException
OutputStream.os - the OutputStream to be written tojava.io.IOException - if failed on IO operationpublic void encode(java.io.OutputStream os,
boolean numpy)
throws java.io.IOException
OutputStream.os - the OutputStream to be written tonumpy - encode in npz format if truejava.io.IOException - if failed on IO operationpublic byte[] getAsBytes()
byte[] presentation of the object.getAsBytes in interface BytesSupplierbyte[] presentation of the objectpublic java.nio.ByteBuffer toByteBuffer()
ByteBuffer presentation of the object.toByteBuffer in interface BytesSupplierByteBuffer presentation of the objectpublic Shape[] getShapes()
NDList.NDListpublic void close()
close in interface NDResourceclose in interface java.lang.AutoCloseablepublic java.lang.String toString()
toString in class java.util.AbstractCollection<NDArray>