You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2019/07/19 03:42:33 UTC

[incubator-mxnet] 13/28: Resize When SampleUniform Size is Odd

This is an automated email from the ASF dual-hosted git repository.

zhasheng pushed a commit to tag v1.1
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git

commit 9839379f25b3610516e6d69996823416e16afcb7
Author: reyoung <re...@126.com>
AuthorDate: Wed May 28 17:05:32 2014 +0800

    Resize When SampleUniform Size is Odd
---
 mshadow/tensor_random.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/mshadow/tensor_random.h b/mshadow/tensor_random.h
index 3fa8c0d..edb9c78 100644
--- a/mshadow/tensor_random.h
+++ b/mshadow/tensor_random.h
@@ -251,7 +251,12 @@ namespace mshadow {
          */
         template<int dim>
         inline expr::ReshapeExp<Tensor<gpu,1>,dim,1> gaussian( Shape<dim> shape, real_t mu=0.0f, real_t sigma=1.0f){
-            buffer_.Resize( Shape1( shape.Size() ) );
+        	int sz = shape.Size();
+        	bool odd = sz %2;
+        	if(odd){
+        		++sz;
+        	}
+            buffer_.Resize( Shape1( sz ) );
             curandStatus_t status;
             #if MSHADOW_SINGLE_PRECISION
             status = curandGenerateNormal(gen_, buffer_.dptr, buffer_.shape[0], mu, sigma);
@@ -259,6 +264,9 @@ namespace mshadow {
             status = curandGenerateNormalDouble(gen_, buffer_.dptr, buffer_.shape[0], mu, sigma);
             #endif
             utils::Assert(status == CURAND_STATUS_SUCCESS, "CURAND Gen Uniform failed\n");
+            if(odd){
+            	buffer_.Resize(Shape1(sz-1));
+            }
             return expr::reshape( buffer_, shape );
         }
         /*!