From d861a7b5c27a6c11ea38be9e3025ede5b151ece5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Defferrard?= Date: Thu, 14 Dec 2017 14:11:22 +0100 Subject: [PATCH] pyunlocbox as an optional dependency --- pygsp/optimization.py | 13 ++++++++++++- setup.py | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pygsp/optimization.py b/pygsp/optimization.py index 1b61f407..658673f1 100644 --- a/pygsp/optimization.py +++ b/pygsp/optimization.py @@ -11,6 +11,16 @@ logger = utils.build_logger(__name__) +def _import_pyunlocbox(): + try: + from pyunlocbox import functions, solvers + except Exception: + raise ImportError('Cannot import pyunlocbox, which is needed to solve ' + 'this optimization problem. Try to install it with ' + 'pip (or conda) install pyunlocbox.') + return functions, solvers + + def prox_tv(x, gamma, G, A=None, At=None, nu=1, tol=10e-4, maxit=200, use_matrix=True): r""" Total Variation proximal operator for graphs. @@ -81,4 +91,5 @@ def l1_a(x): def l1_at(x): return G.div(x) - pyunlocbox.prox_l1(x, gamma, A=l1_a, At=l1_at, tight=tight, maxit=maxit, verbose=verbose, tol=tol) + functions, _ = _import_pyunlocbox() + functions.norm_l1(x, gamma, A=l1_a, At=l1_at, tight=tight, maxit=maxit, verbose=verbose, tol=tol) diff --git a/setup.py b/setup.py index 26dc6499..5b655cbe 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,8 @@ # Approximate nearest neighbors for kNN graphs. 'pyflann; python_version == "2.*"', 'pyflann3; python_version == "3.*"', + # Convex optimization on graph. + 'pyunlocbox', # Plot graphs, signals, and filters. 'matplotlib', # Interactive graph visualization. @@ -44,14 +46,12 @@ ), # Testing dependencies. 'test': [ - 'pyunlocbox', 'flake8', 'coverage', 'coveralls', ], # Dependencies to build the documentation. 'doc': [ - 'pyunlocbox', 'sphinx', 'numpydoc', 'sphinxcontrib-bibtex',