<commit_before>'''
Created on Dec 29, 2012

@author: dstrauss
'''

import numpy as np
import matplotlib.pyplot as plt

def cg(A,b,maxiter=30,tol=1e-6,pll=False):
    x = np.zeros(b.size,dtype=b.dtype)
    
    r=b-A(x)
    p=r
    rsold=np.dot(r.T,r)
    rsn = list()
    
    ix = 0
    while ix < maxiter:
        ix += 1
        Ap = A(p);
        alpha=rsold/np.dot(p.T,Ap);
        x=x+alpha*p;
        r=r-alpha*Ap
        rsnew = np.dot(r.T,r) 
        
        rsn.append(np.sqrt(rsnew))
        if np.sqrt(rsnew)<tol:
            break
          
        p = r+ (rsnew/rsold)*p;
        rsold=rsnew;

    if pll:<commit_msg>oh. and need to block some matplotlib.<commit_after>'''
Created on Dec 29, 2012

@author: dstrauss
'''

import numpy as np


def cg(A,b,maxiter=30,tol=1e-6,pll=False):
    x = np.zeros(b.size,dtype=b.dtype)
    
    r=b-A(x)
    p=r
    rsold=np.dot(r.T,r)
    rsn = list()
    
    ix = 0
    while ix < maxiter:
        ix += 1
        Ap = A(p);
        alpha=rsold/np.dot(p.T,Ap);
        x=x+alpha*p;
        r=r-alpha*Ap
        rsnew = np.dot(r.T,r) 
        
        rsn.append(np.sqrt(rsnew))
        if np.sqrt(rsnew)<tol:
            break
          
        p = r+ (rsnew/rsold)*p;
        rsold=rsnew;

    if pll:
        import matplotlib.pyplot as plt
{'fraction_non_alphanumeric': 0.15076923076923077, 'fraction_numerical': 0.018461538461538463, 'mean_word_length': 1.676954732510288, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5471718', 'n_tokens_mistral': 578, 'n_tokens_neox': 550, 'n_words': 103}