From ae4ff39705143c31f9819c877732008d6c3f1db8 Mon Sep 17 00:00:00 2001 From: janezd Date: Sat, 15 Feb 2020 17:16:46 +0100 Subject: [PATCH] manifold: Load openTSNE lazily --- Orange/projection/manifold.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Orange/projection/manifold.py b/Orange/projection/manifold.py index f67874e59b0..c65952ee657 100644 --- a/Orange/projection/manifold.py +++ b/Orange/projection/manifold.py @@ -8,10 +8,6 @@ from scipy.sparse.linalg import eigsh as arpack_eigh import sklearn.manifold as skl_manifold -import openTSNE -import openTSNE.affinity -import openTSNE.initialization - import Orange from Orange.data import Table, Domain, ContinuousVariable from Orange.distance import Distance, DistanceModel, Euclidean @@ -21,9 +17,19 @@ __all__ = ["MDS", "Isomap", "LocallyLinearEmbedding", "SpectralEmbedding", "TSNE"] -# Disable t-SNE user warnings -openTSNE.tsne.log.setLevel(logging.ERROR) -openTSNE.affinity.log.setLevel(logging.ERROR) + +class _LazyTSNE: # pragma: no cover + def __getattr__(self, attr): + # pylint: disable=import-outside-toplevel,redefined-outer-name,global-statement + global openTSNE + import openTSNE + # Disable t-SNE user warnings + openTSNE.tsne.log.setLevel(logging.ERROR) + openTSNE.affinity.log.setLevel(logging.ERROR) + return openTSNE.__dict__[attr] + + +openTSNE = _LazyTSNE() def torgerson(distances, n_components=2, eigen_solver="auto"):