55#include < string>
66#include < vector>
77
8- namespace itlab_2023 {
9-
10- enum LayerType {
11- kInput ,
12- kPooling ,
13- kNormalization ,
14- kDropout ,
15- kElementWise ,
16- kConvolution ,
17- kFullyConnected ,
18- kOutput
19- };
20-
21- class LayerExample {
22- private:
23- int id_;
24- std::string name_;
25- LayerType type_;
26- std::string version_;
27- int numInputs_;
28- int numNeurons_;
29- std::vector<int > primer_;
8+ #include " layers/Layer.hpp"
309
31- public:
32- LayerExample (LayerType type1) : type_(type1) {}
33- LayerType getType () { return type_; }
34- int getNumInputs () const { return numInputs_; }
35- int getNumNeurons () const { return numNeurons_; }
36- int checkID () const { return id_; }
37- void giveID (int id1) { id_ = id1; }
38- void In (const std::vector<int >& a) { primer_ = a; }
39- void Work () {}
40- std::vector<int > Out () { return primer_; }
41- };
10+ namespace itlab_2023 {
4211
4312class Graph {
4413 int BiggestSize_;
4514 int V_ ;
46- std::vector<LayerExample > layers_;
15+ std::vector<Layer* > layers_;
4716 std::vector<int > arrayV_;
4817 std::vector<int > arrayE_;
49- std::vector< int > startvec_ ;
50- std::vector< int >* outvector_ ;
18+ Tensor inten_ ;
19+ Tensor* outten_ ;
5120 int start_;
5221 int end_;
5322
@@ -59,35 +28,34 @@ class Graph {
5928 arrayV_.push_back (0 );
6029 V_ = 0 ;
6130 }
62- void setInput (LayerExample & lay, const std::vector< int > & vec) {
63- lay.giveID (0 );
64- layers_.push_back (lay);
31+ void setInput (Layer & lay, Tensor & vec) {
32+ lay.setID (0 );
33+ layers_.push_back (& lay);
6534 arrayV_.push_back (0 );
66- startvec_ = vec;
67- start_ = lay.checkID ();
35+ inten_ = vec;
36+ start_ = lay.getID ();
6837 V_ ++;
6938 }
70- void makeConnection (const LayerExample & layPrev, LayerExample & layNext) {
71- layNext.giveID (V_ );
72- layers_.push_back (layNext);
39+ void makeConnection (const Layer & layPrev, Layer & layNext) {
40+ layNext.setID (V_ );
41+ layers_.push_back (& layNext);
7342 arrayV_[V_ ] = arrayV_[V_ - 1 ];
7443 arrayV_.push_back (static_cast <int >(arrayE_.size ()));
75- if (layPrev.checkID () == layNext.checkID ()) {
44+ if (layPrev.getID () == layNext.getID ()) {
7645 throw std::out_of_range (" i=j cant add edge" );
7746 }
7847 for (int ind = 1 ; ind < static_cast <int >(arrayV_.size ()) -
79- static_cast <int >(layPrev.checkID ()) - 1 ;
48+ static_cast <int >(layPrev.getID ()) - 1 ;
8049 ind++)
81- arrayV_[layPrev.checkID () + ind]++;
82- arrayE_.insert (arrayE_.begin () + arrayV_[layPrev.checkID ()],
83- layNext.checkID ());
50+ arrayV_[layPrev.getID () + ind]++;
51+ arrayE_.insert (arrayE_.begin () + arrayV_[layPrev.getID ()], layNext.getID ());
8452 V_ ++;
8553 arrayV_[V_ ] = static_cast <int >(arrayE_.size ());
8654 }
87- bool areLayerNext (const LayerExample & layPrev, const LayerExample & layNext) {
88- for (int i = arrayV_[layPrev.checkID ()]; i < arrayV_[layPrev.checkID () + 1 ];
55+ bool areLayerNext (const Layer & layPrev, const Layer & layNext) {
56+ for (int i = arrayV_[layPrev.getID ()]; i < arrayV_[layPrev.getID () + 1 ];
8957 i++) {
90- if (arrayE_[i] == layNext.checkID ()) {
58+ if (arrayE_[i] == layNext.getID ()) {
9159 return true ;
9260 }
9361 }
@@ -122,15 +90,13 @@ class Graph {
12290 }
12391 }
12492 for (int i : traversal) {
125- layers_[i].In (startvec_);
126- layers_[i].Work ();
127- startvec_ = layers_[i].Out ();
93+ layers_[i]->run (inten_, *outten_);
94+ inten_ = *outten_;
12895 }
129- outvector_->assign (startvec_.begin (), startvec_.end ());
13096 }
131- void setOutput (const LayerExample & lay, std::vector< int > & vec) {
132- end_ = lay.checkID ();
133- outvector_ = &vec;
97+ void setOutput (const Layer & lay, Tensor & vec) {
98+ end_ = lay.getID ();
99+ outten_ = &vec;
134100 }
135101};
136102} // namespace itlab_2023
0 commit comments