Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bindings/js/node/include/model_wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class ModelWrap : public Napi::ObjectWrap<ModelWrap> {
*/
Napi::Value is_dynamic(const Napi::CallbackInfo& info);

/**
* @brief Returns the number of outputs for this model
* @param info Contains information about the environment and passed arguments
* This method does not accept any arguments. If arguments are provided it throws Napi::Error
* @return number indicating the quantity of outputs for the model
*/
Napi::Value get_output_size(const Napi::CallbackInfo& info);

private:
std::shared_ptr<ov::Model> _model;
ov::Core _core;
Expand Down
1 change: 1 addition & 0 deletions src/bindings/js/node/lib/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface Model {
input(nameOrId?: string | number): Output;
getName(): string;
isDynamic(): boolean;
getOutputSize(): number;
}

interface CompiledModel {
Expand Down
11 changes: 11 additions & 0 deletions src/bindings/js/node/src/model_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Napi::Function ModelWrap::get_class(Napi::Env env) {
InstanceMethod("output", &ModelWrap::get_output),
InstanceMethod("input", &ModelWrap::get_input),
InstanceMethod("isDynamic", &ModelWrap::is_dynamic),
InstanceMethod("getOutputSize", &ModelWrap::get_output_size),
InstanceAccessor<&ModelWrap::get_inputs>("inputs"),
InstanceAccessor<&ModelWrap::get_outputs>("outputs")});
}
Expand Down Expand Up @@ -128,3 +129,13 @@ Napi::Value ModelWrap::is_dynamic(const Napi::CallbackInfo& info) {
const auto result = _model->is_dynamic();
return Napi::Boolean::New(env, result);
}

Napi::Value ModelWrap::get_output_size(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() > 0) {
reportError(env, "getOutputSize() does not accept any arguments.");
return env.Undefined();
}
const auto size = static_cast<double>(_model->get_output_size());
return Napi::Number::New(env, size);
}
18 changes: 18 additions & 0 deletions src/bindings/js/node/tests/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,21 @@ describe('Node.js Model.isDynamic()', () => {
assert.strictEqual(model.isDynamic(), expectedStatus, 'Expected isDynamic to return false for a static model');
});
});

describe('Model.getOutputSize()', () => {

it('should return a number indicating number of outputs for the model', () => {
const result = model.getOutputSize();
assert.strictEqual(typeof result, 'number', 'getOutputSize() should return a number');
});

it('should not accept any arguments', () => {
assert.throws(() => {
model.getOutputSize('unexpected argument');
}, /^Error: getOutputSize\(\) does not accept any arguments\.$/, 'Expected getOutputSize to throw an error when called with arguments');
});

it('should return 1 for the default model', () => {
assert.strictEqual(model.getOutputSize(), 1, 'Expected getOutputSize to return 1 for the default model');
});
});