Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //size_t I = 0 means the default value of I is 0(index of tuple is zero)
- template<size_t I = 0, typename DataType, typename... Tp>
- void Forward(const DataType& input, std::tuple<Tp...>& network)
- {
- //set the value of InputParameter of network
- std::get<I>(network).InputParameter() = input;
- //call the forward function of network
- std::get<I>(network).Forward(std::get<I>(network).InputParameter(),
- std::get<I>(network).OutputParameter());
- //now, we start the recursive, increment the I by 1
- ForwardTail<I + 1, Tp...>(network);
- }
- //size_t I = 1 means the default value of I is 0(index of tuple is one)
- //we use std::enable_if to specify the case when the sizeof the tuple
- //are same as I. In short, std::enable_if<I==sizeof...(Tp), void>::type
- //tell the compiler---when the I == sizeof tuple(network), you should
- //call(instantiate) this function, else call another(if exist).
- //This function it the end condition of the Forawrd too
- template<size_t I = 1, typename... Tp>
- typename std::enable_if<I == sizeof...(Tp), void>::type
- ForwardTail(std::tuple<Tp...>& network)
- {
- LinkParameter(network);
- }
- //This function only instantiate if I < sizeof tuple(network)
- //We use std::enable_if to specialize(do some "overload" at compile time)
- //the function
- template<size_t I = 1, typename... Tp>
- typename std::enable_if<I < sizeof...(Tp), void>::type
- ForwardTail(std::tuple<Tp...>& network)
- {
- std::get<I>(network).Forward(std::get<I - 1>(network).OutputParameter(),
- std::get<I>(network).OutputParameter());
- //recursive call, this time we add the index by 1
- ForwardTail<I + 1, Tp...>(network);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement