Skip to main content

scope

fast-tensor


fast-tensor / scope

Function: scope()

scope(callback?): unknown

Start a scope to track any instances created, will automatically clear out any references not returned.

Parameters

callback?

() => unknown

Returns

unknown

Examples

ft.scope(() => {
const a = tf.ones([2,2]);
const b = a.add(2);
const result = b.data();
return result;
});
// "a" and "b" will have been freed from memory
const result = ft.scope(() => {
const a = tf.ones([2,2]);
const b = a.add(2);
return b;
});
// only "a" will have been freed from memory
// you will need to manually delete the instance
result.delete();

Defined in

index.ts:11