<s> """<STR_LIT>""" <EOL> import os <EOL> import subprocess <EOL> def tsv2mtx ( infile , outfile ) : <EOL> num_users , num_items , nnz = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> for line in open ( infile ) : <EOL> u , i , v = line . strip ( ) . split ( ) <EOL> u = int ( u ) <EOL> i = int ( i ) <EOL> if u > num_users : <EOL> num_users = u <EOL> if i > num_items : <EOL> num_items = i <EOL> nnz += <NUM_LIT:1> <EOL> headerfile = outfile + '<STR_LIT>' <EOL> with open ( headerfile , '<STR_LIT:w>' ) as header : <EOL> print >> header , '<STR_LIT>' <EOL> print >> header , '<STR_LIT>' . format ( num_users , num_items , nnz ) <EOL> subprocess . check_call ( [ '<STR_LIT>' , headerfile , infile ] , stdout = open ( outfile , '<STR_LIT:w>' ) ) <EOL> subprocess . check_call ( [ '<STR_LIT>' , headerfile ] ) <EOL> def main ( ) : <EOL> from optparse import OptionParser <EOL> from mrec import load_sparse_matrix , save_sparse_matrix <EOL> parser = OptionParser ( ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT:input>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> ( opts , args ) = parser . parse_args ( ) <EOL> if not opts . input or not opts . output or not opts . input_format or not opts . output_format : <EOL> parser . print_help ( ) <EOL> raise SystemExit <EOL> if opts . output_format == opts . input_format : <EOL> raise SystemExit ( '<STR_LIT>' ) <EOL> if opts . input_format == '<STR_LIT>' and opts . output_format == '<STR_LIT>' : <EOL> tsv2mtx ( opts . input , opts . output ) <EOL> else : <EOL> data = load_sparse_matrix ( opts . input_format , opts . input ) <EOL> save_sparse_matrix ( data , opts . output_format , opts . output ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
