code: def _resize_with_ratio(
      tens: Tensor,
      target_size: Tuple[int, int],
      preserve_aspect_ratio: bool = False,
      interpolation: int = INTER_LINEAR,
  ) -> Tensor:
      """
      Resizes an image using advanced algorithms
      :param target_size: Tuple of size 2 in the format (width,height)
      :param preserve_aspect_ratio: Boolean to keep/ignore aspect ratio when resizing
      """
      _check_target_size(target_size)
  
      if not isinstance(preserve_aspect_ratio, bool):
          raise ValueError("preserve_aspect_ratio must be a boolean")
  
      oh, ow = tens.shape[:2]
      target_w, target_h = target_size
  
      if target_h > oh or target_w > ow:
          raise ValueError(
              "To compute resizing keeping the aspect ratio, the target size dimensions "
              "must be <= actual image dimensions"
          )
  
      # Computing minimal resize
      # min_width, w_factor = _compute_minimal_resize(ow, target_w)
      # min_height, h_factor = _compute_minimal_resize(oh, target_h)
      minimal_resize_factor = _compute_minimal_resize(
          (ow, oh), (target_w, target_h)
      )
  
      # Resizing minimally
      tens = _cv2_resize(
          tens,
          (ow // minimal_resize_factor, oh // minimal_resize_factor),
      )
  
      # Computing centre crop (to avoid extra crop, we resize minimally first)
      tens = _compute_centre_crop(tens, (target_w, target_h))
  
      if tens.shape[:2] != target_size[:2]:
          tens = _cv2_resize(
              tens, (target_w, target_h), interpolation=interpolation
          )
  
      return tens
  
file_path: caer/caer/io/resize.py
imports: import math
  import cv2
  from ..coreten import Tensor, to_tensor
  from .._internal import _check_target_size
  from ..globals import INTER_AREA, INTER_CUBIC, INTER_NEAREST, INTER_LINEAR
  from typing import Tuple, Optional, Union
label_desc: Use image node_id 4 for calling a global function with example usage: _resize_with_ratio(tens, target_size, preserve_aspect_ratio, interpolation) and returns: tens