code: def tensor_repr(
      am_option_data: Dict[str, Any],
      dtype: Optional[types.Dtype] = None,
  ):
      """Creates a tensor representation of an American option."""
      dtype = dtype or tf.float64
      res = dict()
      res["expiry_date"] = tf.convert_to_tensor(
          am_option_data["expiry_date"],
          dtype=tf.int32,
          name="expiry_date",
      )
      am_option_config = am_option_data["config"]
      res["config"] = None
      if am_option_config is not None:
          res["config"] = config_to_dict(am_option_config)
      res["batch_names"] = am_option_data["batch_names"]
      res["is_call_option"] = tf.convert_to_tensor(
          am_option_data["is_call_option"],
          dtype=tf.bool,
          name="is_call_options",
      )
      currency = am_option_data["currency"]
      if not isinstance(currency, (list, tuple)):
          currency = [currency]
      discount_curve_type = []
      for cur in currency:
          if res["config"] is not None:
              if cur in res["config"]["discounting_curve"]:
                  discount_curve = res["config"]["discounting_curve"][
                      cur
                  ]
                  discount_curve_type.append(discount_curve)
              else:
                  risk_free = curve_types_lib.RiskFreeCurve(
                      currency=cur
                  )
                  discount_curve_type.append(risk_free)
          else:
              # Default discounting is the risk free curve
              risk_free = curve_types_lib.RiskFreeCurve(currency=cur)
              discount_curve_type.append(risk_free)
      discount_curve_type, mask = cashflow_streams.process_curve_types(
          discount_curve_type
      )
      res["discount_curve_mask"] = tf.convert_to_tensor(
          mask, dtype=tf.int32
      )
      res["discount_curve_type"] = discount_curve_type
      # Get equity mask
      equity_list = cashflow_streams.to_list(am_option_data["equity"])
      [
          equity,
          equity_mask,
      ] = equity_utils.process_equities(equity_list)
      res["equity_mask"] = tf.convert_to_tensor(equity_mask, tf.int32)
      res["equity"] = equity
      res["contract_amount"] = tf.convert_to_tensor(
          am_option_data["contract_amount"], dtype=dtype
      )
      res["strike"] = tf.convert_to_tensor(
          am_option_data["strike"], dtype=dtype
      )
      res["calendar"] = am_option_data["calendar"]
      res["currency"] = [
          curve.currency for curve in discount_curve_type
      ]
      res["business_day_convention"] = am_option_data[
          "business_day_convention"
      ]
      res["short_position"] = tf.convert_to_tensor(
          am_option_data["short_position"], dtype=tf.bool
      )
      return res
  
file_path: tf-quant-finance/tf_quant_finance/experimental/pricing_platform/framework/equity_instruments/american_option/proto_utils.py
imports: from typing import Any, List, Dict, Tuple, Optional
  import tensorflow.compat.v2
  from tf_quant_finance.experimental.pricing_platform.framework import utils
  from tf_quant_finance.experimental.pricing_platform.framework.core import business_days
  from tf_quant_finance.experimental.pricing_platform.framework.core import currencies
  from tf_quant_finance.experimental.pricing_platform.framework.core import curve_types
  from tf_quant_finance.experimental.pricing_platform.framework.core import types
  from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments import utils
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import cashflow_streams
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import utils
  from tf_quant_finance.experimental.pricing_platform.instrument_protos import american_equity_option_pb2
label_desc: Use image node_id 4 for calling a global function with example usage: tensor_repr(am_option_data, dtype) and returns: res