Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Retribution98 committed Jan 27, 2025
1 parent de8c706 commit e1f1775
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/bindings/js/node/scripts/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('node:path');
const https = require('node:https');
const fs = require('node:fs/promises');
const { createWriteStream } = require('node:fs');
Expand Down
6 changes: 5 additions & 1 deletion src/bindings/js/node/tests/e2e/demo-electron-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ async function main() {
{ length: lengthFromShape(testModelFP32.inputShape) },
() => Math.random() + epsilon,
);
const tensor = new ov.Tensor(ov.element.f32, testModelFP32.inputShape, tensorData);
const tensor = new ov.Tensor(
ov.element.f32,
testModelFP32.inputShape,
tensorData,
);
console.log('Tensor created:', tensor);

const result = await inferRequest.inferAsync([tensor]);
Expand Down
7 changes: 5 additions & 2 deletions src/bindings/js/node/tests/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
const epsilon = 0.5;

describe('ov basic tests.', () => {
const testModelFP32 = testModels.testModelFP32
const { testModelFP32 } = testModels;
const testXml = testModelFP32.xml;
let core = null;
let model = null;
Expand Down Expand Up @@ -278,7 +278,10 @@ describe('ov basic tests.', () => {
assert.strictEqual(obj.input().anyName, 'data');

assert.deepStrictEqual(obj.input(0).shape, testModelFP32.inputShape);
assert.deepStrictEqual(obj.input(0).getShape(), testModelFP32.inputShape);
assert.deepStrictEqual(
obj.input(0).getShape(),
testModelFP32.inputShape,
);
});
});
});
Expand Down
38 changes: 31 additions & 7 deletions src/bindings/js/node/tests/unit/infer_request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
const { addon: ov } = require('../..');
const assert = require('assert');
const { describe, it, before, beforeEach } = require('node:test');
const { testModels, isModelAvailable, lengthFromShape } = require('../utils.js');
const {
testModels,
isModelAvailable,
lengthFromShape,
} = require('../utils.js');

const epsilon = 0.5; // To avoid very small numbers

Expand All @@ -28,8 +32,16 @@ describe('ov.InferRequest tests', () => {
{ length: lengthFromShape(testModelFP32.inputShape) },
() => Math.random() + epsilon,
);
tensor = new ov.Tensor(ov.element.f32, testModelFP32.inputShape, tensorData);
resTensor = new ov.Tensor(ov.element.f32, testModelFP32.outputShape, tensorData.slice(-10));
tensor = new ov.Tensor(
ov.element.f32,
testModelFP32.inputShape,
tensorData,
);
resTensor = new ov.Tensor(
ov.element.f32,
testModelFP32.outputShape,
tensorData.slice(-10),
);
tensorLike = [tensor, tensorData];
});

Expand All @@ -43,15 +55,21 @@ describe('ov.InferRequest tests', () => {
tensorLike.forEach((tl) => {
const result = inferRequest.infer({ data: tl });
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, lengthFromShape(testModelFP32.outputShape));
assert.deepStrictEqual(
result['fc_out'].data.length,
lengthFromShape(testModelFP32.outputShape)
);
});
});

it('Test infer(inputData: Tensor[]/TypedArray[])', () => {
tensorLike.forEach((tl) => {
const result = inferRequest.infer([tl]);
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, lengthFromShape(testModelFP32.outputShape));
assert.deepStrictEqual(
result['fc_out'].data.length,
lengthFromShape(testModelFP32.outputShape),
);
});
});

Expand Down Expand Up @@ -102,15 +120,21 @@ describe('ov.InferRequest tests', () => {
inferRequest.inferAsync({ data: tensor }).then((result) => {
assert.ok(result['fc_out'] instanceof ov.Tensor);
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, lengthFromShape(testModelFP32.outputShape));
assert.deepStrictEqual(
result['fc_out'].data.length,
lengthFromShape(testModelFP32.outputShape),
);
});
});

it('Test inferAsync(inputData: Tensor[])', () => {
inferRequest.inferAsync([tensor]).then((result) => {
assert.ok(result['fc_out'] instanceof ov.Tensor);
assert.deepStrictEqual(Object.keys(result), ['fc_out']);
assert.deepStrictEqual(result['fc_out'].data.length, lengthFromShape(testModelFP32.outputShape));
assert.deepStrictEqual(
result['fc_out'].data.length,
lengthFromShape(testModelFP32.outputShape),
);
});
});

Expand Down
17 changes: 12 additions & 5 deletions src/bindings/js/node/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ const {
} = require('../scripts/lib/utils');

const modelDir = 'tests/unit/test_models/';

function getModelPath(fileName) {
return path.join(modelDir, fileName);
}

const testModels = {
testModelFP32: {
xml: path.join(modelDir, 'test_model_fp32.xml'),
bin: path.join(modelDir, 'test_model_fp32.bin'),
xml: getModelPath('test_model_fp32.xml'),
bin: getModelPath('test_model_fp32.bin'),
inputShape: [1, 3, 32, 32],
outputShape: [1, 10],
xmlURL:
Expand Down Expand Up @@ -62,7 +67,10 @@ function sleep(ms) {
}

function lengthFromShape(shape) {
return shape.reduce((accumulator, currentValue) => accumulator * currentValue, 1);
return shape.reduce(
(accumulator, currentValue) => accumulator * currentValue,
1
);
}

async function downloadTestModel(model) {
Expand All @@ -80,15 +88,14 @@ async function downloadTestModel(model) {

const weightsExists = await checkIfPathExists(model.bin);
if (!weightsExists) await downloadFile(model.binURL, model.bin, proxyUrl);

} catch(error) {
console.error(`Failed to download the model: ${error}.`);
throw error;
}
}

async function isModelAvailable(model) {
const baseArtifactsDir = './tests/unit/test_models';
const modelExists = await checkIfPathExists(model.xml);
if (modelExists) return;

Expand Down

0 comments on commit e1f1775

Please sign in to comment.