コード例 #1
0
 def testParseSingleRange(self):
   self.assertAllClose([[-0.1, 0.2]],
                       command_parser.parse_ranges("[-0.1, 0.2]"))
   self.assertAllClose([[-0.1, self.INF_VALUE]],
                       command_parser.parse_ranges("[-0.1, inf]"))
   self.assertAllClose([[-self.INF_VALUE, self.INF_VALUE]],
                       command_parser.parse_ranges("[-inf, inf]"))
コード例 #2
0
 def testParseSingleListOfRanges(self):
     self.assertAllClose(
         [[-0.1, 0.2], [10.0, 12.0]],
         command_parser.parse_ranges("[[-0.1, 0.2], [10,  12]]"))
     self.assertAllClose(
         [[-self.INF_VALUE, -1.0], [1.0, self.INF_VALUE]],
         command_parser.parse_ranges("[[-inf, -1.0],[1.0, inf]]"))
コード例 #3
0
 def testParseSingleRange(self):
     self.assertAllClose([[-0.1, 0.2]],
                         command_parser.parse_ranges("[-0.1, 0.2]"))
     self.assertAllClose([[-0.1, self.INF_VALUE]],
                         command_parser.parse_ranges("[-0.1, inf]"))
     self.assertAllClose([[-self.INF_VALUE, self.INF_VALUE]],
                         command_parser.parse_ranges("[-inf, inf]"))
コード例 #4
0
ファイル: cli_shared.py プロジェクト: moolighty/tensorflow
def parse_ranges_highlight(ranges_string):
  """Process ranges highlight string.

  Args:
    ranges_string: (str) A string representing a numerical range of a list of
      numerical ranges. See the help info of the -r flag of the print_tensor
      command for more details.

  Returns:
    An instance of tensor_format.HighlightOptions, if range_string is a valid
      representation of a range or a list of ranges.
  """

  ranges = None

  def ranges_filter(x):
    r = np.zeros(x.shape, dtype=bool)
    for range_start, range_end in ranges:
      r = np.logical_or(r, np.logical_and(x >= range_start, x <= range_end))

    return r

  if ranges_string:
    ranges = command_parser.parse_ranges(ranges_string)
    return tensor_format.HighlightOptions(
        ranges_filter, description=ranges_string)
  else:
    return None
コード例 #5
0
ファイル: cli_shared.py プロジェクト: 568xiaoma/WeChatProgram
def parse_ranges_highlight(ranges_string):
    """Process ranges highlight string.

  Args:
    ranges_string: (str) A string representing a numerical range of a list of
      numerical ranges. See the help info of the -r flag of the print_tensor
      command for more details.

  Returns:
    An instance of tensor_format.HighlightOptions, if range_string is a valid
      representation of a range or a list of ranges.
  """

    ranges = None

    def ranges_filter(x):
        r = np.zeros(x.shape, dtype=bool)
        for range_start, range_end in ranges:
            r = np.logical_or(r,
                              np.logical_and(x >= range_start, x <= range_end))

        return r

    if ranges_string:
        ranges = command_parser.parse_ranges(ranges_string)
        return tensor_format.HighlightOptions(ranges_filter,
                                              description=ranges_string)
    else:
        return None
コード例 #6
0
  def testParseInvalidRangeString(self):
    with self.assertRaises(SyntaxError):
      command_parser.parse_ranges("[[1,2]")

    with self.assertRaisesRegexp(ValueError,
                                 "Incorrect number of elements in range"):
      command_parser.parse_ranges("[1,2,3]")

    with self.assertRaisesRegexp(ValueError,
                                 "Incorrect number of elements in range"):
      command_parser.parse_ranges("[inf]")

    with self.assertRaisesRegexp(ValueError,
                                 "Incorrect type in the 1st element of range"):
      command_parser.parse_ranges("[1j, 1]")

    with self.assertRaisesRegexp(ValueError,
                                 "Incorrect type in the 2nd element of range"):
      command_parser.parse_ranges("[1, 1j]")
コード例 #7
0
    def testParseInvalidRangeString(self):
        with self.assertRaises(SyntaxError):
            command_parser.parse_ranges("[[1,2]")

        with self.assertRaisesRegexp(ValueError,
                                     "Incorrect number of elements in range"):
            command_parser.parse_ranges("[1,2,3]")

        with self.assertRaisesRegexp(ValueError,
                                     "Incorrect number of elements in range"):
            command_parser.parse_ranges("[inf]")

        with self.assertRaisesRegexp(
                ValueError, "Incorrect type in the 1st element of range"):
            command_parser.parse_ranges("[1j, 1]")

        with self.assertRaisesRegexp(
                ValueError, "Incorrect type in the 2nd element of range"):
            command_parser.parse_ranges("[1, 1j]")
コード例 #8
0
 def testParseSingleListOfRanges(self):
   self.assertAllClose([[-0.1, 0.2], [10.0, 12.0]],
                       command_parser.parse_ranges("[[-0.1, 0.2], [10,  12]]"))
   self.assertAllClose(
       [[-self.INF_VALUE, -1.0], [1.0, self.INF_VALUE]],
       command_parser.parse_ranges("[[-inf, -1.0],[1.0, inf]]"))
コード例 #9
0
 def testParseEmptyRangeString(self):
   self.assertEqual([], command_parser.parse_ranges(""))
   self.assertEqual([], command_parser.parse_ranges("  "))
コード例 #10
0
 def testParseEmptyRangeString(self):
     self.assertEqual([], command_parser.parse_ranges(""))
     self.assertEqual([], command_parser.parse_ranges("  "))