@@ -249,3 +249,86 @@ TEST(fclayer, new_fc_bias_and_weights_not_same) {
249249 std::vector<Tensor> out{output};
250250 EXPECT_THROW (layer.run (in, out), std::invalid_argument);
251251}
252+ TEST (fclayer, VectorSizeNotDivisibleByMatrixRows) {
253+ std::vector<float > weightsvec = {1 .0f , 2 .0f , 3 .0f , 4 .0f , 5 .0f , 6 .0f };
254+ Shape weights_shape ({3 , 2 });
255+ Tensor weights = make_tensor (weightsvec, weights_shape);
256+
257+ std::vector<float > biasvec = {0 .1f , 0 .2f };
258+ Tensor bias = make_tensor (biasvec, Shape ({2 }));
259+
260+ std::vector<float > input_vec = {1 .0f , 2 .0f , 3 .0f , 4 .0f , 5 .0f };
261+ Tensor input = make_tensor (input_vec, Shape ({5 }));
262+
263+ std::vector<float > output_vec (4 , 0 .0f );
264+ Tensor output = make_tensor (output_vec, Shape ({2 , 2 }));
265+
266+ FCLayer layer (weights, bias);
267+ std::vector<Tensor> in{input};
268+ std::vector<Tensor> out{output};
269+
270+ EXPECT_THROW (layer.run (in, out), std::invalid_argument);
271+ }
272+
273+ TEST (fclayer, VectorSizeNotDivisibleByMatrixRowsInt) {
274+ std::vector<int > weightsvec = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
275+ Shape weights_shape ({4 , 2 });
276+ Tensor weights = make_tensor (weightsvec, weights_shape);
277+
278+ std::vector<int > biasvec = {1 , 2 };
279+ Tensor bias = make_tensor (biasvec, Shape ({2 }));
280+
281+ std::vector<int > input_vec = {1 , 2 , 3 , 4 , 5 , 6 , 7 };
282+ Tensor input = make_tensor (input_vec, Shape ({7 }));
283+
284+ std::vector<int > output_vec (4 , 0 );
285+ Tensor output = make_tensor (output_vec, Shape ({2 , 2 }));
286+
287+ FCLayer layer (weights, bias);
288+ std::vector<Tensor> in{input};
289+ std::vector<Tensor> out{output};
290+
291+ EXPECT_THROW (layer.run (in, out), std::invalid_argument);
292+ }
293+
294+ TEST (fclayer, VectorSizeDivisibleByMatrixRows) {
295+ std::vector<float > weightsvec = {1 .0f , 2 .0f , 3 .0f , 4 .0f , 5 .0f , 6 .0f };
296+ Shape weights_shape ({3 , 2 });
297+ Tensor weights = make_tensor (weightsvec, weights_shape);
298+
299+ std::vector<float > biasvec = {0 .1f , 0 .2f };
300+ Tensor bias = make_tensor (biasvec, Shape ({2 }));
301+
302+ std::vector<float > input_vec = {1 .0f , 2 .0f , 3 .0f , 4 .0f , 5 .0f , 6 .0f };
303+ Tensor input = make_tensor (input_vec, Shape ({6 }));
304+
305+ std::vector<float > output_vec (4 , 0 .0f );
306+ Tensor output = make_tensor (output_vec, Shape ({2 , 2 }));
307+
308+ FCLayer layer (weights, bias);
309+ std::vector<Tensor> in{input};
310+ std::vector<Tensor> out{output};
311+
312+ EXPECT_NO_THROW (layer.run (in, out));
313+ }
314+
315+ TEST (fclayer, ZeroOutputNeuronsWithNonZeroInput) {
316+ std::vector<float > weightsvec = {};
317+ Shape weights_shape ({5 , 0 });
318+ Tensor weights = make_tensor (weightsvec, weights_shape);
319+
320+ std::vector<float > biasvec = {};
321+ Tensor bias = make_tensor (biasvec, Shape ({0 }));
322+
323+ std::vector<float > input_vec = {1 .0f , 2 .0f , 3 .0f , 4 .0f , 5 .0f };
324+ Tensor input = make_tensor (input_vec, Shape ({5 }));
325+
326+ std::vector<float > output_vec = {};
327+ Tensor output = make_tensor (output_vec, Shape ({0 }));
328+
329+ FCLayer layer (weights, bias);
330+ std::vector<Tensor> in{input};
331+ std::vector<Tensor> out{output};
332+
333+ EXPECT_THROW (layer.run (in, out), std::invalid_argument);
334+ }
0 commit comments