Skip to content

Commit

Permalink
Add more desciptive names for cpp methods
Browse files Browse the repository at this point in the history
  • Loading branch information
almilosz committed Nov 3, 2023
1 parent b410177 commit 582736e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/bindings/js/node/include/infer_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ class InferRequestWrap : public Napi::ObjectWrap<InferRequestWrap> {
Napi::Value get_output_tensors(const Napi::CallbackInfo& info);

/** @brief Checks incoming Napi::Value and calls overloaded infer() method */
Napi::Value infer_dispatch(const Napi::CallbackInfo& info);
Napi::Value infer_sync_dispatch(const Napi::CallbackInfo& info);

/** @brief Checks incoming Napi::Value and asynchronously returns the result of inference. */
Napi::Value infer_async(const Napi::CallbackInfo& info);

/** @brief Infers specified inputs in synchronous mode.
* @param inputs An object with a collection of pairs key (input_name) and a value (tensor, tensor's data)
*/
void infer(const Napi::Object& inputs);
void infer_sync(const Napi::Object& inputs);

/** @brief Infers specified inputs in synchronous mode.
* @param inputs An Array with values (tensors, tensors' data)
*/
void infer(const Napi::Array& inputs);
void infer_sync(const Napi::Array& inputs);

/** @return A Javascript CompiledModel. */
Napi::Value get_compiled_model(const Napi::CallbackInfo& info);
Expand Down
12 changes: 6 additions & 6 deletions src/bindings/js/node/src/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Napi::Function InferRequestWrap::GetClassConstructor(Napi::Env env) {
InstanceMethod("getTensor", &InferRequestWrap::get_tensor),
InstanceMethod("getInputTensor", &InferRequestWrap::get_input_tensor),
InstanceMethod("getOutputTensor", &InferRequestWrap::get_output_tensor),
InstanceMethod("inferSync", &InferRequestWrap::infer_dispatch),
InstanceMethod("inferSync", &InferRequestWrap::infer_sync_dispatch),
InstanceMethod("infer", &InferRequestWrap::infer_async),
InstanceMethod("getCompiledModel", &InferRequestWrap::get_compiled_model),
});
Expand Down Expand Up @@ -149,22 +149,22 @@ Napi::Value InferRequestWrap::get_output_tensors(const Napi::CallbackInfo& info)
return outputs_obj;
}

Napi::Value InferRequestWrap::infer_dispatch(const Napi::CallbackInfo& info) {
Napi::Value InferRequestWrap::infer_sync_dispatch(const Napi::CallbackInfo& info) {
if (info.Length() == 0)
_infer_request.infer();
else if (info.Length() == 1 && info[0].IsTypedArray()) {
reportError(info.Env(), "TypedArray cannot be passed directly into inferSync() method.");
return info.Env().Null();
} else if (info.Length() == 1 && info[0].IsArray()) {
try {
infer(info[0].As<Napi::Array>());
infer_sync(info[0].As<Napi::Array>());
} catch (std::exception& e) {
reportError(info.Env(), e.what());
return info.Env().Null();
}
} else if (info.Length() == 1 && info[0].IsObject()) {
try {
infer(info[0].As<Napi::Object>());
infer_sync(info[0].As<Napi::Object>());
} catch (std::exception& e) {
reportError(info.Env(), e.what());
return info.Env().Null();
Expand All @@ -175,15 +175,15 @@ Napi::Value InferRequestWrap::infer_dispatch(const Napi::CallbackInfo& info) {
return get_output_tensors(info);
}

void InferRequestWrap::infer(const Napi::Array& inputs) {
void InferRequestWrap::infer_sync(const Napi::Array& inputs) {
for (size_t i = 0; i < inputs.Length(); ++i) {
auto tensor = value_to_tensor(inputs[i], _infer_request, i);
_infer_request.set_input_tensor(i, tensor);
}
_infer_request.infer();
}

void InferRequestWrap::infer(const Napi::Object& inputs) {
void InferRequestWrap::infer_sync(const Napi::Object& inputs) {
auto keys = inputs.GetPropertyNames();

for (size_t i = 0; i < keys.Length(); ++i) {
Expand Down

0 comments on commit 582736e

Please sign in to comment.