Expression Templates Library (ETL)
bias_add.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::impl::standard {
16 
23 template <typename A, typename B, typename C>
24 void bias_add_4d(const A& lhs, const B& rhs, C&& c) {
25  for (size_t i = 0; i < etl::dim<0>(lhs); ++i) {
26  for (size_t j = 0; j < etl::dim<1>(lhs); ++j) {
27  for (size_t k = 0; k < etl::dim<2>(lhs); ++k) {
28  for (size_t l = 0; l < etl::dim<3>(lhs); ++l) {
29  c(i, j, k, l) = lhs(i, j, k, l) + rhs(j);
30  }
31  }
32  }
33  }
34 }
35 
42 template <typename A, typename B, typename C>
43 void bias_add_2d(const A& lhs, const B& rhs, C&& c) {
44  for (size_t i = 0; i < etl::dim<0>(lhs); ++i) {
45  for (size_t j = 0; j < etl::dim<1>(lhs); ++j) {
46  c(i, j) = lhs(i, j) + rhs(j);
47  }
48  }
49 }
50 
51 } //end of namespace etl::impl::standard
Definition: prob_pooling.hpp:10
bias_add_2d_expr< detail::build_type< E >, detail::build_type< B > > bias_add_2d(const E &x, const B &biases)
Returns the result of adding the bias [K] to the 4D matrix [N1, K, N2, N3].
Definition: bias_add_2d_expr.hpp:378
bias_add_4d_expr< detail::build_type< E >, detail::build_type< B > > bias_add_4d(const E &x, const B &biases)
Returns the result of adding the bias [K] to the 4D matrix [N1, K, N2, N3].
Definition: bias_add_4d_expr.hpp:388