code: def set_scale_and_out_sz(
      in_shape,
      out_shape,
      scale_factors,
      by_convs,
      scale_tolerance,
      max_numerator,
      eps,
      fw,
  ):
      # eventually we must have both scale-factors and out-sizes for all in/out
      # dims. however, we support many possible partial arguments
      if scale_factors is None and out_shape is None:
          raise ValueError(
              "either scale_factors or out_shape should be " "provided"
          )
      if out_shape is not None:
          # if out_shape has less dims than in_shape, we defaultly resize the
          # first dims for numpy and last dims for paddle
          out_shape = (
              list(out_shape) + list(in_shape[len(out_shape) :])
              if fw is numpy
              else list(in_shape[: -len(out_shape)]) + list(out_shape)
          )
          if scale_factors is None:
              # if no scale given, we calculate it as the out to in ratio
              # (not recomended)
              scale_factors = [
                  out_sz / in_sz
                  for out_sz, in_sz in zip(out_shape, in_shape)
              ]
      if scale_factors is not None:
          # by default, if a single number is given as scale, we assume resizing
          # two dims (most common are images with 2 spatial dims)
          scale_factors = (
              scale_factors
              if isinstance(scale_factors, (list, tuple))
              else [scale_factors, scale_factors]
          )
          # if less scale_factors than in_shape dims, we defaultly resize the
          # first dims for numpy and last dims for paddle
          scale_factors = (
              list(scale_factors)
              + [1] * (len(in_shape) - len(scale_factors))
              if fw is numpy
              else [1] * (len(in_shape) - len(scale_factors))
              + list(scale_factors)
          )
          if out_shape is None:
              # when no out_shape given, it is calculated by multiplying the
              # scale by the in_shape (not recomended)
              out_shape = [
                  ceil(scale_factor * in_sz)
                  for scale_factor, in_sz in zip(
                      scale_factors, in_shape
                  )
              ]
          # next part intentionally after out_shape determined for stability
          # we fix by_convs to be a list of truth values in case it is not
          if not isinstance(by_convs, (list, tuple)):
              by_convs = [by_convs] * len(out_shape)
  
          # next loop fixes the scale for each dim to be either frac or float.
          # this is determined by by_convs and by tolerance for scale accuracy.
          for ind, (sf, dim_by_convs) in enumerate(
              zip(scale_factors, by_convs)
          ):
              # first we fractionaize
              if dim_by_convs:
                  frac = Fraction(1 / sf).limit_denominator(
                      max_numerator
                  )
                  frac = Fraction(
                      numerator=frac.denominator,
                      denominator=frac.numerator,
                  )
  
              # if accuracy is within tolerance scale will be frac. if not, then
              # it will be float and the by_convs attr will be set false for
              # this dim
              if scale_tolerance is None:
                  scale_tolerance = eps
              if dim_by_convs and abs(frac - sf) < scale_tolerance:
                  scale_factors[ind] = frac
              else:
                  scale_factors[ind] = float(sf)
                  by_convs[ind] = False
  
          return scale_factors, out_shape, by_convs
  
imports: import warnings
  from fractions import Fraction
  from math import ceil
  from typing import Tuple
  import disco_diffusion_clip_vitb32.resize_right.interp_methods
label_desc: Use image node_id 8 for calling a global function with example usage: set_scale_and_out_sz(in_shape, out_shape, scale_factors, by_convs, scale_tolerance, max_numerator, eps, fw) and returns: scale_factors,  out_shape,  by_convs