jacinle.nd.batch#
Functions
|
Recursively combine a list of inputs into a batch. |
|
Recursively split a batch into a list of inputs. |
Functions
- batchify(inputs)[source]#
Recursively combine a list of inputs into a batch. This function handles tuples, lists, dicts, and numpy arrays.
Examples
>>> batchify([np.array([1, 2, 3]), np.array([4, 5, 6])]) array([[1, 2, 3], [4, 5, 6]]) >>> batchify([ ... {'a': np.array([1, 2, 3]), 'b': np.array([4, 5, 6])}, ... {'a': np.array([7, 8, 9]), 'b': np.array([10, 11, 12])}, ... ]) {'a': array([[1, 2, 3], [7, 8, 9]]), 'b': array([[ 4, 5, 6], [10, 11, 12]])}
- unbatchify(inputs)[source]#
Recursively split a batch into a list of inputs. This function handles tuples, lists, dicts, and numpy arrays. This function is the inverse of
batchify()
.Example
>>> unbatchify(np.array([[1, 2, 3], [4, 5, 6]])) [array([1, 2, 3]), array([4, 5, 6])] >>> unbatchify({'a': np.array([[1, 2, 3], [4, 5, 6]]), 'b': np.array([[7, 8, 9], [10, 11, 12]])}) [{'a': array([1, 2, 3]), 'b': array([7, 8, 9])}, {'a': array([4, 5, 6]), 'b': array([10, 11, 12])}]