summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py2
-rw-r--r--Wrappers/Python/test/test_functions.py14
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__':