Package org.nd4j.linalg.dataset
Class AsyncMultiDataSetIterator
- java.lang.Object
-
- org.nd4j.linalg.dataset.AsyncMultiDataSetIterator
-
- All Implemented Interfaces:
Serializable,Iterator<MultiDataSet>,MultiDataSetIterator
public class AsyncMultiDataSetIterator extends Object implements MultiDataSetIterator
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAsyncMultiDataSetIterator.AsyncPrefetchThread
-
Field Summary
Fields Modifier and Type Field Description protected MultiDataSetIteratorbackedIteratorprotected BlockingQueue<MultiDataSet>bufferprotected DataSetCallbackcallbackprotected IntegerdeviceIdprotected AtomicBooleanhasDepletedprotected MultiDataSetnextElementprotected intprefetchSizeprotected AtomicBooleanshouldWorkprotected MultiDataSetterminatorprotected AsyncMultiDataSetIterator.AsyncPrefetchThreadthreadprotected RuntimeExceptionthrowableprotected booleanuseWorkspacesprotected StringworkspaceId
-
Constructor Summary
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanasyncSupported()Does this DataSetIterator support asynchronous prefetching of multiple DataSet objects? Most DataSetIterators do, but in some cases it may not make sense to wrap this iterator in an iterator that does asynchronous prefetching.protected voidexternalCall()MultiDataSetPreProcessorgetPreProcessor()Get theMultiDataSetPreProcessor, if one has previously been set.booleanhasNext()Returnstrueif the iteration has more elements.MultiDataSetnext()Returns the next element in the iteration.MultiDataSetnext(int num)Like the standard next method but allows a customizable number of examples returnedvoidremove()Removes from the underlying collection the last element returned by this iterator (optional operation).voidreset()Resets the iterator back to the beginningbooleanresetSupported()Is resetting supported by this DataSetIterator? Many DataSetIterators do support resetting, but some don'tvoidsetPreProcessor(MultiDataSetPreProcessor preProcessor)Set the preprocessor to be applied to each MultiDataSet, before each MultiDataSet is returned.voidshutdown()This method will terminate background thread AND will destroy attached workspace (if any) PLEASE NOTE: After shutdown() call, this instance can't be used anymore-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
backedIterator
protected MultiDataSetIterator backedIterator
-
terminator
protected MultiDataSet terminator
-
nextElement
protected MultiDataSet nextElement
-
buffer
protected BlockingQueue<MultiDataSet> buffer
-
thread
protected AsyncMultiDataSetIterator.AsyncPrefetchThread thread
-
shouldWork
protected AtomicBoolean shouldWork
-
throwable
protected volatile RuntimeException throwable
-
useWorkspaces
protected boolean useWorkspaces
-
prefetchSize
protected int prefetchSize
-
workspaceId
protected String workspaceId
-
callback
protected DataSetCallback callback
-
deviceId
protected Integer deviceId
-
hasDepleted
protected AtomicBoolean hasDepleted
-
-
Constructor Detail
-
AsyncMultiDataSetIterator
protected AsyncMultiDataSetIterator()
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator baseIterator)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator iterator, int queueSize, BlockingQueue<MultiDataSet> queue)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator baseIterator, int queueSize)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator baseIterator, int queueSize, boolean useWorkspace)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator baseIterator, int queueSize, boolean useWorkspace, Integer deviceId)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator iterator, int queueSize, BlockingQueue<MultiDataSet> queue, boolean useWorkspace)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator iterator, int queueSize, BlockingQueue<MultiDataSet> queue, boolean useWorkspace, DataSetCallback callback)
-
AsyncMultiDataSetIterator
public AsyncMultiDataSetIterator(MultiDataSetIterator iterator, int queueSize, BlockingQueue<MultiDataSet> queue, boolean useWorkspace, DataSetCallback callback, Integer deviceId)
-
-
Method Detail
-
next
public MultiDataSet next(int num)
Like the standard next method but allows a customizable number of examples returned- Specified by:
nextin interfaceMultiDataSetIterator- Parameters:
num- the number of examples- Returns:
- the next data applyTransformToDestination
-
setPreProcessor
public void setPreProcessor(MultiDataSetPreProcessor preProcessor)
Set the preprocessor to be applied to each MultiDataSet, before each MultiDataSet is returned.- Specified by:
setPreProcessorin interfaceMultiDataSetIterator- Parameters:
preProcessor- MultiDataSetPreProcessor. May be null.
-
getPreProcessor
public MultiDataSetPreProcessor getPreProcessor()
Description copied from interface:MultiDataSetIteratorGet theMultiDataSetPreProcessor, if one has previously been set. Returns null if no preprocessor has been set- Specified by:
getPreProcessorin interfaceMultiDataSetIterator- Returns:
- Preprocessor
-
resetSupported
public boolean resetSupported()
Is resetting supported by this DataSetIterator? Many DataSetIterators do support resetting, but some don't- Specified by:
resetSupportedin interfaceMultiDataSetIterator- Returns:
- true if reset method is supported; false otherwise
-
asyncSupported
public boolean asyncSupported()
Does this DataSetIterator support asynchronous prefetching of multiple DataSet objects? Most DataSetIterators do, but in some cases it may not make sense to wrap this iterator in an iterator that does asynchronous prefetching. For example, it would not make sense to use asynchronous prefetching for the following types of iterators: (a) Iterators that store their full contents in memory already (b) Iterators that re-use features/labels arrays (as future next() calls will overwrite past contents) (c) Iterators that already implement some level of asynchronous prefetching (d) Iterators that may return different data depending on when the next() method is called- Specified by:
asyncSupportedin interfaceMultiDataSetIterator- Returns:
- true if asynchronous prefetching from this iterator is OK; false if asynchronous prefetching should not be used with this iterator
-
reset
public void reset()
Resets the iterator back to the beginning- Specified by:
resetin interfaceMultiDataSetIterator
-
shutdown
public void shutdown()
This method will terminate background thread AND will destroy attached workspace (if any) PLEASE NOTE: After shutdown() call, this instance can't be used anymore
-
hasNext
public boolean hasNext()
Returnstrueif the iteration has more elements. (In other words, returnstrueifnext(int)would return an element rather than throwing an exception.)- Specified by:
hasNextin interfaceIterator<MultiDataSet>- Returns:
trueif the iteration has more elements
-
next
public MultiDataSet next()
Returns the next element in the iteration.- Specified by:
nextin interfaceIterator<MultiDataSet>- Returns:
- the next element in the iteration
-
remove
public void remove()
Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call tonext(int). The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.- Specified by:
removein interfaceIterator<MultiDataSet>- Throws:
UnsupportedOperationException- if theremoveoperation is not supported by this iteratorIllegalStateException- if thenextmethod has not yet been called, or theremovemethod has already been called after the last call to thenextmethod
-
externalCall
protected void externalCall()
-
-