From 75b144e17afbe8607601f2c31589ed9d75de2532 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Mon, 30 Dec 2013 15:12:34 +0100 Subject: [PATCH] polyfit.c, speed up fitting process when degree == 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this patch war provided by Henrik Forstén in "#14 Special case for polyfit, move initw()" http://sourceforge.net/p/ngspice/patches/14/ --- src/maths/poly/polyfit.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/maths/poly/polyfit.c b/src/maths/poly/polyfit.c index 0f9bbc189..7424e6097 100644 --- a/src/maths/poly/polyfit.c +++ b/src/maths/poly/polyfit.c @@ -17,6 +17,13 @@ ft_polyfit(double *xdata, double *ydata, double *result, double *mat2 = scratch + n * n; /* XXX These guys are hacks! */ double d; + /* speed up fitting process, e.g. for command 'linearize' */ + if (degree == 1) { + result[0] = (xdata[1] * ydata[0] - xdata[0] * ydata[1]) / (xdata[1] - xdata[0]); + result[1] = (ydata[1] - ydata[0]) / (xdata[1] - xdata[0]); + return (TRUE); + } + memset(result, 0, (size_t) (n) * sizeof(double)); memset(mat1, 0, (size_t) (n * n) * sizeof(double)); memcpy(mat2, ydata, (size_t) (n) * sizeof(double));