#NEWLINE# def reconcile_file_order( f , names = None , cats = None , write = False ) : #NEWLINE# #INDENT# '\n    Checks that the passed names, cats agree with the cache file f. If both have\n    names, checks only that; otherwise, checks that they agree as well as\n    possible.\n\n    f: an h5py.File\n    names: a string array or None\n    cats: a string array, an array of integers, or None\n    write: if true, add any additional info to the file once they seem the same\n    ' #NEWLINE# have_names = ( names is not None ) #NEWLINE# have_cats = ( cats is not None ) #NEWLINE# if ( ( not have_names ) and ( not have_cats ) ) : #NEWLINE# #INDENT# raise ValueError ( 'reconcile_file_order needs names or cats...' ) #NEWLINE# #UNINDENT# if ( '_meta' in f ) : #NEWLINE# #INDENT# meta_group = f [ '_meta' ] #NEWLINE# have_f_names = ( 'names' in meta_group ) #NEWLINE# have_f_cats = ( 'cats' in meta_group ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# meta_group = None #NEWLINE# have_f_names = have_f_cats = False #NEWLINE# #UNINDENT# if have_names : #NEWLINE# #INDENT# import h5py #NEWLINE# names = np . asarray ( names , dtype = h5py . special_dtype ( vlen = bytes ) ) #NEWLINE# #UNINDENT# if have_f_names : #NEWLINE# #INDENT# f_names = meta_group [ 'names' ] [ ( ) ] #NEWLINE# #UNINDENT# if have_cats : #NEWLINE# #INDENT# ( cats , cats_is_str ) = _convert_cats ( cats ) #NEWLINE# #UNINDENT# if have_f_cats : #NEWLINE# #INDENT# ( f_cats , f_cats_is_str ) = _convert_cats ( meta_group [ 'cats' ] [ ( ) ] ) #NEWLINE# #UNINDENT# if ( have_names and have_f_names ) : #NEWLINE# #INDENT# assert np . all ( ( names == f_names ) ) #NEWLINE# #UNINDENT# if ( have_cats and have_f_cats ) : #NEWLINE# #INDENT# if ( cats_is_str and f_cats_is_str ) : #NEWLINE# #INDENT# assert np . all ( ( cats == f_cats ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( _ , cats_relabeled ) = np . unique ( cats , return_inverse = True ) #NEWLINE# ( _ , f_cats_relabeled ) = np . unique ( f_cats , return_inverse = True ) #NEWLINE# assert np . all ( ( cats_relabeled == f_cats_relabeled ) ) #NEWLINE# #UNINDENT# #UNINDENT# if write : #NEWLINE# #INDENT# if ( meta_group is None ) : #NEWLINE# #INDENT# meta_group = f . create_group ( 'meta' ) #NEWLINE# #UNINDENT# if ( have_names and ( not have_f_names ) ) : #NEWLINE# #INDENT# meta_group [ 'names' ] = names #NEWLINE# #UNINDENT# if ( have_cats and ( ( not have_f_cats ) or ( cats_is_str and ( not f_cats_is_str ) ) ) ) : #NEWLINE# #INDENT# meta_group [ 'cats' ] = cats