MCPcopy Index your code
hub / github.com/tensorflow/tfjs / take

Function take

tfjs-data/src/dataset.ts:473–490  ·  view source on GitHub ↗

* Creates a `Dataset` with at most `count` initial elements from this * dataset. * * ```js * const a = tf.data.array([1, 2, 3, 4, 5, 6]).take(3); * await a.forEachAsync(e => console.log(e)); * ``` * * @param count: The number of elements of this dataset that should be taken

(count: number)

Source from the content-addressed store, hash-verified

471 * @doc {heading: 'Data', subheading: 'Classes'}
472 */
473 take(count: number): Dataset<T> {
474 const base = this;
475 let size;
476 if (this.size != null && this.size > count) {
477 // If the size of this dataset is greater than count, the new dataset's
478 // size is count.
479 size = count;
480 } else if (this.size != null && this.size <= count) {
481 // If the size of this dataset is equal or smaller than count, the new
482 // dataset's size is the size of this dataset.
483 size = this.size;
484 } else {
485 // If the size of this dataset is null, the new dataset's size is null.
486 size = null;
487 }
488 return datasetFromIteratorFn(
489 async () => (await base.iterator()).take(count), size);
490 }
491
492 /**
493 * Collect all elements of this dataset into an array.

Callers

nothing calls this directly

Calls 2

datasetFromIteratorFnFunction · 0.85
iteratorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…