Skip to content

Commit

Permalink
Update view.js (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed May 1, 2024
1 parent 32228b8 commit f874d49
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 336 deletions.
4 changes: 2 additions & 2 deletions source/browser.js
Expand Up @@ -662,7 +662,7 @@ host.BrowserHost.BrowserFileContext = class {
return await this._host.require(id);
}

exception(error, fatal) {
error(error, fatal) {
this._host.exception(error, fatal);
}

Expand Down Expand Up @@ -809,7 +809,7 @@ host.BrowserHost.Context = class {
return this._host.require(id);
}

exception(error, fatal) {
error(error, fatal) {
this._host.exception(error, fatal);
}
};
Expand Down
2 changes: 1 addition & 1 deletion source/electron.mjs
Expand Up @@ -709,7 +709,7 @@ host.ElectronHost.Context = class {
return await this._host.require(id);
}

exception(error, fatal) {
error(error, fatal) {
this._host.exception(error, fatal);
}
};
Expand Down
10 changes: 5 additions & 5 deletions source/pickle.js
Expand Up @@ -26,15 +26,15 @@ pickle.ModelFactory = class {
let format = 'Pickle';
const obj = context.target;
if (obj === null || obj === undefined) {
context.exception(new pickle.Error("Unsupported Pickle null object."));
context.error(new pickle.Error("Unsupported Pickle null object."));
} else if (obj instanceof Error) {
throw obj;
} else if (Array.isArray(obj)) {
if (obj.length > 0 && obj[0] && obj.every((item) => item && item.__class__ && obj[0].__class__ && item.__class__.__module__ === obj[0].__class__.__module__ && item.__class__.__name__ === obj[0].__class__.__name__)) {
const type = `${obj[0].__class__.__module__}.${obj[0].__class__.__name__}`;
context.exception(new pickle.Error(`Unsupported Pickle '${type}' array object.`));
context.error(new pickle.Error(`Unsupported Pickle '${type}' array object.`));
} else if (obj.length > 0) {
context.exception(new pickle.Error("Unsupported Pickle array object."));
context.error(new pickle.Error("Unsupported Pickle array object."));
}
} else if (obj && obj.__class__) {
const formats = new Map([
Expand All @@ -44,10 +44,10 @@ pickle.ModelFactory = class {
if (formats.has(type)) {
format = formats.get(type);
} else {
context.exception(new pickle.Error(`Unsupported Pickle type '${type}'.`));
context.error(new pickle.Error(`Unsupported Pickle type '${type}'.`));
}
} else {
context.exception(new pickle.Error('Unsupported Pickle object.'));
context.error(new pickle.Error('Unsupported Pickle object.'));
}
return new pickle.Model(obj, format);
}
Expand Down
2 changes: 1 addition & 1 deletion source/pytorch.js
Expand Up @@ -25,7 +25,7 @@ pytorch.ModelFactory = class {
const metadata = await pytorch.Metadata.open(context);
const target = context.target;
target.on('resolve', (_, name) => {
context.exception(new pytorch.Error(`Unknown type name '${name}'.`), false);
context.error(new pytorch.Error(`Unknown type name '${name}'.`), false);
});
await target.read(metadata);
return new pytorch.Model(metadata, target);
Expand Down
4 changes: 2 additions & 2 deletions source/tf.js
Expand Up @@ -283,7 +283,7 @@ tf.ModelFactory = class {
const bundle = await tf.TensorBundle.open(stream, identifier, context);
return openModel(null, `TensorFlow Tensor Bundle v${bundle.format}`, null, bundle);
} catch (error) {
context.exception(error, false);
context.error(error, false);
throw error;
}
};
Expand Down Expand Up @@ -1309,7 +1309,7 @@ tf.TensorBundle = class {
const streams = contexts.map((context) => context.stream);
return new tf.TensorBundle(format, table.entries, streams);
} catch (error) {
context.exception(error, false);
context.error(error, false);
return new tf.TensorBundle(format, table.entries, null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/torch.js
Expand Up @@ -18,7 +18,7 @@ torch.ModelFactory = class {
const reader = context.target;
reader.callback = (name) => {
if (name && name !== 'nn.JointTrainModule' && !name.startsWith('nn.MSDNet_') && !name.startsWith('onmt.')) {
context.exception(new torch.Error(`Unsupported type '${name}'.`));
context.error(new torch.Error(`Unsupported type '${name}'.`));
}
return null;
};
Expand Down

0 comments on commit f874d49

Please sign in to comment.