:param t_input: Translator input.
        :param t_output: Translator output.
        :param t_walltime: Total wall-clock time for translation.
555935
def handle(self,
               t_input: inference.TranslatorInput,
               t_output: inference.TranslatorOutput,
               t_walltime: float = 0.):
        
        line = "{sent_id} ||| {target} ||| {score:f} ||| {source} ||| {source_len:d} ||| {target_len:d}\n"
        self.stream.write(line.format(sent_id=t_input.sentence_id,
                                      target=" ".join(t_output.tokens),
                                      score=t_output.score,
                                      source=" ".join(t_input.tokens),
                                      source_len=len(t_input.tokens),
                                      target_len=len(t_output.tokens)))
        attention_matrix = t_output.attention_matrix.T
        for i in range(0, attention_matrix.shape[0]):
            attention_vector = attention_matrix[i]
            self.stream.write(" ".join(["%f" % value for value in attention_vector]))
            self.stream.write("\n")

        self.stream.write("\n")
        self.stream.flush()
19232
def swap_time_and_batch_axes(inputs):
  """"""
  transposed_axes = tf.concat([[1, 0], tf.range(2, tf.rank(inputs))], axis=0)
  return tf.transpose(inputs, transposed_axes)
741648
def _build_time(time, kwargs):
    
    tz = kwargs.pop('tz', 'UTC')
    if time:
        if kwargs:
            raise ValueError('Cannot pass kwargs and a time')
        else:
            return ensure_utc(time, tz)
    elif not kwargs:
        raise ValueError('Must pass a time or kwargs')
    else:
        return datetime.time(**kwargs)
257276
def timeit(func):
    
    import time

    def timed(*args, **kw):
        ts = time.time()
        result = func(*args, **kw)
        te = time.time()

        msg = "{0}{1} {2:.2f}s".format(func.__name__, args, te - ts)
        logging.debug(msg)

        return result

    return timed
1080661
private static long getTransitionTime(TimeZoneTransition tzt, boolean local,
            int NonExistingTimeOpt, int DuplicatedTimeOpt) {
        long time = tzt.getTime();
        if (local) {
            time += getLocalDelta(tzt.getFrom().getRawOffset(), tzt.getFrom().getDSTSavings(),
                                tzt.getTo().getRawOffset(), tzt.getTo().getDSTSavings(),
                                NonExistingTimeOpt, DuplicatedTimeOpt);
        }
        return time;
    }
1089636
def asStructTime(self, tzinfo=None):
        
        dtime = self.asDatetime(tzinfo)
        if tzinfo is None:
            return dtime.utctimetuple()
        else:
            return dtime.timetuple()
905204
def timed (log=sys.stderr, limit=2.0):
    """"""
    return lambda func: timeit(func, log, limit)
606223
def get_sents_times_and_translations(xml_fn):
    

    tree = ElementTree.parse(xml_fn)
    root = tree.getroot()
    if "WORDLIST" in root.tag or root.tag == "TEXT":
        transcriptions = []
        times = []
        translations = []
        for child in root:
            # If it's a sentence or a word (this will be dictated by root_tag)
            if child.tag == "S" or child.tag == "W":
                forms = child.findall("FORM")
                if len(forms) > 1:
                    # Assuming there is kindOf="phono" available.
                    for form in forms:
                        if form.attrib["kindOf"] == "phono":
                            transcription = form.text
                else:
                    transcription = child.find("FORM").text
                audio_info = child.find("AUDIO")
                if audio_info is not None:
                    start_time = float(audio_info.attrib["start"])
                    end_time = float(audio_info.attrib["end"])
                    time = (start_time, end_time)
                    translation = [trans.text for trans in child.findall("TRANSL")]
                    transcriptions.append(transcription)
                    times.append(time)
                    translations.append(translation)

        return root.tag, transcriptions, times, translations
    logger.critical('the root tag, %s, does not contain "WORDLIST", and is not "TEXT"', root.tag)
    assert False, root.tag
383524
def timeit(func):
    

    @wraps(func)
    def timer_wrapper(*args, **kwargs):
        """
        Inner function that uses the Timer context object
        """
        with Timer() as timer:
            result = func(*args, **kwargs)

        return result, timer

    return timer_wrapper
733935
def handle(self,
               t_input: inference.TranslatorInput,
               t_output: inference.TranslatorOutput,
               t_walltime: float = 0.):
        
        alignments = " ".join(
            ["%d-%d" % (s, t) for s, t in get_alignments(t_output.attention_matrix, threshold=self.threshold)])
        self.stream.write("%s\t%s\n" % (t_output.translation, alignments))
        self.stream.flush()
1065436
def from_native(cls, t):
        
        second = (1000000 * t.second + t.microsecond) / 1000000
        return Time(t.hour, t.minute, second, t.tzinfo)
436881
def write(self, message, cur_time=None):
        
        if cur_time is None:
            cur_time = time.time()
        lines = self._line_buffer.add_string(message)
        for line in lines:
            #print('ts line', repr(line))
            timestamp = ''
            if self._prepend_timestamp:
                timestamp = datetime.datetime.utcfromtimestamp(
                    cur_time).isoformat() + ' '
            line = u'{}{}{}'.format(self._line_prepend, timestamp, line)
            self._fsapi.push(self._filename, line)
1240149
def timeit(self, metric, func, *args, **kwargs):
        """"""
        return metrics.timeit(metric, func, *args, **kwargs)
741701
def handle(self,
               t_input: inference.TranslatorInput,
               t_output: inference.TranslatorOutput,
               t_walltime: float = 0.):
        
        self.stream.write("{:.3f}\t{}\t{}\n".format(t_output.score,
                                                    C.TOKEN_SEPARATOR.join(t_input.tokens),
                                                    t_output.translation))
        self.stream.flush()
1113331
def cmd_time(self, args):
        ''''''
        tusec = self.master.field('SYSTEM_TIME', 'time_unix_usec', 0)
        if tusec == 0:
            print("No SYSTEM_TIME time available")
            return
        print("%s (%s)\n" % (time.ctime(tusec * 1.0e-6), time.ctime()))
1107438
def strtime (t, func=time.localtime):
    """"""
    return time.strftime("%Y-%m-%d %H:%M:%S", func(t)) + strtimezone()
886852
def timestamp(self, name="<block>"):
        """"""
        # Make a fake function
        func = lambda x: x
        func.__module__ = ""
        func.__name__ = name
        self.add_function(func)
        timestamps = []
        self.functions[func].append(timestamps)
        # A new object is required each time, since there can be several
        # nested context managers.
        return _TimeStamperCM(timestamps)