[gnumeric] nlsolve: cleanups.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] nlsolve: cleanups.
- Date: Fri, 28 May 2010 12:15:14 +0000 (UTC)
commit 273fc71e63721522ae9d973929b6139432e75935
Author: Morten Welinder <terra gnome org>
Date: Fri May 28 08:15:00 2010 -0400
nlsolve: cleanups.
plugins/nlsolve/gnm-nlsolve.c | 33 ++++++++++++++++++++++++++-------
1 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/plugins/nlsolve/gnm-nlsolve.c b/plugins/nlsolve/gnm-nlsolve.c
index c95be8d..1f2fba8 100644
--- a/plugins/nlsolve/gnm-nlsolve.c
+++ b/plugins/nlsolve/gnm-nlsolve.c
@@ -95,10 +95,25 @@ static void
set_value (GnmNlsolve *nl, int i, gnm_float x)
{
GnmCell *cell = g_ptr_array_index (nl->vars, i);
+ if (cell->value &&
+ VALUE_IS_FLOAT (cell->value) &&
+ value_get_as_float (cell->value) == x)
+ return;
+
gnm_cell_set_value (cell, value_new_float (x));
cell_queue_recalc (cell);
}
+static void
+set_vector (GnmNlsolve *nl, const gnm_float *xs)
+{
+ const int n = nl->vars->len;
+ int i;
+
+ for (i = 0; i < n; i++)
+ set_value (nl, i, xs[i]);
+}
+
static gnm_float
get_value (GnmNlsolve *nl)
{
@@ -114,6 +129,15 @@ get_value (GnmNlsolve *nl)
}
static void
+free_matrix (gnm_float **m, int n)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ g_free (m[i]);
+ g_free (m);
+}
+
+static void
gnm_nlsolve_set_solution (GnmNlsolve *nl)
{
GnmSolver *sol = nl->parent;
@@ -377,10 +401,7 @@ gnm_nlsolve_idle (gpointer data)
}
if (!ok) {
- int i;
- for (i = 0; i < n; i++)
- set_value (nl, i, x0[i]);
-
+ set_vector (nl, x0);
gnm_solver_set_status (sol, GNM_SOLVER_STATUS_DONE);
call_again = FALSE;
}
@@ -393,9 +414,7 @@ gnm_nlsolve_idle (gpointer data)
g_free (d);
g_free (x0);
g_free (g);
- for (i = 0; i < n; i++)
- g_free (H[i]);
- g_free (H);
+ free_matrix (H, n);
return call_again;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]