Skip to content

Commit

Permalink
Update tf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Jan 27, 2024
1 parent e5d1ce5 commit 6d754d9
Showing 1 changed file with 6 additions and 65 deletions.
71 changes: 6 additions & 65 deletions source/tf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1618,74 +1618,13 @@ tf.TensorBundle.Table.Block = class {
}
};

tf.BinaryReader = class {
tf.BinaryReader = class extends base.BinaryReader {

constructor(buffer) {
this._buffer = buffer;
this._position = 0;
this._length = this._buffer.length;
this._dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
super(buffer);
this._decoder = new TextDecoder('utf-8');
}

get position() {
return this._position;
}

get length() {
return this._length;
}

seek(position) {
this._position = position >= 0 ? position : this._length + position;
if (this._position > this._length) {
throw new tf.Error(`Expected ${this._position - this._length} more bytes. The file might be corrupted. Unexpected end of file.`);
}
}

skip(offset) {
this._position += offset;
if (this._position > this._length) {
throw new tf.Error(`Expected ${this._position - this._length} more bytes. The file might be corrupted. Unexpected end of file.`);
}
}

read(size) {
const position = this._position;
this.skip(size);
return this._buffer.subarray(position, this._position);
}

byte() {
const position = this._position;
this.skip(1);
return this._dataView.getUint8(position);
}

uint16() {
const position = this._position;
this.skip(2);
return this._dataView.getUint16(position, true);
}

int32() {
const position = this._position;
this.skip(4);
return this._dataView.getInt32(position, true);
}

uint32() {
const position = this._position;
this.skip(4);
return this._dataView.getUint32(position, true);
}

uint64() {
const position = this._position;
this.skip(4);
return this._dataView.getUint64(position, true);
}

string() {
const size = this.uint32();
const buffer = this.read(size);
Expand Down Expand Up @@ -2149,7 +2088,8 @@ tf.Context = class {
}
break;
}
case 'int64': {
case 'int64':
case 'SymInt': {
if (input.constant !== undefined && Number.isInteger(parseInt(input.constant))) {
continue;
}
Expand Down Expand Up @@ -2209,7 +2149,8 @@ tf.Context = class {
input.metadata = arg;
break;
}
case 'int64': {
case 'int64':
case 'SymInt': {
const value = parseInt(input.constant);
input.attr = new tf.proto.tensorflow.AttrValue();
input.attr.i = value;
Expand Down

0 comments on commit 6d754d9

Please sign in to comment.