[mlpack-git] [mlpack/mlpack] Inception layer (#757)

Tham notifications at github.com
Wed Aug 10 00:27:07 EDT 2016


> +
> +namespace mlpack {
> +namespace ann /** Artificial Neural Network. */ {
> +/**
> + * @tparam JoinLayers Contains all layer modules that need be concatenated.
> + */
> +template <typename JoinLayers,
> +          typename InputDataType = arma::cube,
> +          typename OutputDataType = arma::cube>
> +class ConcatLayer
> +{
> + public:
> +  ConcatLayer(const size_t numLayers,
> +              JoinLayers &&layers) :
> +  numLayers(numLayers),
> +  layers(std::forward<JoinLayers>(layers))

Your solution tell the compiler "JoinLayers must be rvalue", that means

```
SomeLayer layers;
ConcatLayer<SomeLayer> ConcatLayer(layers);
```
Do not work, because layers is an lvalue in this case, but the constructor only accept rvalue.

If you want to perform perfect forwarding by std::forward(which means, if it is rvalue, cast it to rvalue, if it is lvalue, cast it lvalue), you need to write it as

```
template<typename JoinLayersType>
ConcatLayer(const size_t numLayers,
                    JoinLayersType &&layers) ;
```
In this case, the compiler will treat JoinLayers&& as "[universal reference](https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers)", so perfect forwarding work under this case.

You may ask, but I need the JoinLayersType == JoinLayers, use can use static_assert to add this restriction work

```
using RawJLT = typename std::decay<JoinLayersType >::type;
static_assert(std::is_same<RawJLT , JoinLayers>::value, "type of JoinLayerType must equal to JoinLayers");
```


---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/757/files/06d923321f246f2c6ead9ad56e99309fe24a6f5c#r74183802
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160809/df0f4d62/attachment-0001.html>


More information about the mlpack-git mailing list