Creating a C custom layer with dynamic output

Hello everbody,

First of all, I like this community, it is really amazing the collaboration here. I am trying to create a specific layer in Pytorch using C custom modules (CPU for a while using this THFloatTensor ) with a dynamic output depending on the batch quality the code is relative complex and I can’t perform it using common pytorch layers. But I found C custom tools to perform this. I had a problem here, I do not know how can I set a dynamic output for this tensor. Like the following example in this GitHub.

(test would be the main and binding.cpp would be the C custom layer)

cost vector is previously defined before (in the main code) return. I think C custom only fill information in previously defined graphs but I can’t create a new graph inside with my own shape defined in the C code.

Simple example:

int select_high_accuracy_in_batch(	THFloatTensor *batch_tensor, float conf,  THFloatTensor * new_vector_with_high_accuracy){
      float * batch = THFloatTensor_data(batch_tensor);
      float * pointer_to_predefined_vector = THFloatTensor_data(new_vector_with_high_accuracy); // I don't want this.
      int size_b = sizeof(batch) / sizeof(batch[0]);

      for(b = 0; b < size_b; ++b){
             if (size_b[i] > conf){
                   # something like append (in python) in  new_vector_with_high_accuracy
     return 1 # return a vector with size defined inside this C code.

Sorry if something is wrong in the code, but it was just an example that I want to perform.
Thank you in advanced.