Commit 001bca78 authored by Davis King's avatar Davis King

Improved the add_layer forwarding constructor. Also added repeat_group()

variable decorator.
parent 0a1464b6
...@@ -596,6 +596,16 @@ namespace dlib ...@@ -596,6 +596,16 @@ namespace dlib
}; };
template <typename ...T, typename ...U> template <typename ...T, typename ...U>
struct disable_forwarding_constr<std::tuple<T...>,U...> struct disable_forwarding_constr<std::tuple<T...>,U...>
{
const static bool value = disable_forwarding_constr<typename std::remove_reference<T>::type...>::value;
};
template <typename T, typename ...U>
struct disable_forwarding_constr<std::tuple<T>,U...>
{
const static bool value = disable_forwarding_constr<typename std::remove_reference<T>::type>::value;
};
template <typename ...U>
struct disable_forwarding_constr<std::tuple<>,U...>
{ {
const static bool value = true; const static bool value = true;
}; };
...@@ -658,6 +668,10 @@ namespace dlib ...@@ -658,6 +668,10 @@ namespace dlib
T&& ...args T&& ...args
) : add_layer(layer_det,args...) { } ) : add_layer(layer_det,args...) { }
add_layer (
std::tuple<>
) : add_layer() {}
template <typename ...T> template <typename ...T>
add_layer( add_layer(
std::tuple<>, std::tuple<>,
...@@ -1374,6 +1388,23 @@ namespace dlib ...@@ -1374,6 +1388,23 @@ namespace dlib
}; };
} }
template <typename ...T>
struct decorator_repeat_group
{
decorator_repeat_group(
T&& ...args
) : data(std::forward<T>(args)...) {}
std::tuple<T...> data;
};
template <typename ...T>
decorator_repeat_group<T...> repeat_group (
T&& ...args
)
{
return decorator_repeat_group<T...>(std::forward<T>(args)...);
}
template < template <
size_t num, size_t num,
template<typename> class REPEATED_LAYER, template<typename> class REPEATED_LAYER,
...@@ -1440,6 +1471,16 @@ namespace dlib ...@@ -1440,6 +1471,16 @@ namespace dlib
{ {
} }
template <typename ...T, typename ...U>
repeat(
decorator_repeat_group<T...>&& arg1,
U ...args2
):
details(num, arg1.data),
subnetwork(std::move(args2)...)
{
}
template <typename T, typename ...U> template <typename T, typename ...U>
repeat( repeat(
std::tuple<>, std::tuple<>,
......
...@@ -963,6 +963,17 @@ namespace dlib ...@@ -963,6 +963,17 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename ...T>
decorator_repeat_group<T...> repeat_group (
T&& ...args
);
/*!
ensures
- Decorates a group of variables. This is essentially like std::make_tuple()
except it's only purpose is to group variables together so they can be passed
to the repeat object's constructor.
!*/
template < template <
size_t num, size_t num,
template<typename> class REPEATED_LAYER, template<typename> class REPEATED_LAYER,
...@@ -1020,6 +1031,20 @@ namespace dlib ...@@ -1020,6 +1031,20 @@ namespace dlib
SUBNET's constructor. SUBNET's constructor.
!*/ !*/
template <typename ...T, typename ...U>
repeat(
decorator_repeat_group<T...>&& arg1,
U ...args2
);
/*!
ensures
- arg1 is used to initialize the num_repetitions() copies of REPEATED_LAYER inside
this object. That is, all the REPEATED_LAYER elements are initialized identically
by being given copies of an undecorated arg1.
- The rest of the arguments to the constructor, i.e. args2, are passed to
SUBNET's constructor.
!*/
size_t num_repetitions ( size_t num_repetitions (
) const; ) const;
/*! /*!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment