Skip to content

Commit 9616d4c

Browse files
author
Bar Admoni
committed
Trying to fix converts Textures to Arrays of numbers
1 parent 66056fb commit 9616d4c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org

src/neural-network-gpu.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ describe('NeuralNetworkGPU', () => {
6767
describe('mocked GPU mode', () => {
6868
it('converts Textures to Arrays of numbers', () => {
6969
const net = new NeuralNetworkGPU();
70+
const isUsingGPU = net.gpu.mode === 'gpu';
71+
72+
// When running in a machine with GPU, will the type will be `Texture`
73+
// The CI is running on machines WITHOUT GPUs, so in the case of mocking the GPU the return type will be a bit different
74+
const expectedWeightsType = isUsingGPU ? Texture : Array;
75+
const expectedBiasesType = isUsingGPU ? Texture : Float32Array;
76+
7077
net.train(
7178
[
7279
{ input: [1, 2], output: [3] },
@@ -75,17 +82,19 @@ describe('NeuralNetworkGPU', () => {
7582
],
7683
{ iterations: 1 }
7784
);
85+
7886
expect(net.weights.length).toBe(3);
7987
for (let i = 1; i < net.weights.length; i++) {
80-
expect(net.weights[i]).toBeInstanceOf(Texture);
88+
expect(net.weights[i]).toBeInstanceOf(expectedWeightsType);
8189
}
8290

8391
expect(net.biases.length).toBe(3);
8492
for (let i = 1; i < net.biases.length; i++) {
85-
expect(net.biases[i]).toBeInstanceOf(Texture);
93+
expect(net.biases[i]).toBeInstanceOf(expectedBiasesType);
8694
}
8795
const json = net.toJSON();
8896
expect(json.layers.length).toBe(3);
97+
8998
for (let i = 1; i < json.layers.length; i++) {
9099
const layer = json.layers[i];
91100
expect(layer.weights).toBeInstanceOf(Array);

0 commit comments

Comments
 (0)