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

Function scalar

tfjs-core/src/ops/scalar.ts:38–55  ·  view source on GitHub ↗
(
    value: number|boolean|string|Uint8Array, dtype?: DataType)

Source from the content-addressed store, hash-verified

36 * @doc {heading: 'Tensors', subheading: 'Creation'}
37 */
38export function scalar(
39 value: number|boolean|string|Uint8Array, dtype?: DataType): Scalar {
40 if (((isTypedArray(value) && dtype !== 'string') || Array.isArray(value)) &&
41 dtype !== 'complex64') {
42 throw new Error(
43 'Error creating a new Scalar: value must be a primitive ' +
44 '(number|boolean|string)');
45 }
46 if (dtype === 'string' && isTypedArray(value) &&
47 !(value instanceof Uint8Array)) {
48 throw new Error(
49 'When making a scalar from encoded string, ' +
50 'the value must be `Uint8Array`.');
51 }
52 const shape: number[] = [];
53 const inferredShape: number[] = [];
54 return makeTensor(value, shape, inferredShape, dtype) as Scalar;
55}

Callers 15

tensorStatsFunction · 0.90
applyMethod · 0.90
applyMethod · 0.90
models_test.tsFile · 0.90
losses_test.tsFile · 0.90
_binaryCrossentropyFunction · 0.90
customLossFunction · 0.90
metrics_test.tsFile · 0.90
variables_test.tsFile · 0.90

Calls 2

isTypedArrayFunction · 0.90
makeTensorFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…