parameters: (img,
             angle,
             interpolation='nearest',
             expand=False,
             center=None,
             fill=None,
             data_format='CHW')
return_statement: return out.squeeze(0)
docstring: Rotates the image by angle.
  
      Args:
          img (paddle.Tensor): Image to be rotated.
          angle (float or int): In degrees degrees counter clockwise order.
          interpolation (str, optional): Interpolation method. If omitted, or if the 
              image has only one channel, it is set NEAREST . when use pil backend, 
              support method are as following: 
              - "nearest" 
              - "bilinear"
              - "bicubic"
          expand (bool, optional): Optional expansion flag.
              If true, expands the output image to make it large enough to hold the entire rotated image.
              If false or omitted, make the output image the same size as the input image.
              Note that the expand flag assumes rotation around the center and no translation.
          center (2-tuple, optional): Optional center of rotation.
              Origin is the upper left corner.
              Default is the center of the image.
          fill (3-tuple or int): RGB pixel fill value for area outside the rotated image.
              If int, it is used for all channels respectively.
  
      Returns:
          paddle.Tensor: Rotated image.
docstring_summary: Rotates the image by angle.
docstring_tokens: Rotates the image by angle .
function: def rotate(img,
             angle,
             interpolation='nearest',
             expand=False,
             center=None,
             fill=None,
             data_format='CHW'):
      """Rotates the image by angle.
  
      Args:
          img (paddle.Tensor): Image to be rotated.
          angle (float or int): In degrees degrees counter clockwise order.
          interpolation (str, optional): Interpolation method. If omitted, or if the 
              image has only one channel, it is set NEAREST . when use pil backend, 
              support method are as following: 
              - "nearest" 
              - "bilinear"
              - "bicubic"
          expand (bool, optional): Optional expansion flag.
              If true, expands the output image to make it large enough to hold the entire rotated image.
              If false or omitted, make the output image the same size as the input image.
              Note that the expand flag assumes rotation around the center and no translation.
          center (2-tuple, optional): Optional center of rotation.
              Origin is the upper left corner.
              Default is the center of the image.
          fill (3-tuple or int): RGB pixel fill value for area outside the rotated image.
              If int, it is used for all channels respectively.
  
      Returns:
          paddle.Tensor: Rotated image.
  
      """
  
      angle = -angle % 360
      img = img.unsqueeze(0)
  
      # n, c, h, w = img.shape
      w, h = _get_image_size(img, data_format=data_format)
  
      img = img if data_format.lower() == 'chw' else img.transpose((0, 3, 1, 2))
  
      post_trans = [0, 0]
  
      if center is None:
          rotn_center = [0, 0]
      else:
          rotn_center = [(p - s * 0.5) for p, s in zip(center, [w, h])]
  
      angle = math.radians(angle)
      matrix = [
          math.cos(angle),
          math.sin(angle),
          0.0,
          -math.sin(angle),
          math.cos(angle),
          0.0,
      ]
  
      matrix[2] += matrix[0] * (-rotn_center[0] - post_trans[0]) + matrix[1] * (
          -rotn_center[1] - post_trans[1])
      matrix[5] += matrix[3] * (-rotn_center[0] - post_trans[0]) + matrix[4] * (
          -rotn_center[1] - post_trans[1])
  
      matrix[2] += rotn_center[0]
      matrix[5] += rotn_center[1]
  
      matrix = paddle.to_tensor(matrix, place=img.place)
      matrix = matrix.reshape((1, 2, 3))
  
      if expand:
          # calculate output size
          corners = paddle.to_tensor(
              [[-0.5 * w, -0.5 * h, 1.0], [-0.5 * w, 0.5 * h, 1.0],
               [0.5 * w, 0.5 * h, 1.0], [0.5 * w, -0.5 * h, 1.0]],
              place=matrix.place).astype(matrix.dtype)
  
          _pos = corners.reshape(
              (1, -1, 3)).bmm(matrix.transpose((0, 2, 1))).reshape((1, -1, 2))
          _min = _pos.min(axis=-2).floor()
          _max = _pos.max(axis=-2).ceil()
  
          npos = _max - _min
          nw = npos[0][0]
          nh = npos[0][1]
  
          ow, oh = int(nw.numpy()[0]), int(nh.numpy()[0])
  
      else:
          ow, oh = w, h
  
      grid = _affine_grid(matrix, w, h, ow, oh)
  
      out = _grid_transform(img, grid, mode=interpolation, fill=fill)
  
      out = out if data_format.lower() == 'chw' else out.transpose((0, 2, 3, 1))
  
      return out.squeeze(0)
function_tokens: def rotate ( img , angle , interpolation = 'nearest' , expand = False , center = None , fill = None , data_format = 'CHW' ) : angle = - angle % 360 img = img . unsqueeze ( 0 ) # n, c, h, w = img.shape w , h = _get_image_size ( img , data_format = data_format ) img = img if data_format . lower ( ) == 'chw' else img . transpose ( ( 0 , 3 , 1 , 2 ) ) post_trans = [ 0 , 0 ] if center is None : rotn_center = [ 0 , 0 ] else : rotn_center = [ ( p - s * 0.5 ) for p , s in zip ( center , [ w , h ] ) ] angle = math . radians ( angle ) matrix = [ math . cos ( angle ) , math . sin ( angle ) , 0.0 , - math . sin ( angle ) , math . cos ( angle ) , 0.0 , ] matrix [ 2 ] += matrix [ 0 ] * ( - rotn_center [ 0 ] - post_trans [ 0 ] ) + matrix [ 1 ] * ( - rotn_center [ 1 ] - post_trans [ 1 ] ) matrix [ 5 ] += matrix [ 3 ] * ( - rotn_center [ 0 ] - post_trans [ 0 ] ) + matrix [ 4 ] * ( - rotn_center [ 1 ] - post_trans [ 1 ] ) matrix [ 2 ] += rotn_center [ 0 ] matrix [ 5 ] += rotn_center [ 1 ] matrix = paddle . to_tensor ( matrix , place = img . place ) matrix = matrix . reshape ( ( 1 , 2 , 3 ) ) if expand : # calculate output size corners = paddle . to_tensor ( [ [ - 0.5 * w , - 0.5 * h , 1.0 ] , [ - 0.5 * w , 0.5 * h , 1.0 ] , [ 0.5 * w , 0.5 * h , 1.0 ] , [ 0.5 * w , - 0.5 * h , 1.0 ] ] , place = matrix . place ) . astype ( matrix . dtype ) _pos = corners . reshape ( ( 1 , - 1 , 3 ) ) . bmm ( matrix . transpose ( ( 0 , 2 , 1 ) ) ) . reshape ( ( 1 , - 1 , 2 ) ) _min = _pos . min ( axis = - 2 ) . floor ( ) _max = _pos . max ( axis = - 2 ) . ceil ( ) npos = _max - _min nw = npos [ 0 ] [ 0 ] nh = npos [ 0 ] [ 1 ] ow , oh = int ( nw . numpy ( ) [ 0 ] ) , int ( nh . numpy ( ) [ 0 ] ) else : ow , oh = w , h grid = _affine_grid ( matrix , w , h , ow , oh ) out = _grid_transform ( img , grid , mode = interpolation , fill = fill ) out = out if data_format . lower ( ) == 'chw' else out . transpose ( ( 0 , 2 , 3 , 1 ) ) return out . squeeze ( 0 )