<s> import numpy as np <EOL> import cudarray as ca <EOL> from . . wrap import image <EOL> def rescale ( imgs , factor , method , out = None ) : <EOL> img_h , img_w = imgs . shape [ - <NUM_LIT:2> : ] <EOL> batch_shape = imgs . shape [ : - <NUM_LIT:2> ] <EOL> n_imgs = np . prod ( batch_shape ) <EOL> if factor > <NUM_LIT:1> : <EOL> scaled_h = int ( np . floor ( img_h * factor ) ) <EOL> scaled_w = int ( np . floor ( img_w * factor ) ) <EOL> else : <EOL> scaled_h = int ( np . ceil ( img_h * factor ) ) <EOL> scaled_w = int ( np . ceil ( img_w * factor ) ) <EOL> out_shape = batch_shape + ( scaled_h , scaled_w ) <EOL> if out is None : <EOL> out = ca . empty ( out_shape , dtype = imgs . dtype ) <EOL> else : <EOL> if out . shape != out_shape : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> method = image . sample_methods [ method ] <EOL> image . _rescale ( imgs . _data , factor , method , n_imgs , img_h , img_w , out . _data ) <EOL> return out </s>
