Skip to content

Commit

Permalink
Do not extend from ONNX tensor (fix #437)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Dec 11, 2023
1 parent 8e49e5e commit b768cb8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/tensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ const DataTypeMap = new Map([

const ONNXTensor = ONNX.Tensor;

export class Tensor extends ONNXTensor {
export class Tensor {
/**
* Create a new Tensor or copy an existing Tensor.
* @param {[string, DataArray, number[]]|[ONNXTensor]} args
*/
constructor(...args) {
if (args[0] instanceof ONNX.Tensor) {
// Create shallow copy
super(args[0].type, args[0].data, args[0].dims);
Object.assign(this, args[0]);

} else {
// Create new
super(...args);
// Create new tensor
this.type = /** @type {string} */ (args[0]);
this.data = /** @type {DataArray} */ (args[1]);
this.dims = /** @type {number[]} */ (args[2]);
}

return new Proxy(this, {
Expand Down

0 comments on commit b768cb8

Please sign in to comment.