import torch


def tfidf_transform(tfidf_vectorizer, corpus_data, cuda0):
    """
        Apply TFIDF transformation to test data.
        Args:
            vectorizer_train (object): trained tfidf vectorizer
            newsgroups_test (ndarray): corpus of all documents from all categories in test set
        Returns:
            X_test (ndarray): tfidf word-document matrix of test data
    """
    corpus_list = corpus_data["text"].tolist()

    tfidf_vector = tfidf_vectorizer.fit_transform(corpus_list)

    X_test = torch.t(torch.tensor(tfidf_vector.todense(), dtype=torch.float64, device=cuda0))

    return X_test