import pickle
import logging


def get_dataset(feature_set='basic', train=None, cv=None):
    """
    Return the design matrices constructed with the specified feature set.
    If train is specified, split the training set according to train and
    cv (if cv is not given, subsample's complement will be used instead).
    If subsample is omitted, return both the full training and test sets.
    """
    try:
        with open("cache/%s.pkl" % feature_set, 'rb') as f:
            if train is not None:
                X, _ = pickle.load(f)
                if cv is None:
                    cv = [i for i in range(X.shape[0]) if i not in train]

                X_test = X[cv, :]
                X = X[train, :]
            else:
                X, X_test = pickle.load(f)
    except IOError:
        logging.warning("could not find feature set %s", feature_set)
        return False

    return X, X_test