<s> from itertools import izip <EOL> from quagga . matrix import Matrix <EOL> from quagga . context import Context <EOL> from quagga . connector import Connector <EOL> class VerticalStackBlock ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * matrices , ** kwargs ) : <EOL> self . context = Context ( kwargs . get ( '<STR_LIT>' ) ) <EOL> device_id = self . context . device_id <EOL> self . matrices = [ ] <EOL> self . dL_dmatrices = [ ] <EOL> self . bpropagable = [ ] <EOL> for matrix in matrices : <EOL> self . bpropagable . append ( matrix . bpropagable ) <EOL> if matrix . bpropagable : <EOL> matrix , dL_dmatrix = matrix . register_usage ( device_id , device_id ) <EOL> self . dL_dmatrices . append ( dL_dmatrix ) <EOL> else : <EOL> matrix = matrix . register_usage ( device_id ) <EOL> self . matrices . append ( matrix ) <EOL> nrows = [ matrix . nrows for matrix in matrices ] <EOL> nrows = sum ( [ e for e in nrows [ <NUM_LIT:1> : ] ] , nrows [ <NUM_LIT:0> ] ) <EOL> dtype = matrices [ <NUM_LIT:0> ] . dtype <EOL> bu_device_id = device_id if self . dL_dmatrices else None <EOL> output = Matrix . empty ( nrows , matrices [ <NUM_LIT:0> ] . ncols , dtype , device_id ) <EOL> self . output = Connector ( output , bu_device_id ) <EOL> def fprop ( self ) : <EOL> self . output . assign_vstack ( self . context , self . matrices ) <EOL> self . output . fprop ( ) <EOL> def bprop ( self ) : <EOL> if self . dL_dmatrices : <EOL> row_slices = [ ] <EOL> nrows = [ <NUM_LIT:0> ] <EOL> for matrix , bpropagable in izip ( self . matrices , self . bpropagable ) : <EOL> nrows . append ( nrows [ - <NUM_LIT:1> ] + int ( matrix . nrows ) ) <EOL> if bpropagable : <EOL> row_slices . append ( ( nrows [ - <NUM_LIT:2> ] , nrows [ - <NUM_LIT:1> ] ) ) <EOL> self . output . backward_matrix . vsplit ( self . context , self . dL_dmatrices , row_slices ) </s>
