ceras
yet another deep learning engine
value.hpp
Go to the documentation of this file.
1 #ifndef VALUE_HPP_INCLUDED_DS9P8IU4LKJASDOIPUY498YAFKASHFAS9F8Y4OKHDAFSIUOHASDFFS
2 #define VALUE_HPP_INCLUDED_DS9P8IU4LKJASDOIPUY498YAFKASHFAS9F8Y4OKHDAFSIUOHASDFFS
3 
4 #include "./includes.hpp"
5 #include "./tensor.hpp"
6 #include "./utils/id.hpp"
7 #include "./utils/better_assert.hpp"
8 #include "./utils/enable_shared.hpp"
9 
10 namespace ceras
11 {
12 
13  template< typename T > requires std::floating_point<T>
14  struct value : enable_id< value<T>, "Value" >
15  {
16  typedef T value_type;
18 
19  value() = delete;
20  value( value_type v ) noexcept : enable_id<value<T>, "Value">{}, data_{ v } {}
21  value( value const& ) noexcept = default;
22  value( value && ) noexcept = default;
23  value& operator =( value const& ) noexcept = default;
24  value& operator =( value && ) noexcept = default;
25 
26  void backward( auto ) noexcept { }
27 
28  template< Tensor Tsor >
29  Tsor const forward( Tsor const& refer ) const
30  {
31  Tsor ans = ones_like( refer ); // cast it to a tensor
32  ans *= data_;
33  return ans;
34  }
35  };//struct value
36 
37  template< typename T >
38  struct is_value : std::false_type {};
39 
40  template< typename T >
41  struct is_value< value< T > > : std::true_type {};
42 
43  template< class T >
44  inline constexpr bool is_value_v = is_value<T>::value;
45 
46  template< typename T >
47  concept Value = is_value_v<T>;
48 
49 
50  // for tensor_type deduction in a binary operator
51  template< typename L, typename R >
53  {
54  using op_type = std::conditional<is_value_v<L>, R, L>::type;
55  using tensor_type = std::remove_cv_t<decltype(std::declval<op_type>().forward())>;
56  };
57 
58 
59 }//namespace ceras
60 
61 #endif//VALUE_HPP_INCLUDED_DS9P8IU4LKJASDOIPUY498YAFKASHFAS9F8Y4OKHDAFSIUOHASDFFS
62 
Definition: activation.hpp:12
constexpr Tsor ones_like(Tsor const &tsor)
Definition: tensor.hpp:1002
concept Value
Definition: value.hpp:47
constexpr bool is_value_v
Definition: value.hpp:44
Definition: value.hpp:38
Definition: value.hpp:53
std::conditional< is_value_v< L >, R, L >::type op_type
Definition: value.hpp:54
std::remove_cv_t< decltype(std::declval< op_type >().forward())> tensor_type
Definition: value.hpp:55
Definition: value.hpp:15
value(value_type v) noexcept
Definition: value.hpp:20
T value_type
Definition: value.hpp:16
value(value &&) noexcept=default
value_type data_
Definition: value.hpp:17
Tsor const forward(Tsor const &refer) const
Definition: value.hpp:29
value()=delete
void backward(auto) noexcept
Definition: value.hpp:26
value(value const &) noexcept=default