def read_bin_lush_matrix(filepath):
    """
    Reads a binary matrix saved by the lush library.

    Parameters
    ----------
    filepath : str
        The path to the file.

    Returns
    -------
    matrix : ndarray
        A NumPy version of the stored matrix.
    """
    f = open(filepath, 'rb')
    try:
        magic = read_int(f)
    except __HOLE__:
        reraise_as("Couldn't read magic number")
    ndim = read_int(f)

    if ndim == 0:
        shape = ()
    else:
        shape = read_int(f, max(3, ndim))

    total_elems = 1
    for dim in shape:
        total_elems *= dim

    try:
        dtype = lush_magic[magic]
    except KeyError:
        reraise_as(ValueError('Unrecognized lush magic number ' + str(magic)))

    rval = np.fromfile(file=f, dtype=dtype, count=total_elems)

    excess = f.read(-1)

    if excess:
        raise ValueError(str(len(excess)) +
                         ' extra bytes found at end of file.'
                         ' This indicates  mismatch between header '
                         'and content')

    rval = rval.reshape(*shape)

    f.close()

    return rval
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/serial.py/read_bin_lush_matrix