#NEWLINE# def apply( self , dataset , can_fit = False ) : #NEWLINE# #INDENT# '\n        .. todo::\n\n            WRITEME\n        ' #NEWLINE# X = dataset . get_topological_view ( ) #NEWLINE# num_topological_dimensions = ( len ( X . shape ) - 2 ) #NEWLINE# if ( num_topological_dimensions != len ( self . patch_shape ) ) : #NEWLINE# #INDENT# raise ValueError ( ( ( ( ( ( 'ExtractGridPatches with ' + str ( len ( self . patch_shape ) ) ) + ' topological dimensions called on' ) + ' dataset with ' ) + str ( output_shape ) ) + '.' ) ) #NEWLINE# #UNINDENT# num_patches = X . shape [ 0 ] #NEWLINE# max_strides = [ ( X . shape [ 0 ] - 1 ) ] #NEWLINE# for i in xrange ( num_topological_dimensions ) : #NEWLINE# #INDENT# patch_width = self . patch_shape [ i ] #NEWLINE# data_width = X . shape [ ( i + 1 ) ] #NEWLINE# last_valid_coord = ( data_width - patch_width ) #NEWLINE# if ( last_valid_coord < 0 ) : #NEWLINE# #INDENT# raise ValueError ( ( ( ( ( ( 'On topological dimension ' + str ( i ) ) + ', the data has width ' ) + str ( data_width ) ) + ' but the requested patch width is ' ) + str ( patch_width ) ) ) #NEWLINE# #UNINDENT# stride = self . patch_stride [ i ] #NEWLINE# if ( stride == 0 ) : #NEWLINE# #INDENT# max_stride_this_axis = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# max_stride_this_axis = ( last_valid_coord / stride ) #NEWLINE# #UNINDENT# num_strides_this_axis = ( max_stride_this_axis + 1 ) #NEWLINE# max_strides . append ( max_stride_this_axis ) #NEWLINE# num_patches *= num_strides_this_axis #NEWLINE# #UNINDENT# output_shape = [ num_patches ] #NEWLINE# for dim in self . patch_shape : #NEWLINE# #INDENT# output_shape . append ( dim ) #NEWLINE# #UNINDENT# output_shape . append ( X . shape [ ( - 1 ) ] ) #NEWLINE# output = numpy . zeros ( output_shape , dtype = X . dtype ) #NEWLINE# channel_slice = slice ( 0 , X . shape [ ( - 1 ) ] ) #NEWLINE# coords = ( [ 0 ] * ( num_topological_dimensions + 1 ) ) #NEWLINE# 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 ) ] * self . patch_stride [ j ] ) #NEWLINE# args . append ( slice ( coord , ( coord + self . patch_shape [ j ] ) ) ) #NEWLINE# #UNINDENT# args . append ( channel_slice ) #NEWLINE# patch = X [ args ] #NEWLINE# output [ i , : ] = 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 ( output ) #NEWLINE# if ( dataset . y is not None ) : #NEWLINE# #INDENT# dataset . y = numpy . repeat ( dataset . y , ( num_patches / X . shape [ 0 ] ) )