Author: Ronan Lamy <ronan.l...@gmail.com> Branch: can_cast Changeset: r77155:b37ce09bf154 Date: 2015-05-05 20:34 +0100 http://bitbucket.org/pypy/pypy/changeset/b37ce09bf154/
Log: document some equivalences with numpy's C source diff --git a/pypy/module/micronumpy/casting.py b/pypy/module/micronumpy/casting.py --- a/pypy/module/micronumpy/casting.py +++ b/pypy/module/micronumpy/casting.py @@ -56,6 +56,7 @@ UnicodeType.kind: 7, VoidType.kind: 8, ObjectType.kind: 9} def can_cast_type(space, origin, target, casting): + # equivalent to PyArray_CanCastTypeTo if casting == 'no': return origin.eq(space, target) elif casting == 'equiv': @@ -72,6 +73,7 @@ return origin.can_cast_to(target) def can_cast_array(space, w_from, target, casting): + # equivalent to PyArray_CanCastArrayTo origin = w_from.get_dtype() if w_from.is_scalar(): return can_cast_scalar( @@ -80,6 +82,7 @@ return can_cast_type(space, origin, target, casting) def can_cast_scalar(space, from_type, value, target, casting): + # equivalent to CNumPy's can_cast_scalar_to if from_type == target or casting == 'unsafe': return True if not from_type.is_number() or casting in ('no', 'equiv'): @@ -90,7 +93,7 @@ if target.is_unsigned(): dtypenum = altnum dtype = get_dtype_cache(space).dtypes_by_num[dtypenum] - return can_cast_type(space, dtype, target, casting) # XXX: stub impl + return can_cast_type(space, dtype, target, casting) def is_scalar_w(space, w_arg): return (isinstance(w_arg, W_GenericBox) or diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py --- a/pypy/module/micronumpy/descriptor.py +++ b/pypy/module/micronumpy/descriptor.py @@ -96,6 +96,7 @@ return self.itemtype.box_complex(real, imag) def can_cast_to(self, other): + # equivalent to PyArray_CanCastTo result = self.itemtype.can_cast_to(other.itemtype) if result: if self.num == NPY.STRING: diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/micronumpy/types.py +++ b/pypy/module/micronumpy/types.py @@ -135,6 +135,7 @@ return rffi.sizeof(cls.T) def can_cast_to(self, other): + # equivalent to PyArray_CanCastSafely return casting_table[self.num][other.num] class Primitive(object): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit