From 524cdd1fc816ec1cc79d3cf339b694de7f8be00a Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Thu, 6 Feb 2020 16:30:12 +0000 Subject: fix limits of docstring (#495) * fix limits of docstring * add test for IndicatorBox --- .../Python/ccpi/optimisation/functions/IndicatorBox.py | 2 +- Wrappers/Python/test/test_functions.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py b/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py index 4383858..68f7e04 100644 --- a/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py +++ b/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py @@ -44,10 +44,10 @@ class IndicatorBox(Function): :type lower: float, default = :code:`-numpy.inf` :param upper: upper bound :type upper: float, optional, default = :code:`numpy.inf` + ''' super(IndicatorBox, self).__init__() self.lower = lower self.upper = upper - ''' def __call__(self,x): diff --git a/Wrappers/Python/test/test_functions.py b/Wrappers/Python/test/test_functions.py index d63ff90..ffb4551 100644 --- a/Wrappers/Python/test/test_functions.py +++ b/Wrappers/Python/test/test_functions.py @@ -29,7 +29,7 @@ from ccpi.optimisation.operators import Gradient from ccpi.optimisation.functions import Function, KullbackLeibler, L2NormSquared,\ L1Norm, MixedL21Norm, LeastSquares, \ ZeroFunction, FunctionOperatorComposition,\ - Rosenbrock + Rosenbrock, IndicatorBox import unittest import numpy @@ -447,6 +447,18 @@ class TestFunction(unittest.TestCase): x = VectorData(numpy.asarray([1,1])) assert f(x) == 0. numpy.testing.assert_array_almost_equal( f.gradient(x).as_array(), numpy.zeros(shape=(2,), dtype=numpy.float32)) + def test_IndicatorBox(self): + ig = ImageGeometry(10,10) + im = ig.allocate(-1) + ib = IndicatorBox(lower=0) + a = ib(im) + numpy.testing.assert_equal(a, numpy.inf) + ib = IndicatorBox(lower=-2) + a = ib(im) + numpy.testing.assert_array_equal(0, a) + ib = IndicatorBox(lower=-5, upper=-2) + a = ib(im) + numpy.testing.assert_equal(a, numpy.inf) if __name__ == '__main__': -- cgit v1.2.1