diff options
author | Laurens van der Maaten <lvdmaaten@gmail.com> | 2016-04-20 21:16:27 +0300 |
---|---|---|
committer | Laurens van der Maaten <lvdmaaten@gmail.com> | 2016-04-20 21:16:27 +0300 |
commit | 3e5b8b1e1dec6e97b77ddb118270babb78986cb6 (patch) | |
tree | 3ea967a332f01bdc2b935253996574ef3d3e88a9 | |
parent | ecdcfdb315101d7376e8983dc7460c47355d7ef4 (diff) |
Fix bicubic interpolation when source has size 1
The bicubic interpolation code accesses non-allocated memory when `src_len` is 1 because it doesn't have a special case like bilinear interpolation does. This PR addresses that bug.
I ran the following test to confirm it works:
```
require 'image'
im = torch.randn(3, 2, 3):float()
for n = 1,1000 do resim = image.scale(im, 256, 768, 'bicubic') end
```
-rwxr-xr-x | generic/image.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/generic/image.c b/generic/image.c index 33a5293..0990814 100755 --- a/generic/image.c +++ b/generic/image.c @@ -166,6 +166,12 @@ static void image_(Main_scaleCubic_rowcol)(THTensor *Tsrc, long i; for( i = 0; i < dst_len; i++ ) dst[ dst_start + i*dst_stride ] = src[ src_start + i*src_stride ]; + } else if ( src_len == 1 ) { + long i; + for( i = 0; i < dst_len - 1; i++ ) { + long dst_pos = dst_start + i*dst_stride; + dst[dst_pos] = src[ src_start ]; + } } else { long di; float si_f; |