-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added layer tests and updated tests configs
- Loading branch information
Showing
8 changed files
with
109 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/sh | ||
|
||
rm -rf *.a *.o *.out | ||
rm -rf *.a *.o *.out ./build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
#include "layer.h" | ||
#include "../helpers/utils.h" | ||
#include <stdexcept> | ||
|
||
using Matrices::Matrix; | ||
using std::invalid_argument; | ||
using Utils::random; | ||
|
||
namespace Layers { | ||
unsigned int size; | ||
Matrix *values; | ||
|
||
InputLayer::InputLayer(unsigned int size){ | ||
Layer::Layer(unsigned int size){ | ||
this->size = size; | ||
this->values = new Matrix(1, size); | ||
for(unsigned int i = 0; i < size; i++) | ||
this->values->update_value(i, 0, random(-1, 1)); | ||
} | ||
|
||
void InputLayer::set_node_values(Matrix *values){ | ||
if(values->get_width() != 1 || values->get_height() != this->size) | ||
throw std::invalid_argument("Invalid values dimensions!"); | ||
Layer::Layer(Matrix *values){ | ||
if(values->get_width() != 1) | ||
throw invalid_argument("Invalid values dimensions!"); | ||
|
||
this->size = values->get_height(); | ||
this->values = values; | ||
} | ||
|
||
InputLayer::~InputLayer(){ | ||
Matrix* Layer::get_values(){ | ||
return this->values; | ||
} | ||
|
||
Layer::~Layer(){ | ||
delete this->values; | ||
} | ||
|
||
unsigned int Layer::get_size() const { | ||
return this->size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
#include "machine.h" | ||
#include "layer.h" | ||
#include <vector> | ||
|
||
using Machine::NN; | ||
using Layers::Layer; | ||
using std::vector; | ||
|
||
NN::NN(){} | ||
namespace Machine { | ||
vector<Layer*>* layers; | ||
|
||
void NN::add_layer(unsigned int size){ | ||
layers->push_back(new Layer(size)); | ||
} | ||
|
||
void NN::add_layer(Layer* layer){ | ||
layers->push_back(layer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include "layer.h" | ||
|
||
using Layers::Layer; | ||
using std::vector; | ||
|
||
namespace Machine { | ||
|
||
class NN{ | ||
|
||
public: | ||
NN(); | ||
void add_layer(unsigned int size); | ||
void add_layer(Layer* layer); | ||
|
||
private: | ||
|
||
vector<Layer*>* layers = new vector<Layer*>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "../machine/layer.h" | ||
#include <stdexcept> | ||
#include "../matrix/matrix.h" | ||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
using Matrices::Matrix; | ||
using Layers::Layer; | ||
using std::invalid_argument; | ||
using ::testing::AllOf; | ||
using ::testing::Ge; | ||
using ::testing::Le; | ||
|
||
namespace { | ||
|
||
TEST(CreationTest, CreateLayerBySizeTest){ | ||
Layer* layer = new Layer(3); | ||
ASSERT_EQ(layer->get_size(), 3); | ||
ASSERT_EQ(layer->get_values()->get_width(), 1); | ||
ASSERT_EQ(layer->get_values()->get_height(), 3); | ||
delete layer; | ||
} | ||
|
||
TEST(CreationTest, CreateLayerByMatrixTest){ | ||
Matrix* values = new Matrix(1, 3); | ||
Layer* layer = new Layer(values); | ||
|
||
ASSERT_EQ(layer->get_size(), 3); | ||
ASSERT_EQ(layer->get_values(), values); | ||
ASSERT_EQ(layer->get_values()->get_width(), 1); | ||
ASSERT_EQ(layer->get_values()->get_height(), 3); | ||
|
||
delete layer; | ||
} | ||
|
||
TEST(CreationTest, CreateLayerWithInvalidWidhtTest){ | ||
Matrix* values = new Matrix(3, 3); | ||
EXPECT_THROW({ new Layer(values); }, invalid_argument); | ||
delete values; | ||
} | ||
|
||
TEST(ValuesTest, GetValuesTest){ | ||
Layer *layer = new Layer(1); | ||
ASSERT_THAT(layer->get_values()->get_position_value(0, 0), AllOf(Ge(-1), Le(1))); | ||
delete layer; | ||
} | ||
|
||
} |