Expression Templates Library (ETL)
conv_deep.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
13 #pragma once
14 
15 namespace etl::detail {
16 
20 template <size_t S1, size_t S2, size_t P1, size_t P2>
28  template <typename I, typename K, typename C>
29  static void apply(const I& input, const K& kernel, C&& conv) {
30  if constexpr (is_3d<I>) {
31  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
32  conv(i) = conv_2d_valid<S1, S2, P1, P2>(input(i), kernel(i));
33  }
34  } else {
35  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
36  apply(input(i), kernel(i), conv(i));
37  }
38  }
39  }
40 };
41 
45 template <size_t S1, size_t S2, size_t P1, size_t P2>
53  template <typename I, typename K, typename C>
54  static void apply(const I& input, const K& kernel, C&& conv) {
55  if constexpr (is_3d<I>) {
56  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
57  conv(i) = conv_2d_valid_flipped<S1, S2, P1, P2>(input(i), kernel(i));
58  }
59  } else {
60  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
61  apply(input(i), kernel(i), conv(i));
62  }
63  }
64  }
65 };
66 
77  template <typename I, typename K, typename C>
78  static void apply(const I& input, const K& kernel, C&& conv) {
79  if constexpr (is_3d<I>) {
80  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
81  conv(i) = conv_2d_same(input(i), kernel(i));
82  }
83  } else {
84  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
85  apply(input(i), kernel(i), conv(i));
86  }
87  }
88  }
89 };
90 
101  template <typename I, typename K, typename C>
102  static void apply(const I& input, const K& kernel, C&& conv) {
103  if constexpr (is_3d<I>) {
104  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
105  conv(i) = conv_2d_same_flipped(input(i), kernel(i));
106  }
107  } else {
108  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
109  apply(input(i), kernel(i), conv(i));
110  }
111  }
112  }
113 };
114 
125  template <typename I, typename K, typename C>
126  static void apply(const I& input, const K& kernel, C&& conv) {
127  if constexpr (is_3d<I>) {
128  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
129  conv(i) = conv_2d_full(input(i), kernel(i));
130  }
131  } else {
132  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
133  apply(input(i), kernel(i), conv(i));
134  }
135  }
136  }
137 };
138 
149  template <typename I, typename K, typename C>
150  static void apply(const I& input, const K& kernel, C&& conv) {
151  if constexpr (is_3d<I>) {
152  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
153  conv(i) = conv_2d_full_flipped(input(i), kernel(i));
154  }
155  } else {
156  for (size_t i = 0; i < etl::dim<0>(input); ++i) {
157  apply(input(i), kernel(i), conv(i));
158  }
159  }
160  }
161 };
162 
163 } //end of namespace etl::detail
The functor impl for 2D+ conv.
Definition: conv_deep.hpp:21
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_deep.hpp:102
The functor impl for 2D+ conv.
Definition: conv_deep.hpp:46
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_deep.hpp:54
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_deep.hpp:78
Definition: expression_builder.hpp:699
conv_2d_full_expr< detail::build_type< A >, detail::build_type< B >, true > conv_2d_full_flipped(A &&a, B &&b)
Creates an expression representing the &#39;full&#39; 1D convolution of a and flipped b.
Definition: conv_2d_full_expr.hpp:273
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_deep.hpp:150
The functor impl for 2D+ conv.
Definition: conv_deep.hpp:94
The functor impl for 2D+ conv.
Definition: conv_deep.hpp:142
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_deep.hpp:126
The functor impl for 2D+ conv.
Definition: conv_deep.hpp:118
The functor impl for 2D+ conv.
Definition: conv_deep.hpp:70
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_deep.hpp:29
conv_2d_full_expr< detail::build_type< A >, detail::build_type< B >, false > conv_2d_full(A &&a, B &&b)
Creates an expression representing the &#39;full&#39; 1D convolution of a and b.
Definition: conv_2d_full_expr.hpp:238
conv_2d_same_expr< detail::build_type< A >, detail::build_type< B >, false > conv_2d_same(A &&a, B &&b)
Creates an expression representing the &#39;same&#39; 1D convolution of a and b.
Definition: conv_2d_same_expr.hpp:238
conv_2d_same_expr< detail::build_type< A >, detail::build_type< B >, true > conv_2d_same_flipped(A &&a, B &&b)
Creates an expression representing the &#39;same&#39; 1D convolution of a and flipped b.
Definition: conv_2d_same_expr.hpp:273