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:36 UTC
[incubator-mxnet] 16/28: Update tensor_random.h
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 3ad57fa742c67b5ba7f6378460c1a5b9b6f59c9b
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Wed May 28 11:32:00 2014 -0700
Update tensor_random.h
fix random
---
mshadow/tensor_random.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/mshadow/tensor_random.h b/mshadow/tensor_random.h
index 9d10329..e22400b 100644
--- a/mshadow/tensor_random.h
+++ b/mshadow/tensor_random.h
@@ -251,15 +251,18 @@ 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() + 1UL)<<1)>>1 ) );
+ size_t aligned_sz = ((shape.Size() + 1UL)<<1)>>1;
+ // allocate alligned size
+ buffer_.Resize( Shape1( aligned_sz ) );
+ buffer_.Resize( Shape1( shape.Size() ) );
curandStatus_t status;
#if MSHADOW_SINGLE_PRECISION
- status = curandGenerateNormal(gen_, buffer_.dptr, buffer_.shape[0], mu, sigma);
+ status = curandGenerateNormal(gen_, buffer_.dptr, aligned_sz , mu, sigma);
#else
status = curandGenerateNormalDouble(gen_, buffer_.dptr, buffer_.shape[0], mu, sigma);
#endif
utils::Assert(status == CURAND_STATUS_SUCCESS, "CURAND Gen Uniform failed\n");
- return expr::reshape( buffer_.Slice(0, shape.Size()), shape );
+ return expr::reshape( buffer_, shape );
}
/*!
* \brief return a temporal expression storing standard uniform [0,1)