class_docstr: Apply a linear affine transform to the input 2D image tensor. The value at the
  ``(x, y)`` (i.e., ``(w, h)``) coordinate of the output is computed by first computing
  the coordinates ``x’`` and ``y’`` with the following equation, and then computing the
  value at the coordinate ``(x’,y’)`` in the input image using either bilinear or
  nearest neighbor interpolation. If the ``(x’, y’)`` point falls outside the input
  image, then padding information is used to compute the value::
  
      x’ = a0 * x + a1 * y + a2
      y’ = b0 * x + b1 * y + b2
  
  
  Parameters
  ----------
  x: tensor<[B, C, H1, W1], T>
     * Must be rank ``4``.
  transform_matrix: tensor<[D, 6], T>
     * Must be rank ``2``.
     * ``D`` can be either ``B`` or 1.
        * If ``D == B``, there is a separate transform matrix for each batch.
        * If ``D == 1``, the same matrix is used for all input batches.
        * For each batch: ``[a0, a1, a2, b0, b1, b2]``.
  output_height: const<i32>
     * Target output height
  output_width: const<i32>
     * Target output width
  sampling_mode: const<str>
     * Allowed values: ``"bilinear"``
  padding_mode: const<str>
     * Allowed values: ``"constant"``.
     * Note that the following example is 1D case for brevity. The op supports only 2D image input.
     * If ``padding_mode == "constant"``:
        * The input image is assumed to be padded with the padding_value.
        * For example, ``|1, 2, 3| -> |0, 0, 0, 1, 2, 3, 0, 0, 0|``.
  padding_value: const<T>
     * Currently non-zero values are not supported.
     * To be used only when ``padding_mode == "constant"``, ignored in other cases.
  coordinates_mode: const<str>
     * Allowed values: ``"normalized_minus_one_to_one"``.
     * If ``coordinates_mode == "normalized_minus_one_to_one"``, in-image values are ``[-1, 1]``.
     * For example, if ``coordinates_mode == "normalized_minus_one_to_one"``, the in-range values are ``[-1, 1]``. That is:
        * ``(-1, -1)``, i.e. ``(w=-1, h=-1)``, corresponds to the top-left pixel.
        * ``(1, -1)``, i.e. ``(w=1, h=-1)``, corresponds to the top-right pixel.
        * ``(-1, 1)``, i.e. ``(w=-1, h=1)``, corresponds to the bottom-left pixel.
        * ``(1, 1)``, i.e. ``(w=1, h=1)``, corresponds to the bottom-right pixel.
  align_corners: const<bool>
     * Currently ``align_corners=False`` is not supported.
     * To be used only when ``coordinates_mode != unnormalized``, ignored otherwise.
     * If ``align_corners == True``, the extrema coordinates correspond to the center of the first and last corner pixels.
     * If ``align_corners == False``, the extrema coordinates correspond to the edge of the first and last corner pixels.
  
  Returns
  -------
  tensor<[B, C, output_height, output_width], T>
  
  Attributes
  ----------
  T: fp16, fp32
class_docstr_tok: ["Apply","a","linear","affine","transform","to","the","input","2D","image","tensor",".","The","value","at","the","``","(","x",",","y",")","``","(","i.e.",",","``","(","w",",","h",")","``",")","coordinate","of","the","output","is","computed","by","first","computing","the","coordinates","``","x","\u2019","``","and","``","y","\u2019","``","with","the","following","equation",",","and","then","computing","the","value","at","the","coordinate","``","(","x","\u2019",",","y","\u2019",")","``","in","the","input","image","using","either","bilinear","or","nearest","neighbor","interpolation",".","If","the","``","(","x","\u2019",",","y","\u2019",")","``","point","falls","outside","the","input","image",",","then","padding","information","is","used","to","compute","the","value",":",":","x","\u2019","=","a0","*","x","+","a1","*","y","+","a2","y","\u2019","=","b0","*","x","+","b1","*","y","+","b2","Parameters","--","--","--","--","--","x",":","tensor","<","[","B",",","C",",","H1",",","W1","]",",","T",">","*","Must","be","rank","``","4","``",".","transform_matrix",":","tensor","<","[","D",",","6","]",",","T",">","*","Must","be","rank","``","2","``",".","*","``","D","``","can","be","either","``","B","``","or","1",".","*","If","``","D","==","B","``",",","there","is","a","separate","transform","matrix","for","each","batch",".","*","If","``","D","==","1","``",",","the","same","matrix","is","used","for","all","input","batches",".","*","For","each","batch",":","``","[","a0",",","a1",",","a2",",","b0",",","b1",",","b2","]","``",".","output_height",":","const","<","i32",">","*","Target","output","height","output_width",":","const","<","i32",">","*","Target","output","width","sampling_mode",":","const","<","str",">","*","Allowed","values",":","``","``","bilinear","''","``","padding_mode",":","const","<","str",">","*","Allowed","values",":","``","``","constant","''","``",".","*","Note","that","the","following","example","is","1D","case","for","brevity",".","The","op","supports","only","2D","image","input",".","*","If","``","padding_mode","==","``","constant","''","``",":","*","The","input","image","is","assumed","to","be","padded","with","the","padding_value",".","*","For","example",",","``","|1",",","2",",","3|","-",">","|0",",","0",",","0",",","1",",","2",",","3",",","0",",","0",",","0|","``",".","padding_value",":","const","<","T",">","*","Currently","non-zero","values","are","not","supported",".","*","To","be","used","only","when","``","padding_mode","==","``","constant","''","``",",","ignored","in","other","cases",".","coordinates_mode",":","const","<","str",">","*","Allowed","values",":","``","``","normalized_minus_one_to_one","''","``",".","*","If","``","coordinates_mode","==","``","normalized_minus_one_to_one","''","``",",","in-image","values","are","``","[","-1",",","1","]","``",".","*","For","example",",","if","``","coordinates_mode","==","``","normalized_minus_one_to_one","''","``",",","the","in-range","values","are","``","[","-1",",","1","]","``",".","That","is",":","*","``","(","-1",",","-1",")","``",",","i.e",".","``","(","w=-1",",","h=-1",")","``",",","corresponds","to","the","top-left","pixel",".","*","``","(","1",",","-1",")","``",",","i.e",".","``","(","w=1",",","h=-1",")","``",",","corresponds","to","the","top-right","pixel",".","*","``","(","-1",",","1",")","``",",","i.e",".","``","(","w=-1",",","h=1",")","``",",","corresponds","to","the","bottom-left","pixel",".","*","``","(","1",",","1",")","``",",","i.e",".","``","(","w=1",",","h=1",")","``",",","corresponds","to","the","bottom-right","pixel",".","align_corners",":","const","<","bool",">","*","Currently","``","align_corners=False","``","is","not","supported",".","*","To","be","used","only","when","``","coordinates_mode","!","=","unnormalized","``",",","ignored","otherwise",".","*","If","``","align_corners","==","True","``",",","the","extrema","coordinates","correspond","to","the","center","of","the","first","and","last","corner","pixels",".","*","If","``","align_corners","==","False","``",",","the","extrema","coordinates","correspond","to","the","edge","of","the","first","and","last","corner","pixels",".","Returns","--","--","--","-","tensor","<","[","B",",","C",",","output_height",",","output_width","]",",","T",">","Attributes","--","--","--","--","--","T",":","fp16",",","fp32"]
code: def type_inference(self):
      if self.x.rank != 4:
          raise ValueError(
              'input "x" to the "affine" op must be a rank 4 tensor. '
              "Got rank {} tensor of shape {}".format(
                  self.x.rank, self.x.shape
              )
          )
      if self.transform_matrix.rank != 2:
          raise ValueError(
              'input "transform_matrix" to the "affine" op must be a rank 2 tensor. '
              "Got rank {} tensor of shape {}".format(
                  self.transform_matrix.rank,
                  self.transform_matrix.shape,
              )
          )
      if self.sampling_mode.val.lower() != "bilinear":
          raise NotImplementedError(
              'input "sampling_mode" to the "affine" not implemented. '
              'Got "{}"'.format(self.sampling_mode.val)
          )
      if (
          self.coordinates_mode.val.lower()
          != "normalized_minus_one_to_one"
      ):
          raise NotImplementedError(
              'input "coordinates_mode" to the "affine" not implemented. '
              'Got "{}"'.format(self.coordinates_mode.val)
          )
      if (
          self.padding_mode.val.lower() != "constant"
          or self.padding_value.val != 0.0
      ):
          raise NotImplementedError(
              'input "padding_mode" to the "affine" not implemented. '
              'Got "{}" with "padding_value={}"'.format(
                  self.padding_mode.val, self.padding_value.val
              )
          )
  
      input_shape = self.x.shape
      transform_matrix_shape = self.transform_matrix.shape
      if (
          not is_symbolic(transform_matrix_shape[-1])
          and transform_matrix_shape[-1] != 6
      ):
          raise ValueError(
              'input "transform_matrix" to the "affine" op last dimension must be 6 '
              "[a0, a1, a2, b0, b1, b2], "
              "Got {} for last dimension".format(
                  transform_matrix_shape[-1]
              )
          )
  
      ret_shape = list(input_shape)
      ret_shape[2] = self.output_height.val
      ret_shape[3] = self.output_width.val
      return types.tensor(self.x.dtype, tuple(ret_shape))
  
imports: import numpy
  from coremltools.converters.mil.mil import DefaultInputs, InputSpec, Operation, TensorInputType, get_new_symbol, types
  from coremltools.converters.mil.mil.ops.defs._op_reqs import register_op
  from coremltools.converters.mil.mil.ops.defs.iOS15 import _IOS15_TARGET
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic
label_desc: Use image node_id 1 for calling the affine obj's underlying member method code with example usage: obj.type_inference() and returns: types