diff --git a/index.html b/index.html
index 717099e..93630ae 100644
--- a/index.html
+++ b/index.html
@@ -24,8 +24,22 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/advanced_activations/advanced_activations.js b/test/advanced_activations/advanced_activations.js
index bc65b56..e259c0a 100644
--- a/test/advanced_activations/advanced_activations.js
+++ b/test/advanced_activations/advanced_activations.js
@@ -1,6 +1,6 @@
/* eslint-env browser, mocha */
-describe('Layers: Advanced Activations', function () {
+describe('advanced activation layers', function () {
const assert = chai.assert
const styles = testGlobals.styles
const logTime = testGlobals.logTime
@@ -9,7 +9,7 @@ describe('Layers: Advanced Activations', function () {
const layers = KerasJS.layers
before(function () {
- console.log('\n%cLayers: Advanced Activations', styles.h1)
+ console.log('\n%cadvanced activation layers', styles.h1)
})
/*********************************************************
diff --git a/test/core/Activation.js b/test/core/Activation.js
new file mode 100644
index 0000000..ba5e477
--- /dev/null
+++ b/test/core/Activation.js
@@ -0,0 +1,54 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: Activation', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: Activation', styles.h1)
+ })
+
+ it('[core.Activation.0] should produce expected values for tanh activation following Dense layer', function () {
+ const key = 'core.Activation.0'
+ console.log(`\n%c[${key}] test 1 (tanh)`, styles.h3)
+ let testLayer1 = new layers.Dense(2)
+ testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ t = testLayer1.call(t)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ let testLayer2 = new layers.Activation('tanh')
+ const startTime = performance.now()
+ t = testLayer2.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Activation.1] should produce expected values for hardSigmoid activation following Dense layer', function () {
+ const key = 'core.Activation.1'
+ console.log(`\n%c[${key}] test 2 (hardSigmoid)`, styles.h3)
+ let testLayer1 = new layers.Dense(2)
+ testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ t = testLayer1.call(t)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ let testLayer2 = new layers.Activation('hardSigmoid')
+ const startTime = performance.now()
+ t = testLayer2.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+})
diff --git a/test/core/Dense.js b/test/core/Dense.js
new file mode 100644
index 0000000..0fd7fe9
--- /dev/null
+++ b/test/core/Dense.js
@@ -0,0 +1,142 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: Dense', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: Dense', styles.h1)
+ })
+
+ /*********************************************************
+ * CPU
+ *********************************************************/
+
+ describe('CPU', function () {
+ before(function () {
+ console.log('\n%cDense', styles.h2)
+ })
+
+ it('[core.Dense.0] [CPU] should produce expected values', function () {
+ const key = 'core.Dense.0'
+ console.log(`\n%c[${key}] [CPU] test 1`, styles.h3)
+ let testLayer = new layers.Dense(2)
+ testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Dense.1] [CPU] should produce expected values, with sigmoid activation function', function () {
+ const key = 'core.Dense.1'
+ console.log(`\n%c[${key}] [CPU] test 2 (with sigmoid activation)`, styles.h3)
+ let testLayer = new layers.Dense(2, { activation: 'sigmoid' })
+ testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Dense.2] [CPU] should produce expected values, with softplus activation function and no bias', function () {
+ const key = 'core.Dense.2'
+ console.log(`\n%c[${key}] [CPU] test 3 (with softplus activation and no bias)`, styles.h3)
+ let testLayer = new layers.Dense(2, { activation: 'softplus', bias: false })
+ testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+ })
+
+ /*********************************************************
+ * CPU
+ *********************************************************/
+
+ describe('CPU', function () {
+ before(function () {
+ console.log('\n%cDense', styles.h2)
+ })
+
+ it('[core.Dense.3] [GPU] should produce expected values', function () {
+ const key = 'core.Dense.3'
+ console.log(`\n%c[${key}] [GPU] test 1`, styles.h3)
+ let testLayer = new layers.Dense(2)
+ testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Dense.4] [GPU] should produce expected values, with sigmoid activation function', function () {
+ const key = 'core.Dense.4'
+ console.log(`\n%c[${key}] [GPU] test 2 (with sigmoid activation)`, styles.h3)
+ let testLayer = new layers.Dense(2, { activation: 'sigmoid' })
+ testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Dense.5] [GPU] should produce expected values, with softplus activation function and no bias', function () {
+ const key = 'core.Dense.5'
+ console.log(`\n%c[${key}] [GPU] test 3 (with softplus activation and no bias)`, styles.h3)
+ let testLayer = new layers.Dense(2, { activation: 'softplus', bias: false })
+ testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+ })
+})
diff --git a/test/core/Dropout.js b/test/core/Dropout.js
new file mode 100644
index 0000000..b24d7cf
--- /dev/null
+++ b/test/core/Dropout.js
@@ -0,0 +1,34 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: Dropout', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: Dropout', styles.h1)
+ })
+
+ it('[core.Dropout.0] should just pass through tensor during test time', function () {
+ const key = 'core.Dropout.0'
+ console.log(`\n%c[${key}] should pass through`, styles.h3)
+ let testLayer1 = new layers.Dense(2)
+ testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ t = testLayer1.call(t)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ let testLayer2 = new layers.Dropout(0.5)
+ const startTime = performance.now()
+ t = testLayer2.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+})
diff --git a/test/core/Flatten.js b/test/core/Flatten.js
new file mode 100644
index 0000000..6a5e1e9
--- /dev/null
+++ b/test/core/Flatten.js
@@ -0,0 +1,65 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: Flatten', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: Flatten', styles.h1)
+ })
+
+ it('[core.Flatten.0] should do nothing for 1D', function () {
+ const key = 'core.Flatten.0'
+ console.log(`\n%c[${key}] 1D`, styles.h3)
+ let testLayer = new layers.Flatten()
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Flatten.1] should flatten 2D', function () {
+ const key = 'core.Flatten.1'
+ console.log(`\n%c[${key}] 2D`, styles.h3)
+ let testLayer = new layers.Flatten()
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Flatten.2] should flatten 3D', function () {
+ const key = 'core.Flatten.2'
+ console.log(`\n%c[${key}] 3D`, styles.h3)
+ let testLayer = new layers.Flatten()
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+})
diff --git a/test/core/core.js b/test/core/Merge.js
similarity index 53%
rename from test/core/core.js
rename to test/core/Merge.js
index 5b4f1a5..552f9d3 100644
--- a/test/core/core.js
+++ b/test/core/Merge.js
@@ -1,6 +1,6 @@
/* eslint-env browser, mocha */
-describe('Layers: Core', function () {
+describe('core layer: Merge', function () {
const assert = chai.assert
const styles = testGlobals.styles
const logTime = testGlobals.logTime
@@ -9,407 +9,16 @@ describe('Layers: Core', function () {
const layers = KerasJS.layers
before(function () {
- console.log('\n%cLayers: Core', styles.h1)
+ console.log('\n%ccore layer: Merge', styles.h1)
})
/*********************************************************
- * Dense
+ * sum
*********************************************************/
- describe('Dense', function () {
+ describe('sum', function () {
before(function () {
- console.log('\n%cDense', styles.h2)
- })
-
- it('[core.Dense.0] [CPU] should produce expected values', function () {
- const key = 'core.Dense.0'
- console.log(`\n%c[${key}] [CPU] test 1`, styles.h3)
- let testLayer = new layers.Dense(2)
- testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Dense.1] [CPU] should produce expected values, with sigmoid activation function', function () {
- const key = 'core.Dense.1'
- console.log(`\n%c[${key}] [CPU] test 2 (with sigmoid activation)`, styles.h3)
- let testLayer = new layers.Dense(2, { activation: 'sigmoid' })
- testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Dense.2] [CPU] should produce expected values, with softplus activation function and no bias', function () {
- const key = 'core.Dense.2'
- console.log(`\n%c[${key}] [CPU] test 3 (with softplus activation and no bias)`, styles.h3)
- let testLayer = new layers.Dense(2, { activation: 'softplus', bias: false })
- testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Dense.3] [GPU] should produce expected values', function () {
- const key = 'core.Dense.3'
- console.log(`\n%c[${key}] [GPU] test 1`, styles.h3)
- let testLayer = new layers.Dense(2)
- testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Dense.4] [GPU] should produce expected values, with sigmoid activation function', function () {
- const key = 'core.Dense.4'
- console.log(`\n%c[${key}] [GPU] test 2 (with sigmoid activation)`, styles.h3)
- let testLayer = new layers.Dense(2, { activation: 'sigmoid' })
- testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Dense.5] [GPU] should produce expected values, with softplus activation function and no bias', function () {
- const key = 'core.Dense.5'
- console.log(`\n%c[${key}] [GPU] test 3 (with softplus activation and no bias)`, styles.h3)
- let testLayer = new layers.Dense(2, { activation: 'softplus', bias: false })
- testLayer.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape, { useWeblas: true })
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * Activation
- *********************************************************/
-
- describe('Activation', function () {
- before(function () {
- console.log('\n%cActivation', styles.h2)
- })
-
- it('[core.Activation.0] should produce expected values for tanh activation following Dense layer', function () {
- const key = 'core.Activation.0'
- console.log(`\n%c[${key}] test 1 (tanh)`, styles.h3)
- let testLayer1 = new layers.Dense(2)
- testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- t = testLayer1.call(t)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- let testLayer2 = new layers.Activation('tanh')
- const startTime = performance.now()
- t = testLayer2.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Activation.1] should produce expected values for hardSigmoid activation following Dense layer', function () {
- const key = 'core.Activation.1'
- console.log(`\n%c[${key}] test 2 (hardSigmoid)`, styles.h3)
- let testLayer1 = new layers.Dense(2)
- testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- t = testLayer1.call(t)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- let testLayer2 = new layers.Activation('hardSigmoid')
- const startTime = performance.now()
- t = testLayer2.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * Dropout
- *********************************************************/
-
- describe('Dropout', function () {
- before(function () {
- console.log('\n%cDropout', styles.h2)
- })
-
- it('[core.Dropout.0] should just pass through tensor during test time', function () {
- const key = 'core.Dropout.0'
- console.log(`\n%c[${key}] should pass through`, styles.h3)
- let testLayer1 = new layers.Dense(2)
- testLayer1.setWeights(TEST_DATA[key].weights.map(w => new KerasJS.Tensor(w.data, w.shape)))
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- t = testLayer1.call(t)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- let testLayer2 = new layers.Dropout(0.5)
- const startTime = performance.now()
- t = testLayer2.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * Flatten
- *********************************************************/
-
- describe('Flatten', function () {
- before(function () {
- console.log('\n%cFlatten', styles.h2)
- })
-
- it('[core.Flatten.0] should do nothing for 1D', function () {
- const key = 'core.Flatten.0'
- console.log(`\n%c[${key}] 1D`, styles.h3)
- let testLayer = new layers.Flatten()
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Flatten.1] should flatten 2D', function () {
- const key = 'core.Flatten.1'
- console.log(`\n%c[${key}] 2D`, styles.h3)
- let testLayer = new layers.Flatten()
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Flatten.2] should flatten 3D', function () {
- const key = 'core.Flatten.2'
- console.log(`\n%c[${key}] 3D`, styles.h3)
- let testLayer = new layers.Flatten()
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * Reshape
- *********************************************************/
-
- describe('Reshape', function () {
- before(function () {
- console.log('\n%cReshape', styles.h2)
- })
-
- it('[core.Reshape.0] should be able to go from shape [6] -> [2, 3]', function () {
- const key = 'core.Reshape.0'
- console.log(`\n%c[${key}] shape [6] -> [2, 3]`, styles.h3)
- let testLayer = new layers.Reshape([2, 3])
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Reshape.1] should be able to go from shape [3, 2] -> [6]', function () {
- const key = 'core.Reshape.1'
- console.log(`\n%c[${key}] shape [3, 2] -> [6]`, styles.h3)
- let testLayer = new layers.Reshape([6])
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Reshape.2] should be able to go from shape [3, 2, 2] -> [4, 3]', function () {
- const key = 'core.Reshape.2'
- console.log(`\n%c[${key}] shape [3, 2, 2] -> [4, 3]`, styles.h3)
- let testLayer = new layers.Reshape([4, 3])
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * Permute
- *********************************************************/
-
- describe('Permute', function () {
- before(function () {
- console.log('\n%cPermute', styles.h2)
- })
-
- it('[core.Permute.0] should be able to go from shape [3, 2] -> [2, 3]', function () {
- const key = 'core.Permute.0'
- console.log(`\n%c[${key}] shape [3, 2] -> [2, 3]`, styles.h3)
- let testLayer = new layers.Permute([2, 1])
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
-
- it('[core.Permute.1] should be able to go from shape [2, 3, 4] -> [4, 3, 2]', function () {
- const key = 'core.Permute.1'
- console.log(`\n%c[${key}] shape [2, 3, 4] -> [4, 3, 2]`, styles.h3)
- let testLayer = new layers.Permute([3, 2, 1])
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * RepeatVector
- *********************************************************/
-
- describe('RepeatVector', function () {
- before(function () {
- console.log('\n%cRepeatVector', styles.h2)
- })
-
- it('[core.RepeatVector.0] should be able to go from shape [6] -> [7, 6]', function () {
- const key = 'core.RepeatVector.0'
- console.log(`\n%c[${key}] repeat vector, shape [6] -> [7, 6]`, styles.h3)
- let testLayer = new layers.RepeatVector(7)
- let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
- console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
- const startTime = performance.now()
- t = testLayer.call(t)
- const endTime = performance.now()
- console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
- logTime(startTime, endTime)
- const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
- const shapeExpected = TEST_DATA[key].expected.shape
- assert.deepEqual(t.tensor.shape, shapeExpected)
- assert.isTrue(approxEquals(t.tensor, dataExpected))
- })
- })
-
- /*********************************************************
- * Merge
- *********************************************************/
-
- describe('Merge', function () {
- before(function () {
- console.log('\n%cMerge', styles.h2)
+ console.log('\n%csum', styles.h2)
})
it('[core.Merge.0] should produce expected values in sum mode', function () {
@@ -435,6 +44,16 @@ describe('Layers: Core', function () {
assert.deepEqual(t2.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t2.tensor, dataExpected))
})
+ })
+
+ /*********************************************************
+ * mul
+ *********************************************************/
+
+ describe('mul', function () {
+ before(function () {
+ console.log('\n%cmul', styles.h2)
+ })
it('[core.Merge.1] should produce expected values in mul mode', function () {
const key = 'core.Merge.1'
@@ -459,6 +78,16 @@ describe('Layers: Core', function () {
assert.deepEqual(t2.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t2.tensor, dataExpected))
})
+ })
+
+ /*********************************************************
+ * ave
+ *********************************************************/
+
+ describe('ave', function () {
+ before(function () {
+ console.log('\n%cave', styles.h2)
+ })
it('[core.Merge.2] should produce expected values in ave mode', function () {
const key = 'core.Merge.2'
@@ -483,6 +112,16 @@ describe('Layers: Core', function () {
assert.deepEqual(t2.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t2.tensor, dataExpected))
})
+ })
+
+ /*********************************************************
+ * max
+ *********************************************************/
+
+ describe('max', function () {
+ before(function () {
+ console.log('\n%cmax', styles.h2)
+ })
it('[core.Merge.3] should produce expected values in max mode', function () {
const key = 'core.Merge.3'
@@ -507,6 +146,16 @@ describe('Layers: Core', function () {
assert.deepEqual(t2.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t2.tensor, dataExpected))
})
+ })
+
+ /*********************************************************
+ * concat
+ *********************************************************/
+
+ describe('concat', function () {
+ before(function () {
+ console.log('\n%cconcat', styles.h2)
+ })
it('[core.Merge.4] should produce expected values in concat mode (1D)', function () {
const key = 'core.Merge.4'
@@ -643,6 +292,16 @@ describe('Layers: Core', function () {
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
+ })
+
+ /*********************************************************
+ * dot
+ *********************************************************/
+
+ describe('dot', function () {
+ before(function () {
+ console.log('\n%cdot', styles.h2)
+ })
it('[core.Merge.9] should produce expected values in dot mode (2D x 2D, dotAxes=1)', function () {
const key = 'core.Merge.9'
@@ -699,6 +358,16 @@ describe('Layers: Core', function () {
assert.deepEqual(t.tensor.shape, shapeExpected)
assert.isTrue(approxEquals(t.tensor, dataExpected))
})
+ })
+
+ /*********************************************************
+ * cos
+ *********************************************************/
+
+ describe('cos', function () {
+ before(function () {
+ console.log('\n%ccos', styles.h2)
+ })
it('[core.Merge.11] should produce expected values in cos mode (2D x 2D, dotAxes=1)', function () {
const key = 'core.Merge.11'
diff --git a/test/core/Permute.js b/test/core/Permute.js
new file mode 100644
index 0000000..fa8401c
--- /dev/null
+++ b/test/core/Permute.js
@@ -0,0 +1,48 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: Permute', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: Permute', styles.h1)
+ })
+
+ it('[core.Permute.0] should be able to go from shape [3, 2] -> [2, 3]', function () {
+ const key = 'core.Permute.0'
+ console.log(`\n%c[${key}] shape [3, 2] -> [2, 3]`, styles.h3)
+ let testLayer = new layers.Permute([2, 1])
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Permute.1] should be able to go from shape [2, 3, 4] -> [4, 3, 2]', function () {
+ const key = 'core.Permute.1'
+ console.log(`\n%c[${key}] shape [2, 3, 4] -> [4, 3, 2]`, styles.h3)
+ let testLayer = new layers.Permute([3, 2, 1])
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+})
diff --git a/test/core/RepeatVector.js b/test/core/RepeatVector.js
new file mode 100644
index 0000000..b4a53c3
--- /dev/null
+++ b/test/core/RepeatVector.js
@@ -0,0 +1,31 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: RepeatVector', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: RepeatVector', styles.h1)
+ })
+
+ it('[core.RepeatVector.0] should be able to go from shape [6] -> [7, 6]', function () {
+ const key = 'core.RepeatVector.0'
+ console.log(`\n%c[${key}] repeat vector, shape [6] -> [7, 6]`, styles.h3)
+ let testLayer = new layers.RepeatVector(7)
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+})
diff --git a/test/core/Reshape.js b/test/core/Reshape.js
new file mode 100644
index 0000000..fa09cbb
--- /dev/null
+++ b/test/core/Reshape.js
@@ -0,0 +1,65 @@
+/* eslint-env browser, mocha */
+
+describe('core layer: Reshape', function () {
+ const assert = chai.assert
+ const styles = testGlobals.styles
+ const logTime = testGlobals.logTime
+ const stringifyCondensed = testGlobals.stringifyCondensed
+ const approxEquals = KerasJS.testUtils.approxEquals
+ const layers = KerasJS.layers
+
+ before(function () {
+ console.log('\n%ccore layer: Reshape', styles.h1)
+ })
+
+ it('[core.Reshape.0] should be able to go from shape [6] -> [2, 3]', function () {
+ const key = 'core.Reshape.0'
+ console.log(`\n%c[${key}] shape [6] -> [2, 3]`, styles.h3)
+ let testLayer = new layers.Reshape([2, 3])
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Reshape.1] should be able to go from shape [3, 2] -> [6]', function () {
+ const key = 'core.Reshape.1'
+ console.log(`\n%c[${key}] shape [3, 2] -> [6]`, styles.h3)
+ let testLayer = new layers.Reshape([6])
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+
+ it('[core.Reshape.2] should be able to go from shape [3, 2, 2] -> [4, 3]', function () {
+ const key = 'core.Reshape.2'
+ console.log(`\n%c[${key}] shape [3, 2, 2] -> [4, 3]`, styles.h3)
+ let testLayer = new layers.Reshape([4, 3])
+ let t = new KerasJS.Tensor(TEST_DATA[key].input.data, TEST_DATA[key].input.shape)
+ console.log('%cin', styles.h4, stringifyCondensed(t.tensor))
+ const startTime = performance.now()
+ t = testLayer.call(t)
+ const endTime = performance.now()
+ console.log('%cout', styles.h4, stringifyCondensed(t.tensor))
+ logTime(startTime, endTime)
+ const dataExpected = new Float32Array(TEST_DATA[key].expected.data)
+ const shapeExpected = TEST_DATA[key].expected.shape
+ assert.deepEqual(t.tensor.shape, shapeExpected)
+ assert.isTrue(approxEquals(t.tensor, dataExpected))
+ })
+})
diff --git a/test/core/data_Activation.js b/test/core/data_Activation.js
new file mode 100644
index 0000000..29d069f
--- /dev/null
+++ b/test/core/data_Activation.js
@@ -0,0 +1,26 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.Activation.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [0.999999, -0.206966], shape: [2] }
+ },
+ 'core.Activation.1': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [1.0, 0.458], shape: [2] }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()
diff --git a/test/core/data_Dense.js b/test/core/data_Dense.js
new file mode 100644
index 0000000..983fab2
--- /dev/null
+++ b/test/core/data_Dense.js
@@ -0,0 +1,56 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.Dense.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [7.3, -0.21], shape: [2] }
+ },
+ 'core.Dense.1': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [0.999325, 0.447692], shape: [2] }
+ },
+ 'core.Dense.2': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] }
+ ],
+ expected: { data: [6.801113, 0.338274], shape: [2] }
+ },
+ 'core.Dense.3': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [7.3, -0.21], shape: [2] }
+ },
+ 'core.Dense.4': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [0.999325, 0.447692], shape: [2] }
+ },
+ 'core.Dense.5': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] }
+ ],
+ expected: { data: [6.801113, 0.338274], shape: [2] }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()
diff --git a/test/core/data_Dropout.js b/test/core/data_Dropout.js
new file mode 100644
index 0000000..3301305
--- /dev/null
+++ b/test/core/data_Dropout.js
@@ -0,0 +1,18 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.Dropout.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ weights: [
+ { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
+ { data: [0.5, 0.7], shape: [2] }
+ ],
+ expected: { data: [7.3, -0.21], shape: [2] }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()
diff --git a/test/core/data_Flatten.js b/test/core/data_Flatten.js
new file mode 100644
index 0000000..d80474a
--- /dev/null
+++ b/test/core/data_Flatten.js
@@ -0,0 +1,22 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.Flatten.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
+ },
+ 'core.Flatten.1': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
+ expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
+ },
+ 'core.Flatten.2': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2, 2] },
+ expected: { data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0], shape: [12] }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()
diff --git a/test/core/data_core.js b/test/core/data_Merge.js
similarity index 57%
rename from test/core/data_core.js
rename to test/core/data_Merge.js
index 2c1ef0b..f949450 100644
--- a/test/core/data_core.js
+++ b/test/core/data_Merge.js
@@ -4,121 +4,6 @@
(function () {
var DATA = {
- 'core.Dense.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [7.3, -0.21], shape: [2] }
- },
- 'core.Dense.1': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [0.999325, 0.447692], shape: [2] }
- },
- 'core.Dense.2': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] }
- ],
- expected: { data: [6.801113, 0.338274], shape: [2] }
- },
- 'core.Dense.3': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [7.3, -0.21], shape: [2] }
- },
- 'core.Dense.4': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [0.999325, 0.447692], shape: [2] }
- },
- 'core.Dense.5': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] }
- ],
- expected: { data: [6.801113, 0.338274], shape: [2] }
- },
- 'core.Activation.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [0.999999, -0.206966], shape: [2] }
- },
- 'core.Activation.1': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [1.0, 0.458], shape: [2] }
- },
- 'core.Dropout.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- weights: [
- { data: [0.1, 0.4, 0.5, 0.1, 1, -2, 0, 0.3, 0.2, 0.1, 3, 0], shape: [6, 2] },
- { data: [0.5, 0.7], shape: [2] }
- ],
- expected: { data: [7.3, -0.21], shape: [2] }
- },
- 'core.Flatten.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
- },
- 'core.Flatten.1': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
- expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
- },
- 'core.Flatten.2': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2, 2] },
- expected: { data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0], shape: [12] }
- },
- 'core.Reshape.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [2, 3] }
- },
- 'core.Reshape.1': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
- expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
- },
- 'core.Reshape.2': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2, 2] },
- expected: { data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0], shape: [4, 3] }
- },
- 'core.Permute.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
- expected: { data: [0.0, 0.5, 1.0, 0.2, -0.1, 2.0], shape: [2, 3] }
- },
- 'core.Permute.1': {
- input: {
- data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2],
- shape: [2, 3, 4]
- },
- expected: {
- data: [0.0, 0.0, 1.0, 1.0, 0.5, 0.5, 0.2, 0.2, 2.0, 2.0, -0.1, -0.1, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, -0.1, -0.1, 0.2, 0.2, 2.0, 2.0],
- shape: [4, 3, 2]
- }
- },
- 'core.RepeatVector.0': {
- input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
- expected: {
- data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0],
- shape: [7, 6]
- }
- },
'core.Merge.0': {
input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
weights: [
diff --git a/test/core/data_Permute.js b/test/core/data_Permute.js
new file mode 100644
index 0000000..124ec4c
--- /dev/null
+++ b/test/core/data_Permute.js
@@ -0,0 +1,24 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.Permute.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
+ expected: { data: [0.0, 0.5, 1.0, 0.2, -0.1, 2.0], shape: [2, 3] }
+ },
+ 'core.Permute.1': {
+ input: {
+ data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2],
+ shape: [2, 3, 4]
+ },
+ expected: {
+ data: [0.0, 0.0, 1.0, 1.0, 0.5, 0.5, 0.2, 0.2, 2.0, 2.0, -0.1, -0.1, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, -0.1, -0.1, 0.2, 0.2, 2.0, 2.0],
+ shape: [4, 3, 2]
+ }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()
diff --git a/test/core/data_RepeatVector.js b/test/core/data_RepeatVector.js
new file mode 100644
index 0000000..001a64a
--- /dev/null
+++ b/test/core/data_RepeatVector.js
@@ -0,0 +1,17 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.RepeatVector.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ expected: {
+ data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0],
+ shape: [7, 6]
+ }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()
diff --git a/test/core/data_Reshape.js b/test/core/data_Reshape.js
new file mode 100644
index 0000000..ab44b97
--- /dev/null
+++ b/test/core/data_Reshape.js
@@ -0,0 +1,22 @@
+// TEST DATA
+// Keyed by mocha test ID
+// Python code for generating test data can be found in the matching jupyter notebook in folder `notebooks/`.
+
+(function () {
+ var DATA = {
+ 'core.Reshape.0': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] },
+ expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [2, 3] }
+ },
+ 'core.Reshape.1': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2] },
+ expected: { data: [0, 0.2, 0.5, -0.1, 1, 2], shape: [6] }
+ },
+ 'core.Reshape.2': {
+ input: { data: [0, 0.2, 0.5, -0.1, 1, 2, 0, 0.2, 0.5, -0.1, 1, 2], shape: [3, 2, 2] },
+ expected: { data: [0.0, 0.2, 0.5, -0.1, 1.0, 2.0, 0.0, 0.2, 0.5, -0.1, 1.0, 2.0], shape: [4, 3] }
+ }
+ }
+
+ window.TEST_DATA = Object.assign({}, window.TEST_DATA, DATA)
+})()