<commit_before>include("OptimPack.jl")

function rosenbrock_init!{T<:Real}(x0::Array{T,1})
  x0[1:2:end] = -1.2
  x0[2:2:end] =  1.0
end

function rosenbrock_fg!{T<:Real}(x::Array{T,1}, gx::Array{T,1})
  const c1::T = 1
  const c2::T = 2
  const c10::T = 10
  const c200::T = 200
  x1 = x[1:2:end]
  x2 = x[2:2:end]
  t1 = c1 - x1
  t2 = c10*(x2 - x1.*x1)
  g2 = c200*(x2 - x1.*x1)
  gx[1:2:end] = -c2*(x1.*g2 + t1)
  gx[2:2:end] = g2
  return sum(t1.*t1) + sum(t2.*t2)
end

function rosenbrock_test(n::Integer=20, m::Integer=5; single::Bool=false)
  T = (single ? Float32 : Float64)
  x0 = Array(T, n)
  rosenbrock_init!(x0)
  lbfgs(rosenbrock_fg!, x0, 5, verb=true)
end

#space = OptimPack.OptimPackShapedVectorSpace(Float64, 10)

x0 = Array(Float64, 20)
rosenbrock_init!(x0)
x1 = OptimPack.nlcg(rosenbrock_fg!, x0, verb=true)
println(x1)
x2 = OptimPack.vmlm(rosenbrock_fg!, x0, verb=true)
println(x2)

x0 = Array(Float32, 20)
rosenbrock_init!(x0)
x1 = OptimPack.nlcg(rosenbrock_fg!, x0, verb=true)<commit_msg>Fix usage of number of memorized steps<commit_after>include("OptimPack.jl")

function rosenbrock_init!{T<:Real}(x0::Array{T,1})
  x0[1:2:end] = -1.2
  x0[2:2:end] =  1.0
end

function rosenbrock_fg!{T<:Real}(x::Array{T,1}, gx::Array{T,1})
  const c1::T = 1
  const c2::T = 2
  const c10::T = 10
  const c200::T = 200
  x1 = x[1:2:end]
  x2 = x[2:2:end]
  t1 = c1 - x1
  t2 = c10*(x2 - x1.*x1)
  g2 = c200*(x2 - x1.*x1)
  gx[1:2:end] = -c2*(x1.*g2 + t1)
  gx[2:2:end] = g2
  return sum(t1.*t1) + sum(t2.*t2)
end

function rosenbrock_test(n::Integer=20, m::Integer=3; single::Bool=false)
  T = (single ? Float32 : Float64)
  x0 = Array(T, n)
  rosenbrock_init!(x0)
  lbfgs(rosenbrock_fg!, x0, m, verb=true)
end

#space = OptimPack.OptimPackShapedVectorSpace(Float64, 10)

x0 = Array(Float64, 20)
rosenbrock_init!(x0)
x1 = OptimPack.nlcg(rosenbrock_fg!, x0, verb=true)
println(x1)
x2 = OptimPack.vmlm(rosenbrock_fg!, x0, verb=true)
println(x2)

x0 = Array(Float32, 20)
rosenbrock_init!(x0)
x1 = OptimPack.nlcg(rosenbrock_fg!, x0, verb=true)
{'fraction_non_alphanumeric': 0.1903367496339678, 'fraction_numerical': 0.0951683748169839, 'mean_word_length': 4.774647887323944, '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': '2075716', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1036, 'n_words': 179}