Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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);

/**
* @brief Sets a friendly name for a model.
* @param info Contains information about the environment and passed arguments
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 @@ -73,6 +73,7 @@ interface Model {
input(nameOrId?: string | number): Output;
getName(): string;
isDynamic(): boolean;
getOutputSize(): number;
setFriendlyName(name: string): void;
getFriendlyName(): string;
}
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),
InstanceMethod("setFriendlyName", &ModelWrap::set_friendly_name),
InstanceMethod("getFriendlyName", &ModelWrap::get_friendly_name),
InstanceAccessor<&ModelWrap::get_inputs>("inputs"),
Expand Down Expand Up @@ -131,6 +132,16 @@ Napi::Value ModelWrap::is_dynamic(const Napi::CallbackInfo& info) {
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);
}

Napi::Value ModelWrap::set_friendly_name(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
try {
Expand Down
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 @@ -94,3 +94,21 @@ describe('Node.js getFriendlyName() / setFriendlyName()', () => {
});
});
});

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');
});
});