MCPcopy Create free account
hub / github.com/tensorflow/tfjs / validateInput

Function validateInput

tfjs-core/src/ops/sparse_to_dense_util.ts:32–66  ·  view source on GitHub ↗
(
    sparseIndices: Tensor, sparseValues: Tensor, outputShape: number[],
    defaultValues: Tensor)

Source from the content-addressed store, hash-verified

30 * will be thrown if it is set.
31 */
32export function validateInput(
33 sparseIndices: Tensor, sparseValues: Tensor, outputShape: number[],
34 defaultValues: Tensor) {
35 if (sparseIndices.dtype !== 'int32') {
36 throw new Error(
37 'tf.sparseToDense() expects the indices to be int32 type,' +
38 ` but the dtype was ${sparseIndices.dtype}.`);
39 }
40 if (sparseIndices.rank > 2) {
41 throw new Error(
42 'sparseIndices should be a scalar, vector, or matrix,' +
43 ` but got shape ${sparseIndices.shape}.`);
44 }
45
46 const numElems = sparseIndices.rank > 0 ? sparseIndices.shape[0] : 1;
47 const numDims = sparseIndices.rank > 1 ? sparseIndices.shape[1] : 1;
48
49 if (outputShape.length !== numDims) {
50 throw new Error(
51 'outputShape has incorrect number of elements:,' +
52 ` ${outputShape.length}, should be: ${numDims}.`);
53 }
54
55 const numValues = sparseValues.size;
56 if (!(sparseValues.rank === 0 ||
57 sparseValues.rank === 1 && numValues === numElems)) {
58 throw new Error(
59 'sparseValues has incorrect shape ' +
60 `${sparseValues.shape}, should be [] or [${numElems}]`);
61 }
62
63 if (sparseValues.dtype !== defaultValues.dtype) {
64 throw new Error('sparseValues.dtype must match defaultValues.dtype');
65 }
66}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…