Convert a ctypes float pointer array to a numpy array.
514440
def cfloat32_array_to_numpy(cptr, length):
    """"""
    if isinstance(cptr, ctypes.POINTER(ctypes.c_float)):
        return np.fromiter(cptr, dtype=np.float32, count=length)
    else:
        raise RuntimeError('Expected float pointer')
551279
def array(self, dtype=None):
    """"""
    t = self._t
    # timestamp (12) through last enum (76)
    if 11 <= t < 77:
        dtype = dtypeof(self)
        a = numpy.empty(len(self), dtype)
        k2a(a, self)
        return a
    # table (98)
    if t == 98:
        if dtype is None:
            dtype = list(zip(self.cols, (dtypeof(c) for c in self.flip.value)))
        dtype = numpy.dtype(dtype)
        a = numpy.empty(int(self.count), dtype)
        for c in dtype.fields:
            k2a(a[c], self[c])
        return a
    return numpy.array(list(self), dtype)
134794
def to_array(tensor):  # type: (TensorProto) -> np.ndarray[Any]
    
    if tensor.HasField("segment"):
        raise ValueError(
            "Currently not supporting loading segments.")
    if tensor.data_type == TensorProto.UNDEFINED:
        raise ValueError("The data type is not defined.")

    tensor_dtype = tensor.data_type
    np_dtype = mapping.TENSOR_TYPE_TO_NP_TYPE[tensor_dtype]
    storage_type = mapping.TENSOR_TYPE_TO_STORAGE_TENSOR_TYPE[tensor_dtype]
    storage_np_dtype = mapping.TENSOR_TYPE_TO_NP_TYPE[storage_type]
    storage_field = mapping.STORAGE_TENSOR_TYPE_TO_FIELD[storage_type]
    dims = tensor.dims

    if tensor.data_type == TensorProto.STRING:
        utf8_strings = getattr(tensor, storage_field)
        ss = list(s.decode('utf-8') for s in utf8_strings)
        return np.asarray(ss).astype(np_dtype).reshape(dims)

    if tensor.HasField("raw_data"):
        # Raw_bytes support: using frombuffer.
        return np.frombuffer(
            tensor.raw_data,
            dtype=np_dtype).reshape(dims)
    else:
        data = getattr(tensor, storage_field),  # type: Sequence[np.complex64]
        if (tensor_dtype == TensorProto.COMPLEX64
                or tensor_dtype == TensorProto.COMPLEX128):
            data = combine_pairs_to_complex(data)
        return (
            np.asarray(
                data,
                dtype=storage_np_dtype)
            .astype(np_dtype)
            .reshape(dims)
        )
514578
def getUArray(npArr):
  """"""
  ufloats = []
  for dp in npArr:
      u = ufloat(dp[1], abs(dp[3]), 'stat')
      v = ufloat(dp[1], abs(dp[4]), 'syst')
      r = (u+v)/2.*dp[2]*2.
      ufloats.append(r)
      # NOTE: center value ok, but both error contribs half!
      # see getErrorComponent()
  return np.array(ufloats)
1191256
def ctypes2numpy(cptr, length, dtype):
    
    NUMPY_TO_CTYPES_MAPPING = {
        np.float32: ctypes.c_float,
        np.uint32: ctypes.c_uint,
    }
    if dtype not in NUMPY_TO_CTYPES_MAPPING:
        raise RuntimeError('Supported types: {}'.format(NUMPY_TO_CTYPES_MAPPING.keys()))
    ctype = NUMPY_TO_CTYPES_MAPPING[dtype]
    if not isinstance(cptr, ctypes.POINTER(ctype)):
        raise RuntimeError('expected {} pointer'.format(ctype))
    res = np.zeros(length, dtype=dtype)
    if not ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0]):
        raise RuntimeError('memmove failed')
    return res
542087
def data_type_to_numpy(datatype, unsigned=False):
    """"""
    basic_type = _dtypeLookup[datatype]

    if datatype in (stream.STRING, stream.OPAQUE):
        return np.dtype(basic_type)

    if unsigned:
        basic_type = basic_type.replace('i', 'u')
    return np.dtype('=' + basic_type)
622181
def array_bytes(shape, dtype):
    
    return np.product(shape)*np.dtype(dtype).itemsize
9479
def is_float_array(l):
    

    """
    if isinstance(l, np.ndarray):
        if l.dtype.kind == 'f':
            return True
    return False
742772
def _void_array_to_nested_list(res, _func, _args):
    
    try:
        shape = res.coords.len, 2
        ptr = cast(res.coords.data, POINTER(c_double))
        array = np.ctypeslib.as_array(ptr, shape)
        return array.tolist()
    finally:
        drop_array(res.coords)
693735
def to_0d_object_array(value: Any) -> np.ndarray:
    
    result = np.empty((), dtype=object)
    result[()] = value
    return result
326068
def ensure_dtype_float(x, default=np.float64):
    

    """
    if isinstance(x, np.ndarray):
        if x.dtype.kind == 'f':
            return x
        elif x.dtype.kind == 'i':
            return x.astype(default)
        else:
            raise TypeError('x is of type '+str(x.dtype)+' that cannot be converted to float')
    else:
        raise TypeError('x is not an array')
458638
def as_int_array(self):
        
        return self.view(
            type=ndarray,
            dtype=unsigned_int_dtype_with_size_in_bytes(self.itemsize),
        )
659583
def unpack_nullterm_array(array):
    

    addrs = cast(array, POINTER(ctypes.c_void_p))
    l = []
    i = 0
    value = array[i]
    while value:
        l.append(value)
        free(addrs[i])
        i += 1
        value = array[i]
    free(addrs)
    return l
1065233
def c_array(ctype, values):
    """"""
    if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype):
        return (ctype * len(values)).from_buffer_copy(values)
    return (ctype * len(values))(*values)
1268528
def encode_ndarray(obj):
    """"""
    shape = obj.shape
    if len(shape) == 1:
        shape = (1, obj.shape[0])
    if obj.flags.c_contiguous:
        obj = obj.T
    elif not obj.flags.f_contiguous:
        obj = asfortranarray(obj.T)
    else:
        obj = obj.T
    try:
        data = obj.astype(float64).tobytes()
    except AttributeError:
        data = obj.astype(float64).tostring()

    data = base64.b64encode(data).decode('utf-8')
    return data, shape
347129
def to_numpy(nd4j_array):
    
    buff = nd4j_array.data()
    address = buff.pointer().address()
    type_name = java_classes.DataTypeUtil.getDtypeFromContext()
    data_type = java_classes.DataTypeUtil.getDTypeForName(type_name)
    mapping = {
        'double': ctypes.c_double,
        'float': ctypes.c_float
    }
    Pointer = ctypes.POINTER(mapping[data_type])
    pointer = ctypes.cast(address, Pointer)
    np_array = np.ctypeslib.as_array(pointer, tuple(nd4j_array.shape()))
    return np_array
170460
def to_float(stype):
    
    output = []  # List of instructions

    if stype == 'f':
        return []  # Nothing to do

    if stype == 'f16':
        output.append('call __F16TOFREG')
        REQUIRES.add('f16tofreg.asm')
        return output

    # If we reach this point, it's an integer type
    if stype == 'u8':
        output.append('call __U8TOFREG')
    elif stype == 'i8':
        output.append('call __I8TOFREG')
    else:
        output = to_long(stype)
        if stype in ('i16', 'i32'):
            output.append('call __I32TOFREG')
        else:
            output.append('call __U32TOFREG')

    REQUIRES.add('u32tofreg.asm')

    return output