[pypy-commit] pypy can_cast: implement casting=no and casting=equiv
rlamy
noreply at buildbot.pypy.org
Sat Apr 25 05:41:08 CEST 2015
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: can_cast
Changeset: r76931:48070170c83b
Date: 2015-04-25 04:00 +0100
http://bitbucket.org/pypy/pypy/changeset/48070170c83b/
Log: implement casting=no and casting=equiv
diff --git a/pypy/module/micronumpy/arrayops.py b/pypy/module/micronumpy/arrayops.py
--- a/pypy/module/micronumpy/arrayops.py
+++ b/pypy/module/micronumpy/arrayops.py
@@ -304,7 +304,15 @@
def can_cast(space, w_from, w_totype, casting='safe'):
target = as_dtype(space, w_totype)
origin = as_dtype(space, w_from) # XXX
- return space.wrap(origin.can_cast_to(target))
+ return space.wrap(can_cast_type(space, origin, target, casting))
+
+def can_cast_type(space, origin, target, casting):
+ if casting == 'no':
+ return origin.eq(space, target)
+ elif casting == 'equiv':
+ return origin.num == target.num and origin.elsize == target.elsize
+ else:
+ return origin.can_cast_to(target)
def as_dtype(space, w_arg):
More information about the pypy-commit
mailing list