Skip to content

Commit

Permalink
Added argument check and corresponding node runner test for the get_s…
Browse files Browse the repository at this point in the history
…hape method (openvinotoolkit#23637)

This Fixes openvinotoolkit#23441 issue.

Details:

1. Modified get_shape() method to report error in case any argument is
passed.
2. Added Required Tests for the above in `tensor.test.js`.

---------

Co-authored-by: Vishniakov Nikolai <[email protected]>
Co-authored-by: Alicja Miloszewska <[email protected]>
  • Loading branch information
3 people authored and alvoron committed Apr 29, 2024
1 parent f8cf5b3 commit 014d19c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bindings/js/node/src/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ Napi::Value TensorWrap::get_data(const Napi::CallbackInfo& info) {
}

Napi::Value TensorWrap::get_shape(const Napi::CallbackInfo& info) {
if (info.Length() > 0) {
reportError(info.Env(), "No parameters are allowed for the getShape() method.");
return info.Env().Undefined();
}
return cpp_to_js<ov::Shape, Napi::Array>(info, _tensor.get_shape());
}

Expand Down
8 changes: 8 additions & 0 deletions src/bindings/js/node/tests/tensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ describe('Tensor shape', () => {
/Cannot convert argument./
);
});

it('getShape() method does not accept parameters', () => {
const tensor = new ov.Tensor(ov.element.f32, [1, 3, 224, 224], data);
assert.throws(
() => tensor.getShape(1, 2, 3),
{ message: 'No parameters are allowed for the getShape() method.'}
);
});
});

describe('Tensor element type', () => {
Expand Down

0 comments on commit 014d19c

Please sign in to comment.