<commit_before>import scipy.optimize
import numpy as np
import _trustregion_trlib
hasexact = True
try:
    import scipy.optimize._trustregion_exact as _trustregion_exact
except:
    try:
        import _trustregion_exact
    except:
        hasexact = False
import scipy.optimize._trustregion_ncg
import time


def hesspgat(x,d):
    global nhp
    nhp += 1
    return scipy.optimize.rosen_hess_prod(x,d)

n = 1

for ii in range(9):
    n = 2*n

    print("trlib n = {:d}".format(n))
    nhp = 0
    curtime = time.time()
    restr = _trustregion_trlib._minimize_trust_trlib(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hessp=hesspgat)
    trtime = time.time()-curtime
    nhptrlib = nhp
    print("solution time:    {:e} s\n# hessian vector: {:d}\n# NLP iterations: {:d}\nobjective:        {:e}\nmessage:          {:s}".format(trtime, nhp, restr['nit'], restr['fun'], restr['message']))

    print("\ntrlib inexact=False n = {:d}".format(n))
    nhp = 0
    curtime = time.time()
    restr = _trustregion_trlib._minimize_trust_trlib(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hessp=hesspgat, inexact=False)
    trtime = time.time()-curtime
    nhptrlib = nhp
    print("solution time:    {:e} s\n# hessian vector: {:d}\n# NLP iterations: {:d}\nobjective:        {:e}\nmessage:          {:s}".format(trtime, nhp, restr['nit'], restr['fun'], restr['message']))
    
    print("\nncg n = {:d}".format(n))
    nhp = 0
    curtime = time.time()
    resncg = scipy.optimize._trustregion_ncg._minimize_trust_ncg(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hessp=hesspgat)
    ncgtime = time.time()-curtime
    nhpncg = nhp
    print("solution time:    {:e} s\n# hessian vector: {:d}\n# NLP iterations: {:d}\nobjective:        {:e}\nmessage:          {:s}".format(ncgtime, nhp, resncg['nit'], resncg['fun'], resncg['message']))

    if hasexact:
        print("\nexact n = {:d}".format(n))
        curtime = time.time()
        resexa = _trustregion_exact._minimize_trustregion_exact(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hess=scipy.optimize.rosen_hess)
        exatime = time.time()-curtime
        print("solution time:    {:e} s\n# hessians:       {:d}\n# NLP iterations: {:d}\nobjective:        {:e}\nmessage:          {:s}".format(exatime, resexa['nhev'], resexa['nit'], resexa['fun'], resexa['message']))

    print("\n\n")<commit_msg>cleaner output on test example<commit_after>import scipy.optimize
import numpy as np
import _trustregion_trlib
hasexact = True
try:
    import scipy.optimize._trustregion_exact as _trustregion_exact
except:
    try:
        import _trustregion_exact
    except:
        hasexact = False
import scipy.optimize._trustregion_ncg
import time


def hesspgat(x,d):
    global nhp
    nhp += 1
    return scipy.optimize.rosen_hess_prod(x,d)

n = 1

for ii in range(9):
    n = 2*n

    print("n = {:d}".format(n))
    print("subproblem solver      time          #iter  #hpev  #hev   obj            message")

    nhp = 0
    curtime = time.time()
    res = scipy.optimize._trustregion_ncg._minimize_trust_ncg(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hessp=hesspgat)
    soltime = time.time()-curtime
    print("ncg:                   {:+2.4e}s  {:5d}  {:5d}  {:5d}  {:+2.4e}s   {:s}".format(soltime, res['nit'], nhp, 0, res['fun'], res['message']))

    nhp = 0
    curtime = time.time()
    res = _trustregion_trlib._minimize_trust_trlib(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hessp=hesspgat)
    soltime = time.time()-curtime
    print("trlib, inexact=True:   {:+2.4e}s  {:5d}  {:5d}  {:5d}  {:+2.4e}s   {:s}".format(soltime, res['nit'], nhp, 0, res['fun'], res['message']))

    nhp = 0
    curtime = time.time()
    res = _trustregion_trlib._minimize_trust_trlib(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hessp=hesspgat, inexact=False)
    soltime = time.time()-curtime
    print("trlib, inexact=False:  {:+2.4e}s  {:5d}  {:5d}  {:5d}  {:+2.4e}s   {:s}".format(soltime, res['nit'], nhp, 0, res['fun'], res['message']))
    
    if hasexact:
        curtime = time.time()
        res = _trustregion_exact._minimize_trustregion_exact(scipy.optimize.rosen, 0.0*np.ones([n]), jac=scipy.optimize.rosen_der, hess=scipy.optimize.rosen_hess)
        soltime = time.time()-curtime
        print("exact:                 {:+2.4e}s  {:5d}  {:5d}  {:5d}  {:+2.4e}s   {:s}".format(soltime, res['nit'], 0, res['nhev'], res['fun'], res['message']))

    print("")
{'fraction_non_alphanumeric': 0.17242132867132867, 'fraction_numerical': 0.013548951048951048, 'mean_word_length': 3.4009615384615386, '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': '4811405', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1856, 'n_words': 321}