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

Method write

tfjs-converter/src/executor/tensor_array.ts:112–159  ·  view source on GitHub ↗

* Write value into the index of the TensorArray. * @param index number the index to write to. * @param tensor

(index: number, tensor: Tensor)

Source from the content-addressed store, hash-verified

110 * @param tensor
111 */
112 write(index: number, tensor: Tensor) {
113 if (this.closed_) {
114 throw new Error(`TensorArray ${this.name} has already been closed.`);
115 }
116
117 if (index < 0 || !this.dynamicSize && index >= this.maxSize) {
118 throw new Error(`Tried to write to index ${
119 index}, but array is not resizeable and size is: ${this.maxSize}`);
120 }
121
122 const t = this.tensors[index] || {};
123
124 if (tensor.dtype !== this.dtype) {
125 throw new Error(`TensorArray ${
126 this.name}: Could not write to TensorArray index ${index},
127 because the value dtype is ${
128 tensor.dtype}, but TensorArray dtype is ${this.dtype}.`);
129 }
130
131 // Set the shape for the first time write to unknow shape tensor array
132 if (this.size() === 0 &&
133 (this.elementShape == null || this.elementShape.length === 0)) {
134 this.elementShape = tensor.shape;
135 }
136
137 assertShapesMatchAllowUndefinedSize(
138 this.elementShape, tensor.shape,
139 `TensorArray ${this.name}: Could not write to TensorArray index ${
140 index}.`);
141
142 if (t.read) {
143 throw new Error(
144 `TensorArray ${this.name}: Could not write to TensorArray index ${
145 index}, because it has already been read.`);
146 }
147
148 if (t.written) {
149 throw new Error(
150 `TensorArray ${this.name}: Could not write to TensorArray index ${
151 index}, because it has already been written.`);
152 }
153
154 t.tensor = tensor;
155 keep(tensor);
156 t.written = true;
157
158 this.tensors[index] = t;
159 }
160
161 /**
162 * Helper method to write multiple tensors to the specified indices.

Callers 1

writeManyMethod · 0.95

Calls 3

sizeMethod · 0.95
keepFunction · 0.90

Tested by

no test coverage detected