diff --git a/.prettierignore b/.prettierignore index 0c117d759..bf1e819e1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,4 @@ +coverage/** +coverage-gui/** lib/model/nns/onnx/onnx_pb.js onnx_tmp/** diff --git a/create_import_list.js b/create_import_list.js index 6edc16782..b08f7757b 100644 --- a/create_import_list.js +++ b/create_import_list.js @@ -101,7 +101,7 @@ export default { ` const addExports = (key, names) => { - code += ' /**\n * @memberof default\n' + code += ' /**\n' for (const name of names) { code += ` * @property {${name.name}} ${name.name}${name.comment}\n` } diff --git a/lib/model/nns/layer/index.js b/lib/model/nns/layer/index.js index cc47d7262..3531feee8 100644 --- a/lib/model/nns/layer/index.js +++ b/lib/model/nns/layer/index.js @@ -187,7 +187,7 @@ export { default as VarLayer } from './variance.js' * { type: 'huber' } | * { type: 'identity' } | * { type: 'include', net: NeuralNetwork | object[], input_to?: string, train?: boolean } | - * { type: 'input', name?: string, size?: number[], value?: number | number[] | number[][] | nunber[][][] | number[][][][] | Matrix | Tensor } | + * { type: 'input', name?: string, size?: (number | null)[], value?: number | number[] | number[][] | number[][][] | number[][][][] | Matrix | Tensor } | * { type: 'is_inf' } | * { type: 'is_nan' } | * { type: 'isigmoid', a?: number, alpha?: number } | diff --git a/lib/model/nns/layer/input.js b/lib/model/nns/layer/input.js index b9573e593..756a3a362 100644 --- a/lib/model/nns/layer/input.js +++ b/lib/model/nns/layer/input.js @@ -9,8 +9,8 @@ export default class InputLayer extends Layer { /** * @param {object} config object * @param {string} [config.name] Name of the layer - * @param {number[]} [config.size] Size of the layer - * @param {number | number[] | number[][] | nunber[][][] | number[][][][] | Matrix | Tensor} [config.value] Default value + * @param {(number | null)[]} [config.size] Size of the layer + * @param {number | number[] | number[][] | number[][][] | number[][][][] | Matrix | Tensor} [config.value] Default value */ constructor({ name = null, size = null, value, ...rest }) { super(rest) diff --git a/lib/model/nns/onnx/layer/reshape.js b/lib/model/nns/onnx/layer/reshape.js index 79b812ff5..be93a40f9 100644 --- a/lib/model/nns/onnx/layer/reshape.js +++ b/lib/model/nns/onnx/layer/reshape.js @@ -1,5 +1,4 @@ import { onnx } from '../onnx_exporter.js' -import { getConstNodeName } from '../utils.js' /** * Handle reshape layer diff --git a/lib/util/matrix.js b/lib/util/matrix.js index 2fa388250..a1f5e4245 100644 --- a/lib/util/matrix.js +++ b/lib/util/matrix.js @@ -27,7 +27,7 @@ export class MatrixException extends Error { /** * Matrix class - * @template [T=number] + * @template {*} [T=number] - Element type */ export default class Matrix { /** @@ -413,7 +413,7 @@ export default class Matrix { /** * Iterate over the elements. - * @returns {Generator} + * @yields {T} */ *[Symbol.iterator]() { yield* this._value @@ -2043,7 +2043,7 @@ export default class Matrix { /** * Returns diagonal elements. - * @returns {number[]} Diagonal values + * @returns {T[]} Diagonal values */ diag() { let d = [] diff --git a/tests/gui/helper/aimanager.js b/tests/gui/helper/aimanager.js index 5922cc8f0..7ac58a2ee 100644 --- a/tests/gui/helper/aimanager.js +++ b/tests/gui/helper/aimanager.js @@ -28,7 +28,7 @@ export default (page, option = {}) => { for (const key of propNames) { try { stack.push([obj[key], key, o]) - } catch (e) { + } catch { o[key] = 'error' } } @@ -43,7 +43,7 @@ export default (page, option = {}) => { if (descriptor.get) { try { stack.push([obj[key], key, o]) - } catch (e) { + } catch { o[key] = 'error' } } diff --git a/tests/lib/model/n_cubic_interpolation.test.js b/tests/lib/model/n_cubic_interpolation.test.js index 71a7f0024..c2e54a87b 100644 --- a/tests/lib/model/n_cubic_interpolation.test.js +++ b/tests/lib/model/n_cubic_interpolation.test.js @@ -100,36 +100,35 @@ test('interpolation 2d', () => { } } const y0 = model.predict(x0) - for (let i = 0, p = 0; i <= (n - 1) * 4; i++) { + let p = 0 + for (let i = 0; i < 4; i++) { + for (let j = 0; j <= (n - 1) * 4; j++, p++) { + expect(y0[p]).toBeNull() + } + } + for (let i = 4; i <= (n - 2) * 4; i++) { + for (let j = 0; j < 4; j++, p++) { + expect(y0[p]).toBeNull() + } + for (let j = 4; j <= (n - 2) * 4; j++, p++) { + const ps = [ + v[Math.floor(i / 4)][Math.floor(j / 4)], + v[Math.ceil(i / 4)][Math.floor(j / 4)], + v[Math.floor(i / 4)][Math.ceil(j / 4)], + v[Math.ceil(i / 4)][Math.ceil(j / 4)], + ] + const l = Math.min(...ps) + const h = Math.max(...ps) + expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5) + expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5) + } + for (let j = (n - 2) * 4 + 1; j <= (n - 1) * 4; j++, p++) { + expect(y0[p]).toBeNull() + } + } + for (let i = (n - 2) * 4 + 1; i <= (n - 1) * 4; i++) { for (let j = 0; j <= (n - 1) * 4; j++, p++) { - if (i / 4 < 1 || i / 4 > n - 2 || j / 4 < 1 || j / 4 > n - 2) { - expect(y0[p]).toBeNull() - } else if (Number.isInteger(i / 4) && Number.isInteger(j / 4)) { - expect(y0[p]).toBeCloseTo(v[i / 4][j / 4]) - } else if (Number.isInteger(i / 4)) { - const ps = [v[i / 4][Math.ceil(j / 4)], v[i / 4][Math.floor(j / 4)]] - const l = Math.min(...ps) - const h = Math.max(...ps) - expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5) - expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5) - } else if (Number.isInteger(j / 4)) { - const ps = [v[Math.ceil(i / 4)][j / 4], v[Math.floor(i / 4)][j / 4]] - const l = Math.min(...ps) - const h = Math.max(...ps) - expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5) - expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5) - } else { - const ps = [ - v[Math.floor(i / 4)][Math.floor(j / 4)], - v[Math.ceil(i / 4)][Math.floor(j / 4)], - v[Math.floor(i / 4)][Math.ceil(j / 4)], - v[Math.ceil(i / 4)][Math.ceil(j / 4)], - ] - const l = Math.min(...ps) - const h = Math.max(...ps) - expect(y0[p]).toBeGreaterThanOrEqual(l - (h - l) / 1.5) - expect(y0[p]).toBeLessThanOrEqual(h + (h - l) / 1.5) - } + expect(y0[p]).toBeNull() } } diff --git a/tests/lib/model/nns/onnx/layer/const.test.js b/tests/lib/model/nns/onnx/layer/const.test.js index 0d15ff8f6..897d35f00 100644 --- a/tests/lib/model/nns/onnx/layer/const.test.js +++ b/tests/lib/model/nns/onnx/layer/const.test.js @@ -3,7 +3,6 @@ ort.env.wasm.numThreads = 1 import ONNXExporter from '../../../../../../lib/model/nns/onnx/onnx_exporter.js' import constant from '../../../../../../lib/model/nns/onnx/layer/const.js' -import Matrix from '../../../../../../lib/util/matrix.js' describe('export', () => { test('1d array', () => { diff --git a/tests/lib/rl/grid.test.js b/tests/lib/rl/grid.test.js index d2b2ea747..5d929dfb0 100644 --- a/tests/lib/rl/grid.test.js +++ b/tests/lib/rl/grid.test.js @@ -57,11 +57,8 @@ describe('map', () => { for (let j = 0; j < 10; j++) { if ((i === 0 && j === 0) || (i === 19 && j === 9)) { continue - } else if (wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1) { - expect(map[i][j]).toBeTruthy() - } else { - expect(map[i][j]).toBeFalsy() } + expect(!!map[i][j]).toBe(wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1) } } }) diff --git a/tests/lib/rl/maze.test.js b/tests/lib/rl/maze.test.js index f465bce5f..8c2083df3 100644 --- a/tests/lib/rl/maze.test.js +++ b/tests/lib/rl/maze.test.js @@ -44,11 +44,8 @@ describe('map', () => { for (let j = 0; j < 10; j++) { if ((i === 0 && j === 0) || (i === 99 && j === 49)) { continue - } else if (wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1) { - expect(map[i][j]).toBeTruthy() - } else { - expect(map[i][j]).toBeFalsy() } + expect(!!map[i][j]).toBe(wall.reduce((s, v) => s + (v[0] === i && v[1] === j ? 1 : 0), 0) % 2 === 1) } } })