當前位置: 首頁>>代碼示例>>Python>>正文


Python flags.DEFINE_multi_integer方法代碼示例

本文整理匯總了Python中absl.flags.DEFINE_multi_integer方法的典型用法代碼示例。如果您正苦於以下問題:Python flags.DEFINE_multi_integer方法的具體用法?Python flags.DEFINE_multi_integer怎麽用?Python flags.DEFINE_multi_integer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在absl.flags的用法示例。


在下文中一共展示了flags.DEFINE_multi_integer方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_multi_numerical_flags

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import DEFINE_multi_integer [as 別名]
def test_multi_numerical_flags(self):
    """Test multi_int and multi_float flags."""

    int_defaults = [77, 88]
    flags.DEFINE_multi_integer('m_int', int_defaults,
                               'integer option that can occur multiple times',
                               short_name='mi')
    self.assertListEqual(FLAGS.get_flag_value('m_int', None), int_defaults)
    argv = ('./program', '--m_int=-99', '--mi=101')
    FLAGS(argv)
    self.assertListEqual(FLAGS.get_flag_value('m_int', None), [-99, 101])

    float_defaults = [2.2, 3]
    flags.DEFINE_multi_float('m_float', float_defaults,
                             'float option that can occur multiple times',
                             short_name='mf')
    for (expected, actual) in zip(
        float_defaults, FLAGS.get_flag_value('m_float', None)):
      self.assertAlmostEqual(expected, actual)
    argv = ('./program', '--m_float=-17', '--mf=2.78e9')
    FLAGS(argv)
    expected_floats = [-17.0, 2.78e9]
    for (expected, actual) in zip(
        expected_floats, FLAGS.get_flag_value('m_float', None)):
      self.assertAlmostEqual(expected, actual) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:27,代碼來源:flags_test.py

示例2: test_multi_numerical_with_tuples

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import DEFINE_multi_integer [as 別名]
def test_multi_numerical_with_tuples(self):
    """Verify multi_int/float accept tuples as default values."""
    flags.DEFINE_multi_integer(
        'm_int_tuple',
        (77, 88),
        'integer option that can occur multiple times',
        short_name='mi_tuple')
    self.assertListEqual(FLAGS.get_flag_value('m_int_tuple', None), [77, 88])

    dict_with_float_keys = {2.2: 'hello', 3: 'happy'}
    float_defaults = dict_with_float_keys.keys()
    flags.DEFINE_multi_float(
        'm_float_tuple',
        float_defaults,
        'float option that can occur multiple times',
        short_name='mf_tuple')
    for (expected, actual) in zip(float_defaults,
                                  FLAGS.get_flag_value('m_float_tuple', None)):
      self.assertAlmostEqual(expected, actual) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:21,代碼來源:flags_test.py

示例3: define_tpu_flags

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import DEFINE_multi_integer [as 別名]
def define_tpu_flags():
  """Define common flags for TPU."""
  flags.DEFINE_string(
      'tpu',
      default=None,
      help='The Cloud TPU to use for training. This should be either the name '
      'used when creating the Cloud TPU, or a grpc://ip.address.of.tpu:8470 '
      'url.')
  flags.DEFINE_string(
      'gcp_project',
      default=None,
      help='Project name for the Cloud TPU-enabled project. If not specified, we '
      'will attempt to automatically detect the GCE project from metadata.')
  flags.DEFINE_string(
      'tpu_zone',
      default=None,
      help='GCE zone where the Cloud TPU is located in. If not specified, we '
      'will attempt to automatically detect the GCE project from metadata.')
  flags.DEFINE_integer(
      'num_cores', default=8, help='Number of TPU cores for training')
  flags.DEFINE_string(
      'eval_master',
      default='',
      help='GRPC URL of the eval master. Set to an appropiate value when running '
      'on CPU/GPU')
  flags.DEFINE_bool('use_tpu', True, 'Use TPUs rather than CPUs')
  flags.DEFINE_multi_integer(
      'input_partition_dims', [1],
      'A list that describes the partition dims for all the tensors.')
  flags.DEFINE_integer('iterations_per_loop', 8,
                       'Number of iterations per TPU training loop') 
開發者ID:artyompal,項目名稱:tpu_models,代碼行數:33,代碼來源:tpu_executor.py

示例4: test_single_value_default

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import DEFINE_multi_integer [as 別名]
def test_single_value_default(self):
    """Test multi_int and multi_float flags with a single default value."""
    int_default = 77
    flags.DEFINE_multi_integer('m_int1', int_default,
                               'integer option that can occur multiple times')
    self.assertListEqual(FLAGS.get_flag_value('m_int1', None), [int_default])

    float_default = 2.2
    flags.DEFINE_multi_float('m_float1', float_default,
                             'float option that can occur multiple times')
    actual = FLAGS.get_flag_value('m_float1', None)
    self.assertEqual(1, len(actual))
    self.assertAlmostEqual(actual[0], float_default) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:15,代碼來源:flags_test.py

示例5: test_bad_multi_numerical_flags

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import DEFINE_multi_integer [as 別名]
def test_bad_multi_numerical_flags(self):
    """Test multi_int and multi_float flags with non-parseable values."""

    # Test non-parseable defaults.
    self.assertRaisesRegex(
        flags.IllegalFlagValueError,
        r"flag --m_int2=abc: invalid literal for int\(\) with base 10: 'abc'",
        flags.DEFINE_multi_integer, 'm_int2', ['abc'], 'desc')

    self.assertRaisesRegex(
        flags.IllegalFlagValueError,
        r'flag --m_float2=abc: '
        r'(invalid literal for float\(\)|could not convert string to float): '
        r"'?abc'?",
        flags.DEFINE_multi_float, 'm_float2', ['abc'], 'desc')

    # Test non-parseable command line values.
    flags.DEFINE_multi_integer('m_int2', '77',
                               'integer option that can occur multiple times')
    argv = ('./program', '--m_int2=def')
    self.assertRaisesRegex(
        flags.IllegalFlagValueError,
        r"flag --m_int2=def: invalid literal for int\(\) with base 10: 'def'",
        FLAGS, argv)

    flags.DEFINE_multi_float('m_float2', 2.2,
                             'float option that can occur multiple times')
    argv = ('./program', '--m_float2=def')
    self.assertRaisesRegex(
        flags.IllegalFlagValueError,
        r'flag --m_float2=def: '
        r'(invalid literal for float\(\)|could not convert string to float): '
        r"'?def'?",
        FLAGS, argv) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:36,代碼來源:flags_test.py

示例6: test_flag_help_in_xml_multi_int

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import DEFINE_multi_integer [as 別名]
def test_flag_help_in_xml_multi_int(self):
    flags.DEFINE_multi_integer('cols', [5, 7, 23],
                               'Columns to select', flag_values=self.fv)
    expected_output = (
        '<flag>\n'
        '  <file>tool</file>\n'
        '  <name>cols</name>\n'
        '  <meaning>Columns to select;\n    '
        'repeat this option to specify a list of values</meaning>\n'
        '  <default>[5, 7, 23]</default>\n'
        '  <current>[5, 7, 23]</current>\n'
        '  <type>multi int</type>\n'
        '</flag>\n')
    self._check_flag_help_in_xml('cols', 'tool', expected_output) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:16,代碼來源:flags_helpxml_test.py


注:本文中的absl.flags.DEFINE_multi_integer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。