Skip to content

Commit 0fe226d

Browse files
committed
Update onnx.js (#1387)
1 parent 9e75d13 commit 0fe226d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

source/onnx.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -638,19 +638,17 @@ onnx.Tensor = class {
638638
}
639639
case onnx.DataLocation.EXTERNAL: {
640640
if (Array.isArray(tensor.external_data)) {
641-
const external_data = {};
641+
const data = new Map();
642642
for (const entry of tensor.external_data) {
643-
external_data[entry.key] = entry.value;
643+
data.set(entry.key, entry.value);
644644
}
645-
if (external_data.location && external_data.offset && external_data.length) {
646-
this._location = external_data.location.toString();
647-
const offset = parseInt(external_data.offset, 10);
648-
const length = parseInt(external_data.length, 10);
649-
if (Number.isInteger(offset) && Number.isInteger(length)) {
650-
const location = context.location(external_data.location);
651-
this._request = { location, offset, length };
652-
this._encoding = '<';
653-
}
645+
if (data.has('location')) {
646+
this._location = data.get('location').toString();
647+
const location = context.location(this._location);
648+
const offset = data.has('offset') ? parseInt(data.get('offset'), 10) : 0;
649+
const length = data.has('length') ? parseInt(data.get('length'), 10) : -1;
650+
this._request = { location, offset, length };
651+
this._encoding = '<';
654652
}
655653
}
656654
break;
@@ -3002,6 +3000,7 @@ onnx.Location = class {
30023000
const stream = content.stream;
30033001
const position = stream.position;
30043002
stream.seek(offset);
3003+
length = length === -1 ? stream.length - offset : length;
30053004
content = stream.stream(length);
30063005
stream.seek(position);
30073006
this.content.set(key, content);

0 commit comments

Comments
 (0)