import time


def reduce_to_feats(data_mat, feat_list, y_list):
    """ Reduce data matrix to those feature specified in feat_list.

    :param data_mat: data matrix
    :param feat_list: (list) list of features to keep
    :param y_list: (array) class labels, assumed binary
    :return: (array, array, array) reduced data matrix and sub-matrices
    """
    start_time = time.time()
    data_red = data_mat[:, feat_list]
    data_red_0 = data_red[y_list == 0]
    data_red_1 = data_red[y_list == 1]
    print('Dimensionality selection took: {}'.format(time.time() - start_time))

    print('Reduced data shapes:\nall: {}\nclass 0: {}\nclass 1: {}'.format(
        data_red.shape, data_red_0.shape, data_red_1.shape
    ))

    return data_red, data_red_0, data_red_1