本文整理汇总了Python中pypy.interpreter.argument.Arguments.frompacked方法的典型用法代码示例。如果您正苦于以下问题:Python Arguments.frompacked方法的具体用法?Python Arguments.frompacked怎么用?Python Arguments.frompacked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.interpreter.argument.Arguments
的用法示例。
在下文中一共展示了Arguments.frompacked方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_many_to_one
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def call_many_to_one(space, shape, func, res_dtype, in_args, out):
# out must hav been built. func needs no calc_type, is usually an
# external ufunc
nin = len(in_args)
in_iters = [None] * nin
in_states = [None] * nin
for i in range(nin):
in_i = in_args[i]
assert isinstance(in_i, W_NDimArray)
in_iter, in_state = in_i.create_iter(shape)
in_iters[i] = in_iter
in_states[i] = in_state
shapelen = len(shape)
assert isinstance(out, W_NDimArray)
out_iter, out_state = out.create_iter(shape)
vals = [None] * nin
while not out_iter.done(out_state):
call_many_to_one_driver.jit_merge_point(shapelen=shapelen, func=func,
res_dtype=res_dtype, nin=nin)
for i in range(nin):
vals[i] = in_iters[i].getitem(in_states[i])
w_arglist = space.newlist(vals)
w_out_val = space.call_args(func, Arguments.frompacked(space, w_arglist))
out_iter.setitem(out_state, res_dtype.coerce(space, w_out_val))
for i in range(nin):
in_states[i] = in_iters[i].next(in_states[i])
out_state = out_iter.next(out_state)
return out
示例2: checkmodule
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def checkmodule(modname, backend, interactive=False, basepath='pypy.module'):
"Compile a fake PyPy module."
from pypy.objspace.fake.objspace import FakeObjSpace, W_Object
from pypy.translator.driver import TranslationDriver
space = FakeObjSpace()
space.config.translating = True
ModuleClass = __import__(basepath + '.%s' % modname,
None, None, ['Module']).Module
module = ModuleClass(space, space.wrap(modname))
w_moduledict = module.getdict(space)
gateways = find_gateways(modname, basepath, module)
functions = [gw.__spacebind__(space) for gw in gateways]
arguments = Arguments.frompacked(space, W_Object(), W_Object())
dummy_function = copy(functions[0])
def main(argv): # use the standalone mode not to allow SomeObject
dummy_rpython(dummy_function)
for func in functions:
func.call_args(arguments)
return 0
patch_pypy()
driver = TranslationDriver()
driver.setup(main, None)
try:
driver.proceed(['compile_' + backend])
except SystemExit:
raise
except:
if not interactive:
raise
debug(driver)
raise SystemExit(1)
示例3: test_topacked_frompacked
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def test_topacked_frompacked(self):
space = DummySpace()
args = Arguments(space, [1], ['a', 'b'], [2, 3])
w_args, w_kwds = args.topacked()
assert w_args == (1,)
assert w_kwds == {'a': 2, 'b': 3}
args1 = Arguments.frompacked(space, w_args, w_kwds)
assert args.arguments_w == [1]
assert set(args.keywords) == set(['a', 'b'])
assert args.keywords_w[args.keywords.index('a')] == 2
assert args.keywords_w[args.keywords.index('b')] == 3
示例4: test_topacked_frompacked
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def test_topacked_frompacked(self):
space = DummySpace()
args = Arguments(space, [1], ["a", "b"], [2, 3])
w_args, w_kwds = args.topacked()
assert w_args == (1,)
assert w_kwds == {"a": 2, "b": 3}
args1 = Arguments.frompacked(space, w_args, w_kwds)
assert args.arguments_w == [1]
assert set(args.keywords) == set(["a", "b"])
assert args.keywords_w[args.keywords.index("a")] == 2
assert args.keywords_w[args.keywords.index("b")] == 3
args = Arguments(space, [1])
w_args, w_kwds = args.topacked()
assert w_args == (1,)
assert not w_kwds
示例5: call_many_to_many
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def call_many_to_many(space, shape, func, in_dtypes, out_dtypes, in_args, out_args):
# out must hav been built. func needs no calc_type, is usually an
# external ufunc
nin = len(in_args)
in_iters = [None] * nin
in_states = [None] * nin
nout = len(out_args)
out_iters = [None] * nout
out_states = [None] * nout
for i in range(nin):
in_i = in_args[i]
assert isinstance(in_i, W_NDimArray)
in_iter, in_state = in_i.create_iter(shape)
in_iters[i] = in_iter
in_states[i] = in_state
for i in range(nout):
out_i = out_args[i]
assert isinstance(out_i, W_NDimArray)
out_iter, out_state = out_i.create_iter(shape)
out_iters[i] = out_iter
out_states[i] = out_state
shapelen = len(shape)
vals = [None] * nin
test_iter, test_state = in_iters[-1], in_states[-1]
if nout > 0:
test_iter, test_state = out_iters[0], out_states[0]
while not test_iter.done(test_state):
call_many_to_many_driver.jit_merge_point(shapelen=shapelen, func=func,
in_dtypes=in_dtypes, out_dtypes=out_dtypes,
nin=nin, nout=nout)
for i in range(nin):
vals[i] = in_dtypes[i].coerce(space, in_iters[i].getitem(in_states[i]))
w_arglist = space.newlist(vals)
w_outvals = space.call_args(func, Arguments.frompacked(space, w_arglist))
# w_outvals should be a tuple, but func can return a single value as well
if space.isinstance_w(w_outvals, space.w_tuple):
batch = space.listview(w_outvals)
for i in range(len(batch)):
out_iters[i].setitem(out_states[i], out_dtypes[i].coerce(space, batch[i]))
out_states[i] = out_iters[i].next(out_states[i])
elif nout > 0:
out_iters[0].setitem(out_states[0], out_dtypes[0].coerce(space, w_outvals))
out_states[0] = out_iters[0].next(out_states[0])
for i in range(nin):
in_states[i] = in_iters[i].next(in_states[i])
test_state = test_iter.next(test_state)
return space.newtuple([convert_to_array(space, o) for o in out_args])
示例6: descr__setstate__
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def descr__setstate__(self, space, w_args):
w_flags, w_state, w_thunk, w_parent = space.unpackiterable(w_args,
expected_length=4)
self.flags = space.int_w(w_flags)
if space.is_w(w_parent, space.w_None):
w_parent = self.w_getmain(space)
self.parent = space.interp_w(AppCoroutine, w_parent)
ec = self.space.getexecutioncontext()
self.subctx.setstate(space, w_state)
if space.is_w(w_thunk, space.w_None):
if space.is_w(w_state, space.w_None):
self.thunk = None
else:
self.bind(_ResumeThunk(space, self.costate, self.subctx.topframe))
else:
w_func, w_args, w_kwds = space.unpackiterable(w_thunk,
expected_length=3)
args = Arguments.frompacked(space, w_args, w_kwds)
self.bind(_AppThunk(space, self.costate, w_func, args))
示例7: call
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def call(self, w_callable, w_args, w_kwds=None):
args = Arguments.frompacked(self, w_args, w_kwds)
return self.call_args(w_callable, args)
示例8: slot_tp_init
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import frompacked [as 别名]
def slot_tp_init(space, w_self, w_args, w_kwds):
w_descr = space.lookup(w_self, '__init__')
args = Arguments.frompacked(space, w_args, w_kwds)
space.get_and_call_args(w_descr, w_self, args)
return 0