@@ -155,10 +155,14 @@ void THCudaTensor_addcmul(THCState *state, THCudaTensor *self_, THCudaTensor *t,
155155    THCudaTensor_resizeAs (state, self_, t);
156156    THCudaTensor_copy (state, self_, t);
157157  }
158-   THCudaTensor_resizeAs (state, self_, src1);
158+   else 
159+   {
160+     THArgCheck (THCudaTensor_nElement (state, self_) == THCudaTensor_nElement (state, src1),
161+                1 , " sizes do not match" 
162+   }
159163
160-   THArgCheck (THCudaTensor_nElement (state, src1) ==
161-              THCudaTensor_nElement (state, src2),  3 , " sizes do not match" 
164+   THArgCheck (THCudaTensor_nElement (state, src1) ==  THCudaTensor_nElement (state, src2), 
165+              3 , " sizes do not match" 
162166
163167  if  (!THCudaTensor_pointwiseApply3 (state, self_, src1, src2, TensorAddCMulOp (value))) {
164168    THArgCheck (false , 2 , CUTORCH_DIM_WARNING);
@@ -186,9 +190,13 @@ void THCudaTensor_addcdiv(THCState *state, THCudaTensor *self_, THCudaTensor *t,
186190    THCudaTensor_resizeAs (state, self_, t);
187191    THCudaTensor_copy (state, self_, t);
188192  }
189- 
190-   THCudaTensor_resizeAs (state, self_, src1);
191-   THArgCheck (THCudaTensor_nElement (state, src1) == THCudaTensor_nElement (state, src2), 3 , " sizes do not match" 
193+   else 
194+   {
195+     THArgCheck (THCudaTensor_nElement (state, self_) == THCudaTensor_nElement (state, src1),
196+                1 , " sizes do not match" 
197+   }
198+   THArgCheck (THCudaTensor_nElement (state, src1) == THCudaTensor_nElement (state, src2),
199+              3 , " sizes do not match" 
192200
193201  if  (!THCudaTensor_pointwiseApply3 (state, self_, src1, src2, TensorAddCDivOp (value))) {
194202    THArgCheck (false , 2 , CUTORCH_DIM_WARNING);
0 commit comments