<gh_stars>1-10
import numpy as np
from striped.ingestion import BaseDataReader
from keras.datasets import mnist
from keras.utils import to_categorical

class DataReader(BaseDataReader):

    def __init__(self, file_path, schema):
        assert file_path in ("train", "test")
        (x_train, y_train), (x_test, y_test) = mnist.load_data()
        #print (x_train.shape)
        if file_path == "train":
                self.x = np.asarray(x_train, dtype=np.float32)/256.
                self.y = to_categorical(y_train, 10)
        else:
                self.x = np.asarray(x_test, dtype=np.float32)/256.
                self.y = to_categorical(y_test, 10)
        #print (self.x.shape, len(self.x))
        self.Schema = schema
        
    def profile(self):
        return None
                    
    def reopen(self):
        pass
        
    def nevents(self):
        #print ("Nvents=", len(self.x))
        return len(self.x)
        
    def branchSizeArray(self, bname):
        pass

    def stripesAndSizes(self, groups, bname, attr_name, attr_desc):
        src = attr_desc["source"]
        src_array = {'x': self.x, 'y': self.y }[src]
        i = 0
        for g in groups:
                yield np.ascontiguousarray(src_array[i:i+g]), None
                i += g

import numpy as np
from striped.ingestion import BaseDataReader
from keras.datasets import mnist
from keras.utils import to_categorical

class DataReader(BaseDataReader):

    def __init__(self, file_path, schema):
        assert file_path in ("train", "test")
        (x_train, y_train), (x_test, y_test) = mnist.load_data()
        #print (x_train.shape)
        if file_path == "train":
                self.x = np.asarray(x_train, dtype=np.float32)/256.
                self.y = to_categorical(y_train, 10)
        else:
                self.x = np.asarray(x_test, dtype=np.float32)/256.
                self.y = to_categorical(y_test, 10)
        #print (self.x.shape, len(self.x))
        self.Schema = schema
        
    def profile(self):
        return None
                    
    def reopen(self):
        pass
        
    def nevents(self):
        #print ("Nvents=", len(self.x))
        return len(self.x)
        
    def branchSizeArray(self, bname):
        pass

    def stripesAndSizes(self, groups, bname, attr_name, attr_desc):
        src = attr_desc["source"]
        src_array = {'x': self.x, 'y': self.y }[src]
        i = 0
        for g in groups:
                yield np.ascontiguousarray(src_array[i:i+g]), None
                i += g
#print (x_train.shape) #print (self.x.shape, len(self.x)) #print ("Nvents=", len(self.x))