<s> import numpy as np <EOL> from . . utils . math import create_shared <EOL> class HierarData ( object ) : <EOL> def __init__ ( self , data , limit = None ) : <EOL> self . _cpu_data = data <EOL> if limit is None or limit > data . shape [ <NUM_LIT:0> ] : <EOL> limit = data . shape [ <NUM_LIT:0> ] <EOL> self . _limit = limit <EOL> self . _gpu_data = create_shared ( self . _cpu_data [ <NUM_LIT:0> : limit ] ) <EOL> self . _cur_irange = create_shared ( np . asarray ( [ <NUM_LIT:0> , limit ] ) ) <EOL> def prepare ( self , irange ) : <EOL> l , r = irange <EOL> cur_l , cur_r = self . _cur_irange . get_value ( borrow = True ) <EOL> if min ( l , r - <NUM_LIT:1> ) < cur_l or max ( l , r - <NUM_LIT:1> ) >= cur_r : <EOL> self . _cur_irange . set_value ( np . asarray ( [ l , l + self . _limit ] ) ) <EOL> self . _gpu_data . set_value ( <EOL> self . _cpu_data [ l : l + self . _limit ] , borrow = True ) <EOL> @ property <EOL> def cur_irange ( self ) : <EOL> return self . _cur_irange <EOL> @ property <EOL> def cpu_data ( self ) : <EOL> return self . _cpu_data <EOL> @ property <EOL> def gpu_data ( self ) : <EOL> return self . _gpu_data </s>
