def get_batch(X, start=None, stop=None):
"""Like keras.engine.training.slice_X, but supports latent vectors.
Args:
X: Numpy array or list of Numpy arrays.
start: integer, the start of the batch, or a list of integers, the
indices of each sample in to use in this batch.
stop: integer, the end of the batch (only needed if start is an
integer).
Returns:
X[start:stop] if X is array-like, or [x[start:stop] for x in X]
if X is a list. Latent vector functions will be called as appropriate.
"""
if isinstance(X, list):
if hasattr(start, '__len__'):
if hasattr(start, 'shape'):
start = start.tolist()
return [x[start] if is_numpy_array(x)
else x(len(start)) for x in X]
else:
return [x[start:stop] if is_numpy_array(x)
else x(stop - start) for x in X]
else:
if hasattr(start, '__len__'):
if hasattr(start, 'shape'):
start = start.tolist()
return (X[start] if is_numpy_array(X)
else X(len(start)))
else:
return (X[start:stop] if is_numpy_array(X)
else X(stop - start))