<commit_before>from numpy import *
from scipy import sparse
import scipy
import scipy.io
import re
import logging


def readLibSVM(fname, ndata, nfeatures, binary=True, dense=False):
    logger = logging.getLogger("read")
    
    # Read data into a scipy sparse matrix.
    
    n = ndata
    m = nfeatures + 1
    
    if dense:
        X = zeros((n,m))
    else:
        X = sparse.lil_matrix((n, m))
    
    dclass = zeros(n)
    
    h = re.compile('(\d*):(-?\d+\.?\d*)')
    f = open(fname, 'r')
    
    i = 0
    posPoints = 0
    negPoints = 0
    for line in f.xreadlines():
        parts = line.split(' ', 1)
        
        if binary:
            if double(parts[0]) == 1:
                di = 1
            else:
                di = -1
            
            if di == 1:
                posPoints += 1
            else:
                negPoints += 1    
        else:
            di = double(parts[0])
        
         
        dclass[i] = di
        for (j, v) in re.findall(h, parts[1]):
            if int(j) > m:
                raise Exception("Bad column index: %d" % int(j))
            X[i, int(j)] = float(v)
            
        #import pdb; pdb.set_trace()
        
        # libsvm starts at j=1, so we use j=0 as a bias term.
        X[i, 0] = 1.0
        i += 1
        
        if i % 2000 == 0 and i != 0:
            if binary:
                logger.info("--- read %d points, %d positive %d negative", i, posPoints, negPoints)
            else:
                logger.info("--- read %d points", i)
            
      
    logger.info("Finished. %d points.", i) 
    if binary:     
        logger.info("%d positive %d negative", posPoints, negPoints)
    
    f.close()
    <commit_msg>Python3 fix<commit_after>from numpy import *
from scipy import sparse
import scipy
import scipy.io
import re
import logging


def readLibSVM(fname, ndata, nfeatures, binary=True, dense=False):
    logger = logging.getLogger("read")

    # Read data into a scipy sparse matrix.

    n = ndata
    m = nfeatures + 1

    if dense:
        X = zeros((n,m))
    else:
        X = sparse.lil_matrix((n, m))

    dclass = zeros(n)

    h = re.compile('(\d*):(-?\d+\.?\d*)')
    f = open(fname, 'r')

    i = 0
    posPoints = 0
    negPoints = 0
    for line in f:
        parts = line.split(' ', 1)

        if binary:
            if double(parts[0]) == 1:
                di = 1
            else:
                di = -1

            if di == 1:
                posPoints += 1
            else:
                negPoints += 1
        else:
            di = double(parts[0])


        dclass[i] = di
        for (j, v) in re.findall(h, parts[1]):
            if int(j) > m:
                raise Exception("Bad column index: %d" % int(j))
            X[i, int(j)] = float(v)

        #import pdb; pdb.set_trace()

        # libsvm starts at j=1, so we use j=0 as a bias term.
        X[i, 0] = 1.0
        i += 1

        if i % 2000 == 0 and i != 0:
            if binary:
                logger.info("--- read %d points, %d positive %d negative", i, posPoints, negPoints)
            else:
                logger.info("--- read %d points", i)


    logger.info("Finished. %d points.", i)
    if binary:
        logger.info("%d positive %d negative", posPoints, negPoints)

    f.close()

{'fraction_non_alphanumeric': 0.13029020556227328, 'fraction_numerical': 0.016021765417170496, 'mean_word_length': 1.3771551724137931, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7521720', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1069, 'n_words': 327}