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)

  
      github.com
  
  
    SeanNaren/warp-ctc/blob/pytorch_bindings/pytorch_binding/tests/test_cpu.py#L13 1

import pytest




def test_simple():
probs = torch.FloatTensor([[[0.1, 0.6, 0.1, 0.1, 0.1], [0.1, 0.1, 0.6, 0.1, 0.1]]]).transpose(0, 1).contiguous()
grads = torch.zeros(probs.size())
labels = torch.IntTensor([1, 2])
label_sizes = torch.IntTensor([2])
sizes = torch.IntTensor(probs.size(1)).fill_(probs.size(0))
minibatch_size = probs.size(1)
costs = torch.zeros(minibatch_size)
warp_ctc.cpu_ctc(probs,
                 grads,
                 labels,
                 label_sizes,
                 sizes,
                 minibatch_size,
                 costs)
print('CPU_cost: %f' % costs.sum())







  
  
    
    
  
  



  
      github.com
  
  
    SeanNaren/warp-ctc/blob/pytorch_bindings/pytorch_binding/src/binding.cpp#L23

#else
#include "TH.h"
#endif


extern "C" int cpu_ctc(THFloatTensor *probs,
                    THFloatTensor *grads,
                    THIntTensor *labels,
                    THIntTensor *label_sizes,
                    THIntTensor *sizes,
                    int minibatch_size,
                    THFloatTensor *costs) {


float *probs_ptr = probs->storage->data + probs->storageOffset;
float *grads_ptr;
if (grads->storage) {
        grads_ptr = grads->storage->data + grads->storageOffset;
} else {
        grads_ptr = NULL; // this will trigger the score forward code path
}


int *sizes_ptr = sizes->storage->data + sizes->storageOffset;



  
  
    
    
  
  


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.