summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorcookedm <cookedm@localhost>2006-06-06 20:04:32 +0000
committercookedm <cookedm@localhost>2006-06-06 20:04:32 +0000
commit79ab0f4ba033372dc568a115b52fa013f7433495 (patch)
treebc10ac17c80975b759651e93885c5c273e88407b /numpy
parentd1db955edafd63f3cf7d3a331ce3bba94dde48ae (diff)
downloadnumpy-79ab0f4ba033372dc568a115b52fa013f7433495.tar.gz
Add power to integer scalar types.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/scalarmathmodule.c.src20
-rw-r--r--numpy/core/tests/test_scalarmath.py15
-rw-r--r--numpy/distutils/ccompiler.py6
-rw-r--r--numpy/distutils/fcompiler/gnu.py6
4 files changed, 39 insertions, 8 deletions
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index e4b885f59..c983b9ffa 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -249,10 +249,28 @@ static void
/* b will always be positive in this call */
/**begin repeat
#name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#
+ #upc=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#
**/
static void
@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {
-
+ @name@ temp, ix, mult;
+ /* code from Python's intobject.c, with overflow checking removed. */
+ temp = a;
+ ix = 1;
+ while (b > 0) {
+ if (b & 1) {
+ @name@_ctype_multiply(ix, temp, &mult);
+ ix = mult;
+ if (temp == 0)
+ break; /* Avoid ix / 0 */
+ }
+ b >>= 1; /* Shift exponent down by 1 bit */
+ if (b==0) break;
+ /* Square the value of temp */
+ @name@_ctype_multiply(temp, temp, &mult);
+ temp = mult;
+ }
+ *out = ix;
}
/**end repeat**/
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index a8aeb324e..6b74a20bb 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -13,7 +13,7 @@ types = [N.bool_, N.byte, N.ubyte, N.short, N.ushort, N.intc, N.uintc,
# This compares scalarmath against ufuncs.
-class test_types(ScipyTestCase):
+class test_types(NumpyTestCase):
def check_types(self, level=1):
# list of types
for k, atype in enumerate(types):
@@ -28,5 +28,18 @@ class test_types(ScipyTestCase):
val.dtype.char == valo.dtype.char, \
"error with (%d,%d)" % (k,l)
+class test_power(NumpyTestCase):
+ def check_small_types(self):
+ for t in [N.int8, N.int16]:
+ a = t(3)
+ b = a ** 4
+ assert b == 81, "error with %r: got %r" % (t,b)
+
+ def check_large_types(self):
+ for t in [N.int32, N.int64, N.float32, N.float64, N.longdouble]:
+ a = t(51)
+ b = a ** 4
+ assert b == 6765201, "error with %r: got %r" % (t,b)
+
if __name__ == "__main__":
NumpyTest().run()
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py
index 815a197a1..a631464e6 100644
--- a/numpy/distutils/ccompiler.py
+++ b/numpy/distutils/ccompiler.py
@@ -232,7 +232,7 @@ def CCompiler_get_version(self, force=0, ok_status=[0]):
try:
version_cmd = self.version_cmd
except AttributeError:
- return
+ return None
cmd = ' '.join(version_cmd)
try:
matcher = self.version_match
@@ -240,7 +240,7 @@ def CCompiler_get_version(self, force=0, ok_status=[0]):
try:
pat = self.version_pattern
except AttributeError:
- return
+ return None
def matcher(version_string):
m = re.match(pat, version_string)
if not m:
@@ -319,7 +319,7 @@ def new_compiler (plat=None,
("can't compile C/C++ code: unable to find class '%s' " +
"in module '%s'") % (class_name, module_name)
compiler = klass(None, dry_run, force)
- log.debug('new_fcompiler returns %s' % (klass))
+ log.debug('new_compiler returns %s' % (klass))
return compiler
ccompiler.new_compiler = new_compiler
diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py
index abcad285d..e56e0303d 100644
--- a/numpy/distutils/fcompiler/gnu.py
+++ b/numpy/distutils/fcompiler/gnu.py
@@ -27,13 +27,13 @@ class GnuFCompiler(FCompiler):
break
executables = {
'version_cmd' : [fc_exe,"--version"],
- 'compiler_f77' : [fc_exe,"-Wall","-fno-second-underscore"],
+ 'compiler_f77' : [fc_exe, "-g", "-Wall","-fno-second-underscore"],
'compiler_f90' : None,
'compiler_fix' : None,
- 'linker_so' : [fc_exe,"-Wall"],
+ 'linker_so' : [fc_exe, "-g", "-Wall"],
'archiver' : ["ar", "-cr"],
'ranlib' : ["ranlib"],
- 'linker_exe' : [fc_exe,"-Wall"]
+ 'linker_exe' : [fc_exe, "-g", "-Wall"]
}
module_dir_switch = None
module_include_switch = None