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

Function assertFeedCompatibility

tfjs-layers/src/engine/executor.ts:28–43  ·  view source on GitHub ↗

* Helper function to check the dtype and shape compatibility of a feed value.

(key: SymbolicTensor, val: Tensor)

Source from the content-addressed store, hash-verified

26 * Helper function to check the dtype and shape compatibility of a feed value.
27 */
28function assertFeedCompatibility(key: SymbolicTensor, val: Tensor): Tensor {
29 // Check dtype compatibility.
30 if (key.dtype == null || key.dtype === val.dtype) {
31 // a. If types match, return val tensor as is.
32 return val;
33 }
34 try {
35 // b. Attempt to convert to expected type.
36 return cast(val, key.dtype);
37 } catch (err) {
38 // c. If conversion fails, return helpful error.
39 throw new ValueError(
40 `The dtype of the feed (${val.dtype}) can not be cast to the dtype ` +
41 `of the key '${key.name}' (${key.dtype}).`);
42 }
43}
44
45/**
46 * A concrete Tensor value for a symbolic tensor as the key.

Callers 1

addMethod · 0.85

Calls 1

castFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…