def _from_int_array(msg: TIntMsg, dtype_base: npt.DTypeLike) -> np.ndarray:
    """Convert a Int16Array/Int32Array proto to a numpy array of the same shape.

    Args:
        msg: Message to extract array from.
        dtype_size: Number of bytes per int.

    Returns:
        Numpy array with signed integer type.
    """
    if not msg.shape:
        raise ValueError(f"Cannot convert unset/empty {type(msg)} message to a numpy array.")

    array_format = msg.WhichOneof("data")
    if array_format != "flat_bytes":
        raise ValueError(
            "Error deserializing int ndarray proto: only flat_bytes format "
            f"supported; given {array_format}"
        )  # pragma: no cover

    dtype = _from_dtype(
        getattr(msg, "endianness", cast(ndarrays_pb2.Endianness, ndarrays_pb2.LITTLE_ENDIAN)),
        dtype_base,
    )
    flat = np.frombuffer(msg.flat_bytes, dtype=dtype)
    return np.reshape(flat, msg.shape)
Convert a Int16Array/Int32Array proto to a numpy array of the same shape.

    Args:
        msg: Message to extract array from.
        dtype_size: Number of bytes per int.

    Returns:
        Numpy array with signed integer type.
    
cirq-google/cirq_google/api/v2/ndarrays.py