MCPcopy Create free account
hub / github.com/data61/MP-SPDZ / new_tape

Method new_tape

Compiler/program.py:358–398  ·  view source on GitHub ↗

Create a new tape from a function. See :py:func:`~Compiler.library.multithread` and :py:func:`~Compiler.library.for_range_opt_multithread` for easier-to-use higher-level functionality. The following runs two threads defined by two different functions::

(self, function, args=[], name=None, single_thread=False,
                 finalize=True, **kwargs)

Source from the content-addressed store, hash-verified

356 self.options.ring = str(ring_size)
357
358 def new_tape(self, function, args=[], name=None, single_thread=False,
359 finalize=True, **kwargs):
360 """
361 Create a new tape from a function. See
362 :py:func:`~Compiler.library.multithread` and
363 :py:func:`~Compiler.library.for_range_opt_multithread` for
364 easier-to-use higher-level functionality. The following runs
365 two threads defined by two different functions::
366
367 def f():
368 ...
369 def g():
370 ...
371 tapes = [program.new_tape(x) for x in (f, g)]
372 thread_numbers = program.run_tapes(tapes)
373 program.join_tapes(threads_numbers)
374
375 :param function: Python function defining the thread
376 :param args: arguments to the function
377 :param name: name used for files
378 :param single_thread: Boolean indicating whether tape will
379 never be run in parallel to itself
380 :returns: tape handle
381
382 """
383 if name is None:
384 name = function.__name__
385 name = "%s-%s" % (self.name, name)
386 # make sure there is a current tape
387 self.curr_tape
388 tape_index = len(self.tapes)
389 self.tape_stack.append(self.curr_tape)
390 self.curr_tape = Tape(name, self, **kwargs)
391 self.curr_tape.singular = single_thread
392 self.tapes.append(self.curr_tape)
393 function(*args)
394 if finalize:
395 self.finalize_tape(self.curr_tape)
396 if self.tape_stack:
397 self.curr_tape = self.tape_stack.pop()
398 return tape_index
399
400 def run_tape(self, tape_index, arg):
401 return self.run_tapes([[tape_index, arg]])[0]

Callers 3

__init__Method · 0.80
on_first_callMethod · 0.80
decoratorFunction · 0.80

Calls 5

finalize_tapeMethod · 0.95
TapeClass · 0.85
functionFunction · 0.85
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected