MCPcopy
hub / github.com/tensorflow/tfjs / shuffle

Function shuffle

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

* Pseudorandomly shuffles the elements of this dataset. This is done in a * streaming manner, by sampling from a given number of prefetched elements. * * ```js * const a = tf.data.array([1, 2, 3, 4, 5, 6]).shuffle(3); * await a.forEachAsync(e => console.log(e)); * ``` * * @pa

(bufferSize: number, seed?: string, reshuffleEachIteration = true)

Source from the content-addressed store, hash-verified

429 * @doc {heading: 'Data', subheading: 'Classes'}
430 */
431 shuffle(bufferSize: number, seed?: string, reshuffleEachIteration = true):
432 Dataset<T> {
433 if (bufferSize == null || bufferSize < 0) {
434 if (this.size == null) {
435 throw new RangeError(
436 '`Dataset.shuffle()` requires bufferSize to be specified.');
437 } else {
438 throw new RangeError(
439 '`Dataset.shuffle()` requires bufferSize to be specified. ' +
440 'If your data fits in main memory (for regular JS objects), ' +
441 'and/or GPU memory (for `tf.Tensor`s), consider setting ' +
442 `bufferSize to the dataset size (${this.size} elements)`);
443 }
444 }
445 const base = this;
446 const random = seedrandom.alea(seed || tf.util.now().toString());
447 return datasetFromIteratorFn(async () => {
448 let seed2 = random.int32();
449 if (reshuffleEachIteration) {
450 seed2 += random.int32();
451 }
452 return (await base.iterator()).shuffle(bufferSize, seed2.toString());
453 }, this.size);
454 }
455
456 /**
457 * Creates a `Dataset` with at most `count` initial elements from this

Callers

nothing calls this directly

Calls 4

datasetFromIteratorFnFunction · 0.85
toStringMethod · 0.80
nowMethod · 0.65
iteratorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…