-
Notifications
You must be signed in to change notification settings - Fork 18
Support async/sync functions #172
Support async/sync functions #172
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BruceDai , thanks for the work, left some comments, please take a look.
95c9af5
to
7061d3a
Compare
Thanks @huningxin. |
createContext() / createContextSync() build() / buildSync() compute() / computeSync()
c0e1419
to
886b278
Compare
Thanks @huningxin ! |
test/api/graph_builder.js
Outdated
|
||
it('builder.build should throw for invalid parameters', async () => { | ||
try { | ||
await builder.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it reject with an error or throw?
ef227fc
to
d635418
Compare
@huningxin I've update this patch to address your comments, and added a sample by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BruceDai, leave a few comments, PTAL.
src/nn/graph.ts
Outdated
utils.assert( | ||
utils.isTypedArray(resource), | ||
'Only resource of ArrayBufferView type is supported.'); | ||
utils.validateTypedArray( | ||
resource as ArrayBufferView, inputOperand.desc.type, dimensions); | ||
resource , inputOperand.desc.type, dimensions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
resource , inputOperand.desc.type, dimensions); | |
resource, inputOperand.desc.type, dimensions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
@@ -245,10 +199,18 @@ export class MLGraph { | |||
} | |||
|
|||
/** @internal */ | |||
static buildAndCompile(outputs?: MLNamedOperands): MLGraph { | |||
static async buildAndCompile(outputs?: MLNamedOperands): Promise<MLGraph> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can try merger buildAndCompile
and buildAndCompileSync
into one and declare the return types with |
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to merge them to one function, but there's message The return type of an async function or method must be the global Promise<T> type.
, so I leave it as is.
src/nn/graph_builder.ts
Outdated
return new Promise((resolve, reject) => { | ||
let graph; | ||
try { | ||
graph = MLGraph.buildAndCompile(outputs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildAndCompile
is async function, missing await
keyword.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, please take another look at new commit, thanks.
test/api/context.js
Outdated
expect(() => navigator.ml.createContext({ | ||
powerPreference: 'invalid', | ||
})).to.throw(Error); | ||
describe('test MLContext.compute', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be better to use ES6 expression for consistency purpose.
describe('test MLContext.compute', function() { | |
describe('test MLContext.compute', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks.
0acebaa
to
d18b99c
Compare
@Honry I've update PR, please take another review, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
d18b99c
to
79e4ed1
Compare
79e4ed1
to
1baf6ac
Compare
src/nn/graph.ts
Outdated
compute(inputs: MLNamedInputs, outputs: MLNamedOutputs): void { | ||
/** @internal */ | ||
async compute( | ||
inputs:MLNamedArrayBufferViews, outputs: MLNamedArrayBufferViews, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a blank space between inputs: and MLNamedArraybufferViews
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks.
2b3fe63
to
988cdc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting better, thanks for the update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the great work.
Thanks @Honry and @huningxin for your reviewing. I will merge this PR. |
In first commit, I just updated add op tests using Async function. @huningxin PTAL, thanks.