From 36b9ae4a623f5b553566aedce570400e60b6b620 Mon Sep 17 00:00:00 2001 From: naoaki Date: Thu, 10 Jul 2008 06:17:35 +0000 Subject: [PATCH] Added owlqn_project() function. git-svn-id: file:///home/svnrepos/software/liblbfgs/trunk@19 ecf4c44f-38d1-4fa4-9757-a0b4dd0349fc --- lib/lbfgs.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/lbfgs.c b/lib/lbfgs.c index 7766d20..9988963 100644 --- a/lib/lbfgs.c +++ b/lib/lbfgs.c @@ -192,6 +192,13 @@ static void owlqn_direction( const int n ); +static void owlqn_project( + lbfgsfloatval_t* d, + const lbfgsfloatval_t* sign, + const int start, + const int n + ); + #if defined(USE_SSE) && (defined(__SSE__) || defined(__SSE2__)) static int round_out_variables(int n) @@ -600,11 +607,7 @@ static int line_search_backtracking( if (param->orthantwise_c != 0.) { /* The current point is projected onto the orthant of the initial one. */ - for (i = param->orthantwise_start;i < n;++i) { - if (x[i] * xp[i] < 0.) { - x[i] = 0.; - } - } + owlqn_project(x, xp, param->orthantwise_start, n); } /* Evaluate the function and gradient values. */ @@ -767,11 +770,7 @@ static int line_search_morethuente( if (param->orthantwise_c != 0.) { /* The current point is projected onto the orthant of the previous one. */ - for (i = param->orthantwise_start;i < n;++i) { - if (x[i] * wa[i] < 0.) { - x[i] = 0.; - } - } + owlqn_project(x, wa, param->orthantwise_start, n); } /* Evaluate the function and gradient values. */ @@ -1280,3 +1279,19 @@ static void owlqn_direction( } } } + +static void owlqn_project( + lbfgsfloatval_t* d, + const lbfgsfloatval_t* sign, + const int start, + const int n + ) +{ + int i; + + for (i = start;i < n;++i) { + if (d[i] * sign[i] < 0) { + d[i] = 0; + } + } +}