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

Class Tensor

tfjs-core/src/tensor.ts:257–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255 * @doc {heading: 'Tensors', subheading: 'Classes'}
256 */
257export class Tensor<R extends Rank = Rank> implements TensorInfo {
258 /** Unique id of this tensor. */
259 readonly id: number;
260 /**
261 * Id of the bucket holding the data for this tensor. Multiple arrays can
262 * point to the same bucket (e.g. when calling array.reshape()).
263 */
264 dataId: DataId;
265 /** The shape of the tensor. */
266 readonly shape: ShapeMap[R];
267 /** Number of elements in the tensor. */
268 readonly size: number;
269 /** The data type for the array. */
270 readonly dtype: DataType;
271 /** The rank type for the array (see `Rank` enum). */
272 readonly rankType: R;
273
274 /** Whether this tensor has been globally kept. */
275 kept = false;
276 /** The id of the scope this tensor is being tracked in. */
277 scopeId: number;
278 /** The keras mask that some keras layers attach to the tensor */
279 kerasMask?: Tensor;
280
281 /**
282 * Number of elements to skip in each dimension when indexing. See
283 * https://docs.scipy.org/doc/numpy/reference/generated/\
284 * numpy.ndarray.strides.html
285 */
286 readonly strides: number[];
287
288 constructor(shape: ShapeMap[R], dtype: DataType, dataId: DataId, id: number) {
289 this.shape = shape.slice() as ShapeMap[R];
290 this.dtype = dtype || 'float32';
291 this.size = util.sizeFromShape(shape);
292 this.strides = computeStrides(shape);
293 this.dataId = dataId;
294 this.id = id;
295 this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher') as R;
296 }
297
298 get rank(): number {
299 return this.shape.length;
300 }
301
302 /**
303 * Returns a promise of `tf.TensorBuffer` that holds the underlying data.
304 *
305 * @doc {heading: 'Tensors', subheading: 'Classes'}
306 */
307 async buffer<D extends DataType = 'float32'>(): Promise<TensorBuffer<R, D>> {
308 const vals = await this.data<D>();
309 return opHandler.buffer(this.shape, this.dtype as D, vals);
310 }
311
312 /**
313 * Returns a `tf.TensorBuffer` that holds the underlying data.
314 * @doc {heading: 'Tensors', subheading: 'Classes'}

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…