#NEWLINE# def _fromstring_rows( fid , tag_size , dtype = None , shape = None , rlims = None ) : #NEWLINE# #INDENT# 'Helper for getting a range of rows from a large tag' #NEWLINE# if ( shape is not None ) : #NEWLINE# #INDENT# item_size = np . dtype ( dtype ) . itemsize #NEWLINE# if ( not ( len ( shape ) == 2 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Only implemented for 2D matrices' ) #NEWLINE# #UNINDENT# want_shape = np . prod ( shape ) #NEWLINE# have_shape = ( tag_size // item_size ) #NEWLINE# if ( want_shape != have_shape ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Wrong shape specified, requested %s have %s' % ( want_shape , have_shape ) ) ) #NEWLINE# #UNINDENT# if ( not ( len ( rlims ) == 2 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'rlims must have two elements' ) #NEWLINE# #UNINDENT# n_row_out = ( rlims [ 1 ] - rlims [ 0 ] ) #NEWLINE# if ( n_row_out <= 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'rlims must yield at least one output' ) #NEWLINE# #UNINDENT# row_size = ( item_size * shape [ 1 ] ) #NEWLINE# start_skip = int ( ( rlims [ 0 ] * row_size ) ) #NEWLINE# read_size = int ( ( n_row_out * row_size ) ) #NEWLINE# end_pos = int ( ( fid . tell ( ) + tag_size ) ) #NEWLINE# fid . seek ( start_skip , 1 ) #NEWLINE# out = np . fromstring ( fid . read ( read_size ) , dtype = dtype ) #NEWLINE# fid . seek ( end_pos ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# out = np . fromstring ( fid . read ( tag_size ) , dtype = dtype ) #NEWLINE# #UNINDENT# return out