From ef847de99679ac825069068d20025312b45eb756 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 17 Sep 2014 12:03:06 +0100 Subject: [PATCH] done arithmetic testsuite all passes, woo --- ChangeLog | 2 ++ python/test_arithmetic.py | 69 ++++++++++++++++++++++++++++++++++++++- python/vips8/vips.py | 8 +++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 747d1ff4..2f0c170c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,8 @@ which modifies its argument - rename VIPS_OPERATION_RELATIONAL_NOTEQUAL as VIPS_OPERATION_RELATIONAL_NOTEQ for consistency +- python vips8 binding +- python vips8 test suite: test_arithmetic.py 8/9/14 started 7.40.9 - support jfif resunit "none" diff --git a/python/test_arithmetic.py b/python/test_arithmetic.py index 22f257e0..08c8e1f9 100755 --- a/python/test_arithmetic.py +++ b/python/test_arithmetic.py @@ -107,7 +107,7 @@ class TestArithmetic(unittest.TestCase): for x in self.all_images for y in fmt for z in fmt] def setUp(self): - im = Vips.Image.mask_ideal(100, 100, 0.5) + im = Vips.Image.mask_ideal(100, 100, 0.5, optical = True) self.colour = im * [1, 2, 3] + [2, 3, 4] self.mono = self.colour.extract_band(1) self.all_images = [self.mono, self.colour] @@ -559,6 +559,47 @@ class TestArithmetic(unittest.TestCase): self.run_unary(self.all_images, my_exp10, fmt = noncomplex_formats) + def test_floor(self): + def my_floor(x): + if isinstance(x, Vips.Image): + return x.floor() + else: + return math.floor(x) + + self.run_unary(self.all_images, my_floor) + + def test_ceil(self): + def my_ceil(x): + if isinstance(x, Vips.Image): + return x.ceil() + else: + return math.ceil(x) + + self.run_unary(self.all_images, my_ceil) + + def test_rint(self): + def my_rint(x): + if isinstance(x, Vips.Image): + return x.rint() + else: + return round(x) + + self.run_unary(self.all_images, my_rint) + + def test_sign(self): + def my_sign(x): + if isinstance(x, Vips.Image): + return x.sign() + else: + if x > 0: + return 1 + elif x < 0: + return -1 + else: + return 0 + + self.run_unary(self.all_images, my_sign) + def test_max(self): test = Vips.Image.black(100, 100).draw_rect(100, 40, 50, 1, 1) @@ -624,8 +665,34 @@ class TestArithmetic(unittest.TestCase): self.assertAlmostEqualObjects(rows.getpoint(0,10), [50 * 10]) + def test_stats(self): + im = Vips.Image.black(50, 50) + test = im.insert(im + 10, 50, 0, expand = True) + for x in noncomplex_formats: + a = test.cast(x) + matrix = a.stats() + self.assertAlmostEqualObjects(matrix.getpoint(0, 0), [a.min()]) + self.assertAlmostEqualObjects(matrix.getpoint(1, 0), [a.max()]) + self.assertAlmostEqualObjects(matrix.getpoint(2, 0), [50 * 50 * 10]) + self.assertAlmostEqualObjects(matrix.getpoint(3, 0), [50 * 50 * 100]) + self.assertAlmostEqualObjects(matrix.getpoint(4, 0), [a.avg()]) + self.assertAlmostEqualObjects(matrix.getpoint(5, 0), [a.deviate()]) + + self.assertAlmostEqualObjects(matrix.getpoint(0, 1), [a.min()]) + self.assertAlmostEqualObjects(matrix.getpoint(1, 1), [a.max()]) + self.assertAlmostEqualObjects(matrix.getpoint(2, 1), [50 * 50 * 10]) + self.assertAlmostEqualObjects(matrix.getpoint(3, 1), [50 * 50 * 100]) + self.assertAlmostEqualObjects(matrix.getpoint(4, 1), [a.avg()]) + self.assertAlmostEqualObjects(matrix.getpoint(5, 1), [a.deviate()]) + + def test_sum(self): + for fmt in all_formats: + im = Vips.Image.black(50, 50) + im2 = [(im + x).cast(fmt) for x in range(0, 100, 10)] + im3 = Vips.Image.sum(im2) + self.assertAlmostEqual(im3.max(), sum(range(0, 100, 10))) if __name__ == '__main__': unittest.main() diff --git a/python/vips8/vips.py b/python/vips8/vips.py index 6cb99a82..b8070ad8 100644 --- a/python/vips8/vips.py +++ b/python/vips8/vips.py @@ -364,6 +364,12 @@ def vips_rdiv(self, other): def vips_floor(self): return self.round(Vips.OperationRound.FLOOR) +def vips_ceil(self): + return self.round(Vips.OperationRound.CEIL) + +def vips_rint(self): + return self.round(Vips.OperationRound.RINT) + def vips_floordiv(self, other): if isinstance(other, Vips.Image): return self.divide(other).floor() @@ -563,6 +569,8 @@ Vips.Image.write_to_buffer = vips_image_write_to_buffer # a few useful things Vips.Image.floor = vips_floor +Vips.Image.ceil = vips_ceil +Vips.Image.rint = vips_rint Vips.Image.bandsplit = vips_bandsplit Vips.Image.maxpos = vips_maxpos Vips.Image.minpos = vips_minpos