You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by GitBox <gi...@apache.org> on 2020/07/01 02:38:08 UTC

[GitHub] [singa] joddiy edited a comment on pull request #748: add exp && round && rounde operators

joddiy edited a comment on pull request #748:
URL: https://github.com/apache/singa/pull/748#issuecomment-652152006


   > > Hi @joddiy , will this work for you? #749
   > 
   > seems not to work:
   > 
   > ![image](https://user-images.githubusercontent.com/14108933/85279938-d1cc5480-b4b9-11ea-84a2-91daf7f866c3.png)
   
   Hi, shicong, the `round` and `rounde` works now. However, the result of `rounde` is wrong now.
   
   please use this test:
   ```
   def rounde_helper(self, dev):
       X = np.array([0.1, 0.5, 0.9, 1.2, 1.5,
                   1.8, 2.3, 2.5, 2.7, -1.1,
                   -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float32)
       x = tensor.from_numpy(X)
       x.to_device(dev)
   
       y_t = np.array([0., 0., 1., 1., 2.,
                   2., 2., 2., 3., -1.,
                   -2., -2., -2., -2., -3.]).astype(np.float32)
       dy = tensor.from_numpy(y_t)
       dy.to_device(dev)
   
       y = autograd.rounde(x)
       np.testing.assert_array_almost_equal(tensor.to_numpy(y), y_t)
   
   def test_rounde_cpu(self):
       self.rounde_helper(cpu_dev)
   
   @unittest.skipIf(not singa_wrap.USE_CUDA, 'CUDA is not enabled')
   def test_rounde_gpu(self):
       self.rounde_helper(gpu_dev)
   ```
   
   Specifically, Rounde(0.9) should be 1 instead of 0.
   
   I guess the formula should be:
   ```
   apply round(x / 2) * 2 if x - floor(x) == 0.5  else round(x)
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org