ceras
yet another deep learning engine
place_holder.hpp
Go to the documentation of this file.
1 #ifndef JPSBQEEADUPURARCCBVXOLXVMQHTNWCQWXUKKHCOTWFGOGXSODKEEYLSSTFGTVXNBROLKKEJM
2 #define JPSBQEEADUPURARCCBVXOLXVMQHTNWCQWXUKKHCOTWFGOGXSODKEEYLSSTFGTVXNBROLKKEJM
3 
4 #include "./includes.hpp"
5 #include "./tensor.hpp"
6 #include "./utils/better_assert.hpp"
7 #include "./utils/debug.hpp"
8 #include "./utils/id.hpp"
9 #include "./utils/enable_shared.hpp"
10 #include "./utils/state.hpp"
11 
12 namespace ceras
13 {
14 
15  template< Tensor Tsor >
17  {
18  Tsor data_;
19  std::vector< unsigned long> shape_hint_;
20  };
21 
22  template< Tensor Tsor >
23  struct place_holder : enable_id< place_holder<Tsor>, "PlaceHolder" >, enable_shared_state<place_holder<Tsor>, place_holder_state<Tsor>>
24  {
25  typedef Tsor tensor_type;
26 
27  place_holder( place_holder const& other) = default;
28  place_holder( place_holder && other) = default;
29  place_holder& operator = ( place_holder const& other) = default;
30  place_holder& operator = ( place_holder && other) = default;
31 
33  {
34  (*this).state_ = std::make_shared<place_holder_state<Tsor>>();
35  }
36 
37  place_holder( std::vector<unsigned long> const& shape_hint )
38  {
39  (*this).state_ = std::make_shared<place_holder_state<Tsor>>();
40  (*((*this).state_)).shape_hint_ = shape_hint;
41  }
42 
43  void bind( Tsor data )
44  {
45  better_assert( (*this).state_, "Error with empty state." );
46  (*((*this).state_)).data_ = data;
47  }
48 
49  Tsor const forward() const
50  {
51  better_assert( (*this).state_, "Error with empty state." );
52  better_assert( !((*((*this).state_)).data_.empty()), "Error with empty tensor." );
53  return (*((*this).state_)).data_;
54  }
55 
56  void reset() { }
57 
58  void backward( auto ) const noexcept { }
59  };
60 
61  template< typename T >
62  struct is_place_holder : std::false_type {};
63 
64  template< Tensor Tsor >
65  struct is_place_holder< place_holder< Tsor > > : std::true_type {};
66 
67  template< class T >
69 
70  template< typename T >
71  concept Place_Holder = is_place_holder_v<T>;
72 
73  template< Place_Holder Ph >
74  bool operator == ( Ph const& lhs, Ph const& rhs )
75  {
76  return lhs.id() == rhs.id();
77  }
78 
79  template< Place_Holder Ph >
80  bool operator != ( Ph const& lhs, Ph const& rhs )
81  {
82  return lhs.id() != rhs.id();
83  }
84 
85  template< Place_Holder Ph >
86  bool operator < ( Ph const& lhs, Ph const& rhs )
87  {
88  return lhs.id() < rhs.id();
89  }
90 
91  template< Place_Holder Ph >
92  bool operator > ( Ph const& lhs, Ph const& rhs )
93  {
94  return lhs.id() < rhs.id();
95  }
96 
97  template< Place_Holder Ph >
98  bool operator <= ( Ph const& lhs, Ph const& rhs )
99  {
100  return lhs.id() <= rhs.id();
101  }
102 
103  template< Place_Holder Ph >
104  bool operator >= ( Ph const& lhs, Ph const& rhs )
105  {
106  return lhs.id() >= rhs.id();
107  }
108 
109 }//namespace ceras
110 
111 #endif//JPSBQEEADUPURARCCBVXOLXVMQHTNWCQWXUKKHCOTWFGOGXSODKEEYLSSTFGTVXNBROLKKEJM
112 
Definition: activation.hpp:12
concept Place_Holder
Definition: place_holder.hpp:71
constexpr bool is_place_holder_v
Definition: place_holder.hpp:68
bool operator>(Ph const &lhs, Ph const &rhs)
Definition: place_holder.hpp:92
bool operator!=(Ph const &lhs, Ph const &rhs)
Definition: place_holder.hpp:80
bool operator<(Ph const &lhs, Ph const &rhs)
Definition: place_holder.hpp:86
bool operator>=(Ph const &lhs, Ph const &rhs)
Definition: place_holder.hpp:104
bool operator==(Ph const &lhs, Ph const &rhs)
Definition: place_holder.hpp:74
bool operator<=(Ph const &lhs, Ph const &rhs)
Definition: place_holder.hpp:98
Definition: place_holder.hpp:62
Definition: place_holder.hpp:17
std::vector< unsigned long > shape_hint_
Definition: place_holder.hpp:19
Tsor data_
Definition: place_holder.hpp:18
Definition: place_holder.hpp:24
place_holder()
Definition: place_holder.hpp:32
place_holder(place_holder const &other)=default
place_holder & operator=(place_holder const &other)=default
void bind(Tsor data)
Definition: place_holder.hpp:43
Tsor tensor_type
Definition: place_holder.hpp:25
Tsor const forward() const
Definition: place_holder.hpp:49
place_holder(std::vector< unsigned long > const &shape_hint)
Definition: place_holder.hpp:37
void backward(auto) const noexcept
Definition: place_holder.hpp:58
place_holder(place_holder &&other)=default
void reset()
Definition: place_holder.hpp:56