round in PyTorch is a “Python-like” round (std::nearbyint) but not a “Cpp-like” round (std::round). It means, round([-0.5, 0.5]) would return [0, 0] but not [-1, 1]. I need “Cpp-like” round, especially when deploying my model.
I check the source code and find
  

      github.com
  

  
    pytorch/pytorch/blob/178010455d5cd477af5a98b0e03084ffeecaecf2/aten/src/ATen/cpu/vec/vec_base.h#L469-L471



      
      
          Vectorized<T> round() const {
            // We do not use std::round because we would like to round midway numbers to the nearest even integer.
            return map(at::native::round_impl);
      
    
  


  

  
    
    
  

  



  

      github.com
  

  
    pytorch/pytorch/blob/178010455d5cd477af5a98b0e03084ffeecaecf2/aten/src/ATen/native/cpu/zmath.h#L175-L178



      
      
          template <typename TYPE>
          inline TYPE round_impl (TYPE z) {
            return std::nearbyint(z);
          }
      
    
  


  

  
    
    
  

  


One year ago, I posted Is there any faster way to rounding a tensor? 2 and found a temporary solution. But it is complex and inefficient.
Does PyTorch have a “Cpp-like” round function, or an option?
Thank you.