File: 0002-fmin-no-longer-modifies-its-input.patch

package info (click to toggle)
libalgorithm-lbfgs-perl 0.16-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 580 kB
  • sloc: perl: 2,765; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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