本文整理汇总了Python中pypy.module.micronumpy.base.W_NDimArray.implementation方法的典型用法代码示例。如果您正苦于以下问题:Python W_NDimArray.implementation方法的具体用法?Python W_NDimArray.implementation怎么用?Python W_NDimArray.implementation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.module.micronumpy.base.W_NDimArray
的用法示例。
在下文中一共展示了W_NDimArray.implementation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: array
# 需要导入模块: from pypy.module.micronumpy.base import W_NDimArray [as 别名]
# 或者: from pypy.module.micronumpy.base.W_NDimArray import implementation [as 别名]
def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
ndmin=0):
from pypy.module.micronumpy import strides
# for anything that isn't already an array, try __array__ method first
if not isinstance(w_object, W_NDimArray):
w___array__ = space.lookup(w_object, "__array__")
if w___array__ is not None:
if space.is_none(w_dtype):
w_dtype = space.w_None
w_array = space.get_and_call_function(w___array__, w_object, w_dtype)
if isinstance(w_array, W_NDimArray):
# feed w_array back into array() for other properties
return array(space, w_array, w_dtype, False, w_order, subok, ndmin)
else:
raise oefmt(space.w_ValueError,
"object __array__ method not producing an array")
dtype = descriptor.decode_w_dtype(space, w_dtype)
if space.is_none(w_order):
order = 'C'
else:
order = space.str_w(w_order)
if order == 'K':
order = 'C'
if order != 'C': # or order != 'F':
raise oefmt(space.w_ValueError, "Unknown order: %s", order)
# arrays with correct dtype
if isinstance(w_object, W_NDimArray) and \
(space.is_none(w_dtype) or w_object.get_dtype() is dtype):
shape = w_object.get_shape()
if copy:
w_ret = w_object.descr_copy(space)
else:
if ndmin <= len(shape):
return w_object
new_impl = w_object.implementation.set_shape(space, w_object, shape)
w_ret = W_NDimArray(new_impl)
if ndmin > len(shape):
shape = [1] * (ndmin - len(shape)) + shape
w_ret.implementation = w_ret.implementation.set_shape(space,
w_ret, shape)
return w_ret
# not an array or incorrect dtype
shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype)
if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
dtype = strides.find_dtype_for_seq(space, elems_w, dtype)
if dtype is None:
dtype = descriptor.get_dtype_cache(space).w_float64dtype
elif dtype.is_str_or_unicode() and dtype.elsize < 1:
# promote S0 -> S1, U0 -> U1
dtype = descriptor.variable_dtype(space, dtype.char + '1')
if ndmin > len(shape):
shape = [1] * (ndmin - len(shape)) + shape
w_arr = W_NDimArray.from_shape(space, shape, dtype, order=order)
if len(elems_w) == 1:
w_arr.set_scalar_value(dtype.coerce(space, elems_w[0]))
else:
loop.assign(space, w_arr, elems_w)
return w_arr