<commit_before>#!/usr/bin/env dumbo

"""
Convert a textual matrix file into a sequence file of typed bytes
"""

import sys

"""
Map lines of a matrix to a sequence file:
  Key=<lineno>, Value=[row_i]
"""
def mapper(key,value):
    valarray = [float(v) for v in value.split()]
    if len(valarray) == 0:
        return
    yield key, valarray
    
class Converter:
    def __init__(self,opts):
        pass
    def __call__(self,data):
        item = 0
        for key,value in data:
            for entry in value:
                print "%18.16e"%(entry), 
            print
            item += 1
    
if __name__ == '__main__':
    import dumbo<commit_msg>instruction for outputting typed bytes string<commit_after>#!/usr/bin/env dumbo

"""
Convert a textual matrix file into a sequence file of typed bytes
"""

import sys

"""
Map lines of a matrix to a sequence file:
  Key=<lineno>, Value=[row_i]
"""
def mapper(key,value):
    valarray = [float(v) for v in value.split()]
    if len(valarray) == 0:
        return
    # for typed bytes string output, set the following to True
    # TODO(arbenson): make this cleaner
    use_tb_str = False
    if not use_tb_str:
        yield key, valarray
    else:
        yield key, struct.pack('d'*len(valarray), *valarray)
    
class Converter:
    def __init__(self,opts):
        pass
    def __call__(self,data):
        item = 0
        for key,value in data:
            for entry in value:
                print "%18.16e"%(entry), 
            print
            item += 1
    
if __name__ == '__main__':
    import dumbo
{'fraction_non_alphanumeric': 0.1070063694267516, 'fraction_numerical': 0.008917197452229299, 'mean_word_length': 2.286610878661088, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4787539', 'n_tokens_mistral': 509, 'n_tokens_neox': 487, 'n_words': 166}