Skip to content

Commit

Permalink
Continue concepts
Browse files Browse the repository at this point in the history
wichtounet committed Oct 26, 2023
1 parent 17cae77 commit e026a9e
Showing 3 changed files with 36 additions and 35 deletions.
14 changes: 7 additions & 7 deletions include/etl/impl/common/conv.hpp
Original file line number Diff line number Diff line change
@@ -269,7 +269,7 @@ etl::dyn_matrix<value_t<I>, 2> pad_right_flip(const I& input, size_t pad) {
* \param pad The number of padding elements
* \return a new matrix containing the result
*/
template <typename I, cpp_enable_iff(is_3d<I>)>
template <etl_3d I>
etl::dyn_matrix<value_t<I>, 3> pad_right_multi(const I& input, size_t pad) {
using T = value_t<I>;

@@ -296,7 +296,7 @@ etl::dyn_matrix<value_t<I>, 3> pad_right_multi(const I& input, size_t pad) {
* \param pad The number of padding elements
* \return a new matrix containing the result
*/
template <typename I, cpp_enable_iff(is_4d<I>)>
template <etl_4d I>
etl::dyn_matrix<value_t<I>, 4> pad_right_multi(const I& input, size_t pad) {
using T = value_t<I>;

@@ -335,7 +335,7 @@ etl::dyn_matrix<value_t<I>, 4> pad_right_multi(const I& input, size_t pad) {
*
* \return a new matrix containing the result
*/
template <typename I, cpp_enable_iff(is_4d<I>)>
template <etl_4d I>
etl::dyn_matrix<value_t<I>, 4> pad_right_multi_double(const I& input, size_t pad, size_t p1, size_t p2) {
using T = value_t<I>;

@@ -371,7 +371,7 @@ etl::dyn_matrix<value_t<I>, 4> pad_right_multi_double(const I& input, size_t pad
* \param pad The number of padding elements
* \return a new matrix containing the result
*/
template <typename I, cpp_enable_iff(is_3d<I>)>
template <etl_3d I>
etl::dyn_matrix<value_t<I>, 3> pad_right_flip_multi(const I& input, size_t pad) {
using T = value_t<I>;

@@ -406,7 +406,7 @@ etl::dyn_matrix<value_t<I>, 3> pad_right_flip_multi(const I& input, size_t pad)
* \param pad The number of padding elements
* \return a new matrix containing the result
*/
template <typename I, cpp_enable_iff(is_4d<I>)>
template <etl_4d I>
etl::dyn_matrix<value_t<I>, 4> pad_right_flip_multi(const I& input, size_t pad) {
using T = value_t<I>;

@@ -456,7 +456,7 @@ etl::dyn_matrix<value_t<I>, 4> pad_right_flip_multi(const I& input, size_t pad)
* \return A matrix containing the same elements as the input with some innner
* padding.
*/
template <typename I, cpp_enable_iff(etl::dimensions<I>() == 2)>
template <etl_2d I>
etl::dyn_matrix<value_t<I>, 2> inner_pad(const I& in, size_t s1, size_t s2) {
etl::dyn_matrix<value_t<I>, 2> result((etl::dim<0>(in) - 1) * s1 + 1, (etl::dim<1>(in) - 1) * s2 + 1);

@@ -486,7 +486,7 @@ etl::dyn_matrix<value_t<I>, 2> inner_pad(const I& in, size_t s1, size_t s2) {
* \return A matrix containing the same elements as the input with some innner
* padding.
*/
template <typename I, cpp_enable_iff(etl::dimensions<I>() == 4)>
template <etl_4d I>
etl::dyn_matrix<value_t<I>, 4> inner_pad(const I& in, size_t s1, size_t s2) {
etl::dyn_matrix<value_t<I>, 4> result(etl::dim<0>(in), etl::dim<1>(in), (etl::dim<2>(in) - 1) * s1 + 1, (etl::dim<3>(in) - 1) * s2 + 1);

29 changes: 15 additions & 14 deletions include/etl/impl/std/avg_pooling_upsample.hpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@

#pragma once

#include "etl/concepts.hpp"
namespace etl::impl::standard {

/*!
@@ -322,7 +323,7 @@ struct avg_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(is_2d<A>)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_2d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m) {
if constexpr (S1 != C1 || S2 != C2) {
m = 0;
@@ -342,7 +343,7 @@ struct avg_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_2d<A>)>
template <etl_2d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
if (s1 != c1 || s2 != c2) {
m = 0;
@@ -364,7 +365,7 @@ struct avg_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_3d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m) {
if constexpr (S1 != C1 || S2 != C2) {
m = 0;
@@ -392,7 +393,7 @@ struct avg_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <etl_3d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
if (s1 != c1 || s2 != c2) {
m = 0;
@@ -422,7 +423,7 @@ struct avg_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_4d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m) {
if constexpr (S1 != C1 || S2 != C2) {
m = 0;
@@ -452,7 +453,7 @@ struct avg_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <etl_4d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
if (s1 != c1 || s2 != c2) {
m = 0;
@@ -484,7 +485,7 @@ struct avg_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(decay_traits<A>::dimensions() > 4)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply<C1, C2, S1, S2, P1, P2>(in(i), out(i), errors(i), m(i));
@@ -498,7 +499,7 @@ struct avg_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(decay_traits<A>::dimensions() > 4)>
template <etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply(in(i), out(i), errors(i), m(i), c1, c2, s1, s2, p1, p2);
@@ -614,7 +615,7 @@ struct avg_pool_upsample_3d {
* \tparam C2 The second dimension pooling ratio
* \tparam C3 The third dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t C3, typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <size_t C1, size_t C2, size_t C3, etl_3d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m) {
for (size_t i = 0; i < etl::dim<0>(out); ++i) {
for (size_t j = 0; j < etl::dim<1>(out); ++j) {
@@ -633,7 +634,7 @@ struct avg_pool_upsample_3d {
* \param c2 The second dimension pooling ratio
* \param c3 The third dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <etl_3d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t c3) {
for (size_t i = 0; i < etl::dim<0>(out); ++i) {
for (size_t j = 0; j < etl::dim<1>(out); ++j) {
@@ -660,7 +661,7 @@ struct avg_pool_upsample_3d {
* \tparam C2 The second dimension pooling ratio
* \tparam C3 The third dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t C3, typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <size_t C1, size_t C2, size_t C3, etl_4d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M& m) {
auto batch_fun_n = [&](const size_t first, const size_t last) {
for (size_t n = first; n < last; ++n) {
@@ -687,7 +688,7 @@ struct avg_pool_upsample_3d {
* \param c2 The second dimension pooling ratio
* \param c3 The third dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <etl_4d A, typename B, typename C, typename M>
static void apply([[maybe_unused]] A&& in, [[maybe_unused]] B&& out, C&& errors, M& m, size_t c1, size_t c2, size_t c3) {
auto batch_fun_n = [&](const size_t first, const size_t last) {
for (size_t n = first; n < last; ++n) {
@@ -716,7 +717,7 @@ struct avg_pool_upsample_3d {
* \tparam C2 The second dimension pooling ratio
* \tparam C3 The third dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t C3, typename A, typename B, typename C, typename M, cpp_enable_iff(!is_3d<A> && !is_4d<A>)>
template <size_t C1, size_t C2, size_t C3, etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply<C1, C2, C3>(in(i), out(i), errors(i), m(i));
@@ -731,7 +732,7 @@ struct avg_pool_upsample_3d {
* \param c2 The second dimension pooling ratio
* \param c3 The third dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(!is_3d<A> && !is_4d<A>)>
template <etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m, size_t c1, size_t c2, size_t c3) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply(in(i), out(i), errors(i), m(i), c1, c2, c3);
28 changes: 14 additions & 14 deletions include/etl/impl/std/max_pooling_upsample.hpp
Original file line number Diff line number Diff line change
@@ -406,7 +406,7 @@ struct max_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(is_2d<A>)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_2d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m) {
if constexpr (S1 != C1 || S2 != C2) {
m = 0;
@@ -426,7 +426,7 @@ struct max_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_2d<A>)>
template <etl_2d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
if (s1 != c1 || s2 != c2) {
m = 0;
@@ -448,7 +448,7 @@ struct max_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_3d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m) {
if (S1 != C1 || S2 != C2) {
m = 0;
@@ -476,7 +476,7 @@ struct max_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <etl_3d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
if (s1 != c1 || s2 != c2) {
m = 0;
@@ -506,7 +506,7 @@ struct max_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_4d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m) {
if (S1 != C1 || S2 != C2) {
m = 0;
@@ -536,7 +536,7 @@ struct max_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <etl_4d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
if (s1 != c1 || s2 != c2) {
m = 0;
@@ -568,7 +568,7 @@ struct max_pool_upsample_2d {
* \tparam C1 The first dimension pooling ratio
* \tparam C2 The second dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, typename A, typename B, typename C, typename M, cpp_enable_iff(decay_traits<A>::dimensions() > 4)>
template <size_t C1, size_t C2, size_t S1, size_t S2, size_t P1, size_t P2, etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply<C1, C2, S1, S2, P1, P2>(in(i), out(i), errors(i), m(i));
@@ -582,7 +582,7 @@ struct max_pool_upsample_2d {
* \param c1 The first dimension pooling ratio
* \param c2 The second dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(decay_traits<A>::dimensions() > 4)>
template <etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m, size_t c1, size_t c2, size_t s1, size_t s2, size_t p1, size_t p2) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply(in(i), out(i), errors(i), m(i), c1, c2, s1, s2, p1, p2);
@@ -662,7 +662,7 @@ struct max_pool_upsample_3d {
* \tparam C2 The second dimension pooling ratio
* \tparam C3 The third dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t C3, typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <size_t C1, size_t C2, size_t C3, etl_3d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m) {
for (size_t i = 0; i < etl::dim<0>(out); ++i) {
for (size_t j = 0; j < etl::dim<1>(out); ++j) {
@@ -741,7 +741,7 @@ struct max_pool_upsample_3d {
* \param c2 The second dimension pooling ratio
* \param c3 The third dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_3d<A>)>
template <etl_3d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M&& m, size_t c1, size_t c2, size_t c3) {
for (size_t i = 0; i < etl::dim<0>(out); ++i) {
for (size_t j = 0; j < etl::dim<1>(out); ++j) {
@@ -768,7 +768,7 @@ struct max_pool_upsample_3d {
* \tparam C2 The second dimension pooling ratio
* \tparam C3 The third dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t C3, typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <size_t C1, size_t C2, size_t C3, etl_4d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m) {
auto batch_fun_n = [&](const size_t first, const size_t last) {
for (size_t n = first; n < last; ++n) {
@@ -795,7 +795,7 @@ struct max_pool_upsample_3d {
* \param c2 The second dimension pooling ratio
* \param c3 The third dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(is_4d<A>)>
template <etl_4d A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m, size_t c1, size_t c2, size_t c3) {
auto batch_fun_n = [&](const size_t first, const size_t last) {
for (size_t n = first; n < last; ++n) {
@@ -824,7 +824,7 @@ struct max_pool_upsample_3d {
* \tparam C2 The second dimension pooling ratio
* \tparam C3 The third dimension pooling ratio
*/
template <size_t C1, size_t C2, size_t C3, typename A, typename B, typename C, typename M, cpp_enable_iff(!is_3d<A> && !is_4d<A>)>
template <size_t C1, size_t C2, size_t C3, etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply<C1, C2, C3>(in(i), out(i), errors(i), m(i));
@@ -839,7 +839,7 @@ struct max_pool_upsample_3d {
* \param c2 The second dimension pooling ratio
* \param c3 The third dimension pooling ratio
*/
template <typename A, typename B, typename C, typename M, cpp_enable_iff(!is_3d<A> && !is_4d<A>)>
template <etl_5d_and_plus A, typename B, typename C, typename M>
static void apply(A&& in, B&& out, C&& errors, M& m, size_t c1, size_t c2, size_t c3) {
for (size_t i = 0; i < etl::dim<0>(in); ++i) {
apply(in(i), out(i), errors(i), m(i), c1, c2, c3);

0 comments on commit e026a9e

Please sign in to comment.