#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import division
import math


class ManualScheduleTrigger(object):

    """Trigger invoked at specified point(s) of iterations or epochs.

    This trigger accepts iterations or epochs indicated by given point(s).
    There are two ways to specify the point(s): iteration and epoch.
    ``iteration`` means the number of updates, while ``epoch`` means the number
    of sweeps over the training dataset. Fractional values are allowed
    if the point is a number of epochs; the trigger uses the ``iteration``
    and ``epoch_detail`` attributes defined by the updater.

    Args:
        points (int, float, or list of int or float): time of the trigger.
            Must be an integer or list of integer if unit is ``'iteration'``.
        unit (str): Unit of the time specified by ``points``. It must be
            either ``'iteration'`` or ``'epoch'``.

    """

    def __init__(self, points, unit):
        assert unit == 'epoch' or unit == 'iteration'
        self.points = (points if isinstance(points, list) else [points])
        self.unit = unit

    def __call__(self, trainer):
        """Decides whether the extension should be called on this iteration.

        Args:
            trainer (Trainer): Trainer object that this trigger is associated
                with. The updater associated with this trainer is used to
                determine if the trigger should fire.

        Returns:
            bool: True if the corresponding extension should be invoked in this
                iteration.

        """

        updater = trainer.updater
        iteration = updater.iteration
        epoch = updater.epoch_detail
        if self.unit == 'epoch':
            return any(
                math.ceil(p * iteration / epoch) == iteration
                for p in self.points)
        else:
            return iteration > 0 and iteration in self.points

@@ -1,93 +1,4 @@
-#!/usr/bin/python%0A# -*- coding: utf-8 -*-%0A%0Afrom __future__ import division%0Aimport math%0A%0A%0A
 clas
@@ -1538,50 +1538,113 @@
    i
-teration = updater.iteration%0A        epoch
+f self.unit == 'epoch':%0A            epoch_detail = updater.epoch_detail%0A            previous_epoch_detail
  = u
@@ -1642,32 +1642,41 @@
 etail = updater.
+previous_
 epoch_detail%0A   
@@ -1684,118 +1684,170 @@
     
-if self.unit == 'epoch':%0A            return any(%0A                math.ceil(p * iteration / epoch) == iteration
+    if previous_epoch_detail is None:%0A                previous_epoch_detail = -1%0A            return any(%0A                previous_epoch_detail %3C p %3C= epoch_detail
 %0A   
@@ -1895,16 +1895,58 @@
   else:%0A
+            iteration = updater.iteration%0A
         

modify ManualScheduletrigger to use previous_epoch_detail