From 9e7c6a0465607450c3821d473f7306bf35887c89 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 09:53:53 +0200 Subject: [PATCH 01/11] Minor bug fix, remove elif --- modopt/base/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modopt/base/backend.py b/modopt/base/backend.py index def77151..5fbe912f 100644 --- a/modopt/base/backend.py +++ b/modopt/base/backend.py @@ -95,7 +95,7 @@ def get_array_module(input_data): if LIBRARIES['tensorflow'] is not None: if isinstance(input_data, LIBRARIES['tensorflow'].ndarray): return LIBRARIES['tensorflow'] - elif LIBRARIES['cupy'] is not None: + if LIBRARIES['cupy'] is not None: if isinstance(input_data, LIBRARIES['cupy'].ndarray): return LIBRARIES['cupy'] return np From 7158fc06f445b420841f68b7e6001d7d21120269 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 10:08:29 +0200 Subject: [PATCH 02/11] Add tests for backend --- modopt/tests/test_base.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index 26e1e4ea..a52a19d5 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -9,12 +9,13 @@ """ from builtins import range -from unittest import TestCase +from unittest import TestCase, skipIf import numpy as np import numpy.testing as npt from modopt.base import np_adjust, transform, types +from modopt.base.backend import LIBRARIES, get_array_module, change_backend, get_backend class NPAdjustTestCase(TestCase): @@ -275,3 +276,28 @@ def test_check_npndarray(self): self.data3, dtype=np.integer, ) + + +class TestBackend(TestCase): + """Test the backend codes.""" + def setUp(self): + self.input = np.array([10, 10]) + + @skipIf(LIBRARIES['tensorflow'] is None, "tensorflow library not installed") + def test_tf_backend(self): + tf_input, backend = change_backend(self.input, 'tensorflow') + if get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow'] or + get_array_module(tf_input) != LIBRARIES['tensorflow'] or + backend != 'cupy': + assert "tensorflow backend fails!" + + @skipIf(LIBRARIES['cupy'] is None, "cupy library not installed") + def test_cp_backend(self): + cp_input, backend = change_backend(self.input, 'cupy') + if get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy'] or + get_array_module(cp_input) != LIBRARIES['cupy'] or + backend != 'cupy': + assert "cupy backend fails!" + + def tearDown(self): + self.input = None \ No newline at end of file From ed75b7dfe98618be05f7271fe08004574b848017 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 10:12:43 +0200 Subject: [PATCH 03/11] Fix tests --- modopt/tests/test_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index a52a19d5..25c72b90 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -286,17 +286,17 @@ def setUp(self): @skipIf(LIBRARIES['tensorflow'] is None, "tensorflow library not installed") def test_tf_backend(self): tf_input, backend = change_backend(self.input, 'tensorflow') - if get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow'] or + if (get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow'] or get_array_module(tf_input) != LIBRARIES['tensorflow'] or - backend != 'cupy': + backend != 'tensorflow'): assert "tensorflow backend fails!" @skipIf(LIBRARIES['cupy'] is None, "cupy library not installed") def test_cp_backend(self): cp_input, backend = change_backend(self.input, 'cupy') - if get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy'] or + if (get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy'] or get_array_module(cp_input) != LIBRARIES['cupy'] or - backend != 'cupy': + backend != 'cupy'): assert "cupy backend fails!" def tearDown(self): From d88bd83815f1ee1a8482992fa716c185f7c759fc Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 10:32:46 +0200 Subject: [PATCH 04/11] Add tests --- .github/workflows/ci-build.yml | 1 + modopt/tests/test_base.py | 33 ++++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 2ed4960d..3aaf3283 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -53,6 +53,7 @@ jobs: python -m pip install -r develop.txt python -m pip install -r docs/requirements.txt python -m pip install astropy scikit-image scikit-learn + python -m pip install tensorflow>=2.4.1 cupy python -m pip install twine python -m pip install . diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index 25c72b90..a66305da 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -14,8 +14,9 @@ import numpy as np import numpy.testing as npt +from modopt.base.backend import LIBRARIES, get_array_module +from modopt.base.backend import change_backend, get_backend from modopt.base import np_adjust, transform, types -from modopt.base.backend import LIBRARIES, get_array_module, change_backend, get_backend class NPAdjustTestCase(TestCase): @@ -280,24 +281,42 @@ def test_check_npndarray(self): class TestBackend(TestCase): """Test the backend codes.""" + def setUp(self): + """Setup class for doing tests.""" self.input = np.array([10, 10]) @skipIf(LIBRARIES['tensorflow'] is None, "tensorflow library not installed") def test_tf_backend(self): - tf_input, backend = change_backend(self.input, 'tensorflow') + """Test tensorflow backend.""" + xp, backend = get_backend('tensorflow') + if backend != 'tensorflow' or xp != LIBRARIES['tensorflow']: + assert "tensorflow get_backend fails!" + tf_input = change_backend(self.input, 'tensorflow') if (get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow'] or - get_array_module(tf_input) != LIBRARIES['tensorflow'] or - backend != 'tensorflow'): + get_array_module(tf_input) != LIBRARIES['tensorflow']): assert "tensorflow backend fails!" @skipIf(LIBRARIES['cupy'] is None, "cupy library not installed") def test_cp_backend(self): - cp_input, backend = change_backend(self.input, 'cupy') + """Test cupy backend.""" + xp, backend = get_backend('cupy') + if backend != 'cupy' or xp != LIBRARIES['cupy']: + assert "cupy get_backend fails!" + cp_input = change_backend(self.input, 'cupy') if (get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy'] or - get_array_module(cp_input) != LIBRARIES['cupy'] or - backend != 'cupy'): + get_array_module(cp_input) != LIBRARIES['cupy']): assert "cupy backend fails!" + def test_np_backend(self): + """Test numpy backend.""" + xp, backend = get_backend('numpy') + if backend != 'numpy' or xp != LIBRARIES['numpy']: + assert "numpy get_backend fails!" + np_input = change_backend(self.input, 'numpy') + if (get_array_module(LIBRARIES['numpy'].ones(1)) != LIBRARIES['numpy'] or + get_array_module(np_input) != LIBRARIES['numpy']): + assert "numpy backend fails!" + def tearDown(self): self.input = None \ No newline at end of file From 94e89ca3f99c4629b331de7c5859a032b7a01d10 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 10:47:01 +0200 Subject: [PATCH 05/11] Remove cupy --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 3aaf3283..3ffcb6f4 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -53,7 +53,7 @@ jobs: python -m pip install -r develop.txt python -m pip install -r docs/requirements.txt python -m pip install astropy scikit-image scikit-learn - python -m pip install tensorflow>=2.4.1 cupy + python -m pip install tensorflow>=2.4.1 python -m pip install twine python -m pip install . From 0ebcec5c951aa7516177bc58b096c6379cb0ec42 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 14:25:39 +0200 Subject: [PATCH 06/11] PEP fixes --- modopt/tests/test_base.py | 44 ++++++++++++++++++++++----------------- setup.cfg | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index a66305da..496456ca 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -14,9 +14,8 @@ import numpy as np import numpy.testing as npt -from modopt.base.backend import LIBRARIES, get_array_module -from modopt.base.backend import change_backend, get_backend from modopt.base import np_adjust, transform, types +from modopt.base.backend import change_backend, get_array_module, get_backend, LIBRARIES class NPAdjustTestCase(TestCase): @@ -283,40 +282,47 @@ class TestBackend(TestCase): """Test the backend codes.""" def setUp(self): - """Setup class for doing tests.""" + """Set test parameter values.""" self.input = np.array([10, 10]) - @skipIf(LIBRARIES['tensorflow'] is None, "tensorflow library not installed") + @skipIf(LIBRARIES['tensorflow'] is None, 'tensorflow library not installed') def test_tf_backend(self): """Test tensorflow backend.""" xp, backend = get_backend('tensorflow') - if backend != 'tensorflow' or xp != LIBRARIES['tensorflow']: - assert "tensorflow get_backend fails!" + if backend != ':tensorflow' or xp != LIBRARIES['tensorflow']: + raise AssertionError('tensorflow get_backend fails!') tf_input = change_backend(self.input, 'tensorflow') - if (get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow'] or - get_array_module(tf_input) != LIBRARIES['tensorflow']): - assert "tensorflow backend fails!" + if ( + get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow'] + or get_array_module(tf_input) != LIBRARIES['tensorflow'] + ): + raise AssertionError('tensorflow backend fails!') - @skipIf(LIBRARIES['cupy'] is None, "cupy library not installed") + @skipIf(LIBRARIES['cupy'] is None, 'cupy library not installed') def test_cp_backend(self): """Test cupy backend.""" xp, backend = get_backend('cupy') if backend != 'cupy' or xp != LIBRARIES['cupy']: - assert "cupy get_backend fails!" + raise AssertionError('cupy get_backend fails!') cp_input = change_backend(self.input, 'cupy') - if (get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy'] or - get_array_module(cp_input) != LIBRARIES['cupy']): - assert "cupy backend fails!" + if ( + get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy'] + or get_array_module(cp_input) != LIBRARIES['cupy'] + ): + raise AssertionError('cupy backend fails!') def test_np_backend(self): """Test numpy backend.""" xp, backend = get_backend('numpy') if backend != 'numpy' or xp != LIBRARIES['numpy']: - assert "numpy get_backend fails!" + raise AssertionError('numpy get_backend fails!') np_input = change_backend(self.input, 'numpy') - if (get_array_module(LIBRARIES['numpy'].ones(1)) != LIBRARIES['numpy'] or - get_array_module(np_input) != LIBRARIES['numpy']): - assert "numpy backend fails!" + if ( + get_array_module(LIBRARIES['numpy'].ones(1)) != LIBRARIES['numpy'] + or get_array_module(np_input) != LIBRARIES['numpy'] + ): + raise AssertionError('numpy backend fails!') def tearDown(self): - self.input = None \ No newline at end of file + """Tear Down of objects.""" + self.input = None diff --git a/setup.cfg b/setup.cfg index 74fb3f79..f5e7eeb4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,7 +54,7 @@ per-file-ignores = #Todo: Check security of using system executable call modopt/signal/wavelet.py: S404,S603 #Todo: Clean up tests - modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604 + modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604,E501 #WPS Settings max-arguments = 25 max-attributes = 40 From c67b41fde1f4ca1031361d1602588bcf5b21ff82 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 14:39:04 +0200 Subject: [PATCH 07/11] Fix PEP --- modopt/tests/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index 496456ca..3fb6693e 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -15,7 +15,7 @@ import numpy.testing as npt from modopt.base import np_adjust, transform, types -from modopt.base.backend import change_backend, get_array_module, get_backend, LIBRARIES +from modopt.base.backend import LIBRARIES, change_backend, get_array_module, get_backend class NPAdjustTestCase(TestCase): From 73588079c4d9409d1f95d345b78de0e434dd89e4 Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 15:07:53 +0200 Subject: [PATCH 08/11] Fix PEP and update --- modopt/tests/test_base.py | 3 ++- setup.cfg | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index 3fb6693e..f814522a 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -15,7 +15,8 @@ import numpy.testing as npt from modopt.base import np_adjust, transform, types -from modopt.base.backend import LIBRARIES, change_backend, get_array_module, get_backend +from modopt.base.backend import LIBRARIES +from modopt.base.backend import change_backend, get_array_module, get_backend class NPAdjustTestCase(TestCase): diff --git a/setup.cfg b/setup.cfg index f5e7eeb4..d6992561 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,6 +55,8 @@ per-file-ignores = modopt/signal/wavelet.py: S404,S603 #Todo: Clean up tests modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604,E501 + #Todo: Import has bad paramthesis + modopt/tests/test_base.py: WPS318,WPS319 #WPS Settings max-arguments = 25 max-attributes = 40 From 4eecce6ed183af584d019fe9096f92d38d3d841b Mon Sep 17 00:00:00 2001 From: chaithyagr Date: Tue, 20 Apr 2021 16:29:43 +0200 Subject: [PATCH 09/11] Final PEP --- modopt/tests/test_base.py | 4 ++-- setup.cfg | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index f814522a..fcc3789a 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -15,8 +15,8 @@ import numpy.testing as npt from modopt.base import np_adjust, transform, types -from modopt.base.backend import LIBRARIES -from modopt.base.backend import change_backend, get_array_module, get_backend +from modopt.base.backend import (LIBRARIES, change_backend, get_array_module, + get_backend) class NPAdjustTestCase(TestCase): diff --git a/setup.cfg b/setup.cfg index d6992561..56295be3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,9 +54,9 @@ per-file-ignores = #Todo: Check security of using system executable call modopt/signal/wavelet.py: S404,S603 #Todo: Clean up tests - modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604,E501 + modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604 #Todo: Import has bad paramthesis - modopt/tests/test_base.py: WPS318,WPS319 + modopt/tests/test_base.py: WPS318,WPS319,E501,WPS301 #WPS Settings max-arguments = 25 max-attributes = 40 From c6bbdea1497e5f91704c4dffae5b1f5b6e2dda1a Mon Sep 17 00:00:00 2001 From: Chaithya G R Date: Tue, 20 Apr 2021 19:38:48 +0200 Subject: [PATCH 10/11] Update setup.cfg Co-authored-by: Samuel Farrens --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 56295be3..d2f544f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,7 +55,7 @@ per-file-ignores = modopt/signal/wavelet.py: S404,S603 #Todo: Clean up tests modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604 - #Todo: Import has bad paramthesis + #Todo: Import has bad parenthesis modopt/tests/test_base.py: WPS318,WPS319,E501,WPS301 #WPS Settings max-arguments = 25 From 1b661a543c70ededeee0c5fb62d148b54bb5540a Mon Sep 17 00:00:00 2001 From: Chaithya G R Date: Tue, 20 Apr 2021 19:52:17 +0200 Subject: [PATCH 11/11] Update test_base.py --- modopt/tests/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modopt/tests/test_base.py b/modopt/tests/test_base.py index fcc3789a..873a4506 100644 --- a/modopt/tests/test_base.py +++ b/modopt/tests/test_base.py @@ -290,7 +290,7 @@ def setUp(self): def test_tf_backend(self): """Test tensorflow backend.""" xp, backend = get_backend('tensorflow') - if backend != ':tensorflow' or xp != LIBRARIES['tensorflow']: + if backend != 'tensorflow' or xp != LIBRARIES['tensorflow']: raise AssertionError('tensorflow get_backend fails!') tf_input = change_backend(self.input, 'tensorflow') if (