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
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
coverage/**
coverage-gui/**
lib/model/nns/onnx/onnx_pb.js
onnx_tmp/**
2 changes: 1 addition & 1 deletion create_import_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
Expand Down
2 changes: 1 addition & 1 deletion lib/model/nns/layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } |
Expand Down
4 changes: 2 additions & 2 deletions lib/model/nns/layer/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lib/model/nns/onnx/layer/reshape.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { onnx } from '../onnx_exporter.js'
import { getConstNodeName } from '../utils.js'

/**
* Handle reshape layer
Expand Down
6 changes: 3 additions & 3 deletions lib/util/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class MatrixException extends Error {

/**
* Matrix class
* @template [T=number]
* @template {*} [T=number] - Element type
*/
export default class Matrix {
/**
Expand Down Expand Up @@ -413,7 +413,7 @@ export default class Matrix {

/**
* Iterate over the elements.
* @returns {Generator<T>}
* @yields {T}
*/
*[Symbol.iterator]() {
yield* this._value
Expand Down Expand Up @@ -2043,7 +2043,7 @@ export default class Matrix {

/**
* Returns diagonal elements.
* @returns {number[]} Diagonal values
* @returns {T[]} Diagonal values
*/
diag() {
let d = []
Expand Down
4 changes: 2 additions & 2 deletions tests/gui/helper/aimanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand All @@ -43,7 +43,7 @@ export default (page, option = {}) => {
if (descriptor.get) {
try {
stack.push([obj[key], key, o])
} catch (e) {
} catch {
o[key] = 'error'
}
}
Expand Down
57 changes: 28 additions & 29 deletions tests/lib/model/n_cubic_interpolation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/lib/model/nns/onnx/layer/const.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 1 addition & 4 deletions tests/lib/rl/grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
Expand Down
5 changes: 1 addition & 4 deletions tests/lib/rl/maze.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
Expand Down