Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions tfjs-core/src/tensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ export class Tensor<R extends Rank = Rank> {
return opHandler.buffer(this.shape, this.dtype as D, vals);
}

/** Returns a `tf.TensorBuffer` that holds the underlying data.
/**
* Returns a `tf.TensorBuffer` that holds the underlying data.
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
bufferSync<D extends DataType = 'float32'>(): TensorBuffer<R, D> {
Expand Down Expand Up @@ -411,7 +412,8 @@ export class Tensor<R extends Rank = Rank> {
return opHandler.print(this, verbose);
}

/** Returns a copy of the tensor. See `tf.clone` for details.
/**
* Returns a copy of the tensor. See `tf.clone` for details.
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
clone<T extends Tensor>(this: T): T {
Expand Down Expand Up @@ -441,8 +443,13 @@ export class Tensor<R extends Rank = Rank> {
}
Object.defineProperty(Tensor, Symbol.hasInstance, {
value: (instance: Tensor) => {
return !!instance && instance.dataId != null && instance.shape != null &&
instance.dtype != null;
// Implementation note: we should use properties of the object that will be
// defined before the constructor body has finished executing (methods).
// This is because when this code is transpiled by babel, babel will call
// classCallCheck before the constructor body is run.
// See https://github.com/tensorflow/tfjs/issues/3384 for backstory.
return !!instance && instance.data != null && instance.dataSync != null &&
instance.throwIfDisposed != null;
}
});

Expand Down
5 changes: 0 additions & 5 deletions tfjs-core/src/tensor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2208,11 +2208,6 @@ describeWithFlags('x instanceof Tensor', ALL_ENVS, () => {
expect(t instanceof Tensor).toBe(true);
});

it('x: Tensor-like', () => {
const t = {shape: [2], dtype: 'float32', dataId: {}};
expect(t instanceof Tensor).toBe(true);
});

it('x: other object, fails', () => {
const t = {something: 'else'};
expect(t instanceof Tensor).toBe(false);
Expand Down
5 changes: 0 additions & 5 deletions tfjs-core/src/variable_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ describeWithFlags('x instanceof Variable', ALL_ENVS, () => {
expect(t instanceof Variable).toBe(true);
});

it('x: Variable-like', () => {
const t = {assign: () => {}, shape: [2], dtype: 'float32', dataId: {}};
expect(t instanceof Variable).toBe(true);
});

it('x: other object, fails', () => {
const t = {something: 'else'};
expect(t instanceof Variable).toBe(false);
Expand Down