@@ -67,6 +67,13 @@ describe('NeuralNetworkGPU', () => {
67
67
describe ( 'mocked GPU mode' , ( ) => {
68
68
it ( 'converts Textures to Arrays of numbers' , ( ) => {
69
69
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
+
70
77
net . train (
71
78
[
72
79
{ input : [ 1 , 2 ] , output : [ 3 ] } ,
@@ -75,17 +82,19 @@ describe('NeuralNetworkGPU', () => {
75
82
] ,
76
83
{ iterations : 1 }
77
84
) ;
85
+
78
86
expect ( net . weights . length ) . toBe ( 3 ) ;
79
87
for ( let i = 1 ; i < net . weights . length ; i ++ ) {
80
- expect ( net . weights [ i ] ) . toBeInstanceOf ( Texture ) ;
88
+ expect ( net . weights [ i ] ) . toBeInstanceOf ( expectedWeightsType ) ;
81
89
}
82
90
83
91
expect ( net . biases . length ) . toBe ( 3 ) ;
84
92
for ( let i = 1 ; i < net . biases . length ; i ++ ) {
85
- expect ( net . biases [ i ] ) . toBeInstanceOf ( Texture ) ;
93
+ expect ( net . biases [ i ] ) . toBeInstanceOf ( expectedBiasesType ) ;
86
94
}
87
95
const json = net . toJSON ( ) ;
88
96
expect ( json . layers . length ) . toBe ( 3 ) ;
97
+
89
98
for ( let i = 1 ; i < json . layers . length ; i ++ ) {
90
99
const layer = json . layers [ i ] ;
91
100
expect ( layer . weights ) . toBeInstanceOf ( Array ) ;
0 commit comments