add log and trig

to selftest and vips8 python
This commit is contained in:
John Cupitt 2014-09-16 12:47:00 +01:00
parent 4968b9edaf
commit e8f5c606df
2 changed files with 134 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/python
import unittest
import math
#import logging
#logging.basicConfig(level = logging.DEBUG)
@ -387,5 +388,98 @@ class TestArithmetic(unittest.TestCase):
self.assertAlmostEqual(angle, 45)
self.assertAlmostEqual(distance, 70)
def test_sin(self):
def my_sin(x):
if isinstance(x, Vips.Image):
return x.sin()
else:
return math.sin(math.radians(x))
self.run_unary(self.all_images, my_sin, fmt = noncomplex_formats)
def test_cos(self):
def my_cos(x):
if isinstance(x, Vips.Image):
return x.cos()
else:
return math.cos(math.radians(x))
self.run_unary(self.all_images, my_cos, fmt = noncomplex_formats)
def test_tan(self):
def my_tan(x):
if isinstance(x, Vips.Image):
return x.tan()
else:
return math.tan(math.radians(x))
self.run_unary(self.all_images, my_tan, fmt = noncomplex_formats)
def test_asin(self):
def my_asin(x):
if isinstance(x, Vips.Image):
return x.asin()
else:
return math.degrees(math.asin(x))
im = (Vips.Image.black(100, 100) + [1, 2, 3]) / 3.0
self.run_unary([im], my_asin, fmt = noncomplex_formats)
def test_acos(self):
def my_acos(x):
if isinstance(x, Vips.Image):
return x.acos()
else:
return math.degrees(math.acos(x))
im = (Vips.Image.black(100, 100) + [1, 2, 3]) / 3.0
self.run_unary([im], my_acos, fmt = noncomplex_formats)
def test_atan(self):
def my_atan(x):
if isinstance(x, Vips.Image):
return x.atan()
else:
return math.degrees(math.atan(x))
im = (Vips.Image.black(100, 100) + [1, 2, 3]) / 3.0
self.run_unary([im], my_atan, fmt = noncomplex_formats)
def test_log(self):
def my_log(x):
if isinstance(x, Vips.Image):
return x.log()
else:
return math.log(x)
self.run_unary(self.all_images, my_log, fmt = noncomplex_formats)
def test_log10(self):
def my_log10(x):
if isinstance(x, Vips.Image):
return x.log10()
else:
return math.log10(x)
self.run_unary(self.all_images, my_log10, fmt = noncomplex_formats)
def test_exp(self):
def my_exp(x):
if isinstance(x, Vips.Image):
return x.exp()
else:
return math.exp(x)
self.run_unary(self.all_images, my_exp, fmt = noncomplex_formats)
def test_exp10(self):
def my_exp10(x):
if isinstance(x, Vips.Image):
return x.exp10()
else:
return math.pow(10, x)
self.run_unary(self.all_images, my_exp10, fmt = noncomplex_formats)
if __name__ == '__main__':
unittest.main()

View File

@ -442,6 +442,36 @@ def vips_rect(self):
def vips_conj(self):
return self.complex(Vips.OperationComplex.CONJ)
def vips_sin(self):
return self.math(Vips.OperationMath.SIN)
def vips_cos(self):
return self.math(Vips.OperationMath.COS)
def vips_tan(self):
return self.math(Vips.OperationMath.TAN)
def vips_asin(self):
return self.math(Vips.OperationMath.ASIN)
def vips_acos(self):
return self.math(Vips.OperationMath.ACOS)
def vips_atan(self):
return self.math(Vips.OperationMath.ATAN)
def vips_log(self):
return self.math(Vips.OperationMath.LOG)
def vips_log10(self):
return self.math(Vips.OperationMath.LOG10)
def vips_exp(self):
return self.math(Vips.OperationMath.EXP)
def vips_exp10(self):
return self.math(Vips.OperationMath.EXP10)
# paste our methods into Vips.Image
# class methods
@ -502,6 +532,16 @@ Vips.Image.imag = vips_imag
Vips.Image.polar = vips_polar
Vips.Image.rect = vips_rect
Vips.Image.conj = vips_conj
Vips.Image.sin = vips_sin
Vips.Image.cos = vips_cos
Vips.Image.tan = vips_tan
Vips.Image.asin = vips_asin
Vips.Image.acos = vips_acos
Vips.Image.atan = vips_atan
Vips.Image.log = vips_log
Vips.Image.log10 = vips_log10
Vips.Image.exp = vips_exp
Vips.Image.exp10 = vips_exp10
# operator overloads
Vips.Image.__getattr__ = vips_image_getattr