<commit_before>"""
This module should handle:
* conversion of TTrees into NumPy arrays
* conversion of TTrees into carrays (http://pypi.python.org/pypi/carray)
"""
from .types import Variable, convert
import numpy as np

def to_numpy_array(tree, branches=None, use_cache=False, cache_size=1000000):
    
    # if branches is None then select only branches with basic types
    # i.e. no vectors or other special objects
    _branches = []
    if branches is None:
        for name, value in tree.buffer.items():
            if isinstance(value, Variable):
                _branches.append((name, value))
    else:
        for branch in branches:
            if branch not in tree.buffer:
                raise ValueError("Branch %s does not exist in tree" % branch)
            value = tree.buffer[branch]
            if not isinstance(value, Variable):
                raise TypeError("Branch %s is not a basic type: %s" % 
                                (branch, type(value)))
            _branches.append((branch, tree.buffer[branch]))    
    if not _branches:
        return None
    dtype = [(name, convert('ROOTCODE', 'NUMPY', value.type)) for name, value in _branches]
    array = np.recarray(shape=(tree.GetEntries(),), dtype=dtype)
    tree.use_cache(use_cache, cache_size=cache_size, learn_entries=1)
    if use_cache:
        tree.always_read([name for name, value in _branches])
    for i, entry in enumerate(tree):
        for j, (branch, value) in enumerate(_branches):
            array[i][j] = value.value
    return array
<commit_msg>allow multiple trees in conversion to numpy array<commit_after>"""
This module should handle:
* conversion of TTrees into NumPy arrays
* conversion of TTrees into carrays (http://pypi.python.org/pypi/carray)
"""
from .types import Variable, convert
import numpy as np

def to_numpy_array(*trees, branches=None, use_cache=False, cache_size=1000000):
    
    # if branches is None then select only branches with basic types
    # i.e. no vectors or other special objects
    _branches = []
    if branches is None:
        for name, value in tree.buffer.items():
            if isinstance(value, Variable):
                _branches.append((name, value))
    else:
        for branch in branches:
            if branch not in tree.buffer:
                raise ValueError("Branch %s does not exist in tree" % branch)
            value = tree.buffer[branch]
            if not isinstance(value, Variable):
                raise TypeError("Branch %s is not a basic type: %s" % 
                                (branch, type(value)))
            _branches.append((branch, tree.buffer[branch]))    
    if not _branches:
        return None
    dtype = [(name, convert('ROOTCODE', 'NUMPY', value.type)) for name, value in _branches]
    total_entries = sum([tree.GetEntries() for tree in trees])
    array = np.recarray(shape=(total_entries,), dtype=dtype)
    i = 0
    for tree in trees:
        tree.use_cache(use_cache, cache_size=cache_size, learn_entries=1)
        if use_cache:
            tree.always_read([name for name, value in _branches])
        for entry in tree:
            for j, (branch, value) in enumerate(_branches):
                array[i][j] = entry[branch].value
                i += 1
    return array

{'fraction_non_alphanumeric': 0.09856576136710406, 'fraction_numerical': 0.00549282880683552, 'mean_word_length': 2.4872340425531916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4399629', 'n_tokens_mistral': 952, 'n_tokens_neox': 915, 'n_words': 312}