From: Dima Kogan <dima@secretsauce.net>
Date: Sat, 17 Nov 2012 12:24:54 -0800
Subject: fmin() no longer modifies its input
Forwarded: https://rt.cpan.org/Ticket/Display.html?id=81251

---
 lib/Algorithm/LBFGS.pm |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/Algorithm/LBFGS.pm b/lib/Algorithm/LBFGS.pm
index 2cb7c68..90ac036 100644
--- a/lib/Algorithm/LBFGS.pm
+++ b/lib/Algorithm/LBFGS.pm
@@ -75,11 +75,16 @@ sub fmin {
         $lbfgs_prgr = $verbose_monitor if ($lbfgs_prgr eq 'verbose');
         $lbfgs_prgr = $logging_monitor if ($lbfgs_prgr eq 'logging');
     }
+
+    # do_lbfgs() modifies the state vector; I don't want to modify the input so
+    # I make a copy here
+    my @x = @$x0;
+
     my $instance =
         create_lbfgs_instance($lbfgs_eval, $lbfgs_prgr, $user_data);
-    $self->{status} = status_2pv(do_lbfgs($self->{param}, $instance, $x0));
+    $self->{status} = status_2pv(do_lbfgs($self->{param}, $instance, \@x));
     destroy_lbfgs_instance($instance);
-    return $x0;
+    return \@x;
 }
 
 # query status
