diff options
author | Edward Z. Yang <ezyang@fb.com> | 2017-06-10 00:08:37 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2017-06-13 23:19:35 +0300 |
commit | 6ec27dc9d941d90eea421e1bb1d0e953d68279b6 (patch) | |
tree | 31f5466c2ee67a7f65679752e8198bfba14f9c98 | |
parent | a3b3526922b64bf994681cf17c9cb0ea693cecc6 (diff) |
Short-circuit copy if src and dest are equal.
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
-rw-r--r-- | lib/TH/generic/THTensorCopy.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/TH/generic/THTensorCopy.c b/lib/TH/generic/THTensorCopy.c index 71ccfdd..d9cd1c0 100644 --- a/lib/TH/generic/THTensorCopy.c +++ b/lib/TH/generic/THTensorCopy.c @@ -68,6 +68,7 @@ void THTensor_(copyTranspose)(THTensor *tensor, THTensor *src) { void THTensor_(copy)(THTensor *tensor, THTensor *src) { + if (tensor == src) return; if (THTensor_(isContiguous)(tensor) && THTensor_(isContiguous)(src) && THTensor_(nElement)(tensor) == THTensor_(nElement)(src)) { real *sp = THTensor_(data)(src); real *rp = THTensor_(data)(tensor); |