|
33 | 33 | # Places for the accepted error when comparing results
|
34 | 34 | PLACES = 8
|
35 | 35 |
|
36 |
| -# TODO: make some tests that check that prox work. |
37 | 36 |
|
38 | 37 | # TODO: Test that prox and conjugate functionals are not returned for negative
|
39 | 38 | # left scaling.
|
|
42 | 41 |
|
43 | 42 | # TODO: Test flags for translations etc.
|
44 | 43 |
|
45 |
| -# TODO: Add test for composition, both from letf and right, with a vector |
46 |
| - |
47 | 44 |
|
48 | 45 | def test_derivative():
|
49 | 46 | """Test for the derivative of a functional.
|
@@ -188,7 +185,6 @@ def test_functional_composition():
|
188 | 185 |
|
189 | 186 | def test_functional_sum():
|
190 | 187 | """Test for the sum of two functionals."""
|
191 |
| - |
192 | 188 | space = odl.uniform_discr(0, 1, 10)
|
193 | 189 |
|
194 | 190 | func1 = odl.solvers.L2NormSquare(space)
|
@@ -271,7 +267,6 @@ def test_functional_plus_scalar():
|
271 | 267 |
|
272 | 268 | def test_translation_of_functional():
|
273 | 269 | """Test for the translation of a functional: (f(. - y))^*"""
|
274 |
| - |
275 | 270 | space = odl.uniform_discr(0, 1, 10)
|
276 | 271 |
|
277 | 272 | # The translation; an element in the domain
|
@@ -328,10 +323,49 @@ def test_translation_of_functional():
|
328 | 323 | places=PLACES)
|
329 | 324 |
|
330 | 325 |
|
| 326 | +def test_multiplication_with_vector(): |
| 327 | + """Test for multiplying a functional with a vector, both left and right.""" |
| 328 | + |
| 329 | + space = odl.uniform_discr(0, 1, 10) |
| 330 | + |
| 331 | + x = example_element(space) |
| 332 | + y = example_element(space) |
| 333 | + func = odl.solvers.L1Norm(space) |
| 334 | + |
| 335 | + wrong_space = odl.uniform_discr(1, 2, 10) |
| 336 | + y_other_space = example_element(wrong_space) |
| 337 | + |
| 338 | + # Multiplication from the right. Make sure it is a OperatorRightVectorMult |
| 339 | + func_times_y = func * y |
| 340 | + assert isinstance(func_times_y, odl.OperatorRightVectorMult) |
| 341 | + |
| 342 | + expected_result = func(y*x) |
| 343 | + assert almost_equal((func*y)(x), expected_result, places=PLACES) |
| 344 | + |
| 345 | + # Make sure that right muliplication is not allowed with vector from |
| 346 | + # another space |
| 347 | + with pytest.raises(TypeError): |
| 348 | + func * y_other_space |
| 349 | + |
| 350 | + # Multiplication from the left. Make sure it is a FunctionalLeftVectorMult |
| 351 | + y_times_func = y * func |
| 352 | + assert isinstance(y_times_func, odl.FunctionalLeftVectorMult) |
| 353 | + |
| 354 | + expected_result = y * func(x) |
| 355 | + assert all_almost_equal(y_times_func(x), expected_result, places=PLACES) |
| 356 | + |
| 357 | + # Now, multiplication with vector from another space is ok (since it is the |
| 358 | + # same as scaling that vector with the scalar returned by the functional). |
| 359 | + y_other_times_func = y_other_space * func |
| 360 | + assert isinstance(y_other_times_func, odl.FunctionalLeftVectorMult) |
| 361 | + |
| 362 | + expected_result = y_other_space * func(x) |
| 363 | + assert all_almost_equal(y_other_times_func(x), expected_result, |
| 364 | + places=PLACES) |
| 365 | + |
| 366 | + |
331 | 367 | def test_convex_conjugate_translation():
|
332 | 368 | """Test for the convex conjugate of a translation: (f(. - y))^*"""
|
333 |
| - |
334 |
| - # Image space |
335 | 369 | space = odl.uniform_discr(0, 1, 10)
|
336 | 370 |
|
337 | 371 | # The translation; an element in the domain
|
@@ -394,8 +428,6 @@ def test_convex_conjugate_translation():
|
394 | 428 |
|
395 | 429 | def test_convex_conjugate_arg_scaling():
|
396 | 430 | """Test for the convex conjugate of a scaling: (f(. scaling))^*"""
|
397 |
| - |
398 |
| - # Image space |
399 | 431 | space = odl.uniform_discr(0, 1, 10)
|
400 | 432 |
|
401 | 433 | # The scaling parameter
|
@@ -446,8 +478,6 @@ def test_convex_conjugate_arg_scaling():
|
446 | 478 |
|
447 | 479 | def test_convex_conjugate_functional_scaling():
|
448 | 480 | """Test for the convex conjugate of a scaling: (scaling * f(.))^*"""
|
449 |
| - |
450 |
| - # Image space |
451 | 481 | space = odl.uniform_discr(0, 1, 10)
|
452 | 482 |
|
453 | 483 | # The scaling parameter
|
@@ -500,8 +530,6 @@ def test_convex_conjugate_functional_scaling():
|
500 | 530 |
|
501 | 531 | def test_convex_conjugate_linear_perturbation():
|
502 | 532 | """Test for the convex conjugate of a scaling: (f(.) + <y,.>)^*"""
|
503 |
| - |
504 |
| - # Image space |
505 | 533 | space = odl.uniform_discr(0, 1, 10)
|
506 | 534 |
|
507 | 535 | # The perturbation; an element in the domain (which is the same as the dual
|
|
0 commit comments