def test_tfidf_transformer_sparse(): X = cupyx.scipy.sparse.rand(10, 2000, dtype=np.float64, random_state=123) X_csc = cupyx.scipy.sparse.csc_matrix(X) X_csr = cupyx.scipy.sparse.csr_matrix(X) X_trans_csc = TfidfTransformer().fit_transform(X_csc).todense() X_trans_csr = TfidfTransformer().fit_transform(X_csr).todense() cp.testing.assert_array_almost_equal(X_trans_csc, X_trans_csr)
def test_tfidf_transformer_copy(norm, use_idf, smooth_idf, sublinear_tf): if use_idf: pytest.xfail( "cupyx.scipy.sparse.csr does not support inplace multiply.") data_gpu = cupyx.scipy.sparse.csr_matrix( cp.array([[0, 1, 1, 1], [0, 2, 0, 1]], dtype=cp.float64, order='F')) tfidf = TfidfTransformer(norm=norm, use_idf=use_idf, smooth_idf=smooth_idf, sublinear_tf=sublinear_tf) res = tfidf.fit_transform(data_gpu, copy=False) cp.testing.assert_array_almost_equal(data_gpu.todense(), res.todense())
def test_tfidf_transformer(data, norm, use_idf, smooth_idf, sublinear_tf): data_gpu = cp.array(data) tfidf = TfidfTransformer(norm=norm, use_idf=use_idf, smooth_idf=smooth_idf, sublinear_tf=sublinear_tf) sk_tfidf = SkTfidfTransfo(norm=norm, use_idf=use_idf, smooth_idf=smooth_idf, sublinear_tf=sublinear_tf) res = tfidf.fit_transform(data_gpu).todense() ref = sk_tfidf.fit_transform(data).todense() cp.testing.assert_array_almost_equal(res, ref)