Hi @tom,
Thanks for you answer.  I do not completely understand your proposal. I do not see how to convert this piece of code:
for(int i = startd; i < (startd+numd); i = i+1){
                if (degs[i] > 0){
                        output[i] = at::mean(products.narrow(0,k,int(degs[i])));
                }else{
                        output[i].fill_(0);
                }

                k = k + degs[i];
        }

I need to put the results of the mean in a specific order using k and degs[i] indexes. I can not compute the mean in one shoot. I think I do not completely understood your point. Can you give more details?
In reference of the pytorch 1.0 preview. Taking the code from the github repository under the tag v1.0rc1, and the path from this pr, Will I have all the necessary?
Finally I would like to ask you some help with this piece of code(corresponds to the backward function):
  k = 0
        for i in range(startd, startd+numd):
                if self._degs[i]>0:
                        torch.div(grad_output[i], self._degs[i], out=grad_products[k])
                        if self._degs[i]>1:
                                grad_products.narrow(0, k+1, self._degs[i]-1).copy_( grad_products[k].expand(self._degs[i]-1,1,self._out_channels).squeeze(1) )
                        k = k + self._degs[i]    



I have issues with this line:
grad_products.narrow(0, k+1, self._degs[i]-1).copy_( grad_products[k].expand(self._degs[i]-1,1,self._out_channels).squeeze(1) )

I found in the documentation that in at I have the same methods and I am trying to do this in c++:
int k = 0;

        for(int i = startd; i < (startd+numd); i = i+1){
                auto degs_int = degs[i].toCLong();

                if(degs_int > 0){
                        grad_products[k] = at::div(grad_output[i], degs_int);

                        if (degs_int > 1){

                                at::IntList sizes = {degs_int-1,1,out_channels};
                                grad_products.narrow(0, k+1, degs_int-1).copy_(grad_products[k].expand(sizes).squeeze(1));

                        }
                        k = k + degs_int;
                }


But it is not working, this is the error in runtime:
RuntimeError: The expanded size of the tensor (140414365974784) must match the existing size (64) at non-singleton dimension 2 (inferExpandGeometry at /pytorch/aten/src/ATen/ExpandUtils.cpp:69)
frame #0: at::native::expand(at::Tensor const&, at::ArrayRef<long>, bool) + 0x52 (0x7fb4bd3210c2 in /imatge/amosella/env/ecc_torch0.4.1_py36/lib/python3.6/site-packages/torch/lib/libcaffe2.so)
frame #1: at::Type::expand(at::Tensor const&, at::ArrayRef<long>, bool) const + 0x4a (0x7fb4bd4d4eda in /imatge/amosella/env/ecc_torch0.4.1_py36/lib/python3.6/site-packages/torch/lib/libcaffe2.so)
frame #2: torch::autograd::VariableType::expand(at::Tensor const&, at::ArrayRef<long>, bool) const + 0x4ad (0x7fb4c50d414d in /imatge/amosella/env/ecc_torch0.4.1_py36/lib/python3.6/site-packages/torch/_C.
cpython-36m-x86_64-linux-gnu.so)


Again, Thank you so much Tom, you are helping me a lot of with my first steps with the c++ api. Sorry if I am asking basics things, but honestly I am little lost with this.