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

Function getCartesianProductOfValues

tfjs-layers/src/utils/generic_utils.ts:541–563  ·  view source on GitHub ↗
(...arrayOfValues: PossibleValues)

Source from the content-addressed store, hash-verified

539 * @return The cartesian product.
540 */
541export function getCartesianProductOfValues(...arrayOfValues: PossibleValues):
542 PossibleValues {
543 assert(arrayOfValues.length > 0, 'arrayOfValues is empty');
544
545 for (const values of arrayOfValues) {
546 assert(Array.isArray(values), 'one of the values is not an array');
547 assert(values.length > 0, 'one of the values is empty');
548 }
549
550 return arrayOfValues.reduce((products, values) => {
551 if (products.length === 0) {
552 return values.map(value => [value]);
553 }
554
555 return values
556 .map(value => {
557 return products.map((prevValue) => [...prevValue, value]);
558 })
559 .reduce((flattenedProduct, unflattenedProduct) => {
560 return flattenedProduct.concat(unflattenedProduct);
561 }, []);
562 }, [] as PossibleValues);
563}

Callers 1

Calls 2

assertFunction · 0.70
concatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…