# Path: dlearn/utils/math.py
# def create_shared(x):
#     return theano.shared(np.asarray(x), borrow=True)
# 
# Path: dlearn/utils/serialize.py
# def load_data(fpath):
#     with open(fpath, 'rb') as f:
#         data = cPickle.load(f)
#     return data


from glob import glob
from os.path import join as pj
from ..utils.math import create_shared
from ..utils.serialize import load_data


class Subset(object):
    def __init__(self, homepath, irange, pfunc=None):
        super(Subset, self).__init__()

        self._batch_files = [pj(homepath, 'data_batch_{}'.format(i))
                             for i in xrange(irange[0], irange[1] + 1)]
        self._pfunc = pfunc

        self._input = None
        self._target = None
        self.prepare(0)
        
    def prepare(self, index):
        input, target = load_data(self._batch_files[index])
        if self._pfunc is not None:
            input, target = self._pfunc(input, target)

        if self._input is None:
            self._input = [create_shared(X) for X in input]

# Path: dlearn/utils/math.py
# def create_shared(x):
#     return theano.shared(np.asarray(x), borrow=True)
# 
# Path: dlearn/utils/serialize.py
# def load_data(fpath):
#     with open(fpath, 'rb') as f:
#         data = cPickle.load(f)
#     return data


# Path: dlearn/data/data_provider.py
from glob import glob
from os.path import join as pj
from ..utils.math import create_shared
from ..utils.serialize import load_data



class Subset(object):
    def __init__(self, homepath, irange, pfunc=None):
        super(Subset, self).__init__()

        self._batch_files = [pj(homepath, 'data_batch_{}'.format(i))
                             for i in xrange(irange[0], irange[1] + 1)]
        self._pfunc = pfunc

        self._input = None
        self._target = None
        self.prepare(0)
        
    def prepare(self, index):
        input, target = load_data(self._batch_files[index])
        if self._pfunc is not None:
            input, target = self._pfunc(input, target)

        if self._input is None:
            self._input = [create_shared(X) for X in input]

            self._target = [create_shared(X) for X in target]