parameters: (self, spec)
return_statement: return self
docstring: Parse a `DeviceSpec` name into its components.
  
      Args:
        spec: a string of the form
         /job:<name>/replica:<id>/task:<id>/device:CPU:<id>
        or
         /job:<name>/replica:<id>/task:<id>/device:GPU:<id>
        as cpu and gpu are mutually exclusive.
        All entries are optional.
  
      Returns:
        The `DeviceSpec`.
  
      Raises:
        ValueError: if the spec was not valid.
docstring_summary: Parse a `DeviceSpec` name into its components.
docstring_tokens: Parse a DeviceSpec name into its components .
function: def parse_from_string(self, spec):
      """Parse a `DeviceSpec` name into its components.
  
      Args:
        spec: a string of the form
         /job:<name>/replica:<id>/task:<id>/device:CPU:<id>
        or
         /job:<name>/replica:<id>/task:<id>/device:GPU:<id>
        as cpu and gpu are mutually exclusive.
        All entries are optional.
  
      Returns:
        The `DeviceSpec`.
  
      Raises:
        ValueError: if the spec was not valid.
      """
      self._clear()
      splits = [x.split(":") for x in spec.split("/")]
      for y in splits:
        ly = len(y)
        if y:
          # NOTE(touts): we use the property getters here.
          if ly == 2 and y[0] == "job":
            self.job = y[1]
          elif ly == 2 and y[0] == "replica":
            self.replica = y[1]
          elif ly == 2 and y[0] == "task":
            self.task = y[1]
          elif ((ly == 1 or ly == 2) and
                ((y[0].upper() == "GPU") or (y[0].upper() == "CPU"))):
            if self.device_type is not None:
              raise ValueError("Cannot specify multiple device types: %s" % spec)
            self.device_type = y[0].upper()
            if ly == 2 and y[1] != "*":
              self.device_index = int(y[1])
          elif ly == 3 and y[0] == "device":
            if self.device_type is not None:
              raise ValueError("Cannot specify multiple device types: %s" % spec)
            self.device_type = y[1]
            if y[2] != "*":
              self.device_index = int(y[2])
          elif ly and y[0] != "":  # pylint: disable=g-explicit-bool-comparison
            raise ValueError("Unknown attribute: '%s' in '%s'" % (y[0], spec))
  
      return self
function_tokens: def parse_from_string ( self , spec ) : self . _clear ( ) splits = [ x . split ( ":" ) for x in spec . split ( "/" ) ] for y in splits : ly = len ( y ) if y : # NOTE(touts): we use the property getters here. if ly == 2 and y [ 0 ] == "job" : self . job = y [ 1 ] elif ly == 2 and y [ 0 ] == "replica" : self . replica = y [ 1 ] elif ly == 2 and y [ 0 ] == "task" : self . task = y [ 1 ] elif ( ( ly == 1 or ly == 2 ) and ( ( y [ 0 ] . upper ( ) == "GPU" ) or ( y [ 0 ] . upper ( ) == "CPU" ) ) ) : if self . device_type is not None : raise ValueError ( "Cannot specify multiple device types: %s" % spec ) self . device_type = y [ 0 ] . upper ( ) if ly == 2 and y [ 1 ] != "*" : self . device_index = int ( y [ 1 ] ) elif ly == 3 and y [ 0 ] == "device" : if self . device_type is not None : raise ValueError ( "Cannot specify multiple device types: %s" % spec ) self . device_type = y [ 1 ] if y [ 2 ] != "*" : self . device_index = int ( y [ 2 ] ) elif ly and y [ 0 ] != "" : # pylint: disable=g-explicit-bool-comparison raise ValueError ( "Unknown attribute: '%s' in '%s'" % ( y [ 0 ] , spec ) ) return self