Class NDList

    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Constructor Description
      NDList()
      Constructs an empty NDList.
      NDList​(int initialCapacity)
      Constructs an empty NDList with the specified initial capacity.
      NDList​(NDArray... arrays)
      Constructs and initiates an NDList with the specified NDArrays.
      NDList​(java.util.Collection<NDArray> other)
      Constructs and initiates an NDList with the specified NDArrays.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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)
      Converts all the NDArray in NDList to a different Device.
      java.lang.String toString()
      • Methods inherited from class java.util.ArrayList

        add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
      • Methods inherited from class java.util.AbstractCollection

        containsAll
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream, toArray
      • Methods inherited from interface java.util.List

        containsAll
    • Constructor Detail

      • NDList

        public NDList()
        Constructs an empty NDList.
      • NDList

        public NDList​(int initialCapacity)
        Constructs an empty NDList with the specified initial capacity.
        Parameters:
        initialCapacity - the initial capacity of the list
        Throws:
        java.lang.IllegalArgumentException - if the specified initial capacity is negative
      • NDList

        public NDList​(NDArray... arrays)
        Constructs and initiates an NDList with the specified NDArrays.
        Parameters:
        arrays - the NDArrays
      • NDList

        public NDList​(java.util.Collection<NDArray> other)
        Constructs and initiates an NDList with the specified NDArrays.
        Parameters:
        other - the NDArrays
    • Method Detail

      • decode

        public static NDList decode​(NDManager manager,
                                    byte[] byteArray)
        Decodes NDList from byte array.
        Parameters:
        manager - manager assigned to NDArray
        byteArray - byte array to load from
        Returns:
        NDList
      • decode

        public static NDList decode​(NDManager manager,
                                    java.io.InputStream is)
        Decodes NDList from InputStream.
        Parameters:
        manager - manager assigned to NDArray
        is - input stream contains the ndlist information
        Returns:
        NDList
      • get

        public NDArray get​(java.lang.String name)
        Returns the first occurrence of the specified element from this NDList if it is present.
        Parameters:
        name - the name of the NDArray
        Returns:
        the first occurrence
      • remove

        public NDArray remove​(java.lang.String name)
        Removes the first occurrence of the specified element from this NDList if it is present.

        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&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))) (if such an element exists).

        Parameters:
        name - the name of the NDArray to be removed from this NDList, if present
        Returns:
        the element that was removed
      • contains

        public boolean contains​(java.lang.String name)
        Returns true if this NDList contains an NDArray with the specified name.
        Parameters:
        name - the name of the NDArray to be removed from this NDList, if present
        Returns:
        true if this list contains the specified element
      • head

        public NDArray head()
        Returns the head index of the NDList.
        Returns:
        the head NDArray
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range (index &lt; 0 || index &gt;= size())
      • singletonOrThrow

        public NDArray singletonOrThrow()
        Returns the only element if this is a singleton NDList or throws an exception if multiple elements.
        Returns:
        the head NDArray
        Throws:
        java.lang.IndexOutOfBoundsException - if the list does not contain exactly one element
      • addAll

        public 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.
        Parameters:
        other - the NDList containing NDArray to be added to this list
        Returns:
        this NDList after the addition
      • subNDList

        public NDList subNDList​(int fromIndex)
        Returns a view of the portion of this NDList between the specified fromIndex, inclusive, and to the end.
        Parameters:
        fromIndex - the start index (inclusive)
        Returns:
        a view of the portion of this NDList
      • toDevice

        public NDList toDevice​(Device device,
                               boolean copy)
        Converts all the NDArray in NDList to a different Device.
        Parameters:
        device - the Device to be set
        copy - set true if you want to return a copy of the underlying NDArray
        Returns:
        a new NDList with the NDArrays on specified Device
      • detach

        public void detach()
        Detaches the 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.

        Specified by:
        detach in interface NDResource
        See Also:
        NDManager
      • encode

        public byte[] encode()
        Encodes the NDList to byte array.
        Returns:
        the byte array
      • encode

        public void encode​(java.io.OutputStream os)
                    throws java.io.IOException
        Writes the encoded NDList to OutputStream.
        Parameters:
        os - the OutputStream to be written to
        Throws:
        java.io.IOException - if failed on IO operation
      • encode

        public void encode​(java.io.OutputStream os,
                           boolean numpy)
                    throws java.io.IOException
        Writes the encoded NDList to OutputStream.
        Parameters:
        os - the OutputStream to be written to
        numpy - encode in npz format if true
        Throws:
        java.io.IOException - if failed on IO operation
      • getAsBytes

        public byte[] getAsBytes()
        Returns the byte[] presentation of the object.
        Specified by:
        getAsBytes in interface BytesSupplier
        Returns:
        the byte[] presentation of the object
      • toByteBuffer

        public java.nio.ByteBuffer toByteBuffer()
        Returns the ByteBuffer presentation of the object.
        Specified by:
        toByteBuffer in interface BytesSupplier
        Returns:
        the ByteBuffer presentation of the object
      • getShapes

        public Shape[] getShapes()
        Gets all of shapes in the NDList.
        Returns:
        shapes in NDList
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface NDResource
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractCollection<NDArray>