MCPcopy Index your code
hub / github.com/tensorflow/tfjs / makeVariable

Method makeVariable

tfjs-core/src/engine.ts:856–870  ·  view source on GitHub ↗
(
      initialValue: Tensor, trainable = true, name?: string,
      dtype?: DataType)

Source from the content-addressed store, hash-verified

854 }
855
856 makeVariable(
857 initialValue: Tensor, trainable = true, name?: string,
858 dtype?: DataType): Variable {
859 name = name || this.nextVariableId().toString();
860 if (dtype != null && dtype !== initialValue.dtype) {
861 initialValue = initialValue.cast(dtype);
862 }
863 const v = new Variable(initialValue, trainable, name, this.nextTensorId());
864 if (this.state.registeredVariables[v.name] != null) {
865 throw new Error(`Variable with name ${v.name} was already registered`);
866 }
867 this.state.registeredVariables[v.name] = v;
868 this.incRef(v, this.backend);
869 return v;
870 }
871
872 trackTensor(a: Tensor, backend: KernelBackend): void {
873 this.state.numTensors++;

Callers

nothing calls this directly

Calls 5

nextVariableIdMethod · 0.95
nextTensorIdMethod · 0.95
incRefMethod · 0.95
toStringMethod · 0.80
castMethod · 0.65

Tested by

no test coverage detected