<s> from __future__ import division , print_function , absolute_import <EOL> import numpy as np <EOL> def pad ( data , padwidth , value = <NUM_LIT:0.0> ) : <EOL> """<STR_LIT>""" <EOL> data = np . asarray ( data ) <EOL> shape = data . shape <EOL> if isinstance ( padwidth , int ) : <EOL> padwidth = ( padwidth , ) * len ( shape ) <EOL> padded_shape = tuple ( map ( lambda ix : ix [ <NUM_LIT:1> ] + padwidth [ ix [ <NUM_LIT:0> ] ] * <NUM_LIT:2> , <EOL> enumerate ( shape ) ) ) <EOL> new_data = np . empty ( padded_shape , dtype = data . dtype ) <EOL> new_data [ ... , : ] = value <EOL> new_data [ [ slice ( w , - w ) if w > <NUM_LIT:0> else slice ( None ) for w in padwidth ] ] = data <EOL> return new_data <EOL> def pad_to_size ( data , shape , value = <NUM_LIT:0.0> ) : <EOL> """<STR_LIT>""" <EOL> shape = [ data . shape [ i ] if shape [ i ] == - <NUM_LIT:1> else shape [ i ] <EOL> for i in range ( len ( shape ) ) ] <EOL> new_data = np . empty ( shape ) <EOL> new_data [ : ] = value <EOL> II = [ slice ( ( shape [ i ] - data . shape [ i ] ) // <NUM_LIT:2> , <EOL> ( shape [ i ] - data . shape [ i ] ) // <NUM_LIT:2> + data . shape [ i ] ) <EOL> for i in range ( len ( shape ) ) ] <EOL> new_data [ II ] = data <EOL> return new_data <EOL> def pad_repeat_border ( data , padwidth ) : <EOL> """<STR_LIT>""" <EOL> data = np . asarray ( data ) <EOL> shape = data . shape <EOL> if isinstance ( padwidth , int ) : <EOL> padwidth = ( padwidth , ) * len ( shape ) <EOL> padded_shape = tuple ( map ( lambda ix : ix [ <NUM_LIT:1> ] + padwidth [ ix [ <NUM_LIT:0> ] ] * <NUM_LIT:2> , <EOL> enumerate ( shape ) ) ) <EOL> new_data = np . empty ( padded_shape , dtype = data . dtype ) <EOL> new_data [ [ slice ( w , - w ) if w > <NUM_LIT:0> else slice ( None ) for w in padwidth ] ] = data <EOL> for i , pw in enumerate ( padwidth ) : <EOL> if pw > <NUM_LIT:0> : <EOL> selection = [ slice ( None ) ] * data . ndim <EOL> selection2 = [ slice ( None ) ] * data . ndim <EOL> selection [ i ] = slice ( <NUM_LIT:0> , pw ) <EOL> selection2 [ i ] = slice ( pw , pw + <NUM_LIT:1> ) <EOL> new_data [ tuple ( selection ) ] = new_data [ tuple ( selection2 ) ] <EOL> selection [ i ] = slice ( - pw , None ) <EOL> selection2 [ i ] = slice ( - pw - <NUM_LIT:1> , - pw ) <EOL> new_data [ tuple ( selection ) ] = new_data [ tuple ( selection2 ) ] <EOL> return new_data <EOL> def pad_repeat_border_corner ( data , shape ) : <EOL> """<STR_LIT>""" <EOL> new_data = np . empty ( shape ) <EOL> new_data [ [ slice ( upper ) for upper in data . shape ] ] = data <EOL> for i in range ( len ( shape ) ) : <EOL> selection = [ slice ( None ) ] * i + [ slice ( data . shape [ i ] , None ) ] <EOL> selection2 = [ slice ( None ) ] * i + [ slice ( data . shape [ i ] - <NUM_LIT:1> , data . shape [ i ] ) ] <EOL> new_data [ selection ] = new_data [ selection2 ] <EOL> return new_data </s>
