code: def _setup_leg(
      start_date,
      end_date,
      discount_curve_type,
      leg,
      schedule_fn,
      schedule,
      past_fixing,
  ):
      """Setup swap legs."""
      if isinstance(leg, coupon_specs.FixedCouponSpecs):
          return cashflow_streams.FixedCashflowStream(
              start_date=start_date,
              end_date=end_date,
              coupon_spec=leg,
              schedule_fn=schedule_fn,
              schedule=schedule,
              discount_curve_type=discount_curve_type,
              dtype=tf.float64,
          )
      elif isinstance(leg, coupon_specs.FloatCouponSpecs):
          return cashflow_streams.FloatingCashflowStream(
              start_date=start_date,
              end_date=end_date,
              coupon_spec=leg,
              schedule_fn=schedule_fn,
              schedule=schedule,
              discount_curve_type=discount_curve_type,
              past_fixing=past_fixing,
              dtype=tf.float64,
          )
      elif isinstance(leg, dict):
          coupon_spec = leg["coupon_spec"]
          if "fixed_rate" in coupon_spec:
              coupon_spec = coupon_specs.FixedCouponSpecs(**coupon_spec)
              return cashflow_streams.FixedCashflowStream(
                  start_date=start_date,
                  end_date=end_date,
                  schedule_fn=schedule_fn,
                  schedule=schedule,
                  coupon_spec=coupon_spec,
                  discount_curve_type=leg["discount_curve_type"],
                  discount_curve_mask=leg["discount_curve_mask"],
                  dtype=tf.float64,
              )
          else:
              coupon_spec = coupon_specs.FloatCouponSpecs(**coupon_spec)
              return cashflow_streams.FloatingCashflowStream(
                  start_date=start_date,
                  end_date=end_date,
                  schedule_fn=schedule_fn,
                  schedule=schedule,
                  coupon_spec=coupon_spec,
                  discount_curve_type=leg["discount_curve_type"],
                  discount_curve_mask=leg["discount_curve_mask"],
                  reference_mask=leg["reference_mask"],
                  rate_index_curves=leg["rate_index_curves"],
                  past_fixing=past_fixing,
                  dtype=tf.float64,
              )
      else:
          raise ValueError(f"Unknown leg type {type(leg)}")
  
imports: import copy
  from typing import List, Dict, Optional, Union, Any
  import dataclasses
  import tensorflow.compat.v2
  from tf_quant_finance import datetime
  from tf_quant_finance import math
  from tf_quant_finance.experimental.pricing_platform.framework.core import curve_types
  from tf_quant_finance.experimental.pricing_platform.framework.core import instrument
  from tf_quant_finance.experimental.pricing_platform.framework.core import processed_market_data
  from tf_quant_finance.experimental.pricing_platform.framework.core import types
  from tf_quant_finance.experimental.pricing_platform.framework.market_data 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 coupon_specs
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.interest_rate_swap import proto_utils
  from tf_quant_finance.experimental.pricing_platform.instrument_protos import interest_rate_swap_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: _setup_leg(start_date, end_date, discount_curve_type, leg, schedule_fn, schedule, past_fixing) and returns: cashflow_streams, cashflow_streams, cashflow_streams, cashflow_streams