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:35 UTC
[incubator-mxnet] 15/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 b998f9c4315e4a32b64ebdc995c421f6650c0a3a
Author: Tianqi Chen <tq...@users.noreply.github.com>
AuthorDate: Wed May 28 09:20:34 2014 -0700
Update tensor_random.h
update patch by in #7 by @reyoung . buffer_.Resize is dangerous because it could potentially change the content of data
---
mshadow/tensor_random.h | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/mshadow/tensor_random.h b/mshadow/tensor_random.h
index edb9c78..9d10329 100644
--- a/mshadow/tensor_random.h
+++ b/mshadow/tensor_random.h
@@ -251,12 +251,7 @@ 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){
- int sz = shape.Size();
- bool odd = sz %2;
- if(odd){
- ++sz;
- }
- buffer_.Resize( Shape1( sz ) );
+ buffer_.Resize( Shape1( ((shape.Size() + 1UL)<<1)>>1 ) );
curandStatus_t status;
#if MSHADOW_SINGLE_PRECISION
status = curandGenerateNormal(gen_, buffer_.dptr, buffer_.shape[0], mu, sigma);
@@ -264,10 +259,7 @@ 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 );
+ return expr::reshape( buffer_.Slice(0, shape.Size()), shape );
}
/*!
* \brief return a temporal expression storing standard uniform [0,1)