Obtains value for scalar event given blob and dtype enum.

    Args:
      scalar_data_blob: The blob obtained from the database.
      dtype_enum: The enum representing the dtype.

    Returns:
      The scalar value.
547856
def _get_value(self, scalar_data_blob, dtype_enum):
    
    tensorflow_dtype = tf.DType(dtype_enum)
    buf = np.frombuffer(scalar_data_blob, dtype=tensorflow_dtype.as_numpy_dtype)
    return np.asscalar(buf)
759103
public org.tensorflow.framework.DataType getDtype() {
    org.tensorflow.framework.DataType result = org.tensorflow.framework.DataType.valueOf(dtype_);
    return result == null ? org.tensorflow.framework.DataType.UNRECOGNIZED : result;
  }
1064367
def GetEventTypeString(self, event_type):
    
    if 0 <= event_type < len(self._EVENT_TYPES):
      return self._EVENT_TYPES[event_type]
    return 'Unknown {0:d}'.format(event_type)
498458
def get_data(self, datatype, mode, disp):
        

        # Imports
        import os
        from ..const import EnumDispDirection as _E_DD
        from ..const import EnumAnharmRepoData
        from ..error import RepoError as RErr

        # Must be valid mode
        if not (mode >=0 and isinstance(mode, int)):
            raise ValueError("Mode must be a non-negative integer")
        ## end if

        # Must be a valid disp direction
        if not disp in _E_DD:
            raise ValueError("'{0}' is not a valid " +
                    "displacement enum value".format(disp))
        ## end if

        # Must be a valid data type
        if not datatype in EnumAnharmRepoData:
            raise ValueError("'{0}' is not a valid " +
                    "repository data type enum value".format(datatype))
        ## end if

        # Get the appropriate geom group name
        if disp == _E_DD.NO_DISP:
            grpname = self.G_geom_ref
        else:
            grpname = self.F_mode_fmt % \
                                    (mode, self.dircode[disp])
        ## end if

        # Get the group, complaining if repo not bound
        try:
            grp = self._repo.get(grpname)
        except AttributeError:
            raise RErr(RErr.STATUS,
                        "Cannot load; no repository open", "")
        ## end try

        # If succeeded, check if group not found
        if grp is None:
            raise RErr(RErr.GROUP,
                    "Group '" + grpname + "' not found",
                    self.fname)
        ## end if

        # Group found, try loading the data object; complain if not found
        try:
            out_data = grp.get(datatype).value
        except AttributeError:
            raise RErr(RErr.DATA,
                    "Dataset '" + datatype + "' not found",
                    self.fname)
        ## end try

        # Return as-is (h5py creates NumPy arrays of appropriate dimensions)
        return out_data
1075497
async def blob_load(self, elem_type, params=None, elem=None):
        
        ivalue = await load_uvarint(self.iobj)
        fvalue = bytearray(ivalue)
        await self.iobj.areadinto(fvalue)

        if elem is None:
            return fvalue  # array by default

        elif isinstance(elem, x.BlobType):
            setattr(elem, elem_type.DATA_ATTR, fvalue)
            return elem

        else:
            elem.extend(fvalue)

        return elem
699566
def _get_dbal_column_type(self, type_):
        
        type_ = type_.lower()

        if type_ == "enum":
            return "string"

        return super(PostgresSchemaGrammar, self)._get_dbal_column_type(type_)
820418
def is_enum_type(type_):
    

    return isinstance(type_, type) and issubclass(type_, tuple(_get_types(Types.ENUM)))
323459
private Object getEnumValue(Class<?> type, Object value) {
        Object[] enumValues = type.getEnumConstants();
        for (Object enumValue : enumValues) {
            if (enumValue.toString().equals(value.toString())) {
                value = enumValue;
                break;
            }
        }
        return value;
    }
576564
def publish_event_from_dict(self, event_type, data):
        
        for key, value in self.additional_publish_event_data.items():
            if key in data:
                return {'result': 'error', 'message': 'Key should not be in publish_event data: {}'.format(key)}
            data[key] = value

        self.runtime.publish(self, event_type, data)
        return {'result': 'success'}
514642
def parse_row(schema, data):
    
    def parse_value(data_type, value):
      """Parses a value returned from a BigQuery response.

      Args:
        data_type: the type of the value as specified by the schema.
        value: the raw value to return (before casting to data_type).

      Returns:
        The value cast to the data_type.
      """
      if value is not None:
        if value == 'null':
          value = None
        elif data_type == 'INTEGER':
          value = int(value)
        elif data_type == 'FLOAT':
          value = float(value)
        elif data_type == 'TIMESTAMP':
          value = datetime.datetime.utcfromtimestamp(float(value))
        elif data_type == 'BOOLEAN':
          value = value == 'true'
        elif (type(value) != str):
          # TODO(gram): Handle nested JSON records
          value = str(value)
      return value

    row = {}
    if data is None:
      return row

    for i, (field, schema_field) in enumerate(zip(data['f'], schema)):
      val = field['v']
      name = schema_field['name']
      data_type = schema_field['type']
      repeated = True if 'mode' in schema_field and schema_field['mode'] == 'REPEATED' else False

      if repeated and val is None:
        row[name] = []
      elif data_type == 'RECORD':
        sub_schema = schema_field['fields']
        if repeated:
          row[name] = [Parser.parse_row(sub_schema, v['v']) for v in val]
        else:
          row[name] = Parser.parse_row(sub_schema, val)
      elif repeated:
        row[name] = [parse_value(data_type, v['v']) for v in val]
      else:
        row[name] = parse_value(data_type, val)

    return row
689062
def _get_tbl_numpy_dtype(self, colnum, include_endianness=True):
        
        table_type = self._info['hdutype']
        table_type_string = _hdu_type_map[table_type]
        try:
            ftype = self._info['colinfo'][colnum]['eqtype']
            if table_type == ASCII_TBL:
                npy_type = _table_fits2npy_ascii[abs(ftype)]
            else:
                npy_type = _table_fits2npy[abs(ftype)]
        except KeyError:
            raise KeyError("unsupported %s fits data "
                           "type: %d" % (table_type_string, ftype))

        istbit = False
        if (ftype == 1):
            istbit = True

        isvar = False
        if ftype < 0:
            isvar = True
        if include_endianness:
            # if binary we will read the big endian bytes directly,
            # if ascii we read into native byte order
            if table_type == ASCII_TBL:
                addstr = ''
            else:
                addstr = '>'
            if npy_type not in ['u1', 'i1', 'S', 'U']:
                npy_type = addstr+npy_type

        if npy_type == 'S':
            width = self._info['colinfo'][colnum]['width']
            npy_type = 'S%d' % width
        elif npy_type == 'U':
            width = self._info['colinfo'][colnum]['width']
            npy_type = 'U%d' % width

        return npy_type, isvar, istbit
835468
def _resolve_dtype(data_type):
    """"""
    if isinstance(data_type, _FIXED_ATOMIC):
        out = _get_atomic_dtype(data_type)
    elif isinstance(data_type, _FLEXIBLE_ATOMIC):
        out = (_get_atomic_dtype(data_type), data_type.length)
    elif isinstance(data_type, Array):
        shape = data_type.shape
        if isinstance(shape, _SEQUENCE_TYPES) and len(shape) == 1:
            # Workaround the exception `ValueError: invalid itemsize in
            # generic type tuple` when an `Array` of shape 0 or (0,) is nested
            # within another `Array`.
            shape = shape[0]

        out = (_resolve_dtype(data_type.element_type), shape)
    elif isinstance(data_type, Structure):
        out = [(field.name, _resolve_dtype(field.type))
               for field in data_type.fields]

    return out
1209194
def _cell_scalar(self, name=None):
        
        if name is None:
            # use active scalar array
            field, name = self.active_scalar_info
            if field != CELL_DATA_FIELD:
                raise RuntimeError('Must specify an array to fetch.')

        vtkarr = self.GetCellData().GetArray(name)
        if vtkarr is None:
            raise AssertionError('({}) is not a cell scalar'.format(name))

        # numpy does not support bit array data types
        if isinstance(vtkarr, vtk.vtkBitArray):
            vtkarr = vtk_bit_array_to_char(vtkarr)
            if name not in self._cell_bool_array_names:
                self._cell_bool_array_names.append(name)

        array = vtk_to_numpy(vtkarr)
        if array.dtype == np.uint8 and name in self._cell_bool_array_names:
            array = array.view(np.bool)
        return array
590373
def __recognize_scalar(self, node: yaml.Node,
                           expected_type: Type) -> RecResult:
        
        logger.debug('Recognizing as a scalar')
        if (isinstance(node, yaml.ScalarNode)
                and node.tag == scalar_type_to_tag[expected_type]):
            return [expected_type], ''
        message = 'Failed to recognize a {}\n{}\n'.format(
            type_to_desc(expected_type), node.start_mark)
        return [], message
293705
def decode(self, bytes):
        
        value = self.type.decode(bytes)
        if self._enum is not None:
            for name, val in self._enum.items():
                if value == val:
                    value = name
                    break
        return value
1078596
def _protobuf_value_type(value):
  
  if value.HasField("number_value"):
    return api_pb2.DATA_TYPE_FLOAT64
  if value.HasField("string_value"):
    return api_pb2.DATA_TYPE_STRING
  if value.HasField("bool_value"):
    return api_pb2.DATA_TYPE_BOOL
  return None
884541
def get_value(self) -> ScalarType:
        
        if self.yaml_node.tag == 'tag:yaml.org,2002:str':
            return self.yaml_node.value
        if self.yaml_node.tag == 'tag:yaml.org,2002:int':
            return int(self.yaml_node.value)
        if self.yaml_node.tag == 'tag:yaml.org,2002:float':
            return float(self.yaml_node.value)
        if self.yaml_node.tag == 'tag:yaml.org,2002:bool':
            return self.yaml_node.value in ['TRUE', 'True', 'true']
        if self.yaml_node.tag == 'tag:yaml.org,2002:null':
            return None
        raise RuntimeError('This node with tag {} is not of the right type'
                           ' for get_value()'.format(self.yaml_node.tag))