Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tfjs-data/src/readers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ export function func<T extends TensorContainer>(
*
* @param generator A JavaScript function that returns
* a (potentially async) JavaScript iterator.
* @param size The total number of elements the generator
* is expected to return.
*
* @doc {
* heading: 'Data',
Expand All @@ -198,11 +200,12 @@ export function func<T extends TensorContainer>(
*/
export function generator<T extends TensorContainer>(
generator: () => Iterator<T> | Promise<Iterator<T>> | AsyncIterator<T>,
size: number = null,
): Dataset<T> {
return datasetFromIteratorFn(async () => {
const gen = await generator();
return iteratorFromFunction(() => gen.next());
});
}, size);
}

/**
Expand Down