Skip to content

Commit 19ddf45

Browse files
authored
Fix some lint errors (#952)
* Fix some lint errors * Fix lint error of n_cubic_interpolation * Fix some lint errors * Refactor interpolation 2d test to simplify value selection logic
1 parent 3c7a7dd commit 19ddf45

File tree

11 files changed

+41
-48
lines changed

11 files changed

+41
-48
lines changed

Diff for: .prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
coverage/**
2+
coverage-gui/**
13
lib/model/nns/onnx/onnx_pb.js
24
onnx_tmp/**

Diff for: create_import_list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default {
101101
`
102102

103103
const addExports = (key, names) => {
104-
code += ' /**\n * @memberof default\n'
104+
code += ' /**\n'
105105
for (const name of names) {
106106
code += ` * @property {${name.name}} ${name.name}${name.comment}\n`
107107
}

Diff for: lib/model/nns/layer/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export { default as VarLayer } from './variance.js'
187187
* { type: 'huber' } |
188188
* { type: 'identity' } |
189189
* { type: 'include', net: NeuralNetwork | object[], input_to?: string, train?: boolean } |
190-
* { type: 'input', name?: string, size?: number[], value?: number | number[] | number[][] | nunber[][][] | number[][][][] | Matrix | Tensor } |
190+
* { type: 'input', name?: string, size?: (number | null)[], value?: number | number[] | number[][] | number[][][] | number[][][][] | Matrix | Tensor } |
191191
* { type: 'is_inf' } |
192192
* { type: 'is_nan' } |
193193
* { type: 'isigmoid', a?: number, alpha?: number } |

Diff for: lib/model/nns/layer/input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default class InputLayer extends Layer {
99
/**
1010
* @param {object} config object
1111
* @param {string} [config.name] Name of the layer
12-
* @param {number[]} [config.size] Size of the layer
13-
* @param {number | number[] | number[][] | nunber[][][] | number[][][][] | Matrix | Tensor} [config.value] Default value
12+
* @param {(number | null)[]} [config.size] Size of the layer
13+
* @param {number | number[] | number[][] | number[][][] | number[][][][] | Matrix | Tensor} [config.value] Default value
1414
*/
1515
constructor({ name = null, size = null, value, ...rest }) {
1616
super(rest)

Diff for: lib/model/nns/onnx/layer/reshape.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { onnx } from '../onnx_exporter.js'
2-
import { getConstNodeName } from '../utils.js'
32

43
/**
54
* Handle reshape layer

Diff for: lib/util/matrix.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class MatrixException extends Error {
2727

2828
/**
2929
* Matrix class
30-
* @template [T=number]
30+
* @template {*} [T=number] - Element type
3131
*/
3232
export default class Matrix {
3333
/**
@@ -413,7 +413,7 @@ export default class Matrix {
413413

414414
/**
415415
* Iterate over the elements.
416-
* @returns {Generator<T>}
416+
* @yields {T}
417417
*/
418418
*[Symbol.iterator]() {
419419
yield* this._value
@@ -2043,7 +2043,7 @@ export default class Matrix {
20432043

20442044
/**
20452045
* Returns diagonal elements.
2046-
* @returns {number[]} Diagonal values
2046+
* @returns {T[]} Diagonal values
20472047
*/
20482048
diag() {
20492049
let d = []

Diff for: tests/gui/helper/aimanager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default (page, option = {}) => {
2828
for (const key of propNames) {
2929
try {
3030
stack.push([obj[key], key, o])
31-
} catch (e) {
31+
} catch {
3232
o[key] = 'error'
3333
}
3434
}
@@ -43,7 +43,7 @@ export default (page, option = {}) => {
4343
if (descriptor.get) {
4444
try {
4545
stack.push([obj[key], key, o])
46-
} catch (e) {
46+
} catch {
4747
o[key] = 'error'
4848
}
4949
}

Diff for: tests/lib/model/n_cubic_interpolation.test.js

+28-29
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,35 @@ test('interpolation 2d', () => {
100100
}
101101
}
102102
const y0 = model.predict(x0)
103-
for (let i = 0, p = 0; i <= (n - 1) * 4; i++) {
103+
let p = 0
104+
for (let i = 0; i < 4; i++) {
105+
for (let j = 0; j <= (n - 1) * 4; j++, p++) {
106+
expect(y0[p]).toBeNull()
107+
}
108+
}
109+
for (let i = 4; i <= (n - 2) * 4; i++) {
110+
for (let j = 0; j < 4; j++, p++) {
111+
expect(y0[p]).toBeNull()
112+
}
113+
for (let j = 4; j <= (n - 2) * 4; j++, p++) {
114+
const ps = [
115+
v[Math.floor(i / 4)][Math.floor(j / 4)],
116+
v[Math.ceil(i / 4)][Math.floor(j / 4)],
117+
v[Math.floor(i / 4)][Math.ceil(j / 4)],
118+
v[Math.ceil(i / 4)][Math.ceil(j / 4)],
119+
]
120+
const l = Math.min(...ps)
121+
const h = Math.max(...ps)
122+
expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5)
123+
expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5)
124+
}
125+
for (let j = (n - 2) * 4 + 1; j <= (n - 1) * 4; j++, p++) {
126+
expect(y0[p]).toBeNull()
127+
}
128+
}
129+
for (let i = (n - 2) * 4 + 1; i <= (n - 1) * 4; i++) {
104130
for (let j = 0; j <= (n - 1) * 4; j++, p++) {
105-
if (i / 4 < 1 || i / 4 > n - 2 || j / 4 < 1 || j / 4 > n - 2) {
106-
expect(y0[p]).toBeNull()
107-
} else if (Number.isInteger(i / 4) && Number.isInteger(j / 4)) {
108-
expect(y0[p]).toBeCloseTo(v[i / 4][j / 4])
109-
} else if (Number.isInteger(i / 4)) {
110-
const ps = [v[i / 4][Math.ceil(j / 4)], v[i / 4][Math.floor(j / 4)]]
111-
const l = Math.min(...ps)
112-
const h = Math.max(...ps)
113-
expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5)
114-
expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5)
115-
} else if (Number.isInteger(j / 4)) {
116-
const ps = [v[Math.ceil(i / 4)][j / 4], v[Math.floor(i / 4)][j / 4]]
117-
const l = Math.min(...ps)
118-
const h = Math.max(...ps)
119-
expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5)
120-
expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5)
121-
} else {
122-
const ps = [
123-
v[Math.floor(i / 4)][Math.floor(j / 4)],
124-
v[Math.ceil(i / 4)][Math.floor(j / 4)],
125-
v[Math.floor(i / 4)][Math.ceil(j / 4)],
126-
v[Math.ceil(i / 4)][Math.ceil(j / 4)],
127-
]
128-
const l = Math.min(...ps)
129-
const h = Math.max(...ps)
130-
expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5)
131-
expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5)
132-
}
131+
expect(y0[p]).toBeNull()
133132
}
134133
}
135134

Diff for: tests/lib/model/nns/onnx/layer/const.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ ort.env.wasm.numThreads = 1
33

44
import ONNXExporter from '../../../../../../lib/model/nns/onnx/onnx_exporter.js'
55
import constant from '../../../../../../lib/model/nns/onnx/layer/const.js'
6-
import Matrix from '../../../../../../lib/util/matrix.js'
76

87
describe('export', () => {
98
test('1d array', () => {

Diff for: tests/lib/rl/grid.test.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ describe('map', () => {
5757
for (let j = 0; j < 10; j++) {
5858
if ((i === 0 && j === 0) || (i === 19 && j === 9)) {
5959
continue
60-
} else if (wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1) {
61-
expect(map[i][j]).toBeTruthy()
62-
} else {
63-
expect(map[i][j]).toBeFalsy()
6460
}
61+
expect(!!map[i][j]).toBe(wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1)
6562
}
6663
}
6764
})

Diff for: tests/lib/rl/maze.test.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ describe('map', () => {
4444
for (let j = 0; j < 10; j++) {
4545
if ((i === 0 && j === 0) || (i === 99 && j === 49)) {
4646
continue
47-
} else if (wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1) {
48-
expect(map[i][j]).toBeTruthy()
49-
} else {
50-
expect(map[i][j]).toBeFalsy()
5147
}
48+
expect(!!map[i][j]).toBe(wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1)
5249
}
5350
}
5451
})

0 commit comments

Comments
 (0)