本文整理汇总了Python中pypy.module.micronumpy.descriptor.get_dtype_cache函数的典型用法代码示例。如果您正苦于以下问题:Python get_dtype_cache函数的具体用法?Python get_dtype_cache怎么用?Python get_dtype_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_dtype_cache函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, interp):
w_lhs = self.lhs.execute(interp)
if isinstance(self.rhs, SliceConstant):
w_rhs = self.rhs.wrap(interp.space)
else:
w_rhs = self.rhs.execute(interp)
if not isinstance(w_lhs, W_NDimArray):
# scalar
dtype = get_dtype_cache(interp.space).w_float64dtype
w_lhs = W_NDimArray.new_scalar(interp.space, dtype, w_lhs)
assert isinstance(w_lhs, W_NDimArray)
if self.name == '+':
w_res = w_lhs.descr_add(interp.space, w_rhs)
elif self.name == '*':
w_res = w_lhs.descr_mul(interp.space, w_rhs)
elif self.name == '-':
w_res = w_lhs.descr_sub(interp.space, w_rhs)
elif self.name == '**':
w_res = w_lhs.descr_pow(interp.space, w_rhs)
elif self.name == '->':
if isinstance(w_rhs, FloatObject):
w_rhs = IntObject(int(w_rhs.floatval))
assert isinstance(w_lhs, W_NDimArray)
w_res = w_lhs.descr_getitem(interp.space, w_rhs)
else:
raise NotImplementedError
if (not isinstance(w_res, W_NDimArray) and
not isinstance(w_res, boxes.W_GenericBox)):
dtype = get_dtype_cache(interp.space).w_float64dtype
w_res = W_NDimArray.new_scalar(interp.space, dtype, w_res)
return w_res
开发者ID:Qointum,项目名称:pypy,代码行数:31,代码来源:compile.py
示例2: find_unaryop_result_dtype
def find_unaryop_result_dtype(space, dt, promote_to_float=False,
promote_bools=False, promote_to_largest=False):
if promote_to_largest:
if dt.kind == NPY.GENBOOLLTR or dt.kind == NPY.SIGNEDLTR:
if dt.elsize * 8 < LONG_BIT:
return descriptor.get_dtype_cache(space).w_longdtype
elif dt.kind == NPY.UNSIGNEDLTR:
if dt.elsize * 8 < LONG_BIT:
return descriptor.get_dtype_cache(space).w_ulongdtype
else:
assert dt.kind == NPY.FLOATINGLTR or dt.kind == NPY.COMPLEXLTR
return dt
if promote_bools and (dt.kind == NPY.GENBOOLLTR):
return descriptor.get_dtype_cache(space).w_int8dtype
if promote_to_float:
if dt.kind == NPY.FLOATINGLTR or dt.kind == NPY.COMPLEXLTR:
return dt
if dt.num >= NPY.INT:
return descriptor.get_dtype_cache(space).w_float64dtype
for bytes, dtype in descriptor.get_dtype_cache(space).float_dtypes_by_num_bytes:
if (dtype.kind == NPY.FLOATINGLTR and
dtype.itemtype.get_element_size() >
dt.itemtype.get_element_size()):
return dtype
return dt
开发者ID:yuyichao,项目名称:pypy,代码行数:25,代码来源:ufuncs.py
示例3: call
def call(self, space, args_w):
w_obj = args_w[0]
out = None
if len(args_w) > 1:
out = args_w[1]
if space.is_w(out, space.w_None):
out = None
w_obj = convert_to_array(space, w_obj)
dtype = w_obj.get_dtype()
if dtype.is_flexible():
raise OperationError(space.w_TypeError,
space.wrap('Not implemented for this type'))
if (self.int_only and not dtype.is_int() or
not self.allow_bool and dtype.is_bool() or
not self.allow_complex and dtype.is_complex()):
raise oefmt(space.w_TypeError,
"ufunc %s not supported for the input type", self.name)
calc_dtype = find_unaryop_result_dtype(space,
w_obj.get_dtype(),
promote_to_float=self.promote_to_float,
promote_bools=self.promote_bools)
if out is not None:
if not isinstance(out, W_NDimArray):
raise oefmt(space.w_TypeError, 'output must be an array')
res_dtype = out.get_dtype()
#if not w_obj.get_dtype().can_cast_to(res_dtype):
# raise oefmt(space.w_TypeError,
# "Cannot cast ufunc %s output from dtype('%s') to dtype('%s') with casting rule 'same_kind'", self.name, w_obj.get_dtype().name, res_dtype.name)
elif self.bool_result:
res_dtype = descriptor.get_dtype_cache(space).w_booldtype
else:
res_dtype = calc_dtype
if self.complex_to_float and calc_dtype.is_complex():
if calc_dtype.num == NPY.CFLOAT:
res_dtype = descriptor.get_dtype_cache(space).w_float32dtype
else:
res_dtype = descriptor.get_dtype_cache(space).w_float64dtype
if w_obj.is_scalar():
w_val = self.func(calc_dtype,
w_obj.get_scalar_value().convert_to(space, calc_dtype))
if out is None:
return w_val
w_val = res_dtype.coerce(space, w_val)
if out.is_scalar():
out.set_scalar_value(w_val)
else:
out.fill(space, w_val)
return out
shape = shape_agreement(space, w_obj.get_shape(), out,
broadcast_down=False)
return loop.call1(space, shape, self.func, calc_dtype, res_dtype,
w_obj, out)
开发者ID:yuyichao,项目名称:pypy,代码行数:52,代码来源:ufuncs.py
示例4: test_binops
def test_binops(self, space):
bool_dtype = get_dtype_cache(space).w_booldtype
int8_dtype = get_dtype_cache(space).w_int8dtype
int32_dtype = get_dtype_cache(space).w_int32dtype
float64_dtype = get_dtype_cache(space).w_float64dtype
c64_dtype = get_dtype_cache(space).w_complex64dtype
c128_dtype = get_dtype_cache(space).w_complex128dtype
cld_dtype = get_dtype_cache(space).w_complexlongdtype
fld_dtype = get_dtype_cache(space).w_floatlongdtype
# Basic pairing
assert find_binop_result_dtype(space, bool_dtype, bool_dtype) is bool_dtype
assert find_binop_result_dtype(space, bool_dtype, float64_dtype) is float64_dtype
assert find_binop_result_dtype(space, float64_dtype, bool_dtype) is float64_dtype
assert find_binop_result_dtype(space, int32_dtype, int8_dtype) is int32_dtype
assert find_binop_result_dtype(space, int32_dtype, bool_dtype) is int32_dtype
assert find_binop_result_dtype(space, c64_dtype, float64_dtype) is c128_dtype
assert find_binop_result_dtype(space, c64_dtype, fld_dtype) is cld_dtype
assert find_binop_result_dtype(space, c128_dtype, fld_dtype) is cld_dtype
# With promote bool (happens on div), the result is that the op should
# promote bools to int8
assert find_binop_result_dtype(space, bool_dtype, bool_dtype, promote_bools=True) is int8_dtype
assert find_binop_result_dtype(space, bool_dtype, float64_dtype, promote_bools=True) is float64_dtype
# Coerce to floats
assert find_binop_result_dtype(space, bool_dtype, float64_dtype, promote_to_float=True) is float64_dtype
开发者ID:yuyichao,项目名称:pypy,代码行数:27,代码来源:test_ufuncs.py
示例5: test_allowed_types
def test_allowed_types(self, space):
dt_bool = get_dtype_cache(space).w_booldtype
dt_float16 = get_dtype_cache(space).w_float16dtype
dt_int32 = get_dtype_cache(space).w_int32dtype
ufunc = unary_ufunc(space, None, "x", int_only=True)
assert ufunc._calc_dtype(space, dt_bool, out=None) == (dt_bool, dt_bool)
assert ufunc.dtypes # XXX: shouldn't contain too much stuff
ufunc = unary_ufunc(space, None, "x", promote_to_float=True)
assert ufunc._calc_dtype(space, dt_bool, out=None) == (dt_float16, dt_float16)
assert ufunc._calc_dtype(space, dt_bool, casting="same_kind") == (dt_float16, dt_float16)
raises(OperationError, ufunc._calc_dtype, space, dt_bool, casting="no")
ufunc = unary_ufunc(space, None, "x")
assert ufunc._calc_dtype(space, dt_int32, out=None) == (dt_int32, dt_int32)
开发者ID:Qointum,项目名称:pypy,代码行数:15,代码来源:test_ufuncs.py
示例6: _PyArray_DescrFromType
def _PyArray_DescrFromType(space, typenum):
try:
dtype = get_dtype_cache(space).dtypes_by_num[typenum]
return dtype
except KeyError:
raise OperationError(space.w_ValueError, space.wrap(
'_PyArray_DescrFromType called with invalid dtype %d' % typenum))
开发者ID:Darriall,项目名称:pypy,代码行数:7,代码来源:ndarrayobject.py
示例7: test_can_cast_same_type
def test_can_cast_same_type(space):
dt_bool = get_dtype_cache(space).w_booldtype
assert can_cast_type(space, dt_bool, dt_bool, 'no')
assert can_cast_type(space, dt_bool, dt_bool, 'equiv')
assert can_cast_type(space, dt_bool, dt_bool, 'safe')
assert can_cast_type(space, dt_bool, dt_bool, 'same_kind')
assert can_cast_type(space, dt_bool, dt_bool, 'unsafe')
开发者ID:abhinavthomas,项目名称:pypy,代码行数:7,代码来源:test_casting.py
示例8: argmin_argmax
def argmin_argmax(space, w_arr, w_out, axis):
from pypy.module.micronumpy.descriptor import get_dtype_cache
dtype = w_arr.get_dtype()
shapelen = len(w_arr.get_shape())
axis_flags = [False] * shapelen
axis_flags[axis] = True
inner_iter, outer_iter = split_iter(w_arr.implementation, axis_flags)
outer_state = outer_iter.reset()
out_iter, out_state = w_out.create_iter()
while not outer_iter.done(outer_state):
inner_state = inner_iter.reset()
inner_state.offset = outer_state.offset
cur_best = inner_iter.getitem(inner_state)
inner_state = inner_iter.next(inner_state)
result = 0
idx = 1
while not inner_iter.done(inner_state):
arg_driver.jit_merge_point(shapelen=shapelen, dtype=dtype)
w_val = inner_iter.getitem(inner_state)
new_best = getattr(dtype.itemtype, op_name)(cur_best, w_val)
if dtype.itemtype.ne(new_best, cur_best):
result = idx
cur_best = new_best
inner_state = inner_iter.next(inner_state)
idx += 1
result = get_dtype_cache(space).w_longdtype.box(result)
out_iter.setitem(out_state, result)
out_state = out_iter.next(out_state)
outer_state = outer_iter.next(outer_state)
return w_out
开发者ID:Qointum,项目名称:pypy,代码行数:30,代码来源:loop.py
示例9: numpify
def numpify(space, w_object):
"""Convert the object to a W_NumpyObject"""
# XXX: code duplication with _array()
from pypy.module.micronumpy import strides
if isinstance(w_object, W_NumpyObject):
return w_object
# for anything that isn't already an array, try __array__ method first
w_array = try_array_method(space, w_object)
if w_array is not None:
return w_array
shape, elems_w = strides.find_shape_and_elems(space, w_object, None)
dtype = find_dtype_for_seq(space, elems_w, None)
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 len(elems_w) == 1:
return dtype.coerce(space, elems_w[0])
else:
w_arr = W_NDimArray.from_shape(space, shape, dtype)
loop.assign(space, w_arr, elems_w)
return w_arr
开发者ID:timfel,项目名称:thesis-data,代码行数:25,代码来源:ctors.py
示例10: test_SimpleNew_scalar
def test_SimpleNew_scalar(self, space, api):
ptr_s = lltype.nullptr(rffi.LONGP.TO)
a = api._PyArray_SimpleNew(0, ptr_s, 12)
dtype = get_dtype_cache(space).w_float64dtype
a.set_scalar_value(dtype.itemtype.box(10.))
assert a.get_scalar_value().value == 10.
开发者ID:abhinavthomas,项目名称:pypy,代码行数:8,代码来源:test_ndarrayobject.py
示例11: __init__
def __init__(self, index_stride_size, stride_size, size):
start = 0
dtype = descriptor.get_dtype_cache(space).w_longdtype
indexes = dtype.itemtype.malloc(size * dtype.elsize)
values = alloc_raw_storage(size * stride_size,
track_allocation=False)
Repr.__init__(self, dtype.elsize, stride_size,
size, values, indexes, start, start)
开发者ID:abhinavthomas,项目名称:pypy,代码行数:8,代码来源:selection.py
示例12: from_shape
def from_shape(space, shape, dtype, order='C', w_instance=None, zero=True):
from pypy.module.micronumpy import concrete, descriptor, boxes
from pypy.module.micronumpy.strides import calc_strides
strides, backstrides = calc_strides(shape, dtype.base, order)
impl = concrete.ConcreteArray(shape, dtype.base, order, strides,
backstrides, zero=zero)
if dtype == descriptor.get_dtype_cache(space).w_objectdtype:
impl.fill(space, boxes.W_ObjectBox(space.w_None))
if w_instance:
return wrap_impl(space, space.type(w_instance), w_instance, impl)
return W_NDimArray(impl)
开发者ID:pypyjs,项目名称:pypy,代码行数:11,代码来源:base.py
示例13: _PyArray_FromObject
def _PyArray_FromObject(space, w_obj, typenum, min_depth, max_depth):
try:
dtype = get_dtype_cache(space).dtypes_by_num[typenum]
except KeyError:
raise oefmt(space.w_ValueError, "_PyArray_FromObject called with invalid dtype %d", typenum)
try:
return _PyArray_FromAny(space, w_obj, dtype, min_depth, max_depth, 0, NULL)
except OperationError as e:
if e.match(space, space.w_NotImplementedError):
errstr = space.str_w(e.get_w_value(space))
raise oefmt(space.w_NotImplementedError, "_PyArray_FromObject %s", errstr[16:])
raise
开发者ID:mozillazg,项目名称:pypy,代码行数:12,代码来源:ndarrayobject.py
示例14: find_dtype_for_seq
def find_dtype_for_seq(space, elems_w, dtype):
if len(elems_w) == 1:
w_elem = elems_w[0]
return _dtype_guess(space, dtype, w_elem)
for w_elem in elems_w:
dtype = _dtype_guess(space, dtype, w_elem)
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')
return dtype
开发者ID:mozillazg,项目名称:pypy,代码行数:12,代码来源:ctors.py
示例15: test_type_resolver
def test_type_resolver(self, space):
c128_dtype = get_dtype_cache(space).w_complex128dtype
c64_dtype = get_dtype_cache(space).w_complex64dtype
f64_dtype = get_dtype_cache(space).w_float64dtype
f32_dtype = get_dtype_cache(space).w_float32dtype
u32_dtype = get_dtype_cache(space).w_uint32dtype
b_dtype = get_dtype_cache(space).w_booldtype
ufunc = W_UfuncGeneric(
space,
[None, None, None],
"eigenvals",
None,
1,
1,
[f32_dtype, c64_dtype, f64_dtype, c128_dtype, c128_dtype, c128_dtype],
"",
)
f32_array = W_NDimArray(VoidBoxStorage(0, f32_dtype))
index, dtypes = ufunc.type_resolver(space, [f32_array], [None], "d->D", ufunc.dtypes)
# needs to cast input type, create output type
assert index == 1
assert dtypes == [f64_dtype, c128_dtype]
index, dtypes = ufunc.type_resolver(space, [f32_array], [None], "", ufunc.dtypes)
assert index == 0
assert dtypes == [f32_dtype, c64_dtype]
raises(OperationError, ufunc.type_resolver, space, [f32_array], [None], "u->u", ufunc.dtypes)
exc = raises(OperationError, ufunc.type_resolver, space, [f32_array], [None], "i->i", ufunc.dtypes)
开发者ID:Qointum,项目名称:pypy,代码行数:28,代码来源:test_ufuncs.py
示例16: do_ufunc
def do_ufunc(space, funcs, data, types, ntypes, nin, nout, identity, name, doc,
check_return, w_signature):
funcs_w = [None] * ntypes
dtypes_w = [None] * ntypes * (nin + nout)
for i in range(ntypes):
funcs_w[i] = ufuncs.W_GenericUFuncCaller(rffi.cast(gufunctype, funcs[i]), data)
for i in range(ntypes*(nin+nout)):
dtypes_w[i] = get_dtype_cache(space).dtypes_by_num[ord(types[i])]
w_funcs = space.newlist(funcs_w)
w_dtypes = space.newlist(dtypes_w)
w_doc = rffi.charp2str(doc)
w_name = rffi.charp2str(name)
w_identity = space.wrap(identity)
ufunc_generic = ufuncs.frompyfunc(space, w_funcs, nin, nout, w_dtypes,
w_signature, w_identity, w_name, w_doc, stack_inputs=True)
return ufunc_generic
开发者ID:Darriall,项目名称:pypy,代码行数:16,代码来源:ndarrayobject.py
示例17: _PyArray_FromObject
def _PyArray_FromObject(space, w_obj, typenum, min_depth, max_depth):
try:
dtype = get_dtype_cache(space).dtypes_by_num[typenum]
except KeyError:
raise OperationError(space.w_ValueError, space.wrap(
'_PyArray_FromObject called with invalid dtype %d' % typenum))
try:
return _PyArray_FromAny(space, w_obj, dtype, min_depth, max_depth,
0, NULL);
except OperationError, e:
if e.match(space, space.w_NotImplementedError):
errstr = space.str_w(e.get_w_value(space))
errstr = '_PyArray_FromObject' + errstr[16:]
raise OperationError(space.w_NotImplementedError, space.wrap(
errstr))
raise
开发者ID:Darriall,项目名称:pypy,代码行数:16,代码来源:ndarrayobject.py
示例18: from_shape
def from_shape(space, shape, dtype, order="C", w_instance=None, zero=True):
from pypy.module.micronumpy import concrete, descriptor, boxes
from pypy.module.micronumpy.strides import calc_strides
if len(shape) > NPY.MAXDIMS:
raise oefmt(space.w_ValueError, "sequence too large; must be smaller than %d", NPY.MAXDIMS)
try:
support.product(shape) * dtype.elsize
except OverflowError as e:
raise oefmt(space.w_ValueError, "array is too big")
strides, backstrides = calc_strides(shape, dtype.base, order)
impl = concrete.ConcreteArray(shape, dtype.base, order, strides, backstrides, zero=zero)
if dtype == descriptor.get_dtype_cache(space).w_objectdtype:
impl.fill(space, boxes.W_ObjectBox(space.w_None))
if w_instance:
return wrap_impl(space, space.type(w_instance), w_instance, impl)
return W_NDimArray(impl)
开发者ID:Qointum,项目名称:pypy,代码行数:17,代码来源:base.py
示例19: argsort
def argsort(arr, space, w_axis):
if w_axis is space.w_None:
# note that it's fine ot pass None here as we're not going
# to pass the result around (None is the link to base in slices)
if arr.get_size() > 0:
arr = arr.reshape(None, [arr.get_size()])
axis = 0
elif w_axis is None:
axis = -1
else:
axis = space.int_w(w_axis)
# create array of indexes
dtype = descriptor.get_dtype_cache(space).w_longdtype
index_arr = W_NDimArray.from_shape(space, arr.get_shape(), dtype)
with index_arr.implementation as storage, arr as arr_storage:
if len(arr.get_shape()) == 1:
for i in range(arr.get_size()):
raw_storage_setitem(storage, i * INT_SIZE, i)
r = Repr(INT_SIZE, arr.strides[0], arr.get_size(), arr_storage,
storage, 0, arr.start)
ArgSort(r).sort()
else:
shape = arr.get_shape()
if axis < 0:
axis = len(shape) + axis
if axis < 0 or axis >= len(shape):
raise oefmt(space.w_IndexError, "Wrong axis %d", axis)
arr_iter = AllButAxisIter(arr, axis)
arr_state = arr_iter.reset()
index_impl = index_arr.implementation
index_iter = AllButAxisIter(index_impl, axis)
index_state = index_iter.reset()
stride_size = arr.strides[axis]
index_stride_size = index_impl.strides[axis]
axis_size = arr.shape[axis]
while not arr_iter.done(arr_state):
for i in range(axis_size):
raw_storage_setitem(storage, i * index_stride_size +
index_state.offset, i)
r = Repr(index_stride_size, stride_size, axis_size,
arr_storage, storage, index_state.offset, arr_state.offset)
ArgSort(r).sort()
arr_state = arr_iter.next(arr_state)
index_state = index_iter.next(index_state)
return index_arr
开发者ID:abhinavthomas,项目名称:pypy,代码行数:45,代码来源:selection.py
示例20: add_ufunc
def add_ufunc(self, space, ufunc_name, op_name, argcount, extra_kwargs=None):
if extra_kwargs is None:
extra_kwargs = {}
identity = extra_kwargs.get("identity")
if identity is not None:
identity = \
descriptor.get_dtype_cache(space).w_longdtype.box(identity)
extra_kwargs["identity"] = identity
func = ufunc_dtype_caller(space, ufunc_name, op_name, argcount,
comparison_func=extra_kwargs.get("comparison_func", False),
bool_result=extra_kwargs.get("bool_result", False),
)
if argcount == 1:
ufunc = W_Ufunc1(func, ufunc_name, **extra_kwargs)
elif argcount == 2:
ufunc = W_Ufunc2(func, ufunc_name, **extra_kwargs)
setattr(self, ufunc_name, ufunc)
开发者ID:yuyichao,项目名称:pypy,代码行数:19,代码来源:ufuncs.py
注:本文中的pypy.module.micronumpy.descriptor.get_dtype_cache函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论