# Path: dlearn/utils/math.py
# def create_empty(p):
#     return theano.shared(np.zeros_like(p.get_value(borrow=True)), borrow=True)


import time
import numpy as np
import theano
import theano.tensor as T
from ..utils.math import create_empty
                offset = val.cur_irange[0]
                givens.append((sym, val.gpu_data[l - offset:r - offset]))
        else:
            offset = subset.input.cur_irange[0]
            givens.append(
                (model.input, subset.input.gpu_data[l - offset:r - offset]))

        if isinstance(model.target, list):
            for sym, val in zip(model.target, subset.target):
                offset = val.cur_irange[0]
                givens.append((sym, val.gpu_data[l - offset:r - offset]))
        else:
            offset = subset.target.cur_irange[0]
            givens.append(
                (model.target, subset.target.gpu_data[l - offset:r - offset]))
    else:
        for sym, val in zip(model.input, subset.input):
            givens.append((sym, val))
        for sym, val in zip(model.target, subset.target):
            givens.append((sym, val))

    return givens


def train(model, dataset, lr=1e-4, momentum=0.9,
          batch_size=100, n_epochs=100, valid_freq=None,
          patience_incr=2.0, lr_decr=0.5, epoch_waiting=10,
          never_stop=False):
    r"""Train the model with mini-batch Stochastic Gradient Descent(SGD).


# Path: dlearn/utils/math.py
# def create_empty(p):
#     return theano.shared(np.zeros_like(p.get_value(borrow=True)), borrow=True)


# Path: dlearn/optimization/sgd.py
import time
import numpy as np
import theano
import theano.tensor as T
from ..utils.math import create_empty

                offset = val.cur_irange[0]
                givens.append((sym, val.gpu_data[l - offset:r - offset]))
        else:
            offset = subset.input.cur_irange[0]
            givens.append(
                (model.input, subset.input.gpu_data[l - offset:r - offset]))

        if isinstance(model.target, list):
            for sym, val in zip(model.target, subset.target):
                offset = val.cur_irange[0]
                givens.append((sym, val.gpu_data[l - offset:r - offset]))
        else:
            offset = subset.target.cur_irange[0]
            givens.append(
                (model.target, subset.target.gpu_data[l - offset:r - offset]))
    else:
        for sym, val in zip(model.input, subset.input):
            givens.append((sym, val))
        for sym, val in zip(model.target, subset.target):
            givens.append((sym, val))

    return givens


def train(model, dataset, lr=1e-4, momentum=0.9,
          batch_size=100, n_epochs=100, valid_freq=None,
          patience_incr=2.0, lr_decr=0.5, epoch_waiting=10,
          never_stop=False):
    r"""Train the model with mini-batch Stochastic Gradient Descent(SGD).


    Parameters