* 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)
| 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…