#NEWLINE# def apply( self , dataset , can_fit = False ) : #NEWLINE# #INDENT# '\n        .. todo::\n\n            WRITEME\n        ' #NEWLINE# patches = dataset . get_topological_view ( ) #NEWLINE# num_topological_dimensions = ( len ( patches . shape ) - 2 ) #NEWLINE# if ( num_topological_dimensions != len ( self . patch_shape ) ) : #NEWLINE# #INDENT# raise ValueError ( ( ( ( ( ( 'ReassembleGridPatches with ' + str ( len ( self . patch_shape ) ) ) + ' topological dimensions called on dataset ' ) + ' with ' ) + str ( num_topological_dimensions ) ) + '.' ) ) #NEWLINE# #UNINDENT# num_patches = patches . shape [ 0 ] #NEWLINE# num_examples = num_patches #NEWLINE# for ( im_dim , patch_dim ) in zip ( self . orig_shape , self . patch_shape ) : #NEWLINE# #INDENT# if ( ( im_dim % patch_dim ) != 0 ) : #NEWLINE# #INDENT# raise Exception ( ( ( ( ( 'Trying to assemble patches of shape ' + str ( self . patch_shape ) ) + ' into images of ' ) + 'shape ' ) + str ( self . orig_shape ) ) ) #NEWLINE# #UNINDENT# patches_this_dim = ( im_dim / patch_dim ) #NEWLINE# if ( ( num_examples % patches_this_dim ) != 0 ) : #NEWLINE# #INDENT# raise Exception ( ( ( ( ( ( 'Trying to re-assemble ' + str ( num_patches ) ) + ' patches of shape ' ) + str ( self . patch_shape ) ) + ' into images of shape ' ) + str ( self . orig_shape ) ) ) #NEWLINE# #UNINDENT# num_examples /= patches_this_dim #NEWLINE# #UNINDENT# reassembled_shape = [ num_examples ] #NEWLINE# for dim in self . orig_shape : #NEWLINE# #INDENT# reassembled_shape . append ( dim ) #NEWLINE# #UNINDENT# reassembled_shape . append ( patches . shape [ ( - 1 ) ] ) #NEWLINE# reassembled = numpy . zeros ( reassembled_shape , dtype = patches . dtype ) #NEWLINE# channel_slice = slice ( 0 , patches . shape [ ( - 1 ) ] ) #NEWLINE# coords = ( [ 0 ] * ( num_topological_dimensions + 1 ) ) #NEWLINE# max_strides = [ ( num_examples - 1 ) ] #NEWLINE# for ( dim , pd ) in zip ( self . orig_shape , self . patch_shape ) : #NEWLINE# #INDENT# assert ( ( dim % pd ) == 0 ) #NEWLINE# max_strides . append ( ( ( dim / pd ) - 1 ) ) #NEWLINE# #UNINDENT# keep_going = True #NEWLINE# i = 0 #NEWLINE# while keep_going : #NEWLINE# #INDENT# args = [ coords [ 0 ] ] #NEWLINE# for j in xrange ( num_topological_dimensions ) : #NEWLINE# #INDENT# coord = coords [ ( j + 1 ) ] #NEWLINE# args . append ( slice ( ( coord * self . patch_shape [ j ] ) , ( ( coord + 1 ) * self . patch_shape [ j ] ) ) ) #NEWLINE# next_shape_coord = reassembled . shape [ ( j + 1 ) ] #NEWLINE# assert ( ( ( coord + 1 ) * self . patch_shape [ j ] ) <= next_shape_coord ) #NEWLINE# #UNINDENT# args . append ( channel_slice ) #NEWLINE# try : #NEWLINE# #INDENT# patch = patches [ i , : ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# reraise_as ( IndexError ( ( ( ( 'Gave index of ' + str ( i ) ) + ', : into thing of shape ' ) + str ( patches . shape ) ) ) ) #NEWLINE# #UNINDENT# reassembled [ args ] = patch #NEWLINE# i += 1 #NEWLINE# j = 0 #NEWLINE# keep_going = False #NEWLINE# while ( not keep_going ) : #NEWLINE# #INDENT# if ( coords [ ( - ( j + 1 ) ) ] < max_strides [ ( - ( j + 1 ) ) ] ) : #NEWLINE# #INDENT# coords [ ( - ( j + 1 ) ) ] += 1 #NEWLINE# keep_going = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# coords [ ( - ( j + 1 ) ) ] = 0 #NEWLINE# if ( j == num_topological_dimensions ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# j = ( j + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# dataset . set_topological_view ( reassembled ) #NEWLINE# if ( dataset . y is not None ) : #NEWLINE# #INDENT# dataset . y = dataset . y [ : : ( patches . shape [ 0 ] / reassembled_shape [ 0 ] ) ]