summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/generate_umath.py33
-rw-r--r--numpy/core/src/umathmodule.c.src19
-rw-r--r--numpy/core/tests/test_umath.py12
3 files changed, 62 insertions, 2 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index ddecbbd29..0150417f0 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -5,6 +5,16 @@ One = "PyUFunc_One"
None_ = "PyUFunc_None"
class TypeDescription(object):
+ """Type signature for a ufunc
+
+ Attributes
+ ----------
+
+ type: character representing the type
+ func_data:
+ in_:
+ out:
+ """
def __init__(self, type, f=None, in_=None, out=None):
self.type = type
self.func_data = f
@@ -55,6 +65,17 @@ def TD(types, f=None, in_=None, out=None):
return tds
class Ufunc(object):
+ """Description of a ufunc.
+
+ Attributes
+ ----------
+
+ nin: number of input arguments
+ nout: number of output arguments
+ identity: identity element for a two-argument function
+ docstring: docstring for the ufunc
+ type_descriptions: list of TypeDescription objects
+ """
def __init__(self, nin, nout, identity, docstring,
*type_descriptions):
self.nin = nin
@@ -69,7 +90,7 @@ class Ufunc(object):
for td in self.type_descriptions:
td.finish_signature(self.nin, self.nout)
-#each entry in defdict is
+#each entry in defdict is a Ufunc object.
#name: [string of chars for which it is defined,
# string of characters using func interface,
@@ -304,6 +325,16 @@ defdict = {
TD(ints),
TD(O, f='PyNumber_Rshift'),
),
+'degrees' :
+ Ufunc(1, 1, None,
+ 'converts angle from radians to degrees',
+ TD(fltsM, f='degrees'),
+ ),
+'radians' :
+ Ufunc(1, 1, None,
+ 'converts angle from degrees to radians',
+ TD(fltsM, f='radians'),
+ ),
'arccos' :
Ufunc(1, 1, None,
'inverse cosine elementwise.',
diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src
index 5e24d89a8..ec531e0e5 100644
--- a/numpy/core/src/umathmodule.c.src
+++ b/numpy/core/src/umathmodule.c.src
@@ -413,6 +413,25 @@ rint (double x)
#define isfinitef(x) (!(isinff((x)) || isnanf((x))))
#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))
+float degreesf(float x) {
+ return x * (float)(180.0/M_PI);
+}
+double degrees(double x) {
+ return x * (180.0/M_PI);
+}
+longdouble degreesl(longdouble x) {
+ return x * (180.0L/M_PI);
+}
+
+float radiansf(float x) {
+ return x * (float)(M_PI/180.0);
+}
+double radians(double x) {
+ return x * (M_PI/180.0);
+}
+longdouble radiansl(longdouble x) {
+ return x * (M_PI/180.0L);
+}
/* First, the C functions that do the real work */
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 70076627b..ef5f3047e 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -2,7 +2,7 @@ from numpy.testing import *
set_package_path()
from numpy.core.umath import minimum, maximum, exp
import numpy.core.umath as ncu
-from numpy import zeros, ndarray, array, choose
+from numpy import zeros, ndarray, array, choose, pi
restore_path()
class TestDivision(NumpyTestCase):
@@ -61,6 +61,16 @@ class TestFloatingPoint(NumpyTestCase):
def check_floating_point(self):
assert_equal(ncu.FLOATING_POINT_SUPPORT, 1)
+def TestDegrees(NumpyTestCase):
+ def check_degrees(self):
+ assert_almost_equal(ncu.degrees(pi), 180.0)
+ assert_almost_equal(ncu.degrees(-0.5*pi), -90.0)
+
+def TestRadians(NumpyTestCase):
+ def check_radians(self):
+ assert_almost_equal(ncu.radians(180.0), pi)
+ assert_almost_equal(ncu.degrees(-90.0), -0.5*pi)
+
class TestSpecialMethods(NumpyTestCase):
def test_wrap(self):
class with_wrap(object):