@@ -214,8 +214,6 @@ static int _ccv_nnc_upsample_nearest_forw(const ccv_nnc_cmd_t cmd, const ccv_nnc
214
214
const int hw = bdim[2 ] * bdim[3 ];
215
215
const float rheight = align_corners ? (float )(adim[2 ] - 1 ) / ccv_max (1 , bdim[2 ] - 1 ) : (float )adim[2 ] / bdim[2 ];
216
216
const float rwidth = align_corners ? (float )(adim[3 ] - 1 ) / ccv_max (1 , bdim[3 ] - 1 ) : (float )adim[3 ] / bdim[3 ];
217
- assert (rheight <= 1 );
218
- assert (rwidth <= 1 );
219
217
if (align_corners)
220
218
{
221
219
if (a->info .datatype == CCV_32F)
@@ -232,8 +230,6 @@ static int _ccv_nnc_upsample_nearest_forw(const ccv_nnc_cmd_t cmd, const ccv_nnc
232
230
assert (a->info .format == CCV_TENSOR_FORMAT_NHWC || a->info .format == CCV_TENSOR_FORMAT_CHWN);
233
231
const float rheight = align_corners ? (float )(adim[1 ] - 1 ) / ccv_max (1 , bdim[1 ] - 1 ) : (float )adim[1 ] / bdim[1 ];
234
232
const float rwidth = align_corners ? (float )(adim[2 ] - 1 ) / ccv_max (1 , bdim[2 ] - 1 ) : (float )adim[2 ] / bdim[2 ];
235
- assert (rheight <= 1 );
236
- assert (rwidth <= 1 );
237
233
const int hw = bdim[1 ] * bdim[2 ];
238
234
if (align_corners)
239
235
{
@@ -381,12 +377,12 @@ __global__ void _ccv_nnc_upsample_bilinear_forw_nchw(const int hw, const float r
381
377
const NUM* ap = a;
382
378
NUM* bp = b;
383
379
const float xs = (xd + 0.5 ) * rwidth - 0.5 ;
384
- const int xsi0 = ( int )xs;
380
+ const int xsi0 = ccv_max (( int )xs, 0 ) ;
385
381
const int xsi1 = ccv_min ((int )(xs + 1 ), adim3 - 1 );
386
382
const float xsc1 = xs - xsi0;
387
383
const float xsc0 = 1.0 - xsc1;
388
384
const float ys = (yd + 0.5 ) * rheight - 0.5 ;
389
- const int ysi0 = ( int )ys;
385
+ const int ysi0 = ccv_max (( int )ys, 0 ) ;
390
386
const int ysi1 = ccv_min ((int )(ys + 1 ), adim2 - 1 );
391
387
const float ysc1 = ys - ysi0;
392
388
const float ysc0 = 1.0 - ysc1;
@@ -408,12 +404,12 @@ __global__ void _ccv_nnc_upsample_bilinear_forw_nhwc(const int hw, const float r
408
404
const NUM* ap = a;
409
405
NUM* bp = b;
410
406
const float xs = (xd + 0.5 ) * rwidth - 0.5 ;
411
- const int xsi0 = ( int )xs;
407
+ const int xsi0 = ccv_max (( int )xs, 0 ) ;
412
408
const int xsi1 = ccv_min ((int )(xs + 1 ), adim2 - 1 );
413
409
const float xsc1 = xs - xsi0;
414
410
const float xsc0 = 1.0 - xsc1;
415
411
const float ys = (yd + 0.5 ) * rheight - 0.5 ;
416
- const int ysi0 = ( int )ys;
412
+ const int ysi0 = ccv_max (( int )ys, 0 ) ;
417
413
const int ysi1 = ccv_min ((int )(ys + 1 ), adim1 - 1 );
418
414
const float ysc1 = ys - ysi0;
419
415
const float ysc0 = 1.0 - ysc1;
@@ -497,12 +493,12 @@ __global__ void _ccv_nnc_upsample_bilinear_back_nchw(const size_t tensor_count,
497
493
NUM* const ap = a + idx * ainc2;
498
494
const NUM* const bp = b + idx * binc2;
499
495
const float xs = (xd + 0.5 ) * rwidth - 0.5 ;
500
- const int xsi0 = ( int )xs;
496
+ const int xsi0 = ccv_max (( int )xs, 0 ) ;
501
497
const int xsi1 = ccv_min ((int )(xs + 1 ), adim3 - 1 );
502
498
const float xsc1 = xs - xsi0;
503
499
const float xsc0 = 1.0 - xsc1;
504
500
const float ys = (yd + 0.5 ) * rheight - 0.5 ;
505
- const int ysi0 = ( int )ys;
501
+ const int ysi0 = ccv_max (( int )ys, 0 ) ;
506
502
const int ysi1 = ccv_min ((int )(ys + 1 ), adim2 - 1 );
507
503
const float ysc1 = ys - ysi0;
508
504
const float ysc0 = 1.0 - ysc1;
@@ -525,12 +521,12 @@ __global__ void _ccv_nnc_upsample_bilinear_back_nhwc(const size_t tensor_count,
525
521
NUM* const ap = a + idx * ainc1;
526
522
const NUM* const bp = b + idx * binc1;
527
523
const float xs = (xd + 0.5 ) * rwidth - 0.5 ;
528
- const int xsi0 = ( int )xs;
524
+ const int xsi0 = ccv_max (( int )xs, 0 ) ;
529
525
const int xsi1 = ccv_min ((int )(xs + 1 ), adim2 - 1 );
530
526
const float xsc1 = xs - xsi0;
531
527
const float xsc0 = 1.0 - xsc1;
532
528
const float ys = (yd + 0.5 ) * rheight - 0.5 ;
533
- const int ysi0 = ( int )ys;
529
+ const int ysi0 = ccv_max (( int )ys, 0 ) ;
534
530
const int ysi1 = ccv_min ((int )(ys + 1 ), adim1 - 1 );
535
531
const float ysc1 = ys - ysi0;
536
532
const float ysc0 = 1.0 - ysc1;
@@ -574,8 +570,6 @@ static int _ccv_nnc_upsample_bilinear_forw(const ccv_nnc_cmd_t cmd, const ccv_nn
574
570
const int hw = bdim[2 ] * bdim[3 ];
575
571
const float rheight = align_corners ? (float )(adim[2 ] - 1 ) / ccv_max (1 , bdim[2 ] - 1 ) : (float )adim[2 ] / bdim[2 ];
576
572
const float rwidth = align_corners ? (float )(adim[3 ] - 1 ) / ccv_max (1 , bdim[3 ] - 1 ) : (float )adim[3 ] / bdim[3 ];
577
- assert (rheight <= 1 );
578
- assert (rwidth <= 1 );
579
573
if (align_corners)
580
574
{
581
575
if (a->info .datatype == CCV_32F)
@@ -592,8 +586,6 @@ static int _ccv_nnc_upsample_bilinear_forw(const ccv_nnc_cmd_t cmd, const ccv_nn
592
586
assert (a->info .format == CCV_TENSOR_FORMAT_NHWC || a->info .format == CCV_TENSOR_FORMAT_CHWN);
593
587
const float rheight = align_corners ? (float )(adim[1 ] - 1 ) / ccv_max (1 , bdim[1 ] - 1 ) : (float )adim[1 ] / bdim[1 ];
594
588
const float rwidth = align_corners ? (float )(adim[2 ] - 1 ) / ccv_max (1 , bdim[2 ] - 1 ) : (float )adim[2 ] / bdim[2 ];
595
- assert (rheight <= 1 );
596
- assert (rwidth <= 1 );
597
589
const int hw = bdim[1 ] * bdim[2 ];
598
590
if (align_corners)
599
591
{
0 commit comments