[Scipy-svn] r2844 - in trunk/Lib/sandbox/pyloess: . sandbox sandbox/examples sandbox/src src tests

scipy-svn@scip... scipy-svn@scip...
Mon Mar 12 14:47:35 CDT 2007


Author: pierregm
Date: 2007-03-12 14:47:15 -0500 (Mon, 12 Mar 2007)
New Revision: 2844

Added:
   trunk/Lib/sandbox/pyloess/.project
   trunk/Lib/sandbox/pyloess/README
   trunk/Lib/sandbox/pyloess/__init__.py
   trunk/Lib/sandbox/pyloess/doc/
   trunk/Lib/sandbox/pyloess/pyloess.py
   trunk/Lib/sandbox/pyloess/sandbox/
   trunk/Lib/sandbox/pyloess/sandbox/builder
   trunk/Lib/sandbox/pyloess/sandbox/examples/
   trunk/Lib/sandbox/pyloess/sandbox/examples/sin_data
   trunk/Lib/sandbox/pyloess/sandbox/examples/sin_result
   trunk/Lib/sandbox/pyloess/sandbox/pyloess.py
   trunk/Lib/sandbox/pyloess/sandbox/setup.py
   trunk/Lib/sandbox/pyloess/sandbox/src/
   trunk/Lib/sandbox/pyloess/sandbox/src/S.h
   trunk/Lib/sandbox/pyloess/sandbox/src/c_loess.pxd
   trunk/Lib/sandbox/pyloess/sandbox/src/c_numpy.pxd
   trunk/Lib/sandbox/pyloess/sandbox/src/c_python.pxd
   trunk/Lib/sandbox/pyloess/sandbox/src/cloess.c
   trunk/Lib/sandbox/pyloess/sandbox/src/cloess.h
   trunk/Lib/sandbox/pyloess/sandbox/src/cloess.pyx
   trunk/Lib/sandbox/pyloess/sandbox/src/linpack_lite.f
   trunk/Lib/sandbox/pyloess/sandbox/src/loess.c
   trunk/Lib/sandbox/pyloess/sandbox/src/loess.h
   trunk/Lib/sandbox/pyloess/sandbox/src/loessc.c
   trunk/Lib/sandbox/pyloess/sandbox/src/loessf.f
   trunk/Lib/sandbox/pyloess/sandbox/src/misc.c
   trunk/Lib/sandbox/pyloess/sandbox/src/predict.c
   trunk/Lib/sandbox/pyloess/setup.py
   trunk/Lib/sandbox/pyloess/src/
   trunk/Lib/sandbox/pyloess/src/f_lowess.pyf
   trunk/Lib/sandbox/pyloess/src/f_stl.pyf
   trunk/Lib/sandbox/pyloess/src/lowess.f
   trunk/Lib/sandbox/pyloess/src/stl.f
   trunk/Lib/sandbox/pyloess/tests/
   trunk/Lib/sandbox/pyloess/tests/__init__.py
   trunk/Lib/sandbox/pyloess/tests/co2_data
   trunk/Lib/sandbox/pyloess/tests/co2_results_double
   trunk/Lib/sandbox/pyloess/tests/co2_results_real
   trunk/Lib/sandbox/pyloess/tests/test_pyloess.py
Log:
Initial import.
Currently, only lowess (the univariable, simplified version of loess) and stl (season/trend loess decomposition) are functional.
Please check the sandbox subfolder for a broken attempt to port loess

Added: trunk/Lib/sandbox/pyloess/.project
===================================================================
--- trunk/Lib/sandbox/pyloess/.project	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/.project	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>pyloess</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>

Added: trunk/Lib/sandbox/pyloess/README
===================================================================
--- trunk/Lib/sandbox/pyloess/README	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/README	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,16 @@
+pyloess: a numpy wrapper to lowess and stl.
+
+LOWESS
+------
+
+The initial file is available at: 
+http://netlib.bell-labs.com/netlib/go/lowess.f.gz
+Simple to double precision conversion by Pierre GERARD-MARCHANT, 2007/03.
+
+
+STL 
+-----
+
+The initial file is available at:
+http://netlib.bell-labs.com/netlib/a/stl.gz
+Simple to double precision conversion by Pierre GERARD-MARCHANT, 2007/03.

Added: trunk/Lib/sandbox/pyloess/__init__.py
===================================================================
--- trunk/Lib/sandbox/pyloess/__init__.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/__init__.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,10 @@
+"""
+Numpy wrappers for lowess and stl.
+"""
+__author__ = "Pierre GF Gerard-Marchant"
+__version__ = '1.0'
+__revision__ = "$Revision: 150 $"
+__date__     = '$Date: 2007-02-28 23:42:16 -0500 (Wed, 28 Feb 2007) $'
+
+import pyloess
+from pyloess import lowess, stl
\ No newline at end of file

Added: trunk/Lib/sandbox/pyloess/pyloess.py
===================================================================
--- trunk/Lib/sandbox/pyloess/pyloess.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/pyloess.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,268 @@
+# pylint: disable-msg=E1101
+"""
+Wrapper to lowess and stl routines.
+
+LOWESS:
+Initial Fortran code available at:
+http://netlib.bell-labs.com/netlib/go/lowess.f.gz
+
+initial author: W. S. Cleveland, 1979.
+Simple to double precision conversion of the Fortran code by Pierre
+GERARD-MARCHANT, 2007/03.
+
+STL:
+Initial Fortran code available at:
+http://netlib.bell-labs.com/netlib/a/stl.gz
+Initial Authors: R. B. Cleveland, W. S. Cleveland, J. E. McRae, and
+I. Terpenning, 1990.
+Simple-to-double precision conversion of the Fortran code by Pierre
+GERARD-MARCHANT, 2007/03.
+
+
+:author: Pierre GF Gerard-Marchant
+:contact: pierregm_at_uga_edu
+:date: $Date: 2007-02-28 02:23:25 -0500 (Wed, 28 Feb 2007) $
+:version: $Id: generic.py 145 2007-02-28 07:23:25Z backtopop $
+"""
+__author__ = "Pierre GF Gerard-Marchant ($Author: backtopop $)"
+__version__ = '1.0'
+__revision__ = "$Revision: 145 $"
+__date__     = '$Date: 2007-02-28 02:23:25 -0500 (Wed, 28 Feb 2007) $'
+
+import numpy
+from numpy import bool_, complex_, float_, int_, str_, object_
+import numpy.core.numeric as numeric
+from numpy.core.records import recarray
+
+import _lowess, _stl
+
+
+def lowess(x,y,f=0.5,nsteps=2,delta=0):
+    """Performs a robust locally weighted regression (lowess).
+
+    Outputs a *3xN* array of fitted values, residuals and fit weights.
+
+
+:Parameters:
+    x : ndarray
+        Abscissas of the points on the scatterplot; the values in X must be
+        ordered from smallest to largest.
+    y : ndarray
+        Ordinates of the points on the scatterplot.
+    f : Float *[0.5]*
+        Fraction of the total number of points used to compute each fitted value.
+        As f increases the smoothed values become smoother. Choosing f in the range
+        .2 to .8 usually results in a good fit.
+    nsteps : Integer *[2]*
+        Number of iterations in the robust fit. If nsteps=0, the nonrobust fit
+        is returned; setting nsteps=2 should serve most purposes.
+    delta : Integer *[0]*
+        Nonnegative parameter which may be used to save computations.
+        If N (the number of elements in x) is less than 100, set delta=0.0;
+        if N is greater than 100 you should find out how delta works by reading
+        the additional instructions section.
+
+:Returns:
+    A recarray of smoothed values ('smooth'), residuals ('residuals') and local
+    robust weights ('weights').
+
+
+Additional instructions
+-----------------------
+
+Fro the original author:
+
+        DELTA can be used to save computations.   Very  roughly  the
+        algorithm  is  this:   on the initial fit and on each of the
+        NSTEPS iterations locally weighted regression fitted  values
+        are computed at points in X which are spaced, roughly, DELTA
+        apart; then the fitted values at the  remaining  points  are
+        computed  using  linear  interpolation.   The  first locally
+        weighted regression (l.w.r.) computation is carried  out  at
+        X(1)  and  the  last  is  carried  out at X(N).  Suppose the
+        l.w.r. computation is carried out at  X(I).   If  X(I+1)  is
+        greater  than  or  equal  to  X(I)+DELTA,  the  next  l.w.r.
+        computation is carried out at X(I+1).   If  X(I+1)  is  less
+        than X(I)+DELTA, the next l.w.r.  computation is carried out
+        at the largest X(J) which is greater than or equal  to  X(I)
+        but  is not greater than X(I)+DELTA.  Then the fitted values
+        for X(K) between X(I)  and  X(J),  if  there  are  any,  are
+        computed  by  linear  interpolation  of the fitted values at
+        X(I) and X(J).  If N is less than 100 then DELTA can be  set
+        to  0.0  since  the  computation time will not be too great.
+        For larger N it is typically not necessary to carry out  the
+        l.w.r.  computation for all points, so that much computation
+        time can be saved by taking DELTA to be  greater  than  0.0.
+        If  DELTA =  Range  (X)/k  then,  if  the  values  in X were
+        uniformly  scattered  over  the  range,  the   full   l.w.r.
+        computation  would be carried out at approximately k points.
+        Taking k to be 50 often works well.
+
+Method
+------
+
+        The fitted values are computed by using the nearest neighbor
+        routine  and  robust locally weighted regression of degree 1
+        with the tricube weight function.  A few additional features
+        have  been  added.  Suppose r is FN truncated to an integer.
+        Let  h  be  the  distance  to  the  r-th  nearest   neighbor
+        from X[i].   All  points within h of X[i] are used.  Thus if
+        the r-th nearest neighbor is exactly the  same  distance  as
+        other  points,  more  than r points can possibly be used for
+        the smooth at  X[i].   There  are  two  cases  where  robust
+        locally  weighted regression of degree 0 is actually used at
+        X[i].  One case occurs when  h  is  0.0.   The  second  case
+        occurs  when  the  weighted  standard error of the X[i] with
+        respect to the weights w[j] is  less  than  .001  times  the
+        range  of the X[i], where w[j] is the weight assigned to the
+        j-th point of X (the tricube  weight  times  the  robustness
+        weight)  divided by the sum of all of the weights.  Finally,
+        if the w[j] are all zero for the smooth at X[i], the  fitted
+        value is taken to be Y[i].
+
+References
+----------
+    W. S. Cleveland. 1978. Visual and Computational Considerations in
+    Smoothing Scatterplots by Locally Weighted Regression. In
+    Computer Science and Statistics: Eleventh Annual Symposium on the
+    Interface, pages 96-100. Institute of Statistics, North Carolina
+    State University, Raleigh, North Carolina, 1978.
+
+    W. S. Cleveland, 1979. Robust Locally Weighted Regression and
+    Smoothing Scatterplots. Journal of the American Statistical
+    Association, 74:829-836, 1979.
+
+    W. S. Cleveland, 1981. LOWESS: A Program for Smoothing Scatterplots
+    by Robust Locally Weighted Regression. The American Statistician,
+    35:54.
+
+    """
+    dtyp = [('smooth',float_), ('weigths', float_), ('residuals', float_)]
+    return numeric.fromiter(zip(*_lowess.lowess(x,y,f,nsteps,delta,)),
+                            dtype=dtyp).view(recarray)
+
+#--------------------------------------------------------------------------
+#--- --- STL ---
+#####----------------------------------------------------------------------
+def stl(y, np=12, ns=7, nt=None, nl=13, isdeg=1, itdeg=1, ildeg=1,
+        nsjump=None,ntjump=None,nljump=None, robust=True, ni=None,no=None):
+    """Decomposes a time series into seasonal and trend  components.
+
+:Parameters:
+    y : Numerical array
+        Time Series to be decomposed.
+    np : Integer *[12]*
+        Period of the seasonal component.
+        For example, if  the  time series is monthly with a yearly cycle, then
+        np=12.
+    ns : Integer *[7]*
+        Length of the seasonal smoother.
+        The value of  ns should be an odd integer greater than or equal to 3.
+        A value ns>6 is recommended. As ns  increases  the  values  of  the
+        seasonal component at a given point in the seasonal cycle (e.g., January
+        values of a monthly series with  a  yearly cycle) become smoother.
+    nt : Integer *[None]*
+        Length of the trend smoother.
+        The  value  of  nt should be an odd integer greater than or equal to 3.
+        A value of nt between 1.5*np and 2*np is  recommended. As nt increases,
+        the values of the trend component become  smoother.
+        If nt is None, it is estimated as the smallest odd integer greater
+        or equal to (1.5*np)/[1-(1.5/ns)]
+    nl : Integer *[None]*
+        Length of the low-pass filter.
+        The value of nl should  be an odd integer greater than or equal to 3.
+        The smallest odd integer greater than or equal to np is used by default.
+    isdeg : Integer *[1]*
+        Degree of locally-fitted polynomial in seasonal smoothing.
+        The value is 0 or 1.
+    itdeg : Integer *[1]*
+        Degree of locally-fitted polynomial in trend smoothing.
+        The value is 0 or 1.
+    ildeg : Integer *[1]*
+        Degree of locally-fitted polynomial in low-pass smoothing.
+        The value is 0 or 1.
+    nsjump : Integer *[None]*
+        Skipping value for seasonal smoothing.
+        The seasonal smoother skips ahead nsjump points and then linearly
+        interpolates in between.  The value  of nsjump should be a positive
+        integer; if nsjump=1, a seasonal smooth is calculated at all n points.
+        To make the procedure run faster, a reasonable choice for nsjump is
+        10%-20% of ns. By default, nsjump= 0.1*ns.
+    ntjump : Integer *[1]*
+        Skipping value for trend smoothing. If None, ntjump= 0.1*nt
+    nljump : Integer *[1]*
+        Skipping value for low-pass smoothing. If None, nljump= 0.1*nl
+    robust : Boolean *[True]*
+        Flag indicating whether robust fitting should be performed.
+    ni : Integer *[None]*
+        Number of loops for updating the seasonal and trend  components.
+        The value of ni should be a positive integer.
+        See the next argument for advice on the  choice of ni.
+        If ni is None, ni is set to 1 for robust fitting, to 5 otherwise.
+    no : Integer *[0]*
+        Number of iterations of robust fitting. The value of no should
+        be a nonnegative integer. If the data are well behaved without
+        outliers, then robustness iterations are not needed. In this case
+        set no=0, and set ni=2 to 5 depending on how much security
+        you want that  the seasonal-trend looping converges.
+        If outliers are present then no=3 is a very secure value unless
+        the outliers are radical, in which case no=5 or even 10 might
+        be better.  If no>0 then set ni to 1 or 2.
+        If None, then no is set to 15 for robust fitting, to 0 otherwise.
+
+Returns:
+    A recarray of estimated trend values ('trend'), estimated seasonal
+    components ('seasonal'), local robust weights ('weights') and fit
+    residuals ('residuals').
+    The final local robust weights are all 1 if no=0.
+
+Reference
+---------
+
+    R. B. Cleveland, W. S. Cleveland, J. E. McRae and I. Terpenning.
+    1990. STL: A Seasonal-Trend Decomposition Procedure Based on LOESS
+    (with Discussion). Journal of Official Statistics, 6:3-73.
+
+
+    """
+    ns = max(ns, 3)
+    if ns%2 == 0:
+        ns += 1
+    np = max(2, np)
+    if nt is None:
+        nt = max(int((1.5*np/(1.-1.5/ns))+0.5), 3)
+        if not nt%2:
+            nt += 1
+    if nl is None:
+        nl = max(3,np)
+        if not nl%2:
+            nl += 1
+    if nsjump is None:
+        nsjump = int(0.1*ns + 0.9)
+    if ntjump is None:
+        ntjump = int(0.1*nt + 0.9)
+    if nljump is None:
+        nljump = int(0.1*nl + 0.9)
+    if robust:
+        if ni is None:
+            ni = 1
+        if no is None:
+            no = 15
+    else:
+        if ni is None:
+            ni = 5
+        if no is None:
+            no = 0
+
+    if hasattr(y,'_mask') and numpy.any(y._mask):
+        raise ValueError,"Missing values should first be filled !"
+    y = numeric.array(y, subok=True, copy=False).ravel()
+    (rw,szn,trn,work) = _stl.stl(y,np,ns,nt,nl,isdeg,itdeg,ildeg,
+                                 nsjump,ntjump,nljump,ni,no,)
+    dtyp = [('trend', float_), ('seasonal', float_),
+            ('residuals', float_), ('weights', float_)]
+    result = numeric.fromiter(zip(trn,szn,y-trn-szn,rw), dtype=dtyp)
+    return result.view(recarray)
+
+################################################################################
+

Added: trunk/Lib/sandbox/pyloess/sandbox/builder
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/builder	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/builder	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,15 @@
+rm -rf build
+pushd src
+rm -f cloess.c *.so *.o
+pyrexc cloess.pyx || exit
+gcc -c -fPIC loess.c loessc.c misc.c predict.c loessf.f linpack_lite.f
+gcc -c -fPIC cloess.c -I/usr/include/python2.4 \
+	-I/usr/lib64/python2.4/site-packages/numpy/core/include || exit
+gcc -shared loessf.o linpack_lite.o loess.o loessc.o misc.o predict.o cloess.o \
+	-llapack -lblas -o cloess.so || exit
+rm -f *.o
+popd
+mv src/cloess.so cloess.so
+python -c "import cloess; print dir(cloess)"
+python pyloess.py
+echo "OK"
\ No newline at end of file


Property changes on: trunk/Lib/sandbox/pyloess/sandbox/builder
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/Lib/sandbox/pyloess/sandbox/examples/sin_data
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/examples/sin_data	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/examples/sin_data	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,24 @@
+-0.529631673 -0.476162031  0.122393909 -0.764738290  0.694588529
+ 0.157878753  0.825755505  0.383776725 -0.297611713  0.179712838
+ 0.883403846  1.175870259 -0.222158656  0.887655136  0.506018472
+ 1.201763090  1.358657158  1.766876246  0.945261834  0.242015272
+ 1.108175506  1.588326244  0.086595996  0.135447708  1.674333147
+ 0.087861038  0.150255064  1.662807709  1.918985242  0.334817302
+ 1.995973197  0.269379941  0.469938419  0.719274928  1.441382256
+ 1.856114890 -0.004302644  1.329872080 -0.058310637  0.472398463
+ 0.435258117  1.636500756  1.699950103  1.478820190 -0.190025448
+ 1.300341865 -0.058635213  0.819062806  0.047988842 -0.168558533
+ 0.037056266  0.536154778  0.278227911 -0.313547042  0.722026888
+-0.114359903 -0.376634077  0.652043347 -0.515809282 -0.602277827
+-0.938181382 -1.037834739  0.278491625 -1.092834467 -0.778780405
+-1.070774416  0.539015258 -0.234691028 -0.152634072 -0.066153375
+-0.233711530 -0.959496456 -0.946902608 -0.871057712 -0.583103683
+-1.534738618 -0.662166840 -1.155263966 -0.533407016 -1.319182554
+-0.186566885 -0.897649461 -1.501951078 -0.004479304 -1.678331392
+-1.490781842 -0.589586598 -0.285787771 -0.510207129 -0.627988881
+-1.109061921 -1.310354670  0.002602266 -0.271113225 -0.885954568
+-1.150763444 -0.779791042 -1.053566764 -0.718805204 -0.257604369
+-1.278783228 -0.816685979 -1.417844559 -0.081346747 -1.413808292
+-1.487076480 -0.166387633 -0.922128152  0.267933770 -1.000264981
+-0.638768521 -0.298071585  0.115376460  0.104988650 -0.993492047
+-0.175837760  0.193326045 -0.068244286  0.325014896 -0.506554400
\ No newline at end of file

Added: trunk/Lib/sandbox/pyloess/sandbox/examples/sin_result
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/examples/sin_result	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/examples/sin_result	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,24 @@
+-0.119671288 -0.048917262  0.019498810  0.085541472  0.149175270
+ 0.210364749  0.269074456  0.325268935  0.378912732  0.429970393
+ 0.478406464  0.524185488  0.567272013  0.607630584  0.645225746
+ 0.679964281  0.711826741  0.740888328  0.767224242  0.790909683
+ 0.812019853  0.830629952  0.846815180  0.860650739  0.872211830
+ 0.881573652  0.888811407  0.894000296  0.897215519  0.898532276
+ 0.896495398  0.889853461  0.878987289  0.864277706  0.846105535
+ 0.824851599  0.800896721  0.774621727  0.746407438  0.716634678
+ 0.685684270  0.653937039  0.621773808  0.589575399  0.557722637
+ 0.522992287  0.482466105  0.436982397  0.387379471  0.334495633
+ 0.279169191  0.222238452  0.164541722  0.106917309  0.050203520
+-0.004761338 -0.057138959 -0.106091034 -0.150779258 -0.190365323
+-0.228071840 -0.267406108 -0.307956846 -0.349312773 -0.391062611
+-0.432795078 -0.474098896 -0.514562784 -0.553775463 -0.591325651
+-0.626802071 -0.659793440 -0.689888480 -0.716675911 -0.739744452
+-0.760199435 -0.779384403 -0.797245400 -0.813728466 -0.828779643
+-0.842344973 -0.854370498 -0.864802259 -0.873586297 -0.880668656
+-0.885995376 -0.889512498 -0.891166066 -0.890902119 -0.888666701
+-0.884599958 -0.878878792 -0.871504374 -0.862477875 -0.851800466
+-0.839473318 -0.825497602 -0.809874489 -0.792605150 -0.773690757
+-0.753132480 -0.730931491 -0.707088961 -0.681606061 -0.654483961
+-0.625716944 -0.595298336 -0.563227879 -0.529505317 -0.494130390
+-0.457102841 -0.418422412 -0.378088845 -0.336101881 -0.292461263
+-0.247166733 -0.200218032 -0.151614903 -0.101357088 -0.049444328

Added: trunk/Lib/sandbox/pyloess/sandbox/pyloess.py
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/pyloess.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/pyloess.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,517 @@
+import os
+from math import ceil
+
+import numpy
+from numpy import bool_, int_, float_
+
+narray = numpy.array
+nempty = numpy.empty
+nzeros = numpy.zeros
+
+import logging
+logging.basicConfig(level=logging.DEBUG)
+loesslogging = logging.getLogger('loesss')
+
+import cloess
+reload(cloess)
+
+class paramdict(dict):
+    def __init__(self, **kwargs):
+        dict.__init__(self, **kwargs)
+    
+    def __getattr__(self, attr):
+        _got = getattr(super(paramdict,self), attr, None)
+        if _got is None:
+            _got = self.get(attr, None)
+        return _got
+
+    def __setattr__(self, attr, value):
+        if attr in self.keys():
+            self[attr] = value
+        else:
+            dict.__setattr__(self, attr, value)
+
+#-------------------------------------------------------------------------------    
+class _loess_control(dict):
+
+    _optiondict = dict(surface=('interpolate', 'direct'),
+                       statistics=('approximate', 'exact'),
+                       trace_hat=('wait.to.decide', 'exact', 'approximate'),)
+    
+    def __init__(self, surface="interpolate", statistics="approximate",
+                 trace_hat="wait.to.decide", iterations=4, cell=0.2):
+        dict.__init__(self, surface=None, statistics=None, 
+                      trace_hat=None, iterations=iterations, 
+                      cell=cell)
+        self.surface = surface.lower()
+        self.statistics = statistics.lower()
+        self.trace_hat = trace_hat.lower()
+    #
+    def __getattr__(self, attr):
+        _got = getattr(super(dict,self), attr, None)
+        if _got is None:
+            _got = self.get(attr, None)
+        return _got
+    #
+    def __setattr__(self, attr, value):
+        if attr in self.keys():
+            self.__setitem__(attr, value)
+        else:
+            dict.__setattr__(self, attr, value)
+    #
+    def __setitem__(self, attr, value):
+        if attr in _loess_control._optiondict.keys():
+            self.__setoption__(attr, value)
+        else:
+            dict.__setitem__(self, attr, value)
+    #
+    def __setoption__(self, attr, value):
+        msg = "Invalid argument: %s must be in %s (got %s)"
+        attrlist = _loess_control._optiondict[attr]
+        if (not isinstance(value, str)) or \
+            (value.lower() not in attrlist):
+            raise ValueError, msg % (attr, attrlist, value)
+        dict.__setitem__(self, attr, value.lower())
+    #
+#    def set_surface_status(self, new_stat):
+#        if new_stat.lower() not in ('none','exact','approximate'):
+#            raise ValueError,"Invalid value for the new_stat parameter: "\
+#                  "should be in ('none','exact','approximate'), got %s" % new_stat
+#        if self.surface == "interpolate" and new_stat == "approximate":
+#            if self.trace_hat == "approximate":
+#                new_stat = "2.approx"
+#            else:
+#                trace_hat='exact' in that case
+#                new_stat = "1.approx"
+#        return "/".join([self.surface, new_stat])
+    def set_surface_status(self, new_stat):
+        if new_stat.lower() not in ('none','exact','approximate'):
+            raise ValueError,"Invalid value for the new_stat parameter: "\
+                  "should be in ('none','exact','approximate'), got %s" % new_stat
+        statusdict = {"interpolate":{"none": 10,
+                                     "exact":11,
+                                     "1.approx":12,
+                                     "2.approx":13 },
+                      "direct":{"none" : 20,
+                                "exact": 21,
+                                "approximate": 22}}
+        if self.surface == "interpolate" and new_stat == "approximate":
+            if self.trace_hat == "approximate":
+                status = 13
+            else:
+                # trace_hat='exact' in that case
+                status = 12
+        else:
+            status = statusdict[self.surface][new_stat]
+        return status
+        
+#      
+#            
+#
+#class loess(object):
+#    """
+#    
+#:Ivariables:
+#    x : ndarray
+#        Independent variables
+#    y : ndarray
+#        Dependent variables
+#    weights : ndarray
+#    """
+#    def __init__(self, x, y, weights=None,
+#                 span=0.75, degree=2, normalize=True, family="gaussian",
+#                 surface="interpolate", statistics="approximate", 
+#                 cell=0.2, trace_hat="wait.to.decide",iterations=4):
+#        x = narray(x, copy=False, subok=True, order='F')
+#        if x.ndim == 2:
+#            (n,d) = x.shape
+#        elif x.ndim == 1:
+#            (n,d) = (len(x),1)
+#        else:
+#            raise ValueError,"Argument 'x' should be 2D at most!"
+#        max_kd = max(n, 200)
+#        #    
+#        y = narray(y, copy=False, subok=True, order='F')
+#        if weights is None:
+#            weights = numpy.ones_like(y)
+#        self.inputs = paramdict(x=x, y=y, weights=weights, nobs=n, nvars=d)
+#        self.model = paramdict(span=span, degree=degree, 
+#                               normalize=normalize, family=family.lower(),
+#                               parametric=nzeros((d,), bool_, 'F'),
+#                               drop_square=nzeros((d,), bool_, 'F')
+#                               )        
+#        self.control = _loess_control(surface=surface.lower(), 
+#                                      statistics=statistics.lower(),
+#                                      trace_hat=trace_hat.lower(),
+#                                      iterations=iterations, cell=cell, 
+#                                      )
+#        self.outputs = paramdict(fitted_values=nempty((n,), float_, 'F'),
+#                                 fitted_residuals=nempty((n,), float_, 'F'),
+#                                 pseudovalues=nempty((n,), float_, 'F'),
+#                                 diagonal=nempty((n,), float_, 'F'),
+#                                 robust=numpy.ones((n,), float_, 'F'),
+#                                 divisor=nempty((d,), float_, 'F'),
+#                                 enp=0, s=0, one_delta=0, two_delta=0,
+#                                 trace_hat=0
+#                                 )
+#        self.kd_tree = paramdict(parameter=nempty((7,), int_, 'F'),
+#                                 a=nempty((max_kd,), int_, 'F'),
+#                                 xi=nempty((max_kd,), float_, 'F'),
+#                                 vert=nempty((d*2,), float_, 'F'),
+#                                 vval=nempty(((d+1)*max_kd,), float_, 'F')
+#                                 )
+#        #
+#        if self.model.family == "gaussian":
+#            self.control['iterations'] = 0
+#        if self.control.trace_hat == "wait.to.decide":
+#            if (self.control.surface == "interpolate") and n >= 500:
+#                self.control.trace_hat = "approximate"
+#            else:
+#                self.control.trace_hat = "exact"
+#    #......................................................            
+#    def fit(self, span = 0.75, degree = 2, parametric = False,
+#            drop_square = False, normalize = True,
+#            statistics = "approximate", surface = "interpolate",
+#            cell = 0.2, iterations = 1, trace_hat = "exact"):
+#        
+#        # Get input....................
+#        inputs = self.inputs
+#        (x, y, n, d, weights) = [inputs[k] 
+#                                 for k in ('x','y','nobs','nvars', 'weights')]
+#
+#        max_kd = max(n, 200) 
+##        a = max_kd
+#        one_delta = two_delta = trace_hat_out = 0
+#        
+#        # Set temporary ...............
+#        kd_tree = self.kd_tree
+#        (a, xi, vert, vval, parameter) = [kd_tree[k] 
+#                                          for k in ('a', 'xi', 'vert', 'vval', 
+#                                                    'parameter')]
+#        a_tmp = nempty((max_kd,), int_)
+#        xi_tmp = nempty((max_kd,), float_)
+#        vert_tmp = nempty((2*d,), float_)
+#        vval_tmp = nempty(((d+1)*max_kd,), float_)
+#        
+#        # Check control ................
+#        control = self.control
+#        surface = control.surface
+#        statistics = control.statistics
+#        iterations = control.iterations
+#        trace_hat = control.trace_hat
+#        # Get model ....................
+#        model = self.model
+#        family = model.family
+#        parametric = model.parametric
+#        drop_square = model.drop_square
+#        (span, degree, normalize) = [model[k] 
+#                                     for k in ('span', 'degree', 'normalize')]                         
+#        #
+#        outputs = self.outputs 
+#        fitted_values = outputs.fitted_values
+#        fitted_residuals = outputs.fitted_residuals
+#        pseudovalues = outputs.pseudovalues 
+#        diagonal = outputs.diagonal
+#        robust = outputs.robust
+#        (enp, s, one_delta, two_delta) = [outputs[k]
+#                                          for k in ('enp','s','one_delta','two_delta')]
+#        trace_hat = outputs.trace_hat
+##        parameter = 7
+#        (d1_tmp, d2_tmp, trL_tmp, zero,) = (0., 0., 0., 0.)
+#        (delta1, delta2, trL, trace_hat_in) = (0, 0, 0, 0)
+#        temp = nempty((n,), float_)
+#        diag_tmp = nempty((n,), float_)
+#        param_tmp = nempty((n,), int_)
+#        if iterations > 0:
+#            pseudo_resid = nempty((n,), float_)
+#        #
+#        new_cell = span * cell
+#        #
+#        loesslogging.debug("initial divisor: %s" % self.outputs.divisor)
+#        if normalize and d > 1:
+#            cut = int(ceil(0.1*n))
+#            x_trimmed = numpy.sort(x, axis=0)[cut:-cut]
+#            outputs.divisor = x_trimmed.std(axis=0)
+#            outputs.divisor *= numpy.sqrt(n/float(n-1))
+#            x = x / outputs.divisor
+#        else:
+#            outputs.divisor = numpy.ones(d, float_)
+#        loesslogging.debug("final divisor: %s" % self.outputs.divisor)
+#        #
+#        sum_drop_sqr = sum(drop_square)
+#        #
+#        parametric = narray(parametric, copy=True)
+#        parametric.resize((d,))
+#        sum_parametric = parametric.sum()
+#        nonparametric = numpy.logical_not(parametric).sum()
+#        order_parametric = numpy.argsort(parametric)
+#        #
+#        order_drop_sqr = 2 - drop_square[order_parametric]
+#        x = x[:,order_parametric].ravel()
+#        #
+#        if degree == 1 and sum_drop_sqr:
+#            msg = "Specified the square of a factor predictor to be dropped"\
+#                  " when degree = 1"
+#            raise ValueError, msg
+#        if d == 1 and sum_drop_sqr:
+#            msg = "Specified the square of a predictor to be dropped "\
+#                  "with only one numeric predictor"
+#            raise ValueError, msg  
+#        if sum_parametric == d:
+#            raise ValueError, "Specified parametric for all predictors"
+#        #
+#        new_stat = statistics.lower()
+#        loesslogging.debug("start iteration: %s" % new_stat)
+#        for j in range(iterations+1):
+#            if j > 0:
+#                new_stat = "none"
+#            robust = weights * robust
+#            surf_stat = control.set_surface_status(new_stat)
+#            #setLf = (surf_stat.lower() == "interpolate/exact")
+#            setLf = int(surf_stat == 11)
+#            loesslogging.debug("iteration: %i: %s - %s" % (j, surf_stat, setLf))
+#            #
+#            (surf_stat, fitted_values, parameter, a, 
+#             xi, vert, vval, diagonal, trL, delta1, delta2, 
+#             ) = loess_raw(y, x, weights, robust, d, n, span, degree, 
+#                      nonparametric, order_drop_sqr, sum_drop_sqr, 
+#                      new_cell, surf_stat, fitted_values, parameter, a, 
+#                      xi, vert, vval, diagonal, trL, delta1, delta2, 
+#                      setLf)
+#            #
+#            if j == 0:
+#                trace_hat_out = trL
+#                one_delta = delta1
+#                two_delta = delta2
+#            fitted_residuals = y - fitted_values
+#            if j < iterations:
+#                (fitted_residuals, n, robust, temp) = lowesw(fitted_residuals, n, robust, temp)
+#        #
+#        if (iterations > 0):
+#            lowesp(n, y, fitted_values, weights, robust, temp, pseudovalues)
+#            (temp, param_tmp, a_tmp, xi_tmp,
+#             vert_tmp, vval_tmp, diag_tmp, trL_tmp, d1_tmp, d2_tmp, 
+#             ) = loess_raw(pseudovalues, x, weights, weights, d, n, span, 
+#                               degree, nonparametric, order_drop_sqr, sum_drop_sqr,
+#                               new_cell, surf_stat, temp, param_tmp, a_tmp, xi_tmp,
+#                               vert_tmp, vval_tmp, diag_tmp, trL_tmp, d1_tmp, d2_tmp, 
+#                               zero)
+#            pseudo_resid = pseudovalues - temp
+#        #
+#        if (iterations == 0):
+#            sum_squares = numpy.sum(weights * fitted_residuals**2)
+#        else:
+#            sum_squares = numpy.sum(weights * pseudo_resid**2)
+#        #
+#        loesslogging.debug("setLf:%s" % setLf)
+#        loesslogging.debug("SSR:%s" % sum_squares)
+#        outputs.enp = (one_delta) + 2 * (trace_hat_out) - n;
+#        loesslogging.debug("one_delta:%s-trace_out:%s" % (one_delta, trace_hat_out))
+#        outputs.s = numpy.sqrt(sum_squares / (one_delta))
+#        for attr in ('one_delta','two_delta','diagonal','trace_hat',
+#                     'fitted_values','fitted_residuals','pseudovalues'):
+#            setattr(outputs,attr,eval(attr))
+##        (outputs.one_delta, outputs.two_delta) = (one_delta, two_delta)
+##        outputs.diagonal = diagonal
+##        outputs.
+#        #
+#    #......................................................
+#    def summary(self):
+#        print "Number of Observations         : %d" % self.inputs.nobs
+#        print "Equivalent Number of Parameters: %.1f" % self.outputs.enp
+#        if self.model.family == "gaussian":
+#            print "Residual Standard Error        : %.4f" % self.outputs.s
+#        else:
+#            print "Residual Scale Estimate        : %.4f" % self.outputs.s
+#    #.......................................................
+#    def predict(self):
+#        outputs = self.outputs
+#        self.prediction = paramdict(fit=None,
+#                                    se_fit=None,
+#                                    residual_scale=outputs.s,
+#                                    df=outputs.one_delta**2 / outputs.two_delta,
+#                                    )
+#        raise NotImplementedError
+#    
+#    
+#
+#
+#    
+#
+##    size_info[0] = lo->in.p;
+##    size_info[1] = lo->in.n;
+##    size_info[2] = m;
+##    
+##    pred_(lo->in.y, lo->in.x, eval, size_info, &lo->out.s,
+##        lo->in.weights,
+##        lo->out.robust,
+##        &lo->model.span,
+##        &lo->model.degree,
+##        &lo->model.normalize,
+##        lo->model.parametric,
+##        lo->model.drop_square,
+##        &lo->control.surface,
+##        &lo->control.cell,
+##        &lo->model.family,
+##        lo->kd_tree.parameter,
+##        lo->kd_tree.a,
+##        lo->kd_tree.xi,
+##        lo->kd_tree.vert,
+##        lo->kd_tree.vval,
+##        lo->out.divisor,
+##        &se,
+##        pre->fit,
+##        pre->se_fit);
+##}
+#
+##void
+##pred_(y, x_, new_x, size_info, s, weights, robust, span, degree, 
+##    normalize, parametric, drop_square, surface, cell, family,
+##    parameter, a, xi, vert, vval, divisor, se, fit, se_fit)
+##double  *y, *x_, *new_x, *weights, *robust, *span, *cell, *fit, *s,
+##        *xi, *vert, *vval, *divisor, *se_fit;
+##long    *size_info, *degree, *normalize, *parametric, *drop_square, 
+##        *parameter, *a, *se;
+##char    **surface, **family;
+##{     
+##    double  *x, *x_tmp, *x_evaluate, *L, new_cell, z, tmp, *fit_tmp,
+##            *temp, sum, mean;
+##    long    N, D, M, sum_drop_sqr = 0, sum_parametric = 0,
+##            nonparametric = 0, *order_parametric, *order_drop_sqr;
+##    int     i, j, k, p, cut, comp();
+##
+##    D = size_info[0];
+##    N = size_info[1];
+##    M = size_info[2];
+##
+##    x = (double *) malloc(N * D * sizeof(double));
+##    x_tmp = (double *) malloc(N * D * sizeof(double));
+##    x_evaluate = (double *) malloc(M * D * sizeof(double));
+##    L = (double *) malloc(N * M * sizeof(double));
+##    order_parametric = (long *) malloc(D * sizeof(long));
+##    order_drop_sqr = (long *) malloc(D * sizeof(long));
+##    temp = (double *) malloc(N * D * sizeof(double));
+##
+##    for(i = 0; i < (N * D); i++)
+##        x_tmp[i] = x_[i];
+##    for(i = 0; i < D; i++) {
+##        k = i * M;
+##        for(j = 0; j < M; j++) {
+##            p = k + j;
+##            new_x[p] = new_x[p] / divisor[i];
+##        }
+##    }
+##    if(!strcmp(*surface, "direct") || se) {
+##        for(i = 0; i < D; i++) {
+##            k = i * N;
+##            for(j = 0; j < N; j++) {
+##                p = k + j;
+##                x_tmp[p] = x_[p] / divisor[i];
+##                }
+##        }
+##    }
+##    j = D - 1;
+##    for(i = 0; i < D; i++) {
+##            sum_drop_sqr = sum_drop_sqr + drop_square[i];
+##            sum_parametric = sum_parametric + parametric[i];
+##            if(parametric[i])
+##                order_parametric[j--] = i;
+##        else
+##                order_parametric[nonparametric++] = i;
+##    }
+##    for(i = 0; i < D; i++) {
+##        order_drop_sqr[i] = 2 - drop_square[order_parametric[i]];
+##        k = i * M;
+##        p = order_parametric[i] * M;
+##        for(j = 0; j < M; j++)
+##            x_evaluate[k + j] = new_x[p + j];
+##        k = i * N;
+##        p = order_parametric[i] * N;
+##        for(j = 0; j < N; j++)
+##            x[k + j] = x_tmp[p + j];
+##        }
+##    for(i = 0; i < N; i++)
+##        robust[i] = weights[i] * robust[i];
+##
+##    if(!strcmp(*surface, "direct")) {
+##        if(*se) {
+##            loess_dfitse(y, x, x_evaluate, weights, robust,
+##            !strcmp(*family, "gaussian"), span, degree,
+##                    &nonparametric, order_drop_sqr, &sum_drop_sqr,
+##                    &D, &N, &M, fit, L);
+##            }
+##        else {
+##            loess_dfit(y, x, x_evaluate, robust, span, degree,
+##                       &nonparametric, order_drop_sqr, &sum_drop_sqr,
+##                       &D, &N, &M, fit);
+##            }
+##        }
+##    else {
+##        loess_ifit(parameter, a, xi, vert, vval, &M, x_evaluate, fit);
+##        if(*se) {
+##                new_cell = (*span) * (*cell);
+##                fit_tmp = (double *) malloc(M * sizeof(double));
+##                loess_ise(y, x, x_evaluate, weights, span, degree,
+##                &nonparametric, order_drop_sqr, &sum_drop_sqr,
+##                &new_cell, &D, &N, &M, fit_tmp, L);
+##                free(fit_tmp);
+##                }
+##        }
+##    if(*se) {
+##        for(i = 0; i < N; i++) {
+##            k = i * M;
+##            for(j = 0; j < M; j++) {
+##                p = k + j;
+##                L[p] = L[p] / weights[i];
+##                L[p] = L[p] * L[p];
+##            }
+##        }
+##        for(i = 0; i < M; i++) {
+##            tmp = 0;
+##            for(j = 0; j < N; j++)
+##                tmp = tmp + L[i + j * M];
+##            se_fit[i] = (*s) * sqrt(tmp);
+##        }
+##    }
+##    free(x);
+##    free(x_tmp);
+##    free(x_evaluate);
+##    free(L);
+##    free(order_parametric);
+##    free(order_drop_sqr);
+##    free(temp);
+##}
+##
+##void
+##pred_free_mem(pre)
+##struct    pred_struct    *pre;
+##{
+##    free(pre->fit);
+##    free(pre->se_fit);
+##}
+
+
+
+################################################################################
+if __name__ == '__main__':
+    import numpy as N
+    _data = open(os.path.join('examples','sin_data'), 'r')
+    _result = open(os.path.join('examples','sin_result'), 'r')
+    x = N.arange(1.,121.)
+    y = N.concatenate([N.fromiter((float(v) for v in L.rstrip().split()), float_) 
+                       for L in _data.readlines()])
+    z = N.concatenate([N.fromiter((float(v) for v in L.rstrip().split()), float_) 
+                       for L in _result.readlines()])
+#    x = N.concatenate([N.fromiter((float(v) for v in L.rstrip().split()), float_) 
+#                       for L in open('_data','r').readlines()])
+#    x.shape = (-1,2)
+#    y = N.concatenate([N.fromiter((float(v) for v in L.rstrip().split()), float_) 
+#                       for L in open('_response','r').readlines()])
+    tester = cloess.loess(x,y)
+    enp_theo = 4.34
+    rse_theo = 0.579
+    trc_smoother = 4.73
+    print "OK"
+    tester.fit()
+    tester.summary()
+    print "Fit OK"

Added: trunk/Lib/sandbox/pyloess/sandbox/setup.py
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/setup.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/setup.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+"""Install file for example on how to use Pyrex with Numpy.
+
+For more details, see:
+http://www.scipy.org/Cookbook/Pyrex_and_NumPy
+http://www.scipy.org/Cookbook/ArrayStruct_and_Pyrex
+"""
+
+from distutils.core import setup
+from distutils.extension import Extension
+
+# Make this usable by people who don't have pyrex installed (I've committed
+# the generated C sources to SVN).
+try:
+    from Pyrex.Distutils import build_ext
+    has_pyrex = True
+except ImportError:
+    has_pyrex = False
+import numpy
+
+# Define a pyrex-based extension module, using the generated sources if pyrex
+# is not available.
+if has_pyrex:
+    pyx_sources = ['cloess.pyx']
+    cmdclass    = {'build_ext': build_ext}
+else:
+    pyx_sources = ['cloess.c']
+    cmdclass    = {}
+
+f_sources = ['loessf.f', 'linpack_lite.f']
+c_sources = ['loess.c', 'loessc.c']
+
+
+pyx_ext = Extension('cloess',
+                    pyx_sources + c_sources + f_sources,
+                    include_dirs = [numpy.get_include()])
+
+# Call the routine which does the real work
+setup(name        = 'cloess',
+      description = 'Small example on using Pyrex to write a Numpy extension',
+      url         = 'http://www.scipy.org/Cookbook/Pyrex_and_NumPy',
+      ext_modules = [pyx_ext],
+      cmdclass    = cmdclass,
+      )

Added: trunk/Lib/sandbox/pyloess/sandbox/src/S.h
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/S.h	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/S.h	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <math.h>
+
+#define Calloc(n,t)	(t *)calloc((unsigned)(n),sizeof(t))
+#define Free(p)		free((char *)(p))
+
+/* the mapping from f77 to C intermediate code -- may be machine dependent
+ * the first definition satisfies lint's narrowminded preprocessing & should
+ * stay the same for all implementations.  The __STDC__ definition is for
+ * ANSI standard conforming C compilers. The #else definition should
+ * generate the version of the fortran subroutine & common block names x
+ * handed to the local loader; e.g., "x_" in system V, Berkeley & 9th edition
+ */
+
+#ifdef lint
+#define F77_SUB(x) x
+#define F77_COM(x) x
+#else
+#ifdef __STDC__
+#define F77_SUB(x) x##_
+#define F77_COM(x) x##_
+#else
+#define F77_SUB(x) x/**/_
+#define F77_COM(x) x/**/_
+#endif
+#endif
+
+#define NULL_ENTRY          ((int *)NULL)
+

Added: trunk/Lib/sandbox/pyloess/sandbox/src/c_loess.pxd
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/c_loess.pxd	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/c_loess.pxd	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,87 @@
+# -*- Mode: Python -*-  
+
+cdef extern from "loess.h":
+    ctypedef struct c_loess_inputs "loess_inputs":
+        long    n
+        long    p
+        double  *y
+        double  *x
+        double  *weights
+    ctypedef struct c_loess_model "loess_model":
+        double  span
+        long    degree
+        long    normalize
+        long    parametric[8]
+        long    drop_square[8]
+        char    *family
+    ctypedef struct c_loess_control "loess_control":
+        char    *surface
+        char    *statistics
+        double  cell
+        char    *trace_hat
+        long    iterations
+    ctypedef struct c_loess_kd_tree "loess_kd_tree":
+        long    *parameter
+        long    *a
+        double  *xi
+        double  *vert
+        double  *vval
+    ctypedef struct c_loess_outputs "loess_outputs":
+        double  *fitted_values
+        double  *fitted_residuals
+        double  enp
+        double  s
+        double  one_delta
+        double  two_delta
+        double  *pseudovalues
+        double  trace_hat
+        double  *diagonal
+        double  *robust
+        double  *divisor
+    ctypedef struct c_loess "loess":
+        c_loess_inputs inputs
+        c_loess_model model
+        c_loess_control control
+        c_loess_kd_tree kd_tree
+        c_loess_outputs outputs
+    #typedef struct {
+    #    double  *fit;
+    #    double  *se_fit;
+    #    double  residual_scale;
+    #    double  df;
+    #} predicted;
+    #
+    #struct anova_struct {
+    #    double  dfn;
+    #    double  dfd;
+    #    double  F_value;
+    #    double  Pr_F;
+    #};
+    #
+    #struct ci_struct {
+    #    double    *fit;
+    #    double    *upper;
+    #    double  *lower;
+    #};
+cdef extern from "loess.h":    
+    void loess_setup(double *x, double *y, long n, long p, c_loess *lo)
+    void loess_fit(c_loess *lo)
+    void loess_(double *y, double *x_, int *size_info, double *weights, 
+        double *span, int *degree, int *parametric, int *drop_square, 
+        int *normalize, char **statistics, char **surface, double *cell, 
+        char **trace_hat_in, int *iterations, double *fitted_values, 
+        double *fitted_residuals, double *enp, double *s, double *one_delta, 
+        double *two_delta, double *pseudovalues, double *trace_hat_out, 
+        double *diagonal, double *robust, double *divisor, long *parameter, 
+        long *a, double *xi, double *vert, double *vval)
+    void loess_free_mem(c_loess *lo)
+    void loess_summary(c_loess *lo)
+    void condition(char **surface, char *new_stat, char **trace_hat_in)
+    int comp(double *d1, double *d2)
+
+    void loess_raw(double *y, double *x, double *weights, double *robust, int *d,
+         int*n, double *span, int *degree, int *nonparametric,
+         int *drop_square, int *sum_drop_sqr, double *cell, char **surf_stat,
+         double *surface, long *parameter, long *a, double *xi, double *vert,
+         double *vval, double *diagonal, double *trL, double *one_delta,
+         double *two_delta, int *setLf)

Added: trunk/Lib/sandbox/pyloess/sandbox/src/c_numpy.pxd
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/c_numpy.pxd	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/c_numpy.pxd	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,126 @@
+# :Author:    Travis Oliphant
+
+cdef extern from "numpy/arrayobject.h":
+
+    cdef enum NPY_TYPES:
+        NPY_BOOL
+        NPY_BYTE
+        NPY_UBYTE
+        NPY_SHORT
+        NPY_USHORT 
+        NPY_INT
+        NPY_UINT 
+        NPY_LONG
+        NPY_ULONG
+        NPY_LONGLONG
+        NPY_ULONGLONG
+        NPY_FLOAT
+        NPY_DOUBLE 
+        NPY_LONGDOUBLE
+        NPY_CFLOAT
+        NPY_CDOUBLE
+        NPY_CLONGDOUBLE
+        NPY_OBJECT
+        NPY_STRING
+        NPY_UNICODE
+        NPY_VOID
+        NPY_NTYPES
+        NPY_NOTYPE
+
+    cdef enum requirements:
+        NPY_CONTIGUOUS
+        NPY_FORTRAN
+        NPY_OWNDATA
+        NPY_FORCECAST
+        NPY_ENSURECOPY
+        NPY_ENSUREARRAY
+        NPY_ELEMENTSTRIDES
+        NPY_ALIGNED
+        NPY_NOTSWAPPED
+        NPY_WRITEABLE
+        NPY_UPDATEIFCOPY
+        NPY_ARR_HAS_DESCR
+
+        NPY_BEHAVED
+        NPY_BEHAVED_NS
+        NPY_CARRAY
+        NPY_CARRAY_RO
+        NPY_FARRAY
+        NPY_FARRAY_RO
+        NPY_DEFAULT
+
+        NPY_IN_ARRAY
+        NPY_OUT_ARRAY
+        NPY_INOUT_ARRAY
+        NPY_IN_FARRAY
+        NPY_OUT_FARRAY
+        NPY_INOUT_FARRAY
+
+        NPY_UPDATE_ALL 
+
+    cdef enum defines:
+        # Note: as of Pyrex 0.9.5, enums are type-checked more strictly, so this
+        # can't be used as an integer.
+        NPY_MAXDIMS
+
+    ctypedef struct npy_cdouble:
+        double real
+        double imag
+
+    ctypedef struct npy_cfloat:
+        double real
+        double imag
+
+    ctypedef int npy_intp 
+
+    ctypedef extern class numpy.dtype [object PyArray_Descr]:
+        cdef int type_num, elsize, alignment
+        cdef char type, kind, byteorder, hasobject
+        cdef object fields, typeobj
+
+    ctypedef extern class numpy.ndarray [object PyArrayObject]:
+        cdef char *data
+        cdef int nd
+        cdef npy_intp *dimensions
+        cdef npy_intp *strides
+        cdef object base
+        cdef dtype descr
+        cdef int flags
+
+    ctypedef extern class numpy.flatiter [object PyArrayIterObject]:
+        cdef int  nd_m1
+        cdef npy_intp index, size
+        cdef ndarray ao
+        cdef char *dataptr
+        
+    ctypedef extern class numpy.broadcast [object PyArrayMultiIterObject]:
+        cdef int numiter
+        cdef npy_intp size, index
+        cdef int nd
+        # These next two should be arrays of [NPY_MAXITER], but that is
+        # difficult to cleanly specify in Pyrex. Fortunately, it doesn't matter.
+        cdef npy_intp *dimensions
+        cdef void **iters
+
+    object PyArray_ZEROS(int ndims, npy_intp* dims, NPY_TYPES type_num, int fortran)
+    object PyArray_EMPTY(int ndims, npy_intp* dims, NPY_TYPES type_num, int fortran)
+    dtype PyArray_DescrFromTypeNum(NPY_TYPES type_num)
+    object PyArray_SimpleNew(int ndims, npy_intp* dims, NPY_TYPES type_num)
+    int PyArray_Check(object obj)
+    object PyArray_ContiguousFromAny(object obj, NPY_TYPES type, 
+        int mindim, int maxdim)
+    npy_intp PyArray_SIZE(ndarray arr)
+    npy_intp PyArray_NBYTES(ndarray arr)
+    void *PyArray_DATA(ndarray arr)
+    object PyArray_FromAny(object obj, dtype newtype, int mindim, int maxdim,
+		    int requirements, object context)
+    object PyArray_FROMANY(object obj, NPY_TYPES type_num, int min,
+                           int max, int requirements)
+    object PyArray_NewFromDescr(object subtype, dtype newtype, int nd,
+                                npy_intp* dims, npy_intp* strides, void* data,
+                                int flags, object parent)
+
+    object PyArray_IterNew(object arr)
+    void PyArray_ITER_NEXT(flatiter it)
+
+    void import_array()

Added: trunk/Lib/sandbox/pyloess/sandbox/src/c_python.pxd
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/c_python.pxd	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/c_python.pxd	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,20 @@
+# -*- Mode: Python -*-  Not really, but close enough
+
+# Expose as much of the Python C API as we need here
+
+cdef extern from "stdlib.h":
+    ctypedef int size_t
+
+cdef extern from "Python.h":
+    ctypedef int Py_intptr_t
+    void*  PyMem_Malloc(size_t)
+    void*  PyMem_Realloc(void *p, size_t n)
+    void   PyMem_Free(void *p)
+    char*  PyString_AsString(object string)
+    object PyString_FromString(char *v)
+    object PyString_InternFromString(char *v)
+    int    PyErr_CheckSignals()
+    object PyFloat_FromDouble(double v)
+    void   Py_XINCREF(object o)
+    void   Py_XDECREF(object o)
+    void   Py_CLEAR(object o) # use instead of decref

Added: trunk/Lib/sandbox/pyloess/sandbox/src/cloess.c
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/cloess.c	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/cloess.c	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,2840 @@
+/* Generated by Pyrex 0.9.5.1a on Mon Mar 12 15:39:59 2007 */
+
+#include "Python.h"
+#include "structmember.h"
+#ifndef PY_LONG_LONG
+  #define PY_LONG_LONG LONG_LONG
+#endif
+#ifdef __cplusplus
+#define __PYX_EXTERN_C extern "C"
+#else
+#define __PYX_EXTERN_C extern
+#endif
+__PYX_EXTERN_C double pow(double, double);
+#include "stdlib.h"
+#include "numpy/arrayobject.h"
+#include "loess.h"
+
+
+typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
+typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
+
+static PyObject *__pyx_m;
+static PyObject *__pyx_b;
+static int __pyx_lineno;
+static char *__pyx_filename;
+static char **__pyx_f;
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
+
+static int __Pyx_PrintItem(PyObject *); /*proto*/
+static int __Pyx_PrintNewline(void); /*proto*/
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
+
+static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
+
+static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+
+static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
+
+static void __Pyx_AddTraceback(char *funcname); /*proto*/
+
+/* Declarations from c_python */
+
+
+/* Declarations from c_numpy */
+
+static PyTypeObject *__pyx_ptype_7c_numpy_dtype = 0;
+static PyTypeObject *__pyx_ptype_7c_numpy_ndarray = 0;
+static PyTypeObject *__pyx_ptype_7c_numpy_flatiter = 0;
+static PyTypeObject *__pyx_ptype_7c_numpy_broadcast = 0;
+
+/* Declarations from c_loess */
+
+
+/* Declarations from cloess */
+
+
+struct __pyx_obj_6cloess_loess_inputs {
+  PyObject_HEAD
+  loess_inputs _inputs;
+  long nobs;
+  long nvar;
+  PyArrayObject *x;
+  PyArrayObject *y;
+  PyArrayObject *weights;
+};
+
+
+struct __pyx_obj_6cloess_loess_control {
+  PyObject_HEAD
+  loess_control _control;
+  char (*surface);
+  char (*statistics);
+  char (*trace_hat);
+  double cell;
+  int iterations;
+};
+
+
+struct __pyx_obj_6cloess_loess_outputs {
+  PyObject_HEAD
+  loess_outputs _outputs;
+  PyArrayObject *fitted_values;
+  PyArrayObject *fitted_residuals;
+  PyArrayObject *pseudovalues;
+  PyArrayObject *diagonal;
+  PyArrayObject *robust;
+  PyArrayObject *divisor;
+  double enp;
+  double s;
+  double one_delta;
+  double two_delta;
+  double trace_hat;
+};
+
+
+struct __pyx_obj_6cloess_loess_kd_tree {
+  PyObject_HEAD
+  loess_kd_tree _kdtree;
+  PyArrayObject *parameter;
+  PyArrayObject *a;
+  PyArrayObject *xi;
+  PyArrayObject *vert;
+  PyArrayObject *vval;
+};
+
+
+struct __pyx_obj_6cloess_loess_model {
+  PyObject_HEAD
+  loess_model _model;
+  double span;
+  int degree;
+  int normalize;
+  char (*family);
+  PyObject *parametric_flags;
+  PyObject *drop_square_flags;
+};
+
+
+struct __pyx_obj_6cloess_loess {
+  PyObject_HEAD
+  loess _base;
+  struct __pyx_obj_6cloess_loess_inputs *inputs;
+  struct __pyx_obj_6cloess_loess_model *model;
+  struct __pyx_obj_6cloess_loess_control *control;
+  struct __pyx_obj_6cloess_loess_kd_tree *kd_tree;
+  struct __pyx_obj_6cloess_loess_outputs *outputs;
+};
+
+static PyTypeObject *__pyx_ptype_6cloess_loess_inputs = 0;
+static PyTypeObject *__pyx_ptype_6cloess_loess_control = 0;
+static PyTypeObject *__pyx_ptype_6cloess_loess_outputs = 0;
+static PyTypeObject *__pyx_ptype_6cloess_loess_kd_tree = 0;
+static PyTypeObject *__pyx_ptype_6cloess_loess_model = 0;
+static PyTypeObject *__pyx_ptype_6cloess_loess = 0;
+static PyObject *__pyx_k2;
+static double __pyx_k3;
+static int __pyx_k4;
+static int __pyx_k5;
+static PyObject *__pyx_k6;
+static PyObject *__pyx_k7;
+static PyObject *__pyx_k9;
+static PyObject *__pyx_k10;
+
+
+/* Implementation of cloess */
+
+
+static PyObject *__pyx_n_c_python;
+static PyObject *__pyx_n_c_numpy;
+static PyObject *__pyx_n__N;
+static PyObject *__pyx_n_c_loess;
+static PyObject *__pyx_n_numpy;
+static PyObject *__pyx_n_False;
+static PyObject *__pyx_n_gaussian;
+
+static PyObject *__pyx_n_ndim;
+static PyObject *__pyx_n_ValueError;
+static PyObject *__pyx_n_len;
+static PyObject *__pyx_n_size;
+
+static PyObject *__pyx_k11p;
+static PyObject *__pyx_k12p;
+static PyObject *__pyx_k13p;
+static PyObject *__pyx_k14p;
+
+static char (__pyx_k11[]) = "DEBUG: Initializing loess_inputs...";
+static char (__pyx_k12[]) = "Argument 'x' should be 2D at most!";
+static char (__pyx_k13[]) = "Invalid size of the 'weights' vector!";
+static char (__pyx_k14[]) = " OK.";
+
+static int __pyx_f_6cloess_12loess_inputs___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_f_6cloess_12loess_inputs___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_x = 0;
+  PyObject *__pyx_v_y = 0;
+  PyObject *__pyx_v_weights = 0;
+  double (*__pyx_v_w_dat);
+  npy_intp __pyx_v_n;
+  npy_intp __pyx_v_p;
+  npy_intp (*__pyx_v_dims);
+  PyObject *__pyx_v_i;
+  int __pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  int __pyx_3;
+  PyObject *__pyx_4 = 0;
+  npy_intp __pyx_5;
+  long __pyx_6;
+  static char *__pyx_argnames[] = {"x","y","weights",0};
+  __pyx_v_weights = __pyx_k2;
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO|O", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_weights)) return -1;
+  Py_INCREF(__pyx_v_self);
+  Py_INCREF(__pyx_v_x);
+  Py_INCREF(__pyx_v_y);
+  Py_INCREF(__pyx_v_weights);
+  __pyx_v_i = Py_None; Py_INCREF(Py_None);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":27 */
+  if (__Pyx_PrintItem(__pyx_k11p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":28 */
+  __pyx_1 = PyArray_FROMANY(__pyx_v_x,NPY_DOUBLE,1,1,NPY_OWNDATA); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x));
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":29 */
+  __pyx_1 = PyArray_FROMANY(__pyx_v_y,NPY_DOUBLE,1,1,NPY_OWNDATA); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->y));
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->y = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":31 */
+  __pyx_1 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x), __pyx_n_ndim); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;}
+  __pyx_2 = PyInt_FromLong(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;}
+  if (PyObject_Cmp(__pyx_1, __pyx_2, &__pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;}
+  __pyx_3 = __pyx_3 > 0;
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  if (__pyx_3) {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":32 */
+    __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;}
+    __Pyx_Raise(__pyx_1, __pyx_k12p, 0);
+    Py_DECREF(__pyx_1); __pyx_1 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;}
+    goto __pyx_L2;
+  }
+  __pyx_L2:;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":33 */
+  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x));
+  PyTuple_SET_ITEM(__pyx_1, 0, ((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x));
+  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_5 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+  __pyx_v_n = __pyx_5;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":34 */
+  __pyx_2 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x), __pyx_n_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
+  __pyx_1 = PyInt_FromLong(__pyx_v_n); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
+  __pyx_4 = PyNumber_Divide(__pyx_2, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_5 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;}
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+  __pyx_v_p = __pyx_5;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":36 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->nobs = ((long )__pyx_v_n);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":37 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->nvar = ((long )__pyx_v_p);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":38 */
+  (__pyx_v_dims[0]) = __pyx_v_n;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":40 */
+  __pyx_3 = __pyx_v_weights == Py_None;
+  if (__pyx_3) {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":41 */
+    __pyx_2 = PyArray_EMPTY(1,__pyx_v_dims,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; goto __pyx_L1;}
+    Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_2)));
+    Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights));
+    ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights = ((PyArrayObject *)__pyx_2);
+    Py_DECREF(__pyx_2); __pyx_2 = 0;
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":42 */
+    __pyx_v_w_dat = ((double (*))((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights->data);
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":43 */
+    __pyx_5 = (__pyx_v_dims[0]);
+    for (__pyx_6 = 0; __pyx_6 < __pyx_5; ++__pyx_6) {
+      __pyx_1 = PyInt_FromLong(__pyx_6); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;}
+      Py_DECREF(__pyx_v_i);
+      __pyx_v_i = __pyx_1;
+      __pyx_1 = 0;
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":44 */
+      __pyx_3 = PyInt_AsLong(__pyx_v_i); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; goto __pyx_L1;}
+      (__pyx_v_w_dat[__pyx_3]) = 1;
+    }
+    goto __pyx_L3;
+  }
+  /*else*/ {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":46 */
+    __pyx_4 = PyArray_FROMANY(__pyx_v_weights,NPY_DOUBLE,1,1,NPY_OWNDATA); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; goto __pyx_L1;}
+    Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_4)));
+    Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights));
+    ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights = ((PyArrayObject *)__pyx_4);
+    Py_DECREF(__pyx_4); __pyx_4 = 0;
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":47 */
+    __pyx_2 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights), __pyx_n_ndim); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
+    __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
+    if (PyObject_Cmp(__pyx_2, __pyx_1, &__pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
+    __pyx_3 = __pyx_3 > 0;
+    Py_DECREF(__pyx_2); __pyx_2 = 0;
+    Py_DECREF(__pyx_1); __pyx_1 = 0;
+    if (!__pyx_3) {
+      __pyx_4 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights), __pyx_n_size); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
+      __pyx_2 = PyInt_FromLong(__pyx_v_n); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
+      if (PyObject_Cmp(__pyx_4, __pyx_2, &__pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
+      __pyx_3 = __pyx_3 != 0;
+      Py_DECREF(__pyx_4); __pyx_4 = 0;
+      Py_DECREF(__pyx_2); __pyx_2 = 0;
+    }
+    if (__pyx_3) {
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":48 */
+      __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
+      __Pyx_Raise(__pyx_1, __pyx_k13p, 0);
+      Py_DECREF(__pyx_1); __pyx_1 = 0;
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;}
+      goto __pyx_L6;
+    }
+    __pyx_L6:;
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":49 */
+    __pyx_v_w_dat = ((double (*))((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights->data);
+  }
+  __pyx_L3:;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":51 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->_inputs.n = ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->nobs;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":52 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->_inputs.p = ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->nvar;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":53 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->_inputs.x = ((double (*))((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->x->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":54 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->_inputs.y = ((double (*))((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->y->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":55 */
+  ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->_inputs.weights = ((double (*))((struct __pyx_obj_6cloess_loess_inputs *)__pyx_v_self)->weights->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":62 */
+  if (__Pyx_PrintItem(__pyx_k14p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; goto __pyx_L1;}
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":63 */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_4);
+  __Pyx_AddTraceback("cloess.loess_inputs.__init__");
+  __pyx_r = -1;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_i);
+  Py_DECREF(__pyx_v_self);
+  Py_DECREF(__pyx_v_x);
+  Py_DECREF(__pyx_v_y);
+  Py_DECREF(__pyx_v_weights);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_k15p;
+static PyObject *__pyx_k19p;
+
+static char (__pyx_k15[]) = "DEBUG: Initializing loess_control...";
+static char (__pyx_k16[]) = "interpolate";
+static char (__pyx_k17[]) = "approximate";
+static char (__pyx_k18[]) = "wait.to.decide";
+static char (__pyx_k19[]) = "OK.";
+
+static int __pyx_f_6cloess_13loess_control___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_f_6cloess_13loess_control___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  int __pyx_r;
+  static char *__pyx_argnames[] = {0};
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return -1;
+  Py_INCREF(__pyx_v_self);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":76 */
+  if (__Pyx_PrintItem(__pyx_k15p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":77 */
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->surface = __pyx_k16;
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->_control.surface = __pyx_k16;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":78 */
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->statistics = __pyx_k17;
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->_control.statistics = __pyx_k17;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":79 */
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->cell = 0.2;
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->_control.cell = 0.2;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":80 */
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->trace_hat = __pyx_k18;
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->_control.trace_hat = __pyx_k18;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":81 */
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->iterations = 4;
+  ((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->_control.iterations = 4;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":82 */
+  if (__Pyx_PrintItem(__pyx_k19p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;}
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":83 */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  __Pyx_AddTraceback("cloess.loess_control.__init__");
+  __pyx_r = -1;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n_join;
+
+static PyObject *__pyx_k20p;
+static PyObject *__pyx_k21p;
+static PyObject *__pyx_k22p;
+static PyObject *__pyx_k23p;
+static PyObject *__pyx_k24p;
+static PyObject *__pyx_k25p;
+static PyObject *__pyx_k26p;
+
+static char (__pyx_k20[]) = "Control          :";
+static char (__pyx_k21[]) = "Surface type     : %s";
+static char (__pyx_k22[]) = "Statistics       : %s";
+static char (__pyx_k23[]) = "Trace estimation : %s";
+static char (__pyx_k24[]) = "Cell size        : %s";
+static char (__pyx_k25[]) = "Nb iterations    : %s";
+static char (__pyx_k26[]) = "\n";
+
+static PyObject *__pyx_f_6cloess_13loess_control___str__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_f_6cloess_13loess_control___str__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_v_strg;
+  PyObject *__pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+  PyObject *__pyx_4 = 0;
+  PyObject *__pyx_5 = 0;
+  PyObject *__pyx_6 = 0;
+  Py_INCREF(__pyx_v_self);
+  __pyx_v_strg = Py_None; Py_INCREF(Py_None);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":86 */
+  __pyx_1 = PyString_FromString(((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->surface); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; goto __pyx_L1;}
+  __pyx_2 = PyNumber_Remainder(__pyx_k21p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyString_FromString(((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->statistics); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;}
+  __pyx_3 = PyNumber_Remainder(__pyx_k22p, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyString_FromString(((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->trace_hat); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;}
+  __pyx_4 = PyNumber_Remainder(__pyx_k23p, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyFloat_FromDouble(((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->cell); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
+  __pyx_5 = PyNumber_Remainder(__pyx_k24p, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyInt_FromLong(((struct __pyx_obj_6cloess_loess_control *)__pyx_v_self)->iterations); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;}
+  __pyx_6 = PyNumber_Remainder(__pyx_k25p, __pyx_1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyList_New(6); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; goto __pyx_L1;}
+  Py_INCREF(__pyx_k20p);
+  PyList_SET_ITEM(__pyx_1, 0, __pyx_k20p);
+  PyList_SET_ITEM(__pyx_1, 1, __pyx_2);
+  PyList_SET_ITEM(__pyx_1, 2, __pyx_3);
+  PyList_SET_ITEM(__pyx_1, 3, __pyx_4);
+  PyList_SET_ITEM(__pyx_1, 4, __pyx_5);
+  PyList_SET_ITEM(__pyx_1, 5, __pyx_6);
+  __pyx_2 = 0;
+  __pyx_3 = 0;
+  __pyx_4 = 0;
+  __pyx_5 = 0;
+  __pyx_6 = 0;
+  Py_DECREF(__pyx_v_strg);
+  __pyx_v_strg = __pyx_1;
+  __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":92 */
+  __pyx_2 = PyObject_GetAttr(__pyx_k26p, __pyx_n_join); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
+  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
+  Py_INCREF(__pyx_v_strg);
+  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_strg);
+  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  __pyx_r = __pyx_4;
+  __pyx_4 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  Py_XDECREF(__pyx_4);
+  Py_XDECREF(__pyx_5);
+  Py_XDECREF(__pyx_6);
+  __Pyx_AddTraceback("cloess.loess_control.__str__");
+  __pyx_r = 0;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_strg);
+  Py_DECREF(__pyx_v_self);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n_pesudovalues;
+
+static PyObject *__pyx_k27p;
+static PyObject *__pyx_k28p;
+
+static char (__pyx_k27[]) = "DEBUG: Initializing loess_outputs...";
+static char (__pyx_k28[]) = "OK.";
+
+static int __pyx_f_6cloess_13loess_outputs___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_f_6cloess_13loess_outputs___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_n = 0;
+  PyObject *__pyx_v_p = 0;
+  npy_intp (*__pyx_v_rows);
+  npy_intp (*__pyx_v_cols);
+  int __pyx_r;
+  PyObject *__pyx_1 = 0;
+  static char *__pyx_argnames[] = {"n","p",0};
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_n, &__pyx_v_p)) return -1;
+  Py_INCREF(__pyx_v_self);
+  Py_INCREF(__pyx_v_n);
+  Py_INCREF(__pyx_v_p);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":106 */
+  (__pyx_v_rows[0]) = ((int )__pyx_v_n);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":107 */
+  (__pyx_v_cols[0]) = ((int )__pyx_v_p);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":108 */
+  if (__Pyx_PrintItem(__pyx_k27p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":110 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_rows,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->fitted_values));
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->fitted_values = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":111 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_rows,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->fitted_residuals));
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->fitted_residuals = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":112 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_rows,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L1;}
+  if (PyObject_SetAttr(__pyx_v_self, __pyx_n_pesudovalues, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":113 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_rows,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->diagonal));
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->diagonal = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":114 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_rows,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->robust));
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->robust = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":115 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_cols,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->divisor));
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->divisor = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":117 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.fitted_values = ((double (*))((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->fitted_values->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":118 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.fitted_residuals = ((double (*))((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->fitted_residuals->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":119 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.pseudovalues = ((double (*))((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->pseudovalues->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":120 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.diagonal = ((double (*))((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->diagonal->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":121 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.robust = ((double (*))((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->robust->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":122 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.divisor = ((double (*))((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->divisor->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":124 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->enp = 0;
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.enp = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":125 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->s = 0;
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.s = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":126 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->one_delta = 0;
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.one_delta = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":127 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->two_delta = 0;
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.two_delta = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":128 */
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->trace_hat = 0;
+  ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_v_self)->_outputs.trace_hat = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":129 */
+  if (__Pyx_PrintItem(__pyx_k28p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L1;}
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L1;}
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  __Pyx_AddTraceback("cloess.loess_outputs.__init__");
+  __pyx_r = -1;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  Py_DECREF(__pyx_v_n);
+  Py_DECREF(__pyx_v_p);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n_max;
+static PyObject *__pyx_n_NPY_LONG;
+
+static PyObject *__pyx_k29p;
+static PyObject *__pyx_k30p;
+static PyObject *__pyx_k31p;
+static PyObject *__pyx_k32p;
+
+static char (__pyx_k29[]) = "DEBUG: Initializing loess_kdtree...";
+static char (__pyx_k30[]) = "(python side)";
+static char (__pyx_k31[]) = "(C side)";
+static char (__pyx_k32[]) = "OK.";
+
+static int __pyx_f_6cloess_13loess_kd_tree___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_f_6cloess_13loess_kd_tree___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  long __pyx_v_n;
+  long __pyx_v_p;
+  long __pyx_v_maxkd;
+  long __pyx_v_nval;
+  long __pyx_v_nvert;
+  npy_intp (*__pyx_v_nmaxkd);
+  npy_intp (*__pyx_v_nnval);
+  npy_intp (*__pyx_v_nnvert);
+  npy_intp (*__pyx_v_npars);
+  int __pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+  PyObject *__pyx_4 = 0;
+  long __pyx_5;
+  enum NPY_TYPES __pyx_6;
+  static char *__pyx_argnames[] = {"n","p",0};
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "ll", __pyx_argnames, &__pyx_v_n, &__pyx_v_p)) return -1;
+  Py_INCREF(__pyx_v_self);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":150 */
+  if (__Pyx_PrintItem(__pyx_k29p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":151 */
+  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_max); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
+  __pyx_2 = PyInt_FromLong(__pyx_v_n); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
+  __pyx_3 = PyInt_FromLong(200); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
+  __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
+  PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
+  PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
+  __pyx_2 = 0;
+  __pyx_3 = 0;
+  __pyx_2 = PyObject_CallObject(__pyx_1, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+  __pyx_5 = PyInt_AsLong(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  __pyx_v_maxkd = __pyx_5;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":152 */
+  __pyx_v_nvert = (__pyx_v_p * 2);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":153 */
+  __pyx_v_nval = ((__pyx_v_p + 1) * __pyx_v_maxkd);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":155 */
+  if (__Pyx_PrintItem(__pyx_k30p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":156 */
+  (__pyx_v_nmaxkd[0]) = ((int )__pyx_v_maxkd);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":157 */
+  (__pyx_v_nnvert[0]) = ((int )__pyx_v_nvert);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":158 */
+  (__pyx_v_nnval[0]) = ((int )__pyx_v_nval);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":159 */
+  (__pyx_v_npars[0]) = ((int )8);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":160 */
+  __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_NPY_LONG); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; goto __pyx_L1;}
+  __pyx_6 = ((enum NPY_TYPES )PyInt_AsLong(__pyx_3)); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; goto __pyx_L1;}
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_npars,__pyx_6,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->parameter));
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->parameter = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":161 */
+  __pyx_4 = __Pyx_GetName(__pyx_b, __pyx_n_NPY_LONG); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; goto __pyx_L1;}
+  __pyx_6 = ((enum NPY_TYPES )PyInt_AsLong(__pyx_4)); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; goto __pyx_L1;}
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+  __pyx_2 = PyArray_EMPTY(1,__pyx_v_nmaxkd,__pyx_6,NPY_ALIGNED); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_2)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->a));
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->a = ((PyArrayObject *)__pyx_2);
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":162 */
+  __pyx_3 = PyArray_EMPTY(1,__pyx_v_nmaxkd,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_3)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->xi));
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->xi = ((PyArrayObject *)__pyx_3);
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":163 */
+  __pyx_1 = PyArray_EMPTY(1,__pyx_v_nnvert,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_1)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->vert));
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->vert = ((PyArrayObject *)__pyx_1);
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":164 */
+  __pyx_4 = PyArray_EMPTY(1,__pyx_v_nnval,NPY_DOUBLE,NPY_ALIGNED); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; goto __pyx_L1;}
+  Py_INCREF(((PyObject *)((PyArrayObject *)__pyx_4)));
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->vval));
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->vval = ((PyArrayObject *)__pyx_4);
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":171 */
+  if (__Pyx_PrintItem(__pyx_k31p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":172 */
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->_kdtree.parameter = ((long (*))((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->parameter->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":173 */
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->_kdtree.a = ((long (*))((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->a->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":174 */
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->_kdtree.xi = ((double (*))((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->xi->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":175 */
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->_kdtree.vert = ((double (*))((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->vert->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":176 */
+  ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->_kdtree.vval = ((double (*))((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_v_self)->vval->data);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":187 */
+  if (__Pyx_PrintItem(__pyx_k32p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":188 */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  Py_XDECREF(__pyx_4);
+  __Pyx_AddTraceback("cloess.loess_kd_tree.__init__");
+  __pyx_r = -1;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n_hasattr;
+static PyObject *__pyx_n___len__;
+
+static PyObject *__pyx_k33p;
+static PyObject *__pyx_k36p;
+
+static char (__pyx_k33[]) = "DEBUG: Initializing loess_model...";
+static char (__pyx_k36[]) = "OK.";
+
+static int __pyx_f_6cloess_11loess_model___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_f_6cloess_11loess_model___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  double __pyx_v_span;
+  int __pyx_v_degree;
+  int __pyx_v_normalize;
+  PyObject *__pyx_v_parametric_in = 0;
+  PyObject *__pyx_v_drop_square_in = 0;
+  PyObject *__pyx_v_family = 0;
+  int __pyx_v_i;
+  int __pyx_r;
+  char (*__pyx_1);
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+  PyObject *__pyx_4 = 0;
+  int __pyx_5;
+  long __pyx_6;
+  long __pyx_7;
+  static char *__pyx_argnames[] = {"span","degree","normalize","parametric_in","drop_square_in","family",0};
+  __pyx_v_span = __pyx_k3;
+  __pyx_v_degree = __pyx_k4;
+  __pyx_v_normalize = __pyx_k5;
+  __pyx_v_parametric_in = __pyx_k6;
+  __pyx_v_drop_square_in = __pyx_k7;
+  __pyx_v_family = __pyx_k9;
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "|diiOOO", __pyx_argnames, &__pyx_v_span, &__pyx_v_degree, &__pyx_v_normalize, &__pyx_v_parametric_in, &__pyx_v_drop_square_in, &__pyx_v_family)) return -1;
+  Py_INCREF(__pyx_v_self);
+  Py_INCREF(__pyx_v_parametric_in);
+  Py_INCREF(__pyx_v_drop_square_in);
+  Py_INCREF(__pyx_v_family);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":208 */
+  if (__Pyx_PrintItem(__pyx_k33p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":209 */
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->span = __pyx_v_span;
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.span = __pyx_v_span;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":210 */
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->degree = __pyx_v_degree;
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.degree = __pyx_v_degree;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":211 */
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->normalize = __pyx_v_normalize;
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.normalize = __pyx_v_normalize;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":212 */
+  __pyx_1 = PyString_AsString(__pyx_v_family); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->family = __pyx_1;
+  __pyx_1 = PyString_AsString(__pyx_v_family); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; goto __pyx_L1;}
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.family = __pyx_1;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":214 */
+  __pyx_2 = PyList_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; goto __pyx_L1;}
+  Py_INCREF(Py_None);
+  PyList_SET_ITEM(__pyx_2, 0, Py_None);
+  __pyx_3 = PyInt_FromLong(8); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; goto __pyx_L1;}
+  __pyx_4 = PyNumber_Multiply(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  Py_DECREF(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->parametric_flags);
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->parametric_flags = __pyx_4;
+  __pyx_4 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":215 */
+  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_hasattr); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; goto __pyx_L1;}
+  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; goto __pyx_L1;}
+  Py_INCREF(__pyx_v_parametric_in);
+  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_parametric_in);
+  Py_INCREF(__pyx_n___len__);
+  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_n___len__);
+  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  __pyx_5 = PyObject_IsTrue(__pyx_4); if (__pyx_5 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; goto __pyx_L1;}
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+  if (__pyx_5) {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":216 */
+    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
+    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
+    Py_INCREF(__pyx_v_parametric_in);
+    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_parametric_in);
+    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
+    Py_DECREF(__pyx_2); __pyx_2 = 0;
+    Py_DECREF(__pyx_3); __pyx_3 = 0;
+    __pyx_6 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; goto __pyx_L1;}
+    Py_DECREF(__pyx_4); __pyx_4 = 0;
+    for (__pyx_v_i = 0; __pyx_v_i < __pyx_6; ++__pyx_v_i) {
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":217 */
+      __pyx_2 = PyInt_FromLong(__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; goto __pyx_L1;}
+      __pyx_3 = PyObject_GetItem(__pyx_v_parametric_in, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; goto __pyx_L1;}
+      Py_DECREF(__pyx_2); __pyx_2 = 0;
+      __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; goto __pyx_L1;}
+      if (PyObject_SetItem(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->parametric_flags, __pyx_4, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; goto __pyx_L1;}
+      Py_DECREF(__pyx_4); __pyx_4 = 0;
+      Py_DECREF(__pyx_3); __pyx_3 = 0;
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":218 */
+      __pyx_2 = PyInt_FromLong(__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; goto __pyx_L1;}
+      __pyx_3 = PyObject_GetItem(__pyx_v_parametric_in, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; goto __pyx_L1;}
+      Py_DECREF(__pyx_2); __pyx_2 = 0;
+      __pyx_7 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; goto __pyx_L1;}
+      Py_DECREF(__pyx_3); __pyx_3 = 0;
+      (((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.parametric[__pyx_v_i]) = __pyx_7;
+    }
+    goto __pyx_L2;
+  }
+  /*else*/ {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":220 */
+    for (__pyx_v_i = 0; __pyx_v_i <= 7; ++__pyx_v_i) {
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":221 */
+      __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; goto __pyx_L1;}
+      if (PyObject_SetItem(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->parametric_flags, __pyx_4, __pyx_v_parametric_in) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; goto __pyx_L1;}
+      Py_DECREF(__pyx_4); __pyx_4 = 0;
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":222 */
+      __pyx_7 = PyInt_AsLong(__pyx_v_parametric_in); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; goto __pyx_L1;}
+      (((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.parametric[__pyx_v_i]) = __pyx_7;
+    }
+  }
+  __pyx_L2:;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":224 */
+  __pyx_2 = PyList_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
+  Py_INCREF(Py_None);
+  PyList_SET_ITEM(__pyx_2, 0, Py_None);
+  __pyx_3 = PyInt_FromLong(8); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
+  __pyx_4 = PyNumber_Multiply(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  Py_DECREF(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->drop_square_flags);
+  ((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->drop_square_flags = __pyx_4;
+  __pyx_4 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":225 */
+  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_hasattr); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; goto __pyx_L1;}
+  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; goto __pyx_L1;}
+  Py_INCREF(__pyx_v_drop_square_in);
+  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_drop_square_in);
+  Py_INCREF(__pyx_n___len__);
+  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_n___len__);
+  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  __pyx_5 = PyObject_IsTrue(__pyx_4); if (__pyx_5 < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; goto __pyx_L1;}
+  Py_DECREF(__pyx_4); __pyx_4 = 0;
+  if (__pyx_5) {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":226 */
+    __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
+    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
+    Py_INCREF(__pyx_v_drop_square_in);
+    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_drop_square_in);
+    __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
+    Py_DECREF(__pyx_2); __pyx_2 = 0;
+    Py_DECREF(__pyx_3); __pyx_3 = 0;
+    __pyx_6 = PyInt_AsLong(__pyx_4); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; goto __pyx_L1;}
+    Py_DECREF(__pyx_4); __pyx_4 = 0;
+    for (__pyx_v_i = 0; __pyx_v_i < __pyx_6; ++__pyx_v_i) {
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":227 */
+      __pyx_2 = PyInt_FromLong(__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; goto __pyx_L1;}
+      __pyx_3 = PyObject_GetItem(__pyx_v_drop_square_in, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; goto __pyx_L1;}
+      Py_DECREF(__pyx_2); __pyx_2 = 0;
+      __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; goto __pyx_L1;}
+      if (PyObject_SetItem(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->drop_square_flags, __pyx_4, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; goto __pyx_L1;}
+      Py_DECREF(__pyx_4); __pyx_4 = 0;
+      Py_DECREF(__pyx_3); __pyx_3 = 0;
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":228 */
+      __pyx_2 = PyInt_FromLong(__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; goto __pyx_L1;}
+      __pyx_3 = PyObject_GetItem(__pyx_v_drop_square_in, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; goto __pyx_L1;}
+      Py_DECREF(__pyx_2); __pyx_2 = 0;
+      __pyx_7 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; goto __pyx_L1;}
+      Py_DECREF(__pyx_3); __pyx_3 = 0;
+      (((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.drop_square[__pyx_v_i]) = __pyx_7;
+    }
+    goto __pyx_L7;
+  }
+  /*else*/ {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":230 */
+    for (__pyx_v_i = 0; __pyx_v_i < 8; ++__pyx_v_i) {
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":231 */
+      __pyx_4 = PyInt_FromLong(__pyx_v_i); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; goto __pyx_L1;}
+      if (PyObject_SetItem(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->drop_square_flags, __pyx_4, __pyx_v_drop_square_in) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; goto __pyx_L1;}
+      Py_DECREF(__pyx_4); __pyx_4 = 0;
+
+      /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":232 */
+      __pyx_7 = PyInt_AsLong(__pyx_v_drop_square_in); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; goto __pyx_L1;}
+      (((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.drop_square[__pyx_v_i]) = __pyx_7;
+    }
+  }
+  __pyx_L7:;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":233 */
+  if (__Pyx_PrintItem(__pyx_k36p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; goto __pyx_L1;}
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":246 */
+  __pyx_r = 0;
+  goto __pyx_L0;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  Py_XDECREF(__pyx_4);
+  __Pyx_AddTraceback("cloess.loess_model.__init__");
+  __pyx_r = -1;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  Py_DECREF(__pyx_v_parametric_in);
+  Py_DECREF(__pyx_v_drop_square_in);
+  Py_DECREF(__pyx_v_family);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n_id;
+
+static PyObject *__pyx_k37p;
+
+static char (__pyx_k37[]) = "loess model parameters @%s";
+
+static PyObject *__pyx_f_6cloess_11loess_model___repr__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_f_6cloess_11loess_model___repr__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+  Py_INCREF(__pyx_v_self);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":249 */
+  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_id); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; goto __pyx_L1;}
+  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; goto __pyx_L1;}
+  Py_INCREF(__pyx_v_self);
+  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_self);
+  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  __pyx_1 = PyNumber_Remainder(__pyx_k37p, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; goto __pyx_L1;}
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  __pyx_r = __pyx_1;
+  __pyx_1 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  __Pyx_AddTraceback("cloess.loess_model.__repr__");
+  __pyx_r = 0;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n___name__;
+static PyObject *__pyx_n_parametric;
+static PyObject *__pyx_n_drop_square;
+
+static PyObject *__pyx_k38p;
+static PyObject *__pyx_k39p;
+static PyObject *__pyx_k40p;
+static PyObject *__pyx_k41p;
+static PyObject *__pyx_k42p;
+static PyObject *__pyx_k43p;
+static PyObject *__pyx_k44p;
+static PyObject *__pyx_k45p;
+
+static char (__pyx_k38[]) = "Object      : %s";
+static char (__pyx_k39[]) = "family      : %s";
+static char (__pyx_k40[]) = "span        : %s";
+static char (__pyx_k41[]) = "degree      : %s";
+static char (__pyx_k42[]) = "normalized  : %s";
+static char (__pyx_k43[]) = "parametric  : %s";
+static char (__pyx_k44[]) = "drop_square : %s";
+static char (__pyx_k45[]) = "\n";
+
+static PyObject *__pyx_f_6cloess_11loess_model___str__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_f_6cloess_11loess_model___str__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_v_strg;
+  PyObject *__pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+  PyObject *__pyx_4 = 0;
+  PyObject *__pyx_5 = 0;
+  PyObject *__pyx_6 = 0;
+  PyObject *__pyx_7 = 0;
+  PyObject *__pyx_8 = 0;
+  Py_INCREF(__pyx_v_self);
+  __pyx_v_strg = Py_None; Py_INCREF(Py_None);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":251 */
+  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n___name__); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; goto __pyx_L1;}
+  __pyx_2 = PyNumber_Remainder(__pyx_k38p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyString_FromString(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.family); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; goto __pyx_L1;}
+  __pyx_3 = PyNumber_Remainder(__pyx_k39p, __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyFloat_FromDouble(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.span); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
+  __pyx_4 = PyNumber_Remainder(__pyx_k40p, __pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyInt_FromLong(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.degree); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; goto __pyx_L1;}
+  __pyx_5 = PyNumber_Remainder(__pyx_k41p, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyInt_FromLong(((struct __pyx_obj_6cloess_loess_model *)__pyx_v_self)->_model.normalize); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; goto __pyx_L1;}
+  __pyx_6 = PyNumber_Remainder(__pyx_k42p, __pyx_1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_parametric); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; goto __pyx_L1;}
+  __pyx_7 = PyNumber_Remainder(__pyx_k43p, __pyx_1); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_drop_square); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
+  __pyx_8 = PyNumber_Remainder(__pyx_k44p, __pyx_1); if (!__pyx_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  __pyx_1 = PyList_New(7); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; goto __pyx_L1;}
+  PyList_SET_ITEM(__pyx_1, 0, __pyx_2);
+  PyList_SET_ITEM(__pyx_1, 1, __pyx_3);
+  PyList_SET_ITEM(__pyx_1, 2, __pyx_4);
+  PyList_SET_ITEM(__pyx_1, 3, __pyx_5);
+  PyList_SET_ITEM(__pyx_1, 4, __pyx_6);
+  PyList_SET_ITEM(__pyx_1, 5, __pyx_7);
+  PyList_SET_ITEM(__pyx_1, 6, __pyx_8);
+  __pyx_2 = 0;
+  __pyx_3 = 0;
+  __pyx_4 = 0;
+  __pyx_5 = 0;
+  __pyx_6 = 0;
+  __pyx_7 = 0;
+  __pyx_8 = 0;
+  Py_DECREF(__pyx_v_strg);
+  __pyx_v_strg = __pyx_1;
+  __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":258 */
+  __pyx_2 = PyObject_GetAttr(__pyx_k45p, __pyx_n_join); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; goto __pyx_L1;}
+  __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; goto __pyx_L1;}
+  Py_INCREF(__pyx_v_strg);
+  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_strg);
+  __pyx_4 = PyObject_CallObject(__pyx_2, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  __pyx_r = __pyx_4;
+  __pyx_4 = 0;
+  goto __pyx_L0;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  Py_XDECREF(__pyx_4);
+  Py_XDECREF(__pyx_5);
+  Py_XDECREF(__pyx_6);
+  Py_XDECREF(__pyx_7);
+  Py_XDECREF(__pyx_8);
+  __Pyx_AddTraceback("cloess.loess_model.__str__");
+  __pyx_r = 0;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_strg);
+  Py_DECREF(__pyx_v_self);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_k46p;
+
+static char (__pyx_k46[]) = "DEBUG:Initializing loess_cside";
+
+static int __pyx_f_6cloess_5loess___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_f_6cloess_5loess___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_x = 0;
+  PyObject *__pyx_v_y = 0;
+  PyObject *__pyx_v_weights = 0;
+  long __pyx_v_n;
+  long __pyx_v_p;
+  int __pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  PyObject *__pyx_3 = 0;
+  static char *__pyx_argnames[] = {"x","y","weights",0};
+  __pyx_v_weights = __pyx_k10;
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO|O", __pyx_argnames, &__pyx_v_x, &__pyx_v_y, &__pyx_v_weights)) return -1;
+  Py_INCREF(__pyx_v_self);
+  Py_INCREF(__pyx_v_x);
+  Py_INCREF(__pyx_v_y);
+  Py_INCREF(__pyx_v_weights);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":285 */
+  __pyx_1 = PyTuple_New(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; goto __pyx_L1;}
+  Py_INCREF(__pyx_v_x);
+  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_x);
+  Py_INCREF(__pyx_v_y);
+  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_v_y);
+  Py_INCREF(__pyx_v_weights);
+  PyTuple_SET_ITEM(__pyx_1, 2, __pyx_v_weights);
+  __pyx_2 = PyObject_CallObject(((PyObject*)__pyx_ptype_6cloess_loess_inputs), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_6cloess_loess_inputs)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; goto __pyx_L1;}
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->inputs));
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->inputs = ((struct __pyx_obj_6cloess_loess_inputs *)__pyx_2);
+  __pyx_2 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":286 */
+  __pyx_v_n = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->inputs->nobs;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":287 */
+  __pyx_v_p = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->inputs->nvar;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":288 */
+  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6cloess_loess_model), 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
+  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_6cloess_loess_model)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; goto __pyx_L1;}
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->model));
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->model = ((struct __pyx_obj_6cloess_loess_model *)__pyx_1);
+  __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":289 */
+  __pyx_2 = PyObject_CallObject(((PyObject*)__pyx_ptype_6cloess_loess_control), 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
+  if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_6cloess_loess_control)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; goto __pyx_L1;}
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->control));
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->control = ((struct __pyx_obj_6cloess_loess_control *)__pyx_2);
+  __pyx_2 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":290 */
+  __pyx_1 = PyInt_FromLong(__pyx_v_n); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
+  __pyx_2 = PyInt_FromLong(__pyx_v_p); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
+  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
+  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_1);
+  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_2);
+  __pyx_1 = 0;
+  __pyx_2 = 0;
+  __pyx_1 = PyObject_CallObject(((PyObject*)__pyx_ptype_6cloess_loess_outputs), __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
+  Py_DECREF(__pyx_3); __pyx_3 = 0;
+  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_6cloess_loess_outputs)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; goto __pyx_L1;}
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->outputs));
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->outputs = ((struct __pyx_obj_6cloess_loess_outputs *)__pyx_1);
+  __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":291 */
+  __pyx_2 = PyInt_FromLong(__pyx_v_n); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; goto __pyx_L1;}
+  __pyx_3 = PyInt_FromLong(__pyx_v_p); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; goto __pyx_L1;}
+  __pyx_1 = PyTuple_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; goto __pyx_L1;}
+  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_2);
+  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_3);
+  __pyx_2 = 0;
+  __pyx_3 = 0;
+  __pyx_2 = PyObject_CallObject(((PyObject*)__pyx_ptype_6cloess_loess_kd_tree), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  if (!__Pyx_TypeTest(__pyx_2, __pyx_ptype_6cloess_loess_kd_tree)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; goto __pyx_L1;}
+  Py_DECREF(((PyObject *)((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->kd_tree));
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->kd_tree = ((struct __pyx_obj_6cloess_loess_kd_tree *)__pyx_2);
+  __pyx_2 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":293 */
+  if (__Pyx_PrintItem(__pyx_k46p) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; goto __pyx_L1;}
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":294 */
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->_base.inputs = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->inputs->_inputs;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":295 */
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->_base.model = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->model->_model;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":296 */
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->_base.control = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->control->_control;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":297 */
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->_base.kd_tree = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->kd_tree->_kdtree;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":298 */
+  ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->_base.outputs = ((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->outputs->_outputs;
+
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  Py_XDECREF(__pyx_3);
+  __Pyx_AddTraceback("cloess.loess.__init__");
+  __pyx_r = -1;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  Py_DECREF(__pyx_v_x);
+  Py_DECREF(__pyx_v_y);
+  Py_DECREF(__pyx_v_weights);
+  return __pyx_r;
+}
+
+static PyObject *__pyx_n_n;
+
+static PyObject *__pyx_k47p;
+static PyObject *__pyx_k48p;
+static PyObject *__pyx_k50p;
+static PyObject *__pyx_k51p;
+
+static char (__pyx_k47[]) = "Number of Observations         : %d";
+static char (__pyx_k48[]) = "Equivalent Number of Parameters: %.1f";
+static char (__pyx_k49[]) = "gaussian";
+static char (__pyx_k50[]) = "Residual Standard Error        : %.4f";
+static char (__pyx_k51[]) = "Residual Scale Estimate        : %.4f";
+
+static PyObject *__pyx_f_6cloess_5loess_summary(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyObject *__pyx_f_6cloess_5loess_summary(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_r;
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  int __pyx_3;
+  static char *__pyx_argnames[] = {0};
+  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
+  Py_INCREF(__pyx_v_self);
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":310 */
+  __pyx_1 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->inputs), __pyx_n_n); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; goto __pyx_L1;}
+  __pyx_2 = PyNumber_Remainder(__pyx_k47p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  if (__Pyx_PrintItem(__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":311 */
+  __pyx_1 = PyFloat_FromDouble(((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->outputs->enp); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; goto __pyx_L1;}
+  __pyx_2 = PyNumber_Remainder(__pyx_k48p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+  if (__Pyx_PrintItem(__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; goto __pyx_L1;}
+  Py_DECREF(__pyx_2); __pyx_2 = 0;
+  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":312 */
+  __pyx_3 = (((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->model->family == __pyx_k49);
+  if (__pyx_3) {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":313 */
+    __pyx_1 = PyFloat_FromDouble(((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->outputs->s); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
+    __pyx_2 = PyNumber_Remainder(__pyx_k50p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
+    Py_DECREF(__pyx_1); __pyx_1 = 0;
+    if (__Pyx_PrintItem(__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
+    Py_DECREF(__pyx_2); __pyx_2 = 0;
+    if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; goto __pyx_L1;}
+    goto __pyx_L2;
+  }
+  /*else*/ {
+
+    /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":315 */
+    __pyx_1 = PyFloat_FromDouble(((struct __pyx_obj_6cloess_loess *)__pyx_v_self)->outputs->s); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
+    __pyx_2 = PyNumber_Remainder(__pyx_k51p, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
+    Py_DECREF(__pyx_1); __pyx_1 = 0;
+    if (__Pyx_PrintItem(__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
+    Py_DECREF(__pyx_2); __pyx_2 = 0;
+    if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
+  }
+  __pyx_L2:;
+
+  __pyx_r = Py_None; Py_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  __Pyx_AddTraceback("cloess.loess.summary");
+  __pyx_r = 0;
+  __pyx_L0:;
+  Py_DECREF(__pyx_v_self);
+  return __pyx_r;
+}
+
+static __Pyx_InternTabEntry __pyx_intern_tab[] = {
+  {&__pyx_n_False, "False"},
+  {&__pyx_n_NPY_LONG, "NPY_LONG"},
+  {&__pyx_n_ValueError, "ValueError"},
+  {&__pyx_n__N, "_N"},
+  {&__pyx_n___len__, "__len__"},
+  {&__pyx_n___name__, "__name__"},
+  {&__pyx_n_c_loess, "c_loess"},
+  {&__pyx_n_c_numpy, "c_numpy"},
+  {&__pyx_n_c_python, "c_python"},
+  {&__pyx_n_drop_square, "drop_square"},
+  {&__pyx_n_gaussian, "gaussian"},
+  {&__pyx_n_hasattr, "hasattr"},
+  {&__pyx_n_id, "id"},
+  {&__pyx_n_join, "join"},
+  {&__pyx_n_len, "len"},
+  {&__pyx_n_max, "max"},
+  {&__pyx_n_n, "n"},
+  {&__pyx_n_ndim, "ndim"},
+  {&__pyx_n_numpy, "numpy"},
+  {&__pyx_n_parametric, "parametric"},
+  {&__pyx_n_pesudovalues, "pesudovalues"},
+  {&__pyx_n_size, "size"},
+  {0, 0}
+};
+
+static __Pyx_StringTabEntry __pyx_string_tab[] = {
+  {&__pyx_k11p, __pyx_k11, sizeof(__pyx_k11)},
+  {&__pyx_k12p, __pyx_k12, sizeof(__pyx_k12)},
+  {&__pyx_k13p, __pyx_k13, sizeof(__pyx_k13)},
+  {&__pyx_k14p, __pyx_k14, sizeof(__pyx_k14)},
+  {&__pyx_k15p, __pyx_k15, sizeof(__pyx_k15)},
+  {&__pyx_k19p, __pyx_k19, sizeof(__pyx_k19)},
+  {&__pyx_k20p, __pyx_k20, sizeof(__pyx_k20)},
+  {&__pyx_k21p, __pyx_k21, sizeof(__pyx_k21)},
+  {&__pyx_k22p, __pyx_k22, sizeof(__pyx_k22)},
+  {&__pyx_k23p, __pyx_k23, sizeof(__pyx_k23)},
+  {&__pyx_k24p, __pyx_k24, sizeof(__pyx_k24)},
+  {&__pyx_k25p, __pyx_k25, sizeof(__pyx_k25)},
+  {&__pyx_k26p, __pyx_k26, sizeof(__pyx_k26)},
+  {&__pyx_k27p, __pyx_k27, sizeof(__pyx_k27)},
+  {&__pyx_k28p, __pyx_k28, sizeof(__pyx_k28)},
+  {&__pyx_k29p, __pyx_k29, sizeof(__pyx_k29)},
+  {&__pyx_k30p, __pyx_k30, sizeof(__pyx_k30)},
+  {&__pyx_k31p, __pyx_k31, sizeof(__pyx_k31)},
+  {&__pyx_k32p, __pyx_k32, sizeof(__pyx_k32)},
+  {&__pyx_k33p, __pyx_k33, sizeof(__pyx_k33)},
+  {&__pyx_k36p, __pyx_k36, sizeof(__pyx_k36)},
+  {&__pyx_k37p, __pyx_k37, sizeof(__pyx_k37)},
+  {&__pyx_k38p, __pyx_k38, sizeof(__pyx_k38)},
+  {&__pyx_k39p, __pyx_k39, sizeof(__pyx_k39)},
+  {&__pyx_k40p, __pyx_k40, sizeof(__pyx_k40)},
+  {&__pyx_k41p, __pyx_k41, sizeof(__pyx_k41)},
+  {&__pyx_k42p, __pyx_k42, sizeof(__pyx_k42)},
+  {&__pyx_k43p, __pyx_k43, sizeof(__pyx_k43)},
+  {&__pyx_k44p, __pyx_k44, sizeof(__pyx_k44)},
+  {&__pyx_k45p, __pyx_k45, sizeof(__pyx_k45)},
+  {&__pyx_k46p, __pyx_k46, sizeof(__pyx_k46)},
+  {&__pyx_k47p, __pyx_k47, sizeof(__pyx_k47)},
+  {&__pyx_k48p, __pyx_k48, sizeof(__pyx_k48)},
+  {&__pyx_k50p, __pyx_k50, sizeof(__pyx_k50)},
+  {&__pyx_k51p, __pyx_k51, sizeof(__pyx_k51)},
+  {0, 0, 0}
+};
+
+static PyObject *__pyx_tp_new_6cloess_loess_inputs(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  struct __pyx_obj_6cloess_loess_inputs *p = (struct __pyx_obj_6cloess_loess_inputs *)o;
+  p->x = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->y = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->weights = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_6cloess_loess_inputs(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_inputs *p = (struct __pyx_obj_6cloess_loess_inputs *)o;
+  Py_XDECREF(((PyObject *)p->x));
+  Py_XDECREF(((PyObject *)p->y));
+  Py_XDECREF(((PyObject *)p->weights));
+  (*o->ob_type->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_6cloess_loess_inputs(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_6cloess_loess_inputs *p = (struct __pyx_obj_6cloess_loess_inputs *)o;
+  if (p->x) {
+    e = (*v)(((PyObject*)p->x), a); if (e) return e;
+  }
+  if (p->y) {
+    e = (*v)(((PyObject*)p->y), a); if (e) return e;
+  }
+  if (p->weights) {
+    e = (*v)(((PyObject*)p->weights), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_6cloess_loess_inputs(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_inputs *p = (struct __pyx_obj_6cloess_loess_inputs *)o;
+  Py_XDECREF(((PyObject *)p->x));
+  p->x = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->y));
+  p->y = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->weights));
+  p->weights = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  return 0;
+}
+
+static struct PyMethodDef __pyx_methods_6cloess_loess_inputs[] = {
+  {0, 0, 0, 0}
+};
+
+static struct PyMemberDef __pyx_members_6cloess_loess_inputs[] = {
+  {"nobs", T_LONG, offsetof(struct __pyx_obj_6cloess_loess_inputs, nobs), 0, 0},
+  {"nvar", T_LONG, offsetof(struct __pyx_obj_6cloess_loess_inputs, nvar), 0, 0},
+  {"x", T_OBJECT, offsetof(struct __pyx_obj_6cloess_loess_inputs, x), READONLY, 0},
+  {"y", T_OBJECT, offsetof(struct __pyx_obj_6cloess_loess_inputs, y), READONLY, 0},
+  {"weights", T_OBJECT, offsetof(struct __pyx_obj_6cloess_loess_inputs, weights), READONLY, 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_loess_inputs = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  0, /*nb_divide*/
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  0, /*nb_coerce*/
+  0, /*nb_int*/
+  0, /*nb_long*/
+  0, /*nb_float*/
+  0, /*nb_oct*/
+  0, /*nb_hex*/
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  0, /*nb_inplace_divide*/
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_loess_inputs = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_loess_inputs = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_loess_inputs = {
+  0, /*bf_getreadbuffer*/
+  0, /*bf_getwritebuffer*/
+  0, /*bf_getsegcount*/
+  0, /*bf_getcharbuffer*/
+};
+
+PyTypeObject __pyx_type_6cloess_loess_inputs = {
+  PyObject_HEAD_INIT(0)
+  0, /*ob_size*/
+  "cloess.loess_inputs", /*tp_name*/
+  sizeof(struct __pyx_obj_6cloess_loess_inputs), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_6cloess_loess_inputs, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  0, /*tp_compare*/
+  0, /*tp_repr*/
+  &__pyx_tp_as_number_loess_inputs, /*tp_as_number*/
+  &__pyx_tp_as_sequence_loess_inputs, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_loess_inputs, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_loess_inputs, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_6cloess_loess_inputs, /*tp_traverse*/
+  __pyx_tp_clear_6cloess_loess_inputs, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_6cloess_loess_inputs, /*tp_methods*/
+  __pyx_members_6cloess_loess_inputs, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_f_6cloess_12loess_inputs___init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_6cloess_loess_inputs, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+};
+
+static PyObject *__pyx_tp_new_6cloess_loess_control(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  return o;
+}
+
+static void __pyx_tp_dealloc_6cloess_loess_control(PyObject *o) {
+  (*o->ob_type->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_6cloess_loess_control(PyObject *o, visitproc v, void *a) {
+  return 0;
+}
+
+static int __pyx_tp_clear_6cloess_loess_control(PyObject *o) {
+  return 0;
+}
+
+static struct PyMethodDef __pyx_methods_6cloess_loess_control[] = {
+  {0, 0, 0, 0}
+};
+
+static struct PyMemberDef __pyx_members_6cloess_loess_control[] = {
+  {"surface", T_STRING, offsetof(struct __pyx_obj_6cloess_loess_control, surface), 0, 0},
+  {"statistics", T_STRING, offsetof(struct __pyx_obj_6cloess_loess_control, statistics), 0, 0},
+  {"trace_hat", T_STRING, offsetof(struct __pyx_obj_6cloess_loess_control, trace_hat), 0, 0},
+  {"cell", T_DOUBLE, offsetof(struct __pyx_obj_6cloess_loess_control, cell), 0, 0},
+  {"iterations", T_INT, offsetof(struct __pyx_obj_6cloess_loess_control, iterations), 0, 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_loess_control = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  0, /*nb_divide*/
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  0, /*nb_coerce*/
+  0, /*nb_int*/
+  0, /*nb_long*/
+  0, /*nb_float*/
+  0, /*nb_oct*/
+  0, /*nb_hex*/
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  0, /*nb_inplace_divide*/
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_loess_control = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_loess_control = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_loess_control = {
+  0, /*bf_getreadbuffer*/
+  0, /*bf_getwritebuffer*/
+  0, /*bf_getsegcount*/
+  0, /*bf_getcharbuffer*/
+};
+
+PyTypeObject __pyx_type_6cloess_loess_control = {
+  PyObject_HEAD_INIT(0)
+  0, /*ob_size*/
+  "cloess.loess_control", /*tp_name*/
+  sizeof(struct __pyx_obj_6cloess_loess_control), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_6cloess_loess_control, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  0, /*tp_compare*/
+  0, /*tp_repr*/
+  &__pyx_tp_as_number_loess_control, /*tp_as_number*/
+  &__pyx_tp_as_sequence_loess_control, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_loess_control, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  __pyx_f_6cloess_13loess_control___str__, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_loess_control, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_6cloess_loess_control, /*tp_traverse*/
+  __pyx_tp_clear_6cloess_loess_control, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_6cloess_loess_control, /*tp_methods*/
+  __pyx_members_6cloess_loess_control, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_f_6cloess_13loess_control___init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_6cloess_loess_control, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+};
+
+static PyObject *__pyx_tp_new_6cloess_loess_outputs(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  struct __pyx_obj_6cloess_loess_outputs *p = (struct __pyx_obj_6cloess_loess_outputs *)o;
+  p->fitted_values = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->fitted_residuals = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->pseudovalues = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->diagonal = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->robust = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->divisor = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_6cloess_loess_outputs(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_outputs *p = (struct __pyx_obj_6cloess_loess_outputs *)o;
+  Py_XDECREF(((PyObject *)p->fitted_values));
+  Py_XDECREF(((PyObject *)p->fitted_residuals));
+  Py_XDECREF(((PyObject *)p->pseudovalues));
+  Py_XDECREF(((PyObject *)p->diagonal));
+  Py_XDECREF(((PyObject *)p->robust));
+  Py_XDECREF(((PyObject *)p->divisor));
+  (*o->ob_type->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_6cloess_loess_outputs(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_6cloess_loess_outputs *p = (struct __pyx_obj_6cloess_loess_outputs *)o;
+  if (p->fitted_values) {
+    e = (*v)(((PyObject*)p->fitted_values), a); if (e) return e;
+  }
+  if (p->fitted_residuals) {
+    e = (*v)(((PyObject*)p->fitted_residuals), a); if (e) return e;
+  }
+  if (p->pseudovalues) {
+    e = (*v)(((PyObject*)p->pseudovalues), a); if (e) return e;
+  }
+  if (p->diagonal) {
+    e = (*v)(((PyObject*)p->diagonal), a); if (e) return e;
+  }
+  if (p->robust) {
+    e = (*v)(((PyObject*)p->robust), a); if (e) return e;
+  }
+  if (p->divisor) {
+    e = (*v)(((PyObject*)p->divisor), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_6cloess_loess_outputs(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_outputs *p = (struct __pyx_obj_6cloess_loess_outputs *)o;
+  Py_XDECREF(((PyObject *)p->fitted_values));
+  p->fitted_values = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->fitted_residuals));
+  p->fitted_residuals = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->pseudovalues));
+  p->pseudovalues = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->diagonal));
+  p->diagonal = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->robust));
+  p->robust = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->divisor));
+  p->divisor = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  return 0;
+}
+
+static struct PyMethodDef __pyx_methods_6cloess_loess_outputs[] = {
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_loess_outputs = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  0, /*nb_divide*/
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  0, /*nb_coerce*/
+  0, /*nb_int*/
+  0, /*nb_long*/
+  0, /*nb_float*/
+  0, /*nb_oct*/
+  0, /*nb_hex*/
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  0, /*nb_inplace_divide*/
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_loess_outputs = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_loess_outputs = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_loess_outputs = {
+  0, /*bf_getreadbuffer*/
+  0, /*bf_getwritebuffer*/
+  0, /*bf_getsegcount*/
+  0, /*bf_getcharbuffer*/
+};
+
+PyTypeObject __pyx_type_6cloess_loess_outputs = {
+  PyObject_HEAD_INIT(0)
+  0, /*ob_size*/
+  "cloess.loess_outputs", /*tp_name*/
+  sizeof(struct __pyx_obj_6cloess_loess_outputs), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_6cloess_loess_outputs, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  0, /*tp_compare*/
+  0, /*tp_repr*/
+  &__pyx_tp_as_number_loess_outputs, /*tp_as_number*/
+  &__pyx_tp_as_sequence_loess_outputs, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_loess_outputs, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_loess_outputs, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_6cloess_loess_outputs, /*tp_traverse*/
+  __pyx_tp_clear_6cloess_loess_outputs, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_6cloess_loess_outputs, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_f_6cloess_13loess_outputs___init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_6cloess_loess_outputs, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+};
+
+static PyObject *__pyx_tp_new_6cloess_loess_kd_tree(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  struct __pyx_obj_6cloess_loess_kd_tree *p = (struct __pyx_obj_6cloess_loess_kd_tree *)o;
+  p->parameter = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->xi = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->vert = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  p->vval = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_6cloess_loess_kd_tree(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_kd_tree *p = (struct __pyx_obj_6cloess_loess_kd_tree *)o;
+  Py_XDECREF(((PyObject *)p->parameter));
+  Py_XDECREF(((PyObject *)p->a));
+  Py_XDECREF(((PyObject *)p->xi));
+  Py_XDECREF(((PyObject *)p->vert));
+  Py_XDECREF(((PyObject *)p->vval));
+  (*o->ob_type->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_6cloess_loess_kd_tree(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_6cloess_loess_kd_tree *p = (struct __pyx_obj_6cloess_loess_kd_tree *)o;
+  if (p->parameter) {
+    e = (*v)(((PyObject*)p->parameter), a); if (e) return e;
+  }
+  if (p->a) {
+    e = (*v)(((PyObject*)p->a), a); if (e) return e;
+  }
+  if (p->xi) {
+    e = (*v)(((PyObject*)p->xi), a); if (e) return e;
+  }
+  if (p->vert) {
+    e = (*v)(((PyObject*)p->vert), a); if (e) return e;
+  }
+  if (p->vval) {
+    e = (*v)(((PyObject*)p->vval), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_6cloess_loess_kd_tree(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_kd_tree *p = (struct __pyx_obj_6cloess_loess_kd_tree *)o;
+  Py_XDECREF(((PyObject *)p->parameter));
+  p->parameter = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->a));
+  p->a = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->xi));
+  p->xi = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->vert));
+  p->vert = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->vval));
+  p->vval = ((PyArrayObject *)Py_None); Py_INCREF(Py_None);
+  return 0;
+}
+
+static struct PyMethodDef __pyx_methods_6cloess_loess_kd_tree[] = {
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_loess_kd_tree = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  0, /*nb_divide*/
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  0, /*nb_coerce*/
+  0, /*nb_int*/
+  0, /*nb_long*/
+  0, /*nb_float*/
+  0, /*nb_oct*/
+  0, /*nb_hex*/
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  0, /*nb_inplace_divide*/
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_loess_kd_tree = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_loess_kd_tree = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_loess_kd_tree = {
+  0, /*bf_getreadbuffer*/
+  0, /*bf_getwritebuffer*/
+  0, /*bf_getsegcount*/
+  0, /*bf_getcharbuffer*/
+};
+
+PyTypeObject __pyx_type_6cloess_loess_kd_tree = {
+  PyObject_HEAD_INIT(0)
+  0, /*ob_size*/
+  "cloess.loess_kd_tree", /*tp_name*/
+  sizeof(struct __pyx_obj_6cloess_loess_kd_tree), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_6cloess_loess_kd_tree, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  0, /*tp_compare*/
+  0, /*tp_repr*/
+  &__pyx_tp_as_number_loess_kd_tree, /*tp_as_number*/
+  &__pyx_tp_as_sequence_loess_kd_tree, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_loess_kd_tree, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_loess_kd_tree, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_6cloess_loess_kd_tree, /*tp_traverse*/
+  __pyx_tp_clear_6cloess_loess_kd_tree, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_6cloess_loess_kd_tree, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_f_6cloess_13loess_kd_tree___init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_6cloess_loess_kd_tree, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+};
+
+static PyObject *__pyx_tp_new_6cloess_loess_model(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  struct __pyx_obj_6cloess_loess_model *p = (struct __pyx_obj_6cloess_loess_model *)o;
+  p->parametric_flags = Py_None; Py_INCREF(Py_None);
+  p->drop_square_flags = Py_None; Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_6cloess_loess_model(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_model *p = (struct __pyx_obj_6cloess_loess_model *)o;
+  Py_XDECREF(p->parametric_flags);
+  Py_XDECREF(p->drop_square_flags);
+  (*o->ob_type->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_6cloess_loess_model(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_6cloess_loess_model *p = (struct __pyx_obj_6cloess_loess_model *)o;
+  if (p->parametric_flags) {
+    e = (*v)(p->parametric_flags, a); if (e) return e;
+  }
+  if (p->drop_square_flags) {
+    e = (*v)(p->drop_square_flags, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_6cloess_loess_model(PyObject *o) {
+  struct __pyx_obj_6cloess_loess_model *p = (struct __pyx_obj_6cloess_loess_model *)o;
+  Py_XDECREF(p->parametric_flags);
+  p->parametric_flags = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(p->drop_square_flags);
+  p->drop_square_flags = Py_None; Py_INCREF(Py_None);
+  return 0;
+}
+
+static struct PyMethodDef __pyx_methods_6cloess_loess_model[] = {
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_loess_model = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  0, /*nb_divide*/
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  0, /*nb_coerce*/
+  0, /*nb_int*/
+  0, /*nb_long*/
+  0, /*nb_float*/
+  0, /*nb_oct*/
+  0, /*nb_hex*/
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  0, /*nb_inplace_divide*/
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_loess_model = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_loess_model = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_loess_model = {
+  0, /*bf_getreadbuffer*/
+  0, /*bf_getwritebuffer*/
+  0, /*bf_getsegcount*/
+  0, /*bf_getcharbuffer*/
+};
+
+PyTypeObject __pyx_type_6cloess_loess_model = {
+  PyObject_HEAD_INIT(0)
+  0, /*ob_size*/
+  "cloess.loess_model", /*tp_name*/
+  sizeof(struct __pyx_obj_6cloess_loess_model), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_6cloess_loess_model, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  0, /*tp_compare*/
+  __pyx_f_6cloess_11loess_model___repr__, /*tp_repr*/
+  &__pyx_tp_as_number_loess_model, /*tp_as_number*/
+  &__pyx_tp_as_sequence_loess_model, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_loess_model, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  __pyx_f_6cloess_11loess_model___str__, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_loess_model, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_6cloess_loess_model, /*tp_traverse*/
+  __pyx_tp_clear_6cloess_loess_model, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_6cloess_loess_model, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_f_6cloess_11loess_model___init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_6cloess_loess_model, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+};
+
+static PyObject *__pyx_tp_new_6cloess_loess(PyTypeObject *t, PyObject *a, PyObject *k) {
+  PyObject *o = (*t->tp_alloc)(t, 0);
+  struct __pyx_obj_6cloess_loess *p = (struct __pyx_obj_6cloess_loess *)o;
+  p->inputs = ((struct __pyx_obj_6cloess_loess_inputs *)Py_None); Py_INCREF(Py_None);
+  p->model = ((struct __pyx_obj_6cloess_loess_model *)Py_None); Py_INCREF(Py_None);
+  p->control = ((struct __pyx_obj_6cloess_loess_control *)Py_None); Py_INCREF(Py_None);
+  p->kd_tree = ((struct __pyx_obj_6cloess_loess_kd_tree *)Py_None); Py_INCREF(Py_None);
+  p->outputs = ((struct __pyx_obj_6cloess_loess_outputs *)Py_None); Py_INCREF(Py_None);
+  return o;
+}
+
+static void __pyx_tp_dealloc_6cloess_loess(PyObject *o) {
+  struct __pyx_obj_6cloess_loess *p = (struct __pyx_obj_6cloess_loess *)o;
+  Py_XDECREF(((PyObject *)p->inputs));
+  Py_XDECREF(((PyObject *)p->model));
+  Py_XDECREF(((PyObject *)p->control));
+  Py_XDECREF(((PyObject *)p->kd_tree));
+  Py_XDECREF(((PyObject *)p->outputs));
+  (*o->ob_type->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_6cloess_loess(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_6cloess_loess *p = (struct __pyx_obj_6cloess_loess *)o;
+  if (p->inputs) {
+    e = (*v)(((PyObject*)p->inputs), a); if (e) return e;
+  }
+  if (p->model) {
+    e = (*v)(((PyObject*)p->model), a); if (e) return e;
+  }
+  if (p->control) {
+    e = (*v)(((PyObject*)p->control), a); if (e) return e;
+  }
+  if (p->kd_tree) {
+    e = (*v)(((PyObject*)p->kd_tree), a); if (e) return e;
+  }
+  if (p->outputs) {
+    e = (*v)(((PyObject*)p->outputs), a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_6cloess_loess(PyObject *o) {
+  struct __pyx_obj_6cloess_loess *p = (struct __pyx_obj_6cloess_loess *)o;
+  Py_XDECREF(((PyObject *)p->inputs));
+  p->inputs = ((struct __pyx_obj_6cloess_loess_inputs *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->model));
+  p->model = ((struct __pyx_obj_6cloess_loess_model *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->control));
+  p->control = ((struct __pyx_obj_6cloess_loess_control *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->kd_tree));
+  p->kd_tree = ((struct __pyx_obj_6cloess_loess_kd_tree *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(((PyObject *)p->outputs));
+  p->outputs = ((struct __pyx_obj_6cloess_loess_outputs *)Py_None); Py_INCREF(Py_None);
+  return 0;
+}
+
+static struct PyMethodDef __pyx_methods_6cloess_loess[] = {
+  {"summary", (PyCFunction)__pyx_f_6cloess_5loess_summary, METH_VARARGS|METH_KEYWORDS, 0},
+  {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_loess = {
+  0, /*nb_add*/
+  0, /*nb_subtract*/
+  0, /*nb_multiply*/
+  0, /*nb_divide*/
+  0, /*nb_remainder*/
+  0, /*nb_divmod*/
+  0, /*nb_power*/
+  0, /*nb_negative*/
+  0, /*nb_positive*/
+  0, /*nb_absolute*/
+  0, /*nb_nonzero*/
+  0, /*nb_invert*/
+  0, /*nb_lshift*/
+  0, /*nb_rshift*/
+  0, /*nb_and*/
+  0, /*nb_xor*/
+  0, /*nb_or*/
+  0, /*nb_coerce*/
+  0, /*nb_int*/
+  0, /*nb_long*/
+  0, /*nb_float*/
+  0, /*nb_oct*/
+  0, /*nb_hex*/
+  0, /*nb_inplace_add*/
+  0, /*nb_inplace_subtract*/
+  0, /*nb_inplace_multiply*/
+  0, /*nb_inplace_divide*/
+  0, /*nb_inplace_remainder*/
+  0, /*nb_inplace_power*/
+  0, /*nb_inplace_lshift*/
+  0, /*nb_inplace_rshift*/
+  0, /*nb_inplace_and*/
+  0, /*nb_inplace_xor*/
+  0, /*nb_inplace_or*/
+  0, /*nb_floor_divide*/
+  0, /*nb_true_divide*/
+  0, /*nb_inplace_floor_divide*/
+  0, /*nb_inplace_true_divide*/
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_loess = {
+  0, /*sq_length*/
+  0, /*sq_concat*/
+  0, /*sq_repeat*/
+  0, /*sq_item*/
+  0, /*sq_slice*/
+  0, /*sq_ass_item*/
+  0, /*sq_ass_slice*/
+  0, /*sq_contains*/
+  0, /*sq_inplace_concat*/
+  0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_loess = {
+  0, /*mp_length*/
+  0, /*mp_subscript*/
+  0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_loess = {
+  0, /*bf_getreadbuffer*/
+  0, /*bf_getwritebuffer*/
+  0, /*bf_getsegcount*/
+  0, /*bf_getcharbuffer*/
+};
+
+PyTypeObject __pyx_type_6cloess_loess = {
+  PyObject_HEAD_INIT(0)
+  0, /*ob_size*/
+  "cloess.loess", /*tp_name*/
+  sizeof(struct __pyx_obj_6cloess_loess), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_6cloess_loess, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  0, /*tp_compare*/
+  0, /*tp_repr*/
+  &__pyx_tp_as_number_loess, /*tp_as_number*/
+  &__pyx_tp_as_sequence_loess, /*tp_as_sequence*/
+  &__pyx_tp_as_mapping_loess, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  &__pyx_tp_as_buffer_loess, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_6cloess_loess, /*tp_traverse*/
+  __pyx_tp_clear_6cloess_loess, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_6cloess_loess, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  __pyx_f_6cloess_5loess___init__, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_6cloess_loess, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+};
+
+static struct PyMethodDef __pyx_methods[] = {
+  {0, 0, 0, 0}
+};
+
+static void __pyx_init_filenames(void); /*proto*/
+
+PyMODINIT_FUNC initcloess(void); /*proto*/
+PyMODINIT_FUNC initcloess(void) {
+  PyObject *__pyx_1 = 0;
+  PyObject *__pyx_2 = 0;
+  __pyx_init_filenames();
+  __pyx_m = Py_InitModule4("cloess", __pyx_methods, 0, 0, PYTHON_API_VERSION);
+  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
+  __pyx_b = PyImport_AddModule("__builtin__");
+  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
+  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
+  if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
+  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; goto __pyx_L1;};
+  __pyx_type_6cloess_loess_inputs.tp_free = _PyObject_GC_Del;
+  if (PyType_Ready(&__pyx_type_6cloess_loess_inputs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;}
+  if (PyObject_SetAttrString(__pyx_m, "loess_inputs", (PyObject *)&__pyx_type_6cloess_loess_inputs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;}
+  __pyx_ptype_6cloess_loess_inputs = &__pyx_type_6cloess_loess_inputs;
+  if (PyType_Ready(&__pyx_type_6cloess_loess_control) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;}
+  if (PyObject_SetAttrString(__pyx_m, "loess_control", (PyObject *)&__pyx_type_6cloess_loess_control) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; goto __pyx_L1;}
+  __pyx_ptype_6cloess_loess_control = &__pyx_type_6cloess_loess_control;
+  __pyx_type_6cloess_loess_outputs.tp_free = _PyObject_GC_Del;
+  if (PyType_Ready(&__pyx_type_6cloess_loess_outputs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; goto __pyx_L1;}
+  if (PyObject_SetAttrString(__pyx_m, "loess_outputs", (PyObject *)&__pyx_type_6cloess_loess_outputs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; goto __pyx_L1;}
+  __pyx_ptype_6cloess_loess_outputs = &__pyx_type_6cloess_loess_outputs;
+  __pyx_type_6cloess_loess_kd_tree.tp_free = _PyObject_GC_Del;
+  if (PyType_Ready(&__pyx_type_6cloess_loess_kd_tree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;}
+  if (PyObject_SetAttrString(__pyx_m, "loess_kd_tree", (PyObject *)&__pyx_type_6cloess_loess_kd_tree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; goto __pyx_L1;}
+  __pyx_ptype_6cloess_loess_kd_tree = &__pyx_type_6cloess_loess_kd_tree;
+  __pyx_type_6cloess_loess_model.tp_free = _PyObject_GC_Del;
+  if (PyType_Ready(&__pyx_type_6cloess_loess_model) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; goto __pyx_L1;}
+  if (PyObject_SetAttrString(__pyx_m, "loess_model", (PyObject *)&__pyx_type_6cloess_loess_model) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; goto __pyx_L1;}
+  __pyx_ptype_6cloess_loess_model = &__pyx_type_6cloess_loess_model;
+  __pyx_type_6cloess_loess.tp_free = _PyObject_GC_Del;
+  if (PyType_Ready(&__pyx_type_6cloess_loess) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
+  if (PyObject_SetAttrString(__pyx_m, "loess", (PyObject *)&__pyx_type_6cloess_loess) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
+  __pyx_ptype_6cloess_loess = &__pyx_type_6cloess_loess;
+  __pyx_ptype_7c_numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr)); if (!__pyx_ptype_7c_numpy_dtype) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; goto __pyx_L1;}
+  __pyx_ptype_7c_numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject)); if (!__pyx_ptype_7c_numpy_ndarray) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; goto __pyx_L1;}
+  __pyx_ptype_7c_numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject)); if (!__pyx_ptype_7c_numpy_flatiter) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 90; goto __pyx_L1;}
+  __pyx_ptype_7c_numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject)); if (!__pyx_ptype_7c_numpy_broadcast) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; goto __pyx_L1;}
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":7 */
+  __pyx_1 = __Pyx_Import(__pyx_n_numpy, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
+  if (PyObject_SetAttr(__pyx_m, __pyx_n__N, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
+  Py_DECREF(__pyx_1); __pyx_1 = 0;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":9 */
+  import_array();
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":22 */
+  Py_INCREF(Py_None);
+  __pyx_k2 = Py_None;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":202 */
+  __pyx_k3 = 0.75;
+  __pyx_k4 = 2;
+  __pyx_k5 = 1;
+  __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; goto __pyx_L1;}
+  __pyx_k6 = __pyx_1;
+  __pyx_1 = 0;
+  __pyx_2 = __Pyx_GetName(__pyx_b, __pyx_n_False); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; goto __pyx_L1;}
+  __pyx_k7 = __pyx_2;
+  __pyx_2 = 0;
+  Py_INCREF(__pyx_n_gaussian);
+  __pyx_k9 = __pyx_n_gaussian;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":273 */
+  Py_INCREF(Py_None);
+  __pyx_k10 = Py_None;
+
+  /* "/home/backtopop/workspace/pyloess_c/src/cloess.pyx":309 */
+  return;
+  __pyx_L1:;
+  Py_XDECREF(__pyx_1);
+  Py_XDECREF(__pyx_2);
+  __Pyx_AddTraceback("cloess");
+}
+
+static char *__pyx_filenames[] = {
+  "cloess.pyx",
+  "c_numpy.pxd",
+};
+
+/* Runtime support code */
+
+static void __pyx_init_filenames(void) {
+  __pyx_f = __pyx_filenames;
+}
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
+    PyObject *__import__ = 0;
+    PyObject *empty_list = 0;
+    PyObject *module = 0;
+    PyObject *global_dict = 0;
+    PyObject *empty_dict = 0;
+    PyObject *list;
+    __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
+    if (!__import__)
+        goto bad;
+    if (from_list)
+        list = from_list;
+    else {
+        empty_list = PyList_New(0);
+        if (!empty_list)
+            goto bad;
+        list = empty_list;
+    }
+    global_dict = PyModule_GetDict(__pyx_m);
+    if (!global_dict)
+        goto bad;
+    empty_dict = PyDict_New();
+    if (!empty_dict)
+        goto bad;
+    module = PyObject_CallFunction(__import__, "OOOO",
+        name, global_dict, empty_dict, list);
+bad:
+    Py_XDECREF(empty_list);
+    Py_XDECREF(__import__);
+    Py_XDECREF(empty_dict);
+    return module;
+}
+
+static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
+    PyObject *result;
+    result = PyObject_GetAttr(dict, name);
+    if (!result)
+        PyErr_SetObject(PyExc_NameError, name);
+    return result;
+}
+
+static PyObject *__Pyx_GetStdout(void) {
+    PyObject *f = PySys_GetObject("stdout");
+    if (!f) {
+        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+    }
+    return f;
+}
+
+static int __Pyx_PrintItem(PyObject *v) {
+    PyObject *f;
+    
+    if (!(f = __Pyx_GetStdout()))
+        return -1;
+    if (PyFile_SoftSpace(f, 1)) {
+        if (PyFile_WriteString(" ", f) < 0)
+            return -1;
+    }
+    if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
+        return -1;
+    if (PyString_Check(v)) {
+        char *s = PyString_AsString(v);
+        int len = PyString_Size(v);
+        if (len > 0 &&
+            isspace(Py_CHARMASK(s[len-1])) &&
+            s[len-1] != ' ')
+                PyFile_SoftSpace(f, 0);
+    }
+    return 0;
+}
+
+static int __Pyx_PrintNewline(void) {
+    PyObject *f;
+    
+    if (!(f = __Pyx_GetStdout()))
+        return -1;
+    if (PyFile_WriteString("\n", f) < 0)
+        return -1;
+    PyFile_SoftSpace(f, 0);
+    return 0;
+}
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
+    Py_XINCREF(type);
+    Py_XINCREF(value);
+    Py_XINCREF(tb);
+    /* First, check the traceback argument, replacing None with NULL. */
+    if (tb == Py_None) {
+        Py_DECREF(tb);
+        tb = 0;
+    }
+    else if (tb != NULL && !PyTraceBack_Check(tb)) {
+        PyErr_SetString(PyExc_TypeError,
+            "raise: arg 3 must be a traceback or None");
+        goto raise_error;
+    }
+    /* Next, replace a missing value with None */
+    if (value == NULL) {
+        value = Py_None;
+        Py_INCREF(value);
+    }
+    /* Next, repeatedly, replace a tuple exception with its first item */
+    while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
+        PyObject *tmp = type;
+        type = PyTuple_GET_ITEM(type, 0);
+        Py_INCREF(type);
+        Py_DECREF(tmp);
+    }
+    if (PyString_Check(type)) {
+        if (PyErr_Warn(PyExc_DeprecationWarning,
+                "raising a string exception is deprecated"))
+            goto raise_error;
+    }
+    else if (PyType_Check(type) || PyClass_Check(type))
+        ; /*PyErr_NormalizeException(&type, &value, &tb);*/
+    else {
+        /* Raising an instance.  The value should be a dummy. */
+        if (value != Py_None) {
+            PyErr_SetString(PyExc_TypeError,
+                "instance exception may not have a separate value");
+            goto raise_error;
+        }
+        /* Normalize to raise <class>, <instance> */
+        Py_DECREF(value);
+        value = type;
+        if (PyInstance_Check(type))
+            type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+        else
+            type = (PyObject*) type->ob_type;
+        Py_INCREF(type);
+    }
+    PyErr_Restore(type, value, tb);
+    return;
+raise_error:
+    Py_XDECREF(value);
+    Py_XDECREF(type);
+    Py_XDECREF(tb);
+    return;
+}
+
+static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
+    if (!type) {
+        PyErr_Format(PyExc_SystemError, "Missing type object");
+        return 0;
+    }
+    if (obj == Py_None || PyObject_TypeCheck(obj, type))
+        return 1;
+    PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
+        obj->ob_type->tp_name, type->tp_name);
+    return 0;
+}
+
+static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
+    while (t->p) {
+        *t->p = PyString_InternFromString(t->s);
+        if (!*t->p)
+            return -1;
+        ++t;
+    }
+    return 0;
+}
+
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
+    while (t->p) {
+        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
+        if (!*t->p)
+            return -1;
+        ++t;
+    }
+    return 0;
+}
+
+static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, 
+    long size) 
+{
+    PyObject *py_module_name = 0;
+    PyObject *py_class_name = 0;
+    PyObject *py_name_list = 0;
+    PyObject *py_module = 0;
+    PyObject *result = 0;
+    
+    py_module_name = PyString_FromString(module_name);
+    if (!py_module_name)
+        goto bad;
+    py_class_name = PyString_FromString(class_name);
+    if (!py_class_name)
+        goto bad;
+    py_name_list = PyList_New(1);
+    if (!py_name_list)
+        goto bad;
+    Py_INCREF(py_class_name);
+    if (PyList_SetItem(py_name_list, 0, py_class_name) < 0)
+        goto bad;
+    py_module = __Pyx_Import(py_module_name, py_name_list);
+    if (!py_module)
+        goto bad;
+    result = PyObject_GetAttr(py_module, py_class_name);
+    if (!result)
+        goto bad;
+    if (!PyType_Check(result)) {
+        PyErr_Format(PyExc_TypeError, 
+            "%s.%s is not a type object",
+            module_name, class_name);
+        goto bad;
+    }
+    if (((PyTypeObject *)result)->tp_basicsize != size) {
+        PyErr_Format(PyExc_ValueError, 
+            "%s.%s does not appear to be the correct type object",
+            module_name, class_name);
+        goto bad;
+    }
+    goto done;
+bad:
+    Py_XDECREF(result);
+    result = 0;
+done:
+    Py_XDECREF(py_module_name);
+    Py_XDECREF(py_class_name);
+    Py_XDECREF(py_name_list);
+    return (PyTypeObject *)result;
+}
+
+#include "compile.h"
+#include "frameobject.h"
+#include "traceback.h"
+
+static void __Pyx_AddTraceback(char *funcname) {
+    PyObject *py_srcfile = 0;
+    PyObject *py_funcname = 0;
+    PyObject *py_globals = 0;
+    PyObject *empty_tuple = 0;
+    PyObject *empty_string = 0;
+    PyCodeObject *py_code = 0;
+    PyFrameObject *py_frame = 0;
+    
+    py_srcfile = PyString_FromString(__pyx_filename);
+    if (!py_srcfile) goto bad;
+    py_funcname = PyString_FromString(funcname);
+    if (!py_funcname) goto bad;
+    py_globals = PyModule_GetDict(__pyx_m);
+    if (!py_globals) goto bad;
+    empty_tuple = PyTuple_New(0);
+    if (!empty_tuple) goto bad;
+    empty_string = PyString_FromString("");
+    if (!empty_string) goto bad;
+    py_code = PyCode_New(
+        0,            /*int argcount,*/
+        0,            /*int nlocals,*/
+        0,            /*int stacksize,*/
+        0,            /*int flags,*/
+        empty_string, /*PyObject *code,*/
+        empty_tuple,  /*PyObject *consts,*/
+        empty_tuple,  /*PyObject *names,*/
+        empty_tuple,  /*PyObject *varnames,*/
+        empty_tuple,  /*PyObject *freevars,*/
+        empty_tuple,  /*PyObject *cellvars,*/
+        py_srcfile,   /*PyObject *filename,*/
+        py_funcname,  /*PyObject *name,*/
+        __pyx_lineno,   /*int firstlineno,*/
+        empty_string  /*PyObject *lnotab*/
+    );
+    if (!py_code) goto bad;
+    py_frame = PyFrame_New(
+        PyThreadState_Get(), /*PyThreadState *tstate,*/
+        py_code,             /*PyCodeObject *code,*/
+        py_globals,          /*PyObject *globals,*/
+        0                    /*PyObject *locals*/
+    );
+    if (!py_frame) goto bad;
+    py_frame->f_lineno = __pyx_lineno;
+    PyTraceBack_Here(py_frame);
+bad:
+    Py_XDECREF(py_srcfile);
+    Py_XDECREF(py_funcname);
+    Py_XDECREF(empty_tuple);
+    Py_XDECREF(empty_string);
+    Py_XDECREF(py_code);
+    Py_XDECREF(py_frame);
+}

Added: trunk/Lib/sandbox/pyloess/sandbox/src/cloess.h
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/cloess.h	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/cloess.h	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,87 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "loess.h"
+/*
+loess.c
+*/
+void loess_setup(double *x, double *y, int n, int p, loess *lo);
+void loess_fit(loess *lo);
+void
+loess_(double *y, double *x_, int *size_info, double *weights, double *span,
+       int *degree, int *parametric, int *drop_square, int *normalize,
+       char **statistics, char **surface, double *cell, char **trace_hat_in,
+       int *iterations, double *fitted_values, double *fitted_residuals,
+       double *enp, double *s, double *one_delta, double *two_delta,
+       double *pseudovalues, double *trace_hat_out, double *diagonal,
+       double *robust, double *divisor, int *parameter, int *a, double *xi,
+       double *vert, double *vval);
+void loess_free_mem(loess *lo);
+void loess_summary(loess *lo);
+void condition(char **surface, char *new_stat, char **trace_hat_in);
+int comp(double *d1, double *d2);
+
+/*
+loessc.c
+*/
+void
+loess_raw(double *y, double *x, double *weights, double *robust, int *d,
+          int*n, double *span, int *degree, int *nonparametric,
+          int *drop_square, int *sum_drop_sqr, double *cell, char **surf_stat,
+          double *surface, int *parameter, int *a, double *xi, double *vert,
+          double *vval, double *diagonal, double *trL, double *one_delta,
+          double *two_delta, int *setLf);
+void
+loess_dfit(double *y, double *x, double *x_evaluate, double *weights,
+           double *span, int *degree, int *nonparametric,
+           int *drop_square, int *sum_drop_sqr, int *d, int *n, int *m,
+           double *fit);
+void
+loess_dfitse(double *y, double *x, double *x_evaluate, double *weights,
+             double *robust, int *family, double *span, int *degree,
+             int *nonparametric, int *drop_square, int *sum_drop_sqr,
+             int *d, int *n, int *m, double *fit, double *L);
+void
+loess_ifit(int *parameter, int *a, double *xi, double *vert, double *vval,
+           int *m, double *x_evaluate, double *fit);
+void
+loess_ise(double *y, double *x, double *x_evaluate, double *weights,
+          double *span, int *degree, int *nonparametric, int *drop_square,
+          int *sum_drop_sqr, double *cell, int *d, int *n, int *m,
+          double *fit, double *L);
+void
+loess_workspace(int *d, int *n, double *span, int *degree,
+                int *nonparametric, int *drop_square, int *sum_drop_sqr,
+                int *setLf);
+void
+loess_prune(int *parameter, int *a, double *xi, double *vert, double *vval);
+void
+loess_grow(int *parameter, int *a, double *xi, double *vert, double *vval);
+void
+F77_SUB(lowesw)(double *res, int *n, double *rw, int *pi);
+void
+F77_SUB(lowesp)(int *n, double *y, double *yhat, double *pwgts,
+                double *rwgts, int *pi, double *ytilde);
+                
+//                
+///*
+//misc.c
+//*/
+//void
+//anova(struct loess_struct *one, struct loess_struct *two,
+//      struct anova_struct *out);
+//
+///*
+//predict.c
+//*/
+//void
+//predict(double *eval, int m, struct loess_struct *lo, struct pred_struct *pre,
+//        int se);
+//void
+//pred_(double *y, double *x_, double *new_x, int *size_info, double *s,
+//      double *weights, double *robust, double *span, int *degree,
+//      int *normalize, int *parametric, int *drop_square, char **surface,
+//      double *cell, char **family, int *parameter, int *a, double *xi,
+//      double *vert, double *vval, double *divisor, int *se, double *fit,
+//      double *se_fit);
+//void
+//pred_free_mem(struct pred_struct *pre);

Added: trunk/Lib/sandbox/pyloess/sandbox/src/cloess.pyx
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/cloess.pyx	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/cloess.pyx	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,315 @@
+# -*- Mode: Python -*-  
+cimport c_python
+cimport c_numpy
+from c_numpy cimport ndarray, npy_intp, \
+    PyArray_SIZE, PyArray_EMPTY, PyArray_FROMANY, \
+    NPY_INT, NPY_DOUBLE, NPY_OWNDATA, NPY_ALIGNED
+import numpy as _N
+# NumPy must be initialized
+c_numpy.import_array()
+
+cimport c_loess
+    
+#####---------------------------------------------------------------------------
+#---- ---- loess model ---
+#####---------------------------------------------------------------------------
+
+cdef class loess_inputs:
+    cdef c_loess.c_loess_inputs _inputs
+    cdef public long nobs, nvar
+    cdef readonly ndarray x, y, weights
+    
+    def __init__(self, object x, object y, object weights=None):
+        cdef ndarray x_ndr, y_ndr
+        cdef double *x_dat, *y_in_dat, *w_dat
+        cdef npy_intp n, p
+        cdef npy_intp *dims
+        print "DEBUG: Initializing loess_inputs...",
+        self.x = <ndarray>PyArray_FROMANY(x, NPY_DOUBLE, 1, 1, NPY_OWNDATA)
+        self.y = <ndarray>PyArray_FROMANY(y, NPY_DOUBLE, 1, 1, NPY_OWNDATA)
+        #
+        if self.x.ndim > 2:
+            raise ValueError,"Argument 'x' should be 2D at most!"
+        n = len(self.x)
+        p = self.x.size / n
+        # Initialize the python side ............
+        self.nobs = <long>n
+        self.nvar = <long>p
+        dims[0] = n
+        # ... input weights ...
+        if weights is None:
+            self.weights = <ndarray>PyArray_EMPTY(1, dims, NPY_DOUBLE, NPY_ALIGNED)
+            w_dat = <double *>self.weights.data
+            for i from 0 <= i < dims[0]:
+                w_dat[i] = 1
+        else:
+            self.weights = <ndarray>PyArray_FROMANY(weights, NPY_DOUBLE, 1, 1, NPY_OWNDATA)
+            if self.weights.ndim > 1 or self.weights.size != n:
+                raise ValueError, "Invalid size of the 'weights' vector!"
+            w_dat = <double *>self.weights.data
+        # Initialize the underlying C object ....
+        self._inputs.n = self.nobs
+        self._inputs.p = self.nvar
+        self._inputs.x = <double *>self.x.data
+        self._inputs.y = <double *>self.y.data
+        self._inputs.weights = <double *>self.weights.data
+        
+#        for i from 0 <= i < (self.nobs*self.nvar):
+#            self._inputs.x[i] = self.x.data[i]
+#        for i from 0 <= i < self.nobs:
+#            self._inputs.y[i] = self.y.data[i]
+#            self._inputs.weights[i] = w_dat[i]
+        print " OK."
+        return
+
+       
+#####---------------------------------------------------------------------------
+#---- ---- loess control ---
+#####---------------------------------------------------------------------------
+cdef class loess_control:
+    cdef c_loess.c_loess_control _control
+    cdef public char *surface, *statistics, *trace_hat
+    cdef public double cell
+    cdef public int iterations
+    
+    def __init__(self):
+        print "DEBUG: Initializing loess_control...",
+        self.surface = self._control.surface = "interpolate"
+        self.statistics = self._control.statistics = "approximate"
+        self.cell = self._control.cell = 0.2
+        self.trace_hat = self._control.trace_hat = "wait.to.decide"
+        self.iterations = self._control.iterations = 4
+        print "OK."
+        return 
+        
+    def __str__(self):
+        strg = ["Control          :",
+                "Surface type     : %s" % self.surface,
+                "Statistics       : %s" % self.statistics,
+                "Trace estimation : %s" % self.trace_hat,
+                "Cell size        : %s" % self.cell,
+                "Nb iterations    : %s" % self.iterations,]
+        return '\n'.join(strg)
+        
+    
+#####---------------------------------------------------------------------------
+#---- ---- loess outputs ---
+#####---------------------------------------------------------------------------
+cdef class loess_outputs:
+    cdef c_loess.c_loess_outputs _outputs
+    cdef ndarray fitted_values, fitted_residuals, pseudovalues, diagonal, robust, divisor
+    cdef double enp, s, one_delta, two_delta, trace_hat
+    
+    def __init__(self, n, p):
+        cdef npy_intp *rows, *cols
+        #cdef double *fv_dat, *fr_dat, *pv_dat, *diag_dat, *rw_dat, *div_dat
+        rows[0] = <npy_intp>n
+        cols[0] = <npy_intp>p
+        print "DEBUG: Initializing loess_outputs...",
+        # Initialize the python side ............
+        self.fitted_values = <ndarray>PyArray_EMPTY(1, rows, NPY_DOUBLE, NPY_ALIGNED)
+        self.fitted_residuals = <ndarray>PyArray_EMPTY(1, rows, NPY_DOUBLE, NPY_ALIGNED)
+        self.pesudovalues = <ndarray>PyArray_EMPTY(1, rows, NPY_DOUBLE, NPY_ALIGNED)
+        self.diagonal = <ndarray>PyArray_EMPTY(1, rows, NPY_DOUBLE, NPY_ALIGNED)
+        self.robust = <ndarray>PyArray_EMPTY(1, rows, NPY_DOUBLE, NPY_ALIGNED)
+        self.divisor = <ndarray>PyArray_EMPTY(1, cols, NPY_DOUBLE, NPY_ALIGNED)
+        # Initialize the C side .................
+        self._outputs.fitted_values = <double *>self.fitted_values.data
+        self._outputs.fitted_residuals = <double *>self.fitted_residuals.data
+        self._outputs.pseudovalues = <double *>self.pseudovalues.data
+        self._outputs.diagonal = <double *>self.diagonal.data
+        self._outputs.robust = <double *>self.robust.data
+        self._outputs.divisor = <double *>self.divisor.data
+        # Common initialization .................
+        self.enp = self._outputs.enp = 0
+        self.s = self._outputs.s = 0
+        self.one_delta = self._outputs.one_delta = 0
+        self.two_delta = self._outputs.two_delta = 0
+        self.trace_hat = self._outputs.trace_hat = 0 
+        print "OK."   
+        
+#    def __str__(self):
+#        strg = ["Outputs          :",
+#                "enp       : %s" % self.enp,
+#                "s : %s" % self.s,
+#                "Deltas        : %s/%s" % (self.one_delta, self.two_delta),
+#                "Divisor    : %s" % self.divisor,]
+#        return '\n'.join(strg)
+    
+#####---------------------------------------------------------------------------
+#---- ---- loess kd_tree ---
+#####---------------------------------------------------------------------------
+cdef class loess_kd_tree:
+    cdef c_loess.c_loess_kd_tree _kdtree
+    cdef ndarray parameter, a, xi, vert, vval
+    
+    def __init__(self, long n, long p):
+        cdef long maxkd, nval, nvert
+        cdef npy_intp *nmaxkd, *nnval, *nnvert, *npars
+        #
+        print "DEBUG: Initializing loess_kdtree...",
+        maxkd = max(n, 200)
+        nvert = p * 2
+        nval = (p+1) * maxkd
+        # Initialize the python side ............
+        print "(python side)",
+        nmaxkd[0] = <npy_intp>maxkd
+        nnvert[0] = <npy_intp>nvert
+        nnval[0] = <npy_intp>nval
+        npars[0] = <npy_intp>8
+        self.parameter = <ndarray>PyArray_EMPTY(1, npars, NPY_LONG, NPY_ALIGNED)
+        self.a = <ndarray>PyArray_EMPTY(1, nmaxkd, NPY_LONG, NPY_ALIGNED)
+        self.xi = <ndarray>PyArray_EMPTY(1, nmaxkd, NPY_DOUBLE, NPY_ALIGNED)
+        self.vert = <ndarray>PyArray_EMPTY(1, nnvert, NPY_DOUBLE, NPY_ALIGNED)
+        self.vval = <ndarray>PyArray_EMPTY(1, nnval, NPY_DOUBLE, NPY_ALIGNED)
+#        self.parameter = <ndarray>_N.empty((8,), _N.long, order='F')
+#        self.a = <ndarray>_N.empty((maxkd,), _N.long, order='F')
+#        self.xi = <ndarray>_N.empty((maxkd,), _N.float, order='F')
+#        self.vert = <ndarray>_N.empty((p*2,), _N.float, order='F')
+#        self.vval = <ndarray>_N.empty((nnval,), _N.float, order='F')
+        # Initialize the C side .................
+        print "(C side)",
+        self._kdtree.parameter = <long *>self.parameter.data
+        self._kdtree.a = <long *>self.a.data
+        self._kdtree.xi = <double *>self.xi.data
+        self._kdtree.vert = <double *>self.vert.data
+        self._kdtree.vval = <double *>self.vval.data
+#        # FIXME : Do we need to fill the arrays ?
+#        for i from 0 <= i < 8:
+#            self._kdtree.parameter[i] = 0
+#        for i from 0 <= i < len(self.a):
+#            self._kdtree.a[i] = 0
+#            self._kdtree.xi[i] = 0
+#        for i from 0 <= i < (p*2):
+#            self._kdtree.vert[i] = 0
+#        for i from 0 <= i < nnval:
+#            self._kdtree.vval[i] = 0
+        print "OK."
+        return
+    
+#####---------------------------------------------------------------------------
+#---- ---- loess model ---
+#####---------------------------------------------------------------------------
+
+cdef class loess_model:
+    cdef c_loess.c_loess_model _model
+    cdef double span
+    cdef int degree, normalize
+    cdef char *family
+#    cdef ndarray parametric_flags, drop_square_flags
+    cdef object parametric_flags, drop_square_flags
+    #
+    def __init__(self, double span=0.75, int degree=2, int normalize=1, 
+                 object parametric_in=False, object drop_square_in=False, 
+                 object family="gaussian"):
+        cdef int i
+        cdef int *parmf_dat, *dropsq_dat
+        cdef npy_intp *npars
+        print "DEBUG: Initializing loess_model...",
+        self.span = self._model.span = span
+        self.degree = self._model.degree = degree
+        self.normalize = self._model.normalize = normalize
+        self.family = self._model.family = family
+        # FIXME : trying to use a ndarray crashes around here....
+        self.parametric_flags = [None]*8
+        if hasattr(parametric_in, '__len__'):
+            for i from 0 <= i < len(parametric_in):
+                self.parametric_flags[i] = parametric_in[i]
+                self._model.parametric[i] = parametric_in[i]
+        else:
+            for i from 0 <= i <=7:
+                self.parametric_flags[i] = parametric_in
+                self._model.parametric[i] = parametric_in
+        #....
+        self.drop_square_flags = [None]*8
+        if hasattr(drop_square_in, '__len__'):
+            for i from 0 <= i < len(drop_square_in):
+                self.drop_square_flags[i] = drop_square_in[i]
+                self._model.drop_square[i] = drop_square_in[i]
+        else:
+            for i from 0 <= i < 8:
+                self.drop_square_flags[i] = drop_square_in
+                self._model.drop_square[i] = drop_square_in
+        print "OK."
+#        npars[0] = 8
+#        self.parametric = <ndarray>PyArray_EMPTY(1, npars, NPY_INT, NPY_ALIGNED)
+#        self.drop_square = <ndarray>PyArray_EMPTY(1, npars, NPY_INT, NPY_ALIGNED)
+#        parmf_dat = <int *>self.parametric_flags.data
+#        dropsq_dat = <int *>self.drop_square_flags.data
+#        for i from 0 <= i < 8:
+#            print "i:%i" % i
+#            parmf_dat[i] = 0
+#            self._model.parametric[i] = parmf_dat[i]
+#            dropsq_dat[i] = 0
+#            self._model.drop_square[i] = dropsq_dat[i]
+#        print "DEBUG: loess_model: initialized"
+        return
+    #
+    def __repr__(self):
+        return "loess model parameters @%s" % id(self)
+    def __str__(self):
+        strg = ["Object      : %s" % self.__name__,
+                "family      : %s" % self._model.family,
+                "span        : %s" % self._model.span,
+                "degree      : %s" % self._model.degree,
+                "normalized  : %s" % self._model.normalize,
+                "parametric  : %s" % self.parametric,
+                "drop_square : %s" % self.drop_square]
+        return '\n'.join(strg)
+    
+#####---------------------------------------------------------------------------
+#---- ---- loess base class ---
+#####---------------------------------------------------------------------------
+
+cdef class loess:
+#    cdef c_loess.c_loess *_base # If we try the pure C way
+    cdef c_loess.c_loess _base
+    cdef loess_inputs inputs
+    cdef loess_model model
+    cdef loess_control control
+    cdef loess_kd_tree kd_tree
+    cdef loess_outputs outputs
+    
+    def __init__(self, object x, object y, object weights=None):
+        #
+        cdef ndarray x_ndr, y_ndr
+        cdef double *x_dat, *y_dat
+        cdef long n, p
+        cdef int i
+        #
+#        print "Try setup"
+#        # CHECK : The following function segfaults :(
+#        c_loess.loess_setup(x_dat, y_dat, n, d, self._base)
+#        # CHECK : So we gonna try the hard way
+        # Initialize the python side ............
+        self.inputs = loess_inputs(x, y, weights)
+        n = self.inputs.nobs
+        p = self.inputs.nvar
+        self.model = loess_model()
+        self.control = loess_control()
+        self.outputs = loess_outputs(n,p)
+        self.kd_tree = loess_kd_tree(n,p)
+        # Initialize the C side .................
+        print "DEBUG:Initializing loess_cside"
+        self._base.inputs = self.inputs._inputs
+        self._base.model = self.model._model
+        self._base.control = self.control._control
+        self._base.kd_tree = self.kd_tree._kdtree
+        self._base.outputs = self.outputs._outputs
+
+
+
+#        self.inputs = base.in
+#        self.model = base.model
+#        self.kd_tree = base.kd_tree
+#        self.outputs = base.out
+        
+    
+    #......................................................
+    def summary(self):
+        print "Number of Observations         : %d" % self.inputs.n
+        print "Equivalent Number of Parameters: %.1f" % self.outputs.enp
+        if self.model.family == "gaussian":
+            print "Residual Standard Error        : %.4f" % self.outputs.s
+        else:
+            print "Residual Scale Estimate        : %.4f" % self.outputs.s
\ No newline at end of file

Added: trunk/Lib/sandbox/pyloess/sandbox/src/linpack_lite.f
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/linpack_lite.f	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/linpack_lite.f	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,757 @@
+      subroutine dqrsl(x,ldx,n,k,qraux,y,qy,qty,b,rsd,xb,job,info)
+      integer ldx,n,k,job,info
+      double precision x(ldx,1),qraux(1),y(1),qy(1),qty(1),b(1),rsd(1),
+     *                 xb(1)
+c
+c     dqrsl applies the output of dqrdc to compute coordinate
+c     transformations, projections, and least squares solutions.
+c     for k .le. min(n,p), let xk be the matrix
+c
+c            xk = (x(jpvt(1)),x(jpvt(2)), ... ,x(jpvt(k)))
+c
+c     formed from columnns jpvt(1), ... ,jpvt(k) of the original
+c     n x p matrix x that was input to dqrdc (if no pivoting was
+c     done, xk consists of the first k columns of x in their
+c     original order).  dqrdc produces a factored orthogonal matrix q
+c     and an upper triangular matrix r such that
+c
+c              xk = q * (r)
+c                       (0)
+c
+c     this information is contained in coded form in the arrays
+c     x and qraux.
+c
+c     on entry
+c
+c        x      double precision(ldx,p).
+c               x contains the output of dqrdc.
+c
+c        ldx    integer.
+c               ldx is the leading dimension of the array x.
+c
+c        n      integer.
+c               n is the number of rows of the matrix xk.  it must
+c               have the same value as n in dqrdc.
+c
+c        k      integer.
+c               k is the number of columns of the matrix xk.  k
+c               must nnot be greater than min(n,p), where p is the
+c               same as in the calling sequence to dqrdc.
+c
+c        qraux  double precision(p).
+c               qraux contains the auxiliary output from dqrdc.
+c
+c        y      double precision(n)
+c               y contains an n-vector that is to be manipulated
+c               by dqrsl.
+c
+c        job    integer.
+c               job specifies what is to be computed.  job has
+c               the decimal expansion abcde, with the following
+c               meaning.
+c
+c                    if a.ne.0, compute qy.
+c                    if b,c,d, or e .ne. 0, compute qty.
+c                    if c.ne.0, compute b.
+c                    if d.ne.0, compute rsd.
+c                    if e.ne.0, compute xb.
+c
+c               note that a request to compute b, rsd, or xb
+c               automatically triggers the computation of qty, for
+c               which an array must be provided in the calling
+c               sequence.
+c
+c     on return
+c
+c        qy     double precision(n).
+c               qy conntains q*y, if its computation has been
+c               requested.
+c
+c        qty    double precision(n).
+c               qty contains trans(q)*y, if its computation has
+c               been requested.  here trans(q) is the
+c               transpose of the matrix q.
+c
+c        b      double precision(k)
+c               b contains the solution of the least squares problem
+c
+c                    minimize norm2(y - xk*b),
+c
+c               if its computation has been requested.  (note that
+c               if pivoting was requested in dqrdc, the j-th
+c               component of b will be associated with column jpvt(j)
+c               of the original matrix x that was input into dqrdc.)
+c
+c        rsd    double precision(n).
+c               rsd contains the least squares residual y - xk*b,
+c               if its computation has been requested.  rsd is
+c               also the orthogonal projection of y onto the
+c               orthogonal complement of the column space of xk.
+c
+c        xb     double precision(n).
+c               xb contains the least squares approximation xk*b,
+c               if its computation has been requested.  xb is also
+c               the orthogonal projection of y onto the column space
+c               of x.
+c
+c        info   integer.
+c               info is zero unless the computation of b has
+c               been requested and r is exactly singular.  in
+c               this case, info is the index of the first zero
+c               diagonal element of r and b is left unaltered.
+c
+c     the parameters qy, qty, b, rsd, and xb are not referenced
+c     if their computation is not requested and in this case
+c     can be replaced by dummy variables in the calling program.
+c     to save storage, the user may in some cases use the same
+c     array for different parameters in the calling sequence.  a
+c     frequently occuring example is when one wishes to compute
+c     any of b, rsd, or xb and does not need y or qty.  in this
+c     case one may identify y, qty, and one of b, rsd, or xb, while
+c     providing separate arrays for anything else that is to be
+c     computed.  thus the calling sequence
+c
+c          call dqrsl(x,ldx,n,k,qraux,y,dum,y,b,y,dum,110,info)
+c
+c     will result in the computation of b and rsd, with rsd
+c     overwriting y.  more generally, each item in the following
+c     list contains groups of permissible identifications for
+c     a single callinng sequence.
+c
+c          1. (y,qty,b) (rsd) (xb) (qy)
+c
+c          2. (y,qty,rsd) (b) (xb) (qy)
+c
+c          3. (y,qty,xb) (b) (rsd) (qy)
+c
+c          4. (y,qy) (qty,b) (rsd) (xb)
+c
+c          5. (y,qy) (qty,rsd) (b) (xb)
+c
+c          6. (y,qy) (qty,xb) (b) (rsd)
+c
+c     in any group the value returned in the array allocated to
+c     the group corresponds to the last member of the group.
+c
+c     linpack. this version dated 08/14/78 .
+c     g.w. stewart, university of maryland, argonne national lab.
+c
+c     dqrsl uses the following functions and subprograms.
+c
+c     blas daxpy,dcopy,ddot
+c     fortran dabs,min0,mod
+c
+c     internal variables
+c
+      integer i,j,jj,ju,kp1
+      double precision ddot,t,temp
+      logical cb,cqy,cqty,cr,cxb
+c
+c
+c     set info flag.
+c
+      info = 0
+c
+c     determine what is to be computed.
+c
+      cqy = job/10000 .ne. 0
+      cqty = mod(job,10000) .ne. 0
+      cb = mod(job,1000)/100 .ne. 0
+      cr = mod(job,100)/10 .ne. 0
+      cxb = mod(job,10) .ne. 0
+      ju = min0(k,n-1)
+c
+c     special action when n=1.
+c
+      if (ju .ne. 0) go to 40
+         if (cqy) qy(1) = y(1)
+         if (cqty) qty(1) = y(1)
+         if (cxb) xb(1) = y(1)
+         if (.not.cb) go to 30
+            if (x(1,1) .ne. 0.0d0) go to 10
+               info = 1
+            go to 20
+   10       continue
+               b(1) = y(1)/x(1,1)
+   20       continue
+   30    continue
+         if (cr) rsd(1) = 0.0d0
+      go to 250
+   40 continue
+c
+c        set up to compute qy or qty.
+c
+         if (cqy) call dcopy(n,y,1,qy,1)
+         if (cqty) call dcopy(n,y,1,qty,1)
+         if (.not.cqy) go to 70
+c
+c           compute qy.
+c
+            do 60 jj = 1, ju
+               j = ju - jj + 1
+               if (qraux(j) .eq. 0.0d0) go to 50
+                  temp = x(j,j)
+                  x(j,j) = qraux(j)
+                  t = -ddot(n-j+1,x(j,j),1,qy(j),1)/x(j,j)
+                  call daxpy(n-j+1,t,x(j,j),1,qy(j),1)
+                  x(j,j) = temp
+   50          continue
+   60       continue
+   70    continue
+         if (.not.cqty) go to 100
+c
+c           compute trans(q)*y.
+c
+            do 90 j = 1, ju
+               if (qraux(j) .eq. 0.0d0) go to 80
+                  temp = x(j,j)
+                  x(j,j) = qraux(j)
+                  t = -ddot(n-j+1,x(j,j),1,qty(j),1)/x(j,j)
+                  call daxpy(n-j+1,t,x(j,j),1,qty(j),1)
+                  x(j,j) = temp
+   80          continue
+   90       continue
+  100    continue
+c
+c        set up to compute b, rsd, or xb.
+c
+         if (cb) call dcopy(k,qty,1,b,1)
+         kp1 = k + 1
+         if (cxb) call dcopy(k,qty,1,xb,1)
+         if (cr .and. k .lt. n) call dcopy(n-k,qty(kp1),1,rsd(kp1),1)
+         if (.not.cxb .or. kp1 .gt. n) go to 120
+            do 110 i = kp1, n
+               xb(i) = 0.0d0
+  110       continue
+  120    continue
+         if (.not.cr) go to 140
+            do 130 i = 1, k
+               rsd(i) = 0.0d0
+  130       continue
+  140    continue
+         if (.not.cb) go to 190
+c
+c           compute b.
+c
+            do 170 jj = 1, k
+               j = k - jj + 1
+               if (x(j,j) .ne. 0.0d0) go to 150
+                  info = j
+c           ......exit
+                  go to 180
+  150          continue
+               b(j) = b(j)/x(j,j)
+               if (j .eq. 1) go to 160
+                  t = -b(j)
+                  call daxpy(j-1,t,x(1,j),1,b,1)
+  160          continue
+  170       continue
+  180       continue
+  190    continue
+         if (.not.cr .and. .not.cxb) go to 240
+c
+c           compute rsd or xb as required.
+c
+            do 230 jj = 1, ju
+               j = ju - jj + 1
+               if (qraux(j) .eq. 0.0d0) go to 220
+                  temp = x(j,j)
+                  x(j,j) = qraux(j)
+                  if (.not.cr) go to 200
+                     t = -ddot(n-j+1,x(j,j),1,rsd(j),1)/x(j,j)
+                     call daxpy(n-j+1,t,x(j,j),1,rsd(j),1)
+  200             continue
+                  if (.not.cxb) go to 210
+                     t = -ddot(n-j+1,x(j,j),1,xb(j),1)/x(j,j)
+                     call daxpy(n-j+1,t,x(j,j),1,xb(j),1)
+  210             continue
+                  x(j,j) = temp
+  220          continue
+  230       continue
+  240    continue
+  250 continue
+      return
+      end
+c......................................................................
+      subroutine dsvdc(x,ldx,n,p,s,e,u,ldu,v,ldv,work,job,info)
+      integer ldx,n,p,ldu,ldv,job,info
+      double precision x(ldx,1),s(1),e(1),u(ldu,1),v(ldv,1),work(1)
+c
+c
+c     dsvdc is a subroutine to reduce a double precision nxp matrix x
+c     by orthogonal transformations u and v to diagonal form.  the
+c     diagonal elements s(i) are the singular values of x.  the
+c     columns of u are the corresponding left singular vectors,
+c     and the columns of v the right singular vectors.
+c
+c     on entry
+c
+c         x         double precision(ldx,p), where ldx.ge.n.
+c                   x contains the matrix whose singular value
+c                   decomposition is to be computed.  x is
+c                   destroyed by dsvdc.
+c
+c         ldx       integer.
+c                   ldx is the leading dimension of the array x.
+c
+c         n         integer.
+c                   n is the number of rows of the matrix x.
+c
+c         p         integer.
+c                   p is the number of columns of the matrix x.
+c
+c         ldu       integer.
+c                   ldu is the leading dimension of the array u.
+c                   (see below).
+c
+c         ldv       integer.
+c                   ldv is the leading dimension of the array v.
+c                   (see below).
+c
+c         work      double precision(n).
+c                   work is a scratch array.
+c
+c         job       integer.
+c                   job controls the computation of the singular
+c                   vectors.  it has the decimal expansion ab
+c                   with the following meaning
+c
+c                        a.eq.0    do not compute the left singular
+c                                  vectors.
+c                        a.eq.1    return the n left singular vectors
+c                                  in u.
+c                        a.ge.2    return the first min(n,p) singular
+c                                  vectors in u.
+c                        b.eq.0    do not compute the right singular
+c                                  vectors.
+c                        b.eq.1    return the right singular vectors
+c                                  in v.
+c
+c     on return
+c
+c         s         double precision(mm), where mm=min(n+1,p).
+c                   the first min(n,p) entries of s contain the
+c                   singular values of x arranged in descending
+c                   order of magnitude.
+c
+c         e         double precision(p),
+c                   e ordinarily contains zeros.  however see the
+c                   discussion of info for exceptions.
+c
+c         u         double precision(ldu,k), where ldu.ge.n.  if
+c                                   joba.eq.1 then k.eq.n, if joba.ge.2
+c                                   then k.eq.min(n,p).
+c                   u contains the matrix of left singular vectors.
+c                   u is not referenced if joba.eq.0.  if n.le.p
+c                   or if joba.eq.2, then u may be identified with x
+c                   in the subroutine call.
+c
+c         v         double precision(ldv,p), where ldv.ge.p.
+c                   v contains the matrix of right singular vectors.
+c                   v is not referenced if job.eq.0.  if p.le.n,
+c                   then v may be identified with x in the
+c                   subroutine call.
+c
+c         info      integer.
+c                   the singular values (and their corresponding
+c                   singular vectors) s(info+1),s(info+2),...,s(m)
+c                   are correct (here m=min(n,p)).  thus if
+c                   info.eq.0, all the singular values and their
+c                   vectors are correct.  in any event, the matrix
+c                   b = trans(u)*x*v is the bidiagonal matrix
+c                   with the elements of s on its diagonal and the
+c                   elements of e on its super-diagonal (trans(u)
+c                   is the transpose of u).  thus the singular
+c                   values of x and b are the same.
+c
+c     linpack. this version dated 08/14/78 .
+c              correction made to shift 2/84.
+c     g.w. stewart, university of maryland, argonne national lab.
+c
+c     dsvdc uses the following functions and subprograms.
+c
+c     external drot
+c     blas daxpy,ddot,dscal,dswap,dnrm2,drotg
+c     fortran dabs,dmax1,max0,min0,mod,dsqrt
+c
+c     internal variables
+c
+      integer i,iter,j,jobu,k,kase,kk,l,ll,lls,lm1,lp1,ls,lu,m,maxit,
+     *        mm,mm1,mp1,nct,nctp1,ncu,nrt,nrtp1
+      double precision ddot,t,r
+      double precision b,c,cs,el,emm1,f,g,dnrm2,scale,shift,sl,sm,sn,
+     *                 smm1,t1,test,ztest
+      logical wantu,wantv
+c
+c
+c     set the maximum number of iterations.
+c
+      maxit = 30
+c
+c     determine what is to be computed.
+c
+      wantu = .false.
+      wantv = .false.
+      jobu = mod(job,100)/10
+      ncu = n
+      if (jobu .gt. 1) ncu = min0(n,p)
+      if (jobu .ne. 0) wantu = .true.
+      if (mod(job,10) .ne. 0) wantv = .true.
+c
+c     reduce x to bidiagonal form, storing the diagonal elements
+c     in s and the super-diagonal elements in e.
+c
+      info = 0
+      nct = min0(n-1,p)
+      nrt = max0(0,min0(p-2,n))
+      lu = max0(nct,nrt)
+      if (lu .lt. 1) go to 170
+      do 160 l = 1, lu
+         lp1 = l + 1
+         if (l .gt. nct) go to 20
+c
+c           compute the transformation for the l-th column and
+c           place the l-th diagonal in s(l).
+c
+            s(l) = dnrm2(n-l+1,x(l,l),1)
+            if (s(l) .eq. 0.0d0) go to 10
+               if (x(l,l) .ne. 0.0d0) s(l) = dsign(s(l),x(l,l))
+               call dscal(n-l+1,1.0d0/s(l),x(l,l),1)
+               x(l,l) = 1.0d0 + x(l,l)
+   10       continue
+            s(l) = -s(l)
+   20    continue
+         if (p .lt. lp1) go to 50
+         do 40 j = lp1, p
+            if (l .gt. nct) go to 30
+            if (s(l) .eq. 0.0d0) go to 30
+c
+c              apply the transformation.
+c
+               t = -ddot(n-l+1,x(l,l),1,x(l,j),1)/x(l,l)
+               call daxpy(n-l+1,t,x(l,l),1,x(l,j),1)
+   30       continue
+c
+c           place the l-th row of x into  e for the
+c           subsequent calculation of the row transformation.
+c
+            e(j) = x(l,j)
+   40    continue
+   50    continue
+         if (.not.wantu .or. l .gt. nct) go to 70
+c
+c           place the transformation in u for subsequent back
+c           multiplication.
+c
+            do 60 i = l, n
+               u(i,l) = x(i,l)
+   60       continue
+   70    continue
+         if (l .gt. nrt) go to 150
+c
+c           compute the l-th row transformation and place the
+c           l-th super-diagonal in e(l).
+c
+            e(l) = dnrm2(p-l,e(lp1),1)
+            if (e(l) .eq. 0.0d0) go to 80
+               if (e(lp1) .ne. 0.0d0) e(l) = dsign(e(l),e(lp1))
+               call dscal(p-l,1.0d0/e(l),e(lp1),1)
+               e(lp1) = 1.0d0 + e(lp1)
+   80       continue
+            e(l) = -e(l)
+            if (lp1 .gt. n .or. e(l) .eq. 0.0d0) go to 120
+c
+c              apply the transformation.
+c
+               do 90 i = lp1, n
+                  work(i) = 0.0d0
+   90          continue
+               do 100 j = lp1, p
+                  call daxpy(n-l,e(j),x(lp1,j),1,work(lp1),1)
+  100          continue
+               do 110 j = lp1, p
+                  call daxpy(n-l,-e(j)/e(lp1),work(lp1),1,x(lp1,j),1)
+  110          continue
+  120       continue
+            if (.not.wantv) go to 140
+c
+c              place the transformation in v for subsequent
+c              back multiplication.
+c
+               do 130 i = lp1, p
+                  v(i,l) = e(i)
+  130          continue
+  140       continue
+  150    continue
+  160 continue
+  170 continue
+c
+c     set up the final bidiagonal matrix or order m.
+c
+      m = min0(p,n+1)
+      nctp1 = nct + 1
+      nrtp1 = nrt + 1
+      if (nct .lt. p) s(nctp1) = x(nctp1,nctp1)
+      if (n .lt. m) s(m) = 0.0d0
+      if (nrtp1 .lt. m) e(nrtp1) = x(nrtp1,m)
+      e(m) = 0.0d0
+c
+c     if required, generate u.
+c
+      if (.not.wantu) go to 300
+         if (ncu .lt. nctp1) go to 200
+         do 190 j = nctp1, ncu
+            do 180 i = 1, n
+               u(i,j) = 0.0d0
+  180       continue
+            u(j,j) = 1.0d0
+  190    continue
+  200    continue
+         if (nct .lt. 1) go to 290
+         do 280 ll = 1, nct
+            l = nct - ll + 1
+            if (s(l) .eq. 0.0d0) go to 250
+               lp1 = l + 1
+               if (ncu .lt. lp1) go to 220
+               do 210 j = lp1, ncu
+                  t = -ddot(n-l+1,u(l,l),1,u(l,j),1)/u(l,l)
+                  call daxpy(n-l+1,t,u(l,l),1,u(l,j),1)
+  210          continue
+  220          continue
+               call dscal(n-l+1,-1.0d0,u(l,l),1)
+               u(l,l) = 1.0d0 + u(l,l)
+               lm1 = l - 1
+               if (lm1 .lt. 1) go to 240
+               do 230 i = 1, lm1
+                  u(i,l) = 0.0d0
+  230          continue
+  240          continue
+            go to 270
+  250       continue
+               do 260 i = 1, n
+                  u(i,l) = 0.0d0
+  260          continue
+               u(l,l) = 1.0d0
+  270       continue
+  280    continue
+  290    continue
+  300 continue
+c
+c     if it is required, generate v.
+c
+      if (.not.wantv) go to 350
+         do 340 ll = 1, p
+            l = p - ll + 1
+            lp1 = l + 1
+            if (l .gt. nrt) go to 320
+            if (e(l) .eq. 0.0d0) go to 320
+               do 310 j = lp1, p
+                  t = -ddot(p-l,v(lp1,l),1,v(lp1,j),1)/v(lp1,l)
+                  call daxpy(p-l,t,v(lp1,l),1,v(lp1,j),1)
+  310          continue
+  320       continue
+            do 330 i = 1, p
+               v(i,l) = 0.0d0
+  330       continue
+            v(l,l) = 1.0d0
+  340    continue
+  350 continue
+c
+c     main iteration loop for the singular values.
+c
+      mm = m
+      iter = 0
+  360 continue
+c
+c        quit if all the singular values have been found.
+c
+c     ...exit
+         if (m .eq. 0) go to 620
+c
+c        if too many iterations have been performed, set
+c        flag and return.
+c
+         if (iter .lt. maxit) go to 370
+            info = m
+c     ......exit
+            go to 620
+  370    continue
+c
+c        this section of the program inspects for
+c        negligible elements in the s and e arrays.  on
+c        completion the variables kase and l are set as follows.
+c
+c           kase = 1     if s(m) and e(l-1) are negligible and l.lt.m
+c           kase = 2     if s(l) is negligible and l.lt.m
+c           kase = 3     if e(l-1) is negligible, l.lt.m, and
+c                        s(l), ..., s(m) are not negligible (qr step).
+c           kase = 4     if e(m-1) is negligible (convergence).
+c
+         do 390 ll = 1, m
+            l = m - ll
+c        ...exit
+            if (l .eq. 0) go to 400
+            test = dabs(s(l)) + dabs(s(l+1))
+            ztest = test + dabs(e(l))
+            if (ztest .ne. test) go to 380
+               e(l) = 0.0d0
+c        ......exit
+               go to 400
+  380       continue
+  390    continue
+  400    continue
+         if (l .ne. m - 1) go to 410
+            kase = 4
+         go to 480
+  410    continue
+            lp1 = l + 1
+            mp1 = m + 1
+            do 430 lls = lp1, mp1
+               ls = m - lls + lp1
+c           ...exit
+               if (ls .eq. l) go to 440
+               test = 0.0d0
+               if (ls .ne. m) test = test + dabs(e(ls))
+               if (ls .ne. l + 1) test = test + dabs(e(ls-1))
+               ztest = test + dabs(s(ls))
+               if (ztest .ne. test) go to 420
+                  s(ls) = 0.0d0
+c           ......exit
+                  go to 440
+  420          continue
+  430       continue
+  440       continue
+            if (ls .ne. l) go to 450
+               kase = 3
+            go to 470
+  450       continue
+            if (ls .ne. m) go to 460
+               kase = 1
+            go to 470
+  460       continue
+               kase = 2
+               l = ls
+  470       continue
+  480    continue
+         l = l + 1
+c
+c        perform the task indicated by kase.
+c
+         go to (490,520,540,570), kase
+c
+c        deflate negligible s(m).
+c
+  490    continue
+            mm1 = m - 1
+            f = e(m-1)
+            e(m-1) = 0.0d0
+            do 510 kk = l, mm1
+               k = mm1 - kk + l
+               t1 = s(k)
+               call drotg(t1,f,cs,sn)
+               s(k) = t1
+               if (k .eq. l) go to 500
+                  f = -sn*e(k-1)
+                  e(k-1) = cs*e(k-1)
+  500          continue
+               if (wantv) call drot(p,v(1,k),1,v(1,m),1,cs,sn)
+  510       continue
+         go to 610
+c
+c        split at negligible s(l).
+c
+  520    continue
+            f = e(l-1)
+            e(l-1) = 0.0d0
+            do 530 k = l, m
+               t1 = s(k)
+               call drotg(t1,f,cs,sn)
+               s(k) = t1
+               f = -sn*e(k)
+               e(k) = cs*e(k)
+               if (wantu) call drot(n,u(1,k),1,u(1,l-1),1,cs,sn)
+  530       continue
+         go to 610
+c
+c        perform one qr step.
+c
+  540    continue
+c
+c           calculate the shift.
+c
+            scale = dmax1(dabs(s(m)),dabs(s(m-1)),dabs(e(m-1)),
+     *                    dabs(s(l)),dabs(e(l)))
+            sm = s(m)/scale
+            smm1 = s(m-1)/scale
+            emm1 = e(m-1)/scale
+            sl = s(l)/scale
+            el = e(l)/scale
+            b = ((smm1 + sm)*(smm1 - sm) + emm1**2)/2.0d0
+            c = (sm*emm1)**2
+            shift = 0.0d0
+            if (b .eq. 0.0d0 .and. c .eq. 0.0d0) go to 550
+               shift = dsqrt(b**2+c)
+               if (b .lt. 0.0d0) shift = -shift
+               shift = c/(b + shift)
+  550       continue
+            f = (sl + sm)*(sl - sm) + shift
+            g = sl*el
+c
+c           chase zeros.
+c
+            mm1 = m - 1
+            do 560 k = l, mm1
+               call drotg(f,g,cs,sn)
+               if (k .ne. l) e(k-1) = f
+               f = cs*s(k) + sn*e(k)
+               e(k) = cs*e(k) - sn*s(k)
+               g = sn*s(k+1)
+               s(k+1) = cs*s(k+1)
+               if (wantv) call drot(p,v(1,k),1,v(1,k+1),1,cs,sn)
+               call drotg(f,g,cs,sn)
+               s(k) = f
+               f = cs*e(k) + sn*s(k+1)
+               s(k+1) = -sn*e(k) + cs*s(k+1)
+               g = sn*e(k+1)
+               e(k+1) = cs*e(k+1)
+               if (wantu .and. k .lt. n)
+     *            call drot(n,u(1,k),1,u(1,k+1),1,cs,sn)
+  560       continue
+            e(m-1) = f
+            iter = iter + 1
+         go to 610
+c
+c        convergence.
+c
+  570    continue
+c
+c           make the singular value  positive.
+c
+            if (s(l) .ge. 0.0d0) go to 580
+               s(l) = -s(l)
+               if (wantv) call dscal(p,-1.0d0,v(1,l),1)
+  580       continue
+c
+c           order the singular value.
+c
+  590       if (l .eq. mm) go to 600
+c           ...exit
+               if (s(l) .ge. s(l+1)) go to 600
+               t = s(l)
+               s(l) = s(l+1)
+               s(l+1) = t
+               if (wantv .and. l .lt. p)
+     *            call dswap(p,v(1,l),1,v(1,l+1),1)
+               if (wantu .and. l .lt. n)
+     *            call dswap(n,u(1,l),1,u(1,l+1),1)
+               l = l + 1
+            go to 590
+  600       continue
+            iter = 0
+            m = m - 1
+  610    continue
+      go to 360
+  620 continue
+      return
+      end
+

Added: trunk/Lib/sandbox/pyloess/sandbox/src/loess.c
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/loess.c	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/loess.c	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,325 @@
+#include "S.h"
+#include "loess.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *surf_stat;
+
+void
+loess_setup(double *x, double *y, int n, int p, loess *lo)
+{
+    int i, max_kd;
+
+    max_kd = n > 200 ? n : 200;
+
+    lo->inputs.y = (double *) malloc(n * sizeof(double));
+    lo->inputs.x = (double *) malloc(n * p * sizeof(double));
+    lo->inputs.weights = (double *) malloc(n * sizeof(double));
+    for(i = 0; i < (n * p); i++)
+        lo->inputs.x[i] = x[i];
+    for(i = 0; i < n; i++) {
+        lo->inputs.y[i] = y[i];
+        lo->inputs.weights[i] = 1;
+    }
+    lo->inputs.n = n;
+    lo->inputs.p = p;
+    lo->model.span = 0.75;
+    lo->model.degree = 2;
+    lo->model.normalize = TRUE;
+    for(i = 0; i < 8; i++)
+        lo->model.parametric[i] = lo->model.drop_square[i] = FALSE;
+    lo->model.family = "gaussian";
+
+    lo->control.surface = "interpolate";
+    lo->control.statistics = "approximate";
+    lo->control.cell = 0.2;
+    lo->control.trace_hat = "wait.to.decide";
+    lo->control.iterations = 4;
+
+    lo->outputs.fitted_values = (double *) malloc(n * sizeof(double));
+    lo->outputs.fitted_residuals = (double *) malloc(n * sizeof(double));
+    lo->outputs.pseudovalues = (double *) malloc(n * sizeof(double));
+    lo->outputs.diagonal = (double *) malloc(n * sizeof(double));
+    lo->outputs.robust = (double *) malloc(n * sizeof(double));
+    lo->outputs.divisor = (double *) malloc(p * sizeof(double));
+
+    lo->kd_tree.parameter = (int *) malloc(7 * sizeof(int));
+    lo->kd_tree.a = (int *) malloc(max_kd * sizeof(int));
+    lo->kd_tree.xi = (double *) malloc(max_kd * sizeof(double));
+    lo->kd_tree.vert = (double *) malloc(p * 2 * sizeof(double));
+    lo->kd_tree.vval = (double *) malloc((p + 1) * max_kd * sizeof(double));
+}
+
+void
+loess_fit(loess *lo)
+{
+    int    size_info[2], iterations;
+    void    loess_();
+
+    size_info[0] = lo->inputs.p;
+    size_info[1] = lo->inputs.n;
+
+    iterations = (!strcmp(lo->model.family, "gaussian")) ? 0 :
+    lo->control.iterations;
+    if(!strcmp(lo->control.trace_hat, "wait.to.decide")) {
+        if(!strcmp(lo->control.surface, "interpolate"))
+            lo->control.trace_hat = (lo->inputs.n < 500) ? "exact" :
+"approximate";
+        else
+            lo->control.trace_hat = "exact";
+        }
+    loess_(lo->inputs.y, lo->inputs.x, size_info, lo->inputs.weights,
+           &lo->model.span,
+           &lo->model.degree,
+           lo->model.parametric,
+           lo->model.drop_square,
+           &lo->model.normalize,
+           &lo->control.statistics,
+           &lo->control.surface,
+           &lo->control.cell,
+           &lo->control.trace_hat,
+           &iterations,
+           lo->outputs.fitted_values,
+           lo->outputs.fitted_residuals,
+           &lo->outputs.enp,
+           &lo->outputs.s,
+           &lo->outputs.one_delta,
+           &lo->outputs.two_delta,
+           lo->outputs.pseudovalues,
+           &lo->outputs.trace_hat,
+           lo->outputs.diagonal,
+           lo->outputs.robust,
+           lo->outputs.divisor,
+           lo->kd_tree.parameter,
+           lo->kd_tree.a,
+           lo->kd_tree.xi,
+           lo->kd_tree.vert,
+           lo->kd_tree.vval);
+}
+
+void
+loess_(double *y, double *x_, int *size_info, double *weights, double *span,
+       int *degree, int *parametric, int *drop_square, int *normalize,
+       char **statistics, char **surface, double *cell, char **trace_hat_in,
+       int *iterations, double *fitted_values, double *fitted_residuals,
+       double *enp, double *s, double *one_delta, double *two_delta,
+       double *pseudovalues, double *trace_hat_out, double *diagonal,
+       double *robust, double *divisor, int *parameter, int *a, double *xi,
+       double *vert, double *vval)
+{
+    double  *x, *x_tmp, new_cell, trL, delta1, delta2, sum_squares = 0,
+            *pseudo_resid, *temp, *xi_tmp, *vert_tmp, *vval_tmp,
+            *diag_tmp, trL_tmp = 0, d1_tmp = 0, d2_tmp = 0, sum, mean;
+    int    i, j, k, p, N, D, sum_drop_sqr = 0, sum_parametric = 0,
+            setLf, nonparametric = 0, *order_parametric,
+            *order_drop_sqr, zero = 0, max_kd, *a_tmp, *param_tmp;
+    int     cut, comp();
+    char    *new_stat;
+    void    condition();
+
+    D = size_info[0];
+    N = size_info[1];
+    max_kd = (N > 200 ? N : 200);
+    *one_delta = *two_delta = *trace_hat_out = 0;
+
+    x = (double *) malloc(D * N * sizeof(double));
+    x_tmp = (double *) malloc(D * N * sizeof(double));
+    temp = (double *) malloc(N * sizeof(double));
+    a_tmp = (int *) malloc(max_kd * sizeof(int));
+    xi_tmp = (double *) malloc(max_kd * sizeof(double));
+    vert_tmp = (double *) malloc(D * 2 * sizeof(double));
+    vval_tmp = (double *) malloc((D + 1) * max_kd * sizeof(double));
+    diag_tmp = (double *) malloc(N * sizeof(double));
+    param_tmp = (int *) malloc(N * sizeof(int));
+    order_parametric = (int *) malloc(D * sizeof(int));
+    order_drop_sqr = (int *) malloc(D * sizeof(int));
+    if((*iterations) > 0)
+        pseudo_resid = (double *) malloc(N * sizeof(double));
+
+    new_cell = (*span) * (*cell);
+    for(i = 0; i < N; i++)
+        robust[i] = 1;
+        for(i = 0; i < (N * D); i++)
+            x_tmp[i] = x_[i];
+    if((*normalize) && (D > 1)) {
+        cut = ceil(0.100000000000000000001 * N);
+        for(i = 0; i < D; i++) {
+            k = i * N;
+            for(j = 0; j < N; j++)
+                temp[j] = x_[k + j];
+            qsort(temp, N, sizeof(double), comp);
+            sum = 0;
+            for(j = cut; j <= (N - cut - 1); j++)
+                sum = sum + temp[j];
+            mean = sum / (N - 2 * cut);
+            sum = 0;
+            for(j = cut; j <= (N - cut - 1); j++) {
+                temp[j] = temp[j] - mean;
+                sum = sum + temp[j] * temp[j];
+            }
+            divisor[i] = sqrt(sum / (N - 2 * cut - 1));
+            for(j = 0; j < N; j++) {
+                p = k + j;
+                x_tmp[p] = x_[p] / divisor[i];
+            }
+        }
+    }
+    else
+        for(i = 0; i < D; i++) divisor[i] = 1;
+    j = D - 1;
+    for(i = 0; i < D; i++) {
+        sum_drop_sqr = sum_drop_sqr + drop_square[i];
+        sum_parametric = sum_parametric + parametric[i];
+        if(parametric[i])
+            order_parametric[j--] = i;
+        else
+            order_parametric[nonparametric++] = i;
+    }
+    for(i = 0; i < D; i++) {
+        order_drop_sqr[i] = 2 - drop_square[order_parametric[i]];
+        k = i * N;
+        p = order_parametric[i] * N;
+        for(j = 0; j < N; j++)
+            x[k + j] = x_tmp[p + j];
+    }
+    if((*degree) == 1 && sum_drop_sqr) {
+        fprintf(stderr, "Specified the square of a factor predictor to be"\
+                        "dropped when degree = 1");
+        exit(1);
+    }
+    if(D == 1 && sum_drop_sqr) {
+        fprintf(stderr, "Specified the square of a predictor to be dropped"\
+                        "with only one numeric predictor");
+        exit(1);
+    }
+    if(sum_parametric == D) {
+        fprintf(stderr, "Specified parametric for all predictors");
+        exit(1);
+        }
+    for(j = 0; j <= (*iterations); j++) {
+        new_stat = j ? "none" : *statistics;
+        for(i = 0; i < N; i++)
+            robust[i] = weights[i] * robust[i];
+        condition(surface, new_stat, trace_hat_in);
+        setLf = !strcmp(surf_stat, "interpolate/exact");
+        loess_raw(y, x, weights, robust, &D, &N, span, degree,
+                  &nonparametric, order_drop_sqr, &sum_drop_sqr,
+                  &new_cell, &surf_stat, fitted_values, parameter, a,
+                  xi, vert, vval, diagonal, &trL, &delta1, &delta2,
+                  &setLf);
+        if(j == 0) {
+            *trace_hat_out = trL;
+            *one_delta = delta1;
+            *two_delta = delta2;
+        }
+        for(i = 0; i < N; i++)
+            printf("i:%i y:%.3f f:%.3f\n", i, y[i], fitted_values[i]);
+            fitted_residuals[i] = y[i] - fitted_values[i];
+        if(j < (*iterations))
+            F77_SUB(lowesw)(fitted_residuals, &N, robust, temp);
+    }
+    if((*iterations) > 0) {
+        F77_SUB(lowesp)(&N, y, fitted_values, weights, robust, temp,
+pseudovalues);
+
+        loess_raw(pseudovalues, x, weights, weights, &D, &N, span,
+                  degree, &nonparametric, order_drop_sqr, &sum_drop_sqr,
+                  &new_cell, &surf_stat, temp, param_tmp, a_tmp, xi_tmp,
+                  vert_tmp, vval_tmp, diag_tmp, &trL_tmp, &d1_tmp, &d2_tmp,
+                  &zero);
+        for(i = 0; i < N; i++)
+            pseudo_resid[i] = pseudovalues[i] - temp[i];
+    }
+    if((*iterations) == 0)
+        for(i = 0; i < N; i++)
+            sum_squares = sum_squares + weights[i] *
+                    fitted_residuals[i] * fitted_residuals[i];
+    else
+        for(i = 0; i < N; i++)
+            sum_squares = sum_squares + weights[i] *
+                    pseudo_resid[i] * pseudo_resid[i];
+    *enp = (*one_delta) + 2 * (*trace_hat_out) - N;
+    *s = sqrt(sum_squares / (*one_delta));
+
+    free(x);
+    free(x_tmp);
+    free(temp);
+    free(xi_tmp);
+    free(vert_tmp);
+    free(vval_tmp);
+    free(diag_tmp);
+    free(a_tmp);
+    free(param_tmp);
+    free(order_parametric);
+    free(order_drop_sqr);
+        if((*iterations) > 0)
+                free(pseudo_resid);
+}
+
+void
+loess_free_mem(loess *lo)
+{
+    free(lo->inputs.x);
+    free(lo->inputs.y);
+    free(lo->inputs.weights);
+    free(lo->outputs.fitted_values);
+    free(lo->outputs.fitted_residuals);
+    free(lo->outputs.pseudovalues);
+    free(lo->outputs.diagonal);
+    free(lo->outputs.robust);
+    free(lo->outputs.divisor);
+    free(lo->kd_tree.parameter);
+    free(lo->kd_tree.a);
+    free(lo->kd_tree.xi);
+    free(lo->kd_tree.vert);
+    free(lo->kd_tree.vval);
+}
+
+void
+loess_summary(loess *lo)
+{
+    printf("Number of Observations         : %d\n", lo->inputs.n);
+    printf("Equivalent Number of Parameters: %.1f\n", lo->outputs.enp);
+    if(!strcmp(lo->model.family, "gaussian"))
+        printf("Residual Standard Error        : ");
+    else
+        printf("Residual Scale Estimate: ");
+    printf("%.4f\n", lo->outputs.s);
+}
+
+void
+condition(char **surface, char *new_stat, char **trace_hat_in)
+{
+    if(!strcmp(*surface, "interpolate")) {
+        if(!strcmp(new_stat, "none"))
+            surf_stat = "interpolate/none";
+        else if(!strcmp(new_stat, "exact"))
+            surf_stat = "interpolate/exact";
+        else if(!strcmp(new_stat, "approximate"))
+        {
+            if(!strcmp(*trace_hat_in, "approximate"))
+                surf_stat = "interpolate/2.approx";
+            else if(!strcmp(*trace_hat_in, "exact"))
+                surf_stat = "interpolate/1.approx";
+        }
+    }
+    else if(!strcmp(*surface, "direct")) {
+        if(!strcmp(new_stat, "none"))
+            surf_stat = "direct/none";
+        else if(!strcmp(new_stat, "exact"))
+            surf_stat = "direct/exact";
+        else if(!strcmp(new_stat, "approximate"))
+            surf_stat = "direct/approximate";
+    }
+}
+
+int
+comp(double *d1, double *d2)
+{
+    if(*d1 < *d2)
+        return(-1);
+    else if(*d1 == *d2)
+        return(0);
+    else
+        return(1);
+}

Added: trunk/Lib/sandbox/pyloess/sandbox/src/loess.h
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/loess.h	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/loess.h	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,81 @@
+/* for the meaning of these fields, see struct.m */
+/* longs are used here so that the codes can be called from S */
+
+#define TRUE  1
+#define FALSE 0
+
+typedef struct {
+    long    n;
+    long    p;
+    double  *y;
+    double  *x;
+    double  *weights;
+    } loess_inputs;
+
+typedef struct {
+    double span;
+    int    degree;
+    int    normalize;
+    int    parametric[8];
+    int    drop_square[8];
+    char   *family;
+    } loess_model;
+
+typedef struct {
+    char   *surface;
+    char   *statistics;
+    double cell;
+    char   *trace_hat;
+    int    iterations;
+    } loess_control;
+
+typedef struct {
+    int    *parameter;
+    int    *a;
+    double *xi;
+    double *vert;
+    double *vval;
+    } loess_kd_tree;
+
+typedef struct {
+    double *fitted_values;
+    double *fitted_residuals;
+    double enp;
+    double s;
+    double one_delta;
+    double two_delta;
+    double *pseudovalues;
+    double trace_hat;
+    double *diagonal;
+    double *robust;
+    double *divisor;
+    } loess_outputs;
+
+typedef struct {
+    loess_inputs inputs;
+    loess_model model;
+    loess_control control;
+    loess_kd_tree kd_tree;
+    loess_outputs outputs;
+} loess;
+
+typedef struct {
+    double *fit;
+    double *se_fit;
+    double residual_scale;
+    double df;
+} predicted;
+
+struct anova_struct {
+    double dfn;
+    double dfd;
+    double F_value;
+    double Pr_F;
+};
+
+struct ci_struct {
+    double *fit;
+    double *upper;
+    double *lower;
+};
+

Added: trunk/Lib/sandbox/pyloess/sandbox/src/loessc.c
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/loessc.c	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/loessc.c	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,330 @@
+#include "S.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#define    min(x,y)  ((x) < (y) ? (x) : (y))
+#define    max(x,y)  ((x) > (y) ? (x) : (y))
+#define    GAUSSIAN    1
+#define SYMMETRIC    0
+
+static int *iv, liv, lv, tau;
+static double *v;
+
+loess_raw(double *y, double *x, double *weights, double *robust, int *d,
+          int*n, double *span, int *degree, int *nonparametric,
+          int *drop_square, int *sum_drop_sqr, double *cell, char **surf_stat,
+          double *surface, int *parameter, int *a, double *xi, double *vert,
+          double *vval, double *diagonal, double *trL, double *one_delta,
+          double *two_delta, int *setLf)
+{
+    int    zero = 0, one = 1, two = 2, nsing, i, k;
+    double    *hat_matrix, *LL;
+
+    *trL = 0;
+    loess_workspace(d, n, span, degree, nonparametric, drop_square,
+        sum_drop_sqr, setLf);
+    v[1] = *cell;
+    if(!strcmp(*surf_stat, "interpolate/none")) {
+        F77_SUB(lowesb)(x, y, robust, &zero, &zero, iv, &liv, &lv, v);
+        F77_SUB(lowese)(iv, &liv, &lv, v, n, x, surface);
+        loess_prune(parameter, a, xi, vert, vval);
+    }
+    else if (!strcmp(*surf_stat, "direct/none")) {
+        F77_SUB(lowesf)(x, y, robust, iv, &liv, &lv, v, n, x,
+            &zero, &zero, surface);
+    }
+    else if (!strcmp(*surf_stat, "interpolate/1.approx")) {
+        F77_SUB(lowesb)(x, y, weights, diagonal, &one, iv, &liv, &lv, v);
+        F77_SUB(lowese)(iv, &liv, &lv, v, n, x, surface);
+        nsing = iv[29];
+        for(i = 0; i < (*n); i++) *trL = *trL + diagonal[i];
+        F77_SUB(lowesa)(trL, n, d, &tau, &nsing, one_delta, two_delta);
+        loess_prune(parameter, a, xi, vert, vval);
+    }
+        else if (!strcmp(*surf_stat, "interpolate/2.approx")) {
+        F77_SUB(lowesb)(x, y, robust, &zero, &zero, iv, &liv, &lv, v);
+        F77_SUB(lowese)(iv, &liv, &lv, v, n, x, surface);
+        nsing = iv[29];
+        F77_SUB(ehg196)(&tau, d, span, trL);
+        F77_SUB(lowesa)(trL, n, d, &tau, &nsing, one_delta, two_delta);
+        loess_prune(parameter, a, xi, vert, vval);
+    }
+    else if (!strcmp(*surf_stat, "direct/approximate")) {
+        F77_SUB(lowesf)(x, y, weights, iv, &liv, &lv, v, n, x,
+            diagonal, &one, surface);
+        nsing = iv[29];
+        for(i = 0; i < (*n); i++) *trL = *trL + diagonal[i];
+        F77_SUB(lowesa)(trL, n, d, &tau, &nsing, one_delta, two_delta);
+    }
+    else if (!strcmp(*surf_stat, "interpolate/exact")) {
+        hat_matrix = Calloc((*n)*(*n), double);
+        LL = Calloc((*n)*(*n), double);
+        F77_SUB(lowesb)(x, y, weights, diagonal, &one, iv, &liv, &lv, v);
+        F77_SUB(lowesl)(iv, &liv, &lv, v, n, x, hat_matrix);
+        F77_SUB(lowesc)(n, hat_matrix, LL, trL, one_delta, two_delta);
+        F77_SUB(lowese)(iv, &liv, &lv, v, n, x, surface);
+        loess_prune(parameter, a, xi, vert, vval);
+        Free(hat_matrix);
+        Free(LL);
+    }
+    else if (!strcmp(*surf_stat, "direct/exact")) {
+        hat_matrix = Calloc((*n)*(*n), double);
+        LL = Calloc((*n)*(*n), double);
+        F77_SUB(lowesf)(x, y, weights, iv, liv, lv, v, n, x,
+            hat_matrix, &two, surface);
+        F77_SUB(lowesc)(n, hat_matrix, LL, trL, one_delta, two_delta);
+                k = (*n) + 1;
+        for(i = 0; i < (*n); i++)
+            diagonal[i] = hat_matrix[i * k];
+        Free(hat_matrix);
+        Free(LL);
+    }
+    loess_free();
+}
+
+loess_dfit(double *y, double *x, double *x_evaluate, double *weights,
+           double *span, int *degree, int *nonparametric,
+           int *drop_square, int *sum_drop_sqr, int *d, int *n, int *m,
+           double *fit)
+{
+    int    zero = 0, one = 1;
+    loess_workspace(d, n, span, degree, nonparametric, drop_square,
+                    sum_drop_sqr, &zero);
+    F77_SUB(lowesf)(x, y, weights, iv, &liv, &lv, v, m, x_evaluate,
+                    &zero, &zero, fit);
+    loess_free();
+}
+
+loess_dfitse(double *y, double *x, double *x_evaluate, double *weights,
+             double *robust, int *family, double *span, int *degree,
+             int *nonparametric, int *drop_square, int *sum_drop_sqr,
+             int *d, int *n, int *m, double *fit, double *L)
+{
+    int    zero = 0, one = 1, two = 2;
+    loess_workspace(d, n, span, degree, nonparametric, drop_square,
+                    sum_drop_sqr, &zero);
+    if(*family == GAUSSIAN)
+        F77_SUB(lowesf)(x, y, weights, iv, &liv, &lv, v, m,
+                        x_evaluate, L, &two, fit);
+    else if(*family == SYMMETRIC)
+    {
+        F77_SUB(lowesf)(x, y, weights, iv, &liv, &lv, v, m,
+                        x_evaluate, L, &two, fit);
+        F77_SUB(lowesf)(x, y, robust, iv, &liv, &lv, v, m,
+                        x_evaluate, &zero, &zero, fit);
+    }
+    loess_free();
+}
+
+loess_ifit(int *parameter, int *a, double *xi, double *vert, double *vval,
+           int *m, double *x_evaluate, double *fit)
+{
+    loess_grow(parameter, a, xi, vert, vval);
+    F77_SUB(lowese)(iv, &liv, &lv, v, m, x_evaluate, fit);
+    loess_free();
+}
+
+loess_ise(double *y, double *x, double *x_evaluate, double *weights,
+          double *span, int *degree, int *nonparametric, int *drop_square,
+          int *sum_drop_sqr, double *cell, int *d, int *n, int *m,
+          double *fit, double *L)
+{
+    int    zero = 0, one = 1;
+    loess_workspace(d, n, span, degree, nonparametric, drop_square,
+                   sum_drop_sqr, &one);
+    v[1] = *cell;
+    F77_SUB(lowesb)(x, y, weights, &zero, &zero, iv, &liv, &lv, v);
+    F77_SUB(lowesl)(iv, &liv, &lv, v, m, x_evaluate, L);
+    loess_free();
+}
+
+loess_workspace(int *d, int *n, double *span, int *degree,
+                int *nonparametric, int *drop_square, int *sum_drop_sqr,
+                int *setLf)
+{
+    int    D, N, tau0, nvmax, nf, version = 106, i;
+    D = *d;
+    N = *n;
+    nvmax = max(200, N);
+    nf = min(N, floor(N * (*span)));
+    tau0 = ((*degree) > 1) ? ((D + 2) * (D + 1) * 0.5) : (D + 1);
+    tau = tau0 - (*sum_drop_sqr);
+    lv = 50 + (3 * D + 3) * nvmax + N + (tau0 + 2) * nf;
+    liv = 50 + ((int)pow((double)2, (double)D) + 4) * nvmax + 2 * N;
+    if(*setLf) {
+        lv = lv + (D + 1) * nf * nvmax;
+        liv = liv + nf * nvmax;
+    }
+    iv = Calloc(liv, int);
+    v = Calloc(lv, double);
+
+    F77_SUB(lowesd)(&version, iv, &liv, &lv, v, d, n, span, degree,
+                    &nvmax, setLf);
+    iv[32] = *nonparametric;
+    for(i = 0; i < D; i++)
+        iv[i + 40] = drop_square[i];
+}
+
+loess_prune(int *parameter, int *a, double *xi, double *vert, double *vval)
+{
+    int    d, vc, a1, v1, xi1, vv1, nc, nv, nvmax, i, j, k;
+
+    d = iv[1];
+    vc = iv[3] - 1;
+    nc = iv[4];
+    nv = iv[5];
+    a1 = iv[6] - 1;
+    v1 = iv[10] - 1;
+    xi1 = iv[11] - 1;
+    vv1 = iv[12] - 1;
+    nvmax = iv[13];
+
+    for(i = 0; i < 5; i++)
+        parameter[i] = iv[i + 1];
+    parameter[5] = iv[21] - 1;
+    parameter[6] = iv[14] - 1;
+
+    for(i = 0; i < d; i++){
+        k = nvmax * i;
+        vert[i] = v[v1 + k];
+        vert[i + d] = v[v1 + vc + k];
+    }
+    for(i = 0; i < nc; i++) {
+        xi[i] = v[xi1 + i];
+        a[i] = iv[a1 + i];
+    }
+    k = (d + 1) * nv;
+    for(i = 0; i < k; i++)
+        vval[i] = v[vv1 + i];
+}
+
+loess_grow(int *parameter, int *a, double *xi, double *vert, double *vval)
+{
+    int    d, vc, nc, nv, a1, v1, xi1, vv1, i, j, k;
+
+    d = parameter[0];
+    vc = parameter[2];
+    nc = parameter[3];
+    nv = parameter[4];
+    liv = parameter[5];
+    lv = parameter[6];
+    iv = Calloc(liv, int);
+    v = Calloc(lv, double);
+
+    iv[1] = d;
+    iv[2] = parameter[1];
+    iv[3] = vc;
+    iv[5] = iv[13] = nv;
+    iv[4] = iv[16] = nc;
+    iv[6] = 50;
+    iv[7] = iv[6] + nc;
+    iv[8] = iv[7] + vc * nc;
+    iv[9] = iv[8] + nc;
+    iv[10] = 50;
+    iv[12] = iv[10] + nv * d;
+    iv[11] = iv[12] + (d + 1) * nv;
+    iv[27] = 173;
+
+    v1 = iv[10] - 1;
+    xi1 = iv[11] - 1;
+    a1 = iv[6] - 1;
+    vv1 = iv[12] - 1;
+
+    for(i = 0; i < d; i++) {
+        k = nv * i;
+        v[v1 + k] = vert[i];
+        v[v1 + vc - 1 + k] = vert[i + d];
+    }
+    for(i = 0; i < nc; i++) {
+        v[xi1 + i] = xi[i];
+        iv[a1 + i] = a[i];
+    }
+    k = (d + 1) * nv;
+    for(i = 0; i < k; i++)
+        v[vv1 + i] = vval[i];
+
+    F77_SUB(ehg169)(&d, &vc, &nc, &nc, &nv, &nv, v+v1, iv+a1,
+                    v+xi1, iv+iv[7]-1, iv+iv[8]-1, iv+iv[9]-1);
+}
+
+loess_free()
+{
+        Free(v);
+        Free(iv);
+}
+
+/* begin ehg's FORTRAN-callable C-codes */
+
+void
+F77_SUB(ehg182)(int *i)
+{
+char *mess, mess2[50];
+switch(*i){
+case 100: mess="wrong version number in lowesd.  Probably typo in caller."; break;
+case 101: mess="d>dMAX in ehg131.  Need to recompile with increased dimensions."; break;
+case 102: mess="liv too small.   (Discovered by lowesd)"; break;
+case 103: mess="lv too small.    (Discovered by lowesd)"; break;
+case 104: mess="span too small.  fewer data values than degrees of freedom."; break;
+case 105: mess="k>d2MAX in ehg136.  Need to recompile with increased dimensions."; break;
+case 106: mess="lwork too small"; break;
+case 107: mess="invalid value for kernel"; break;
+case 108: mess="invalid value for ideg"; break;
+case 109: mess="lowstt only applies when kernel=1."; break;
+case 110: mess="not enough extra workspace for robustness calculation"; break;
+case 120: mess="zero-width neighborhood. make span bigger"; break;
+case 121: mess="all data on boundary of neighborhood. make span bigger"; break;
+case 122: mess="extrapolation not allowed with blending"; break;
+case 123: mess="ihat=1 (diag L) in l2fit only makes sense if z=x (eval=data)."; break;
+case 171: mess="lowesd must be called first."; break;
+case 172: mess="lowesf must not come between lowesb and lowese, lowesr, or lowesl."; break;
+case 173: mess="lowesb must come before lowese, lowesr, or lowesl."; break;
+case 174: mess="lowesb need not be called twice."; break;
+case 175: mess="need setLf=.true. for lowesl."; break;
+case 180: mess="nv>nvmax in cpvert."; break;
+case 181: mess="nt>20 in eval."; break;
+case 182: mess="svddc failed in l2fit."; break;
+case 183: mess="didnt find edge in vleaf."; break;
+case 184: mess="zero-width cell found in vleaf."; break;
+case 185: mess="trouble descending to leaf in vleaf."; break;
+case 186: mess="insufficient workspace for lowesf."; break;
+case 187: mess="insufficient stack space"; break;
+case 188: mess="lv too small for computing explicit L"; break;
+case 191: mess="computed trace L was negative; something is wrong!"; break;
+case 192: mess="computed delta was negative; something is wrong!"; break;
+case 193: mess="workspace in loread appears to be corrupted"; break;
+case 194: mess="trouble in l2fit/l2tr"; break;
+case 195: mess="only constant, linear, or quadratic local models allowed"; break;
+case 196: mess="degree must be at least 1 for vertex influence matrix"; break;
+case 999: mess="not yet implemented"; break;
+default: sprintf(mess=mess2,"Assert failed; error code %d\n",*i); break;
+    }
+    Recover(mess,NULL_ENTRY);  /* in /usr/s/current/src/qpe/debug.c */
+}
+
+void
+F77_SUB(ehg183)(char *s,int *i, int *n, int *inc)
+{
+    char mess[4000], num[20];
+    int j;
+    strcpy(mess,s);
+    for (j=0; j<*n; j++) {
+        sprintf(num," %d",i[j * *inc]);
+        strcat(mess,num);
+    }
+    strcat(mess,"\n");
+    Warning(mess,NULL_ENTRY);
+}
+
+void
+F77_SUB(ehg184)(char *s, double *x, int *n, int *inc)
+{
+    char mess[4000], num[30];
+    int j;
+    strcpy(mess,s);
+    for (j=0; j<*n; j++) {
+        sprintf(num," %.5g",x[j * *inc]);
+        strcat(mess,num);
+    }
+    strcat(mess,"\n");
+    Warning(mess,NULL_ENTRY);
+}

Added: trunk/Lib/sandbox/pyloess/sandbox/src/loessf.f
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/loessf.f	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/loessf.f	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,2196 @@
+      subroutine ehg126(d,n,vc,x,v,nvmax)
+      integer d,execnt,i,j,k,n,nv,nvmax,vc
+      DOUBLE PRECISION machin,alpha,beta,mu,t
+      DOUBLE PRECISION v(nvmax,d),x(n,d)
+      DOUBLE PRECISION D1MACH
+      external D1MACH
+      save machin,execnt
+      data execnt /0/
+c     MachInf -> machin
+      execnt=execnt+1
+      if(execnt.eq.1)then
+         machin=D1MACH(2)
+      end if
+c     fill in vertices for bounding box of $x$
+c     lower left, upper right
+      do 3 k=1,d
+         alpha=machin
+         beta=-machin
+         do 4 i=1,n
+            t=x(i,k)
+            alpha=min(alpha,t)
+            beta=max(beta,t)
+    4    continue
+c        expand the box a little
+         mu=0.005D0*max(beta-alpha,1.d-10*max(DABS(alpha),DABS(beta))+1.
+     +d-30)
+         alpha=alpha-mu
+         beta=beta+mu
+         v(1,k)=alpha
+         v(vc,k)=beta
+    3 continue
+c     remaining vertices
+      do 5 i=2,vc-1
+         j=i-1
+         do 6 k=1,d
+            v(i,k)=v(1+mod(j,2)*(vc-1),k)
+            j=DFLOAT(j)/2.D0
+    6    continue
+    5 continue
+      return
+      end
+      subroutine ehg125(p,nv,v,vhit,nvmax,d,k,t,r,s,f,l,u)
+      logical i1,i2,match
+      integer d,execnt,h,i,i3,j,k,m,mm,nv,nvmax,p,r,s
+      integer f(r,0:1,s),l(r,0:1,s),u(r,0:1,s),vhit(nvmax)
+      DOUBLE PRECISION t
+      DOUBLE PRECISION v(nvmax,d)
+      external ehg182
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      h=nv
+      do 3 i=1,r
+         do 4 j=1,s
+            h=h+1
+            do 5 i3=1,d
+               v(h,i3)=v(f(i,0,j),i3)
+    5       continue
+            v(h,k)=t
+c           check for redundant vertex
+            match=.false.
+            m=1
+c           top of while loop
+    6       if(.not.match)then
+               i1=(m.le.nv)
+            else
+               i1=.false.
+            end if
+            if(.not.(i1))goto 7
+               match=(v(m,1).eq.v(h,1))
+               mm=2
+c              top of while loop
+    8          if(match)then
+                  i2=(mm.le.d)
+               else
+                  i2=.false.
+               end if
+               if(.not.(i2))goto 9
+                  match=(v(m,mm).eq.v(h,mm))
+                  mm=mm+1
+                  goto 8
+c              bottom of while loop
+    9          m=m+1
+               goto 6
+c           bottom of while loop
+    7       m=m-1
+            if(match)then
+               h=h-1
+            else
+               m=h
+               if(vhit(1).ge.0)then
+                  vhit(m)=p
+               end if
+            end if
+            l(i,0,j)=f(i,0,j)
+            l(i,1,j)=m
+            u(i,0,j)=m
+            u(i,1,j)=f(i,1,j)
+    4    continue
+    3 continue
+      nv=h
+      if(.not.(nv.le.nvmax))then
+         call ehg182(180)
+      end if
+      return
+      end
+      integer function ehg138(i,z,a,xi,lo,hi,ncmax)
+      logical i1
+      integer d,execnt,i,j,nc,ncmax
+      integer a(ncmax),hi(ncmax),lo(ncmax)
+      DOUBLE PRECISION xi(ncmax),z(8)
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+c     descend tree until leaf or ambiguous
+      j=i
+c     top of while loop
+    3 if(a(j).ne.0)then
+         i1=(z(a(j)).ne.xi(j))
+      else
+         i1=.false.
+      end if
+      if(.not.(i1))goto 4
+         if(z(a(j)).le.xi(j))then
+            j=lo(j)
+         else
+            j=hi(j)
+         end if
+         goto 3
+c     bottom of while loop
+    4 ehg138=j
+      return
+      end
+      subroutine ehg106(il,ir,k,nk,p,pi,n)
+      integer execnt,i,ii,il,ir,j,k,l,n,nk,r
+      integer pi(n)
+      DOUBLE PRECISION t
+      DOUBLE PRECISION p(nk,n)
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+c     find the $k$-th smallest of $n$ elements
+c     Floyd+Rivest, CACM Mar '75, Algorithm 489
+      l=il
+      r=ir
+c     top of while loop
+    3 if(.not.(l.lt.r))goto 4
+c        to avoid recursion, sophisticated partition deleted
+c        partition $x sub {l..r}$ about $t$
+         t=p(1,pi(k))
+         i=l
+         j=r
+         ii=pi(l)
+         pi(l)=pi(k)
+         pi(k)=ii
+         if(t.lt.p(1,pi(r)))then
+            ii=pi(l)
+            pi(l)=pi(r)
+            pi(r)=ii
+         end if
+c        top of while loop
+    5    if(.not.(i.lt.j))goto 6
+            ii=pi(i)
+            pi(i)=pi(j)
+            pi(j)=ii
+            i=i+1
+            j=j-1
+c           top of while loop
+    7       if(.not.(p(1,pi(i)).lt.t))goto 8
+               i=i+1
+               goto 7
+c           bottom of while loop
+    8       continue
+c           top of while loop
+    9       if(.not.(t.lt.p(1,pi(j))))goto 10
+               j=j-1
+               goto 9
+c           bottom of while loop
+   10       goto 5
+c        bottom of while loop
+    6    if(p(1,pi(l)).eq.t)then
+            ii=pi(l)
+            pi(l)=pi(j)
+            pi(j)=ii
+         else
+            j=j+1
+            ii=pi(r)
+            pi(r)=pi(j)
+            pi(j)=ii
+         end if
+         if(j.le.k)then
+            l=j+1
+         end if
+         if(k.le.j)then
+            r=j-1
+         end if
+         goto 3
+c     bottom of while loop
+    4 return
+      end
+      subroutine ehg127(q,n,d,nf,f,x,psi,y,rw,kernel,k,dist,eta,b,od,w,r
+     +cond,sing,sigma,u,e,dgamma,qraux,work,tol,dd,tdeg,cdeg,s)
+      integer column,d,dd,execnt,i,i3,i9,info,inorm2,j,jj,jpvt,k,kernel,
+     +n,nf,od,sing,tdeg
+      integer cdeg(8),psi(n)
+      double precision machep,f,i1,i10,i2,i4,i5,i6,i7,i8,rcond,rho,scal,
+     +tol
+      double precision g(15),sigma(15),u(15,15),e(15,15),b(nf,k),colnor(
+     +15),dist(n),eta(nf),dgamma(15),q(d),qraux(15),rw(n),s(0:od),w(nf),
+     +work(15),x(n,d),y(n)
+      external ehg106,ehg182,ehg184,dqrdc,dqrsl,dsvdc
+      integer idamax
+      external idamax
+      double precision d1mach
+      external d1mach
+      double precision ddot
+      external ddot
+      save machep,execnt
+      data execnt /0/
+c     colnorm -> colnor
+c     E -> g
+c     MachEps -> machep
+c     V -> e
+c     X -> b
+      execnt=execnt+1
+      if(execnt.eq.1)then
+         machep=d1mach(4)
+      end if
+c     sort by distance
+      do 3 i3=1,n
+         dist(i3)=0
+    3 continue
+      do 4 j=1,dd
+         i4=q(j)
+         do 5 i3=1,n
+            dist(i3)=dist(i3)+(x(i3,j)-i4)**2
+    5    continue
+    4 continue
+      call ehg106(1,n,nf,1,dist,psi,n)
+      rho=dist(psi(nf))*max(1.d0,f)
+      if(.not.(0.lt.rho))then
+         call ehg182(120)
+      end if
+c     compute neighborhood weights
+      if(kernel.eq.2)then
+         do 6 i=1,nf
+            if(dist(psi(i)).lt.rho)then
+               i1=dsqrt(rw(psi(i)))
+            else
+               i1=0
+            end if
+            w(i)=i1
+    6    continue
+      else
+         do 7 i3=1,nf
+            w(i3)=dsqrt(dist(psi(i3))/rho)
+    7    continue
+         do 8 i3=1,nf
+            w(i3)=dsqrt(rw(psi(i3))*(1-w(i3)**3)**3)
+    8    continue
+      end if
+      if(dabs(w(idamax(nf,w,1))).eq.0)then
+         call ehg184('at ',q,dd,1)
+         call ehg184('radius ',rho,1,1)
+         if(.not..false.)then
+            call ehg182(121)
+         end if
+      end if
+c     fill design matrix
+      column=1
+      do 9 i3=1,nf
+         b(i3,column)=w(i3)
+    9 continue
+      if(tdeg.ge.1)then
+         do 10 j=1,d
+            if(cdeg(j).ge.1)then
+               column=column+1
+               i5=q(j)
+               do 11 i3=1,nf
+                  b(i3,column)=w(i3)*(x(psi(i3),j)-i5)
+   11          continue
+            end if
+   10    continue
+      end if
+      if(tdeg.ge.2)then
+         do 12 j=1,d
+            if(cdeg(j).ge.1)then
+               if(cdeg(j).ge.2)then
+                  column=column+1
+                  i6=q(j)
+                  do 13 i3=1,nf
+                     b(i3,column)=w(i3)*(x(psi(i3),j)-i6)**2
+   13             continue
+               end if
+               do 14 jj=j+1,d
+                  if(cdeg(jj).ge.1)then
+                     column=column+1
+                     i7=q(j)
+                     i8=q(jj)
+                     do 15 i3=1,nf
+                        b(i3,column)=w(i3)*(x(psi(i3),j)-i7)*(x(psi(i3),
+     +jj)-i8)
+   15                continue
+                  end if
+   14          continue
+            end if
+   12    continue
+         k=column
+      end if
+      do 16 i3=1,nf
+         eta(i3)=w(i3)*y(psi(i3))
+   16 continue
+c     equilibrate columns
+      do 17 j=1,k
+         scal=0
+         do 18 inorm2=1,nf
+            scal=scal+b(inorm2,j)**2
+   18    continue
+         scal=dsqrt(scal)
+         if(0.lt.scal)then
+            do 19 i3=1,nf
+               b(i3,j)=b(i3,j)/scal
+   19       continue
+            colnor(j)=scal
+         else
+            colnor(j)=1
+         end if
+   17 continue
+c     singular value decomposition
+      call dqrdc(b,nf,nf,k,qraux,jpvt,work,0)
+      call dqrsl(b,nf,nf,k,qraux,eta,work,eta,eta,work,work,1000,info)
+      do 20 i9=1,k
+         do 21 i3=1,k
+            u(i3,i9)=0
+   21    continue
+   20 continue
+      do 22 i=1,k
+         do 23 j=i,k
+            u(i,j)=b(i,j)
+   23    continue
+   22 continue
+      call dsvdc(u,15,k,k,sigma,g,u,15,e,15,work,21,info)
+      if(.not.(info.eq.0))then
+         call ehg182(182)
+      end if
+      tol=sigma(1)*(100*machep)
+      rcond=min(rcond,sigma(k)/sigma(1))
+      if(sigma(k).le.tol)then
+         sing=sing+1
+         if(sing.eq.1)then
+            call ehg184('Warning. pseudoinverse used at',q,d,1)
+            call ehg184('neighborhood radius',dsqrt(rho),1,1)
+            call ehg184('reciprocal condition number ',rcond,1,1)
+         else
+            if(sing.eq.2)then
+               call ehg184('There are other near singularities as well.'
+     +,rho,1,1)
+            end if
+         end if
+      end if
+c     compensate for equilibration
+      do 24 j=1,k
+         i10=colnor(j)
+         do 25 i3=1,k
+            e(j,i3)=e(j,i3)/i10
+   25    continue
+   24 continue
+c     solve least squares problem
+      do 26 j=1,k
+         if(tol.lt.sigma(j))then
+            i2=ddot(k,u(1,j),1,eta,1)/sigma(j)
+         else
+            i2=0.d0
+         end if
+         dgamma(j)=i2
+   26 continue
+      do 27 j=0,od
+c        bug fix 2006-07-04 for k=1, od>1.   (thanks btyner@gmail.com)
+         if(j.lt.k)then
+            s(j)=ddot(k,e(j+1,1),15,dgamma,1)
+         else
+            s(j)=0.d0
+         end if
+   27 continue
+      return
+      end
+      subroutine ehg131(x,y,rw,trl,diagl,kernel,k,n,d,nc,ncmax,vc,nv,nvm
+     +ax,nf,f,a,c,hi,lo,pi,psi,v,vhit,vval,xi,dist,eta,b,ntol,fd,w,vval2
+     +,rcond,sing,dd,tdeg,cdeg,lq,lf,setlf)
+      logical setlf
+      integer identi,d,dd,execnt,i1,i2,j,k,kernel,n,nc,ncmax,nf,ntol,nv,
+     +nvmax,sing,tdeg,vc
+      integer lq(nvmax,nf),a(ncmax),c(vc,ncmax),cdeg(8),hi(ncmax),lo(ncm
+     +ax),pi(n),psi(n),vhit(nvmax)
+      double precision f,fd,rcond,trl
+      double precision lf(0:d,nvmax,nf),b(*),delta(8),diagl(n),dist(n),e
+     +ta(nf),rw(n),v(nvmax,d),vval(0:d,nvmax),vval2(0:d,nvmax),w(nf),x(n
+     +,d),xi(ncmax),y(n)
+      external ehg126,ehg182,ehg139,ehg124
+      double precision dnrm2
+      external dnrm2
+      save execnt
+      data execnt /0/
+c     Identity -> identi
+c     X -> b
+      execnt=execnt+1
+      if(.not.(d.le.8))then
+         call ehg182(101)
+      end if
+c     build $k$-d tree
+      call ehg126(d,n,vc,x,v,nvmax)
+      nv=vc
+      nc=1
+      do 3 j=1,vc
+         c(j,nc)=j
+         vhit(j)=0
+    3 continue
+      do 4 i1=1,d
+         delta(i1)=v(vc,i1)-v(1,i1)
+    4 continue
+      fd=fd*dnrm2(d,delta,1)
+      do 5 identi=1,n
+         pi(identi)=identi
+    5 continue
+      call ehg124(1,n,d,n,nv,nc,ncmax,vc,x,pi,a,xi,lo,hi,c,v,vhit,nvmax,
+     +ntol,fd,dd)
+c     smooth
+      if(trl.ne.0)then
+         do 6 i2=1,nv
+            do 7 i1=0,d
+               vval2(i1,i2)=0
+    7       continue
+    6    continue
+      end if
+      call ehg139(v,nvmax,nv,n,d,nf,f,x,pi,psi,y,rw,trl,kernel,k,dist,di
+     +st,eta,b,d,w,diagl,vval2,nc,vc,a,xi,lo,hi,c,vhit,rcond,sing,dd,tde
+     +g,cdeg,lq,lf,setlf,vval)
+      return
+      end
+      subroutine ehg133(n,d,vc,nvmax,nc,ncmax,a,c,hi,lo,v,vval,xi,m,z,s)
+      integer d,execnt,i,i1,m,nc,ncmax,nv,nvmax,vc
+      integer a(ncmax),c(vc,ncmax),hi(ncmax),lo(ncmax)
+      double precision delta(8),s(m),v(nvmax,d),vval(0:d,nvmax),xi(ncmax
+     +),z(m,d)
+      double precision ehg128
+      external ehg128
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      do 3 i=1,m
+         do 4 i1=1,d
+            delta(i1)=z(i,i1)
+    4    continue
+         s(i)=ehg128(delta,d,ncmax,vc,a,xi,lo,hi,c,v,nvmax,vval)
+    3 continue
+      return
+      end
+      subroutine ehg140(iw,i,j)
+      integer execnt,i,j
+      integer iw(i)
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      iw(i)=j
+      return
+      end
+      subroutine ehg141(trl,n,deg,k,d,nsing,dk,delta1,delta2)
+      integer d,deg,dk,k,n,nsing
+      external ehg176
+      double precision ehg176
+      double precision corx,delta1,delta2,trl,z
+      double precision c(48), c1, c2, c3, c4
+c     coef, d, deg, del
+      data c / .2971620d0,.3802660d0,.5886043d0,.4263766d0,.3346498d0,.6
+     +271053d0,.5241198d0,.3484836d0,.6687687d0,.6338795d0,.4076457d0,.7
+     +207693d0,.1611761d0,.3091323d0,.4401023d0,.2939609d0,.3580278d0,.5
+     +555741d0,.3972390d0,.4171278d0,.6293196d0,.4675173d0,.4699070d0,.6
+     +674802d0,.2848308d0,.2254512d0,.2914126d0,.5393624d0,.2517230d0,.3
+     +898970d0,.7603231d0,.2969113d0,.4740130d0,.9664956d0,.3629838d0,.5
+     +348889d0,.2075670d0,.2822574d0,.2369957d0,.3911566d0,.2981154d0,.3
+     +623232d0,.5508869d0,.3501989d0,.4371032d0,.7002667d0,.4291632d0,.4
+     +930370d0 /
+      if(deg.eq.0) dk=1
+      if(deg.eq.1) dk=d+1
+      if(deg.eq.2) dk=dfloat((d+2)*(d+1))/2.d0
+      corx=dsqrt(k/dfloat(n))
+      z=(dsqrt(k/trl)-corx)/(1-corx)
+      if(nsing .eq. 0 .and. 1 .lt. z)   call ehg184('Chernobyl! trL<k',t
+     +rl,1,1)
+      if(z .lt. 0) call ehg184('Chernobyl! trL>n',trl,1,1)
+      z=min(1.0d0,max(0.0d0,z))
+      c4=dexp(ehg176(z))
+      i=1+3*(min(d,4)-1+4*(deg-1))
+      if(d.le.4)then
+         c1=c(i)
+         c2=c(i+1)
+         c3=c(i+2)
+      else
+         c1=c(i)+(d-4)*(c(i)-c(i-3))
+         c2=c(i+1)+(d-4)*(c(i+1)-c(i-2))
+         c3=c(i+2)+(d-4)*(c(i+2)-c(i-1))
+      endif
+      delta1=n-trl*dexp(c1*z**c2*(1-z)**c3*c4)
+      i=i+24
+      if(d.le.4)then
+         c1=c(i)
+         c2=c(i+1)
+         c3=c(i+2)
+      else
+         c1=c(i)+(d-4)*(c(i)-c(i-3))
+         c2=c(i+1)+(d-4)*(c(i+1)-c(i-2))
+         c3=c(i+2)+(d-4)*(c(i+2)-c(i-1))
+      endif
+      delta2=n-trl*dexp(c1*z**c2*(1-z)**c3*c4)
+      return
+      end
+      subroutine lowesc(n,l,ll,trl,delta1,delta2)
+      integer execnt,i,j,n
+      double precision delta1,delta2,trl
+      double precision l(n,n),ll(n,n)
+      double precision ddot
+      external ddot
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+c     compute $LL~=~(I-L)(I-L)'$
+      do 3 i=1,n
+         l(i,i)=l(i,i)-1
+    3 continue
+      do 4 i=1,n
+         do 5 j=1,i
+            ll(i,j)=ddot(n,l(i,1),n,l(j,1),n)
+    5    continue
+    4 continue
+      do 6 i=1,n
+         do 7 j=i+1,n
+            ll(i,j)=ll(j,i)
+    7    continue
+    6 continue
+      do 8 i=1,n
+         l(i,i)=l(i,i)+1
+    8 continue
+c     accumulate first two traces
+      trl=0
+      delta1=0
+      do 9 i=1,n
+         trl=trl+l(i,i)
+         delta1=delta1+ll(i,i)
+    9 continue
+c     $delta sub 2 = "tr" LL sup 2$
+      delta2=0
+      do 10 i=1,n
+         delta2=delta2+ddot(n,ll(i,1),n,ll(1,i),1)
+   10 continue
+      return
+      end
+      subroutine ehg169(d,vc,nc,ncmax,nv,nvmax,v,a,xi,c,hi,lo)
+      integer d,execnt,i,j,k,mc,mv,nc,ncmax,nv,nvmax,p,vc
+      integer a(ncmax),c(vc,ncmax),hi(ncmax),lo(ncmax),novhit(1)
+      DOUBLE PRECISION v(nvmax,d),xi(ncmax)
+      external ehg125,ehg182
+      integer ifloor
+      external ifloor
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+c     as in bbox
+c     remaining vertices
+      do 3 i=2,vc-1
+         j=i-1
+         do 4 k=1,d
+            v(i,k)=v(1+mod(j,2)*(vc-1),k)
+            j=ifloor(DFLOAT(j)/2.D0)
+    4    continue
+    3 continue
+c     as in ehg131
+      mc=1
+      mv=vc
+      novhit(1)=-1
+      do 5 j=1,vc
+         c(j,mc)=j
+    5 continue
+c     as in rbuild
+      p=1
+c     top of while loop
+    6 if(.not.(p.le.nc))goto 7
+         if(a(p).ne.0)then
+            k=a(p)
+c           left son
+            mc=mc+1
+            lo(p)=mc
+c           right son
+            mc=mc+1
+            hi(p)=mc
+            call ehg125(p,mv,v,novhit,nvmax,d,k,xi(p),2**(k-1),2**(d-k),
+     +c(1,p),c(1,lo(p)),c(1,hi(p)))
+         end if
+         p=p+1
+         goto 6
+c     bottom of while loop
+    7 if(.not.(mc.eq.nc))then
+         call ehg182(193)
+      end if
+      if(.not.(mv.eq.nv))then
+         call ehg182(193)
+      end if
+      return
+      end
+       DOUBLE PRECISION function ehg176(z)
+       DOUBLE PRECISION z(*)
+       integer d,vc,nv,nc
+       integer a(17), c(2,17)
+       integer hi(17), lo(17)
+       DOUBLE PRECISION v(10,1)
+       DOUBLE PRECISION vval(0:1,10)
+       DOUBLE PRECISION xi(17)
+       DOUBLE PRECISION ehg128
+       data d,vc,nv,nc /1,2,10,17/
+       data a(1) /1/
+       data hi(1),lo(1),xi(1) /3,2,0.3705D0/
+       data c(1,1) /1/
+       data c(2,1) /2/
+       data a(2) /1/
+       data hi(2),lo(2),xi(2) /5,4,0.2017D0/
+       data c(1,2) /1/
+       data c(2,2) /3/
+       data a(3) /1/
+       data hi(3),lo(3),xi(3) /7,6,0.5591D0/
+       data c(1,3) /3/
+       data c(2,3) /2/
+       data a(4) /1/
+       data hi(4),lo(4),xi(4) /9,8,0.1204D0/
+       data c(1,4) /1/
+       data c(2,4) /4/
+       data a(5) /1/
+       data hi(5),lo(5),xi(5) /11,10,0.2815D0/
+       data c(1,5) /4/
+       data c(2,5) /3/
+       data a(6) /1/
+       data hi(6),lo(6),xi(6) /13,12,0.4536D0/
+       data c(1,6) /3/
+       data c(2,6) /5/
+       data a(7) /1/
+       data hi(7),lo(7),xi(7) /15,14,0.7132D0/
+       data c(1,7) /5/
+       data c(2,7) /2/
+       data a(8) /0/
+       data c(1,8) /1/
+       data c(2,8) /6/
+       data a(9) /0/
+       data c(1,9) /6/
+       data c(2,9) /4/
+       data a(10) /0/
+       data c(1,10) /4/
+       data c(2,10) /7/
+       data a(11) /0/
+       data c(1,11) /7/
+       data c(2,11) /3/
+       data a(12) /0/
+       data c(1,12) /3/
+       data c(2,12) /8/
+       data a(13) /0/
+       data c(1,13) /8/
+       data c(2,13) /5/
+       data a(14) /0/
+       data c(1,14) /5/
+       data c(2,14) /9/
+       data a(15) /1/
+       data hi(15),lo(15),xi(15) /17,16,0.8751D0/
+       data c(1,15) /9/
+       data c(2,15) /2/
+       data a(16) /0/
+       data c(1,16) /9/
+       data c(2,16) /10/
+       data a(17) /0/
+       data c(1,17) /10/
+       data c(2,17) /2/
+       data vval(0,1) /-9.0572D-2/
+       data v(1,1) /-5.D-3/
+       data vval(1,1) /4.4844D0/
+       data vval(0,2) /-1.0856D-2/
+       data v(2,1) /1.005D0/
+       data vval(1,2) /-0.7736D0/
+       data vval(0,3) /-5.3718D-2/
+       data v(3,1) /0.3705D0/
+       data vval(1,3) /-0.3495D0/
+       data vval(0,4) /2.6152D-2/
+       data v(4,1) /0.2017D0/
+       data vval(1,4) /-0.7286D0/
+       data vval(0,5) /-5.8387D-2/
+       data v(5,1) /0.5591D0/
+       data vval(1,5) /0.1611D0/
+       data vval(0,6) /9.5807D-2/
+       data v(6,1) /0.1204D0/
+       data vval(1,6) /-0.7978D0/
+       data vval(0,7) /-3.1926D-2/
+       data v(7,1) /0.2815D0/
+       data vval(1,7) /-0.4457D0/
+       data vval(0,8) /-6.4170D-2/
+       data v(8,1) /0.4536D0/
+       data vval(1,8) /3.2813D-2/
+       data vval(0,9) /-2.0636D-2/
+       data v(9,1) /0.7132D0/
+       data vval(1,9) /0.3350D0/
+       data vval(0,10) /4.0172D-2/
+       data v(10,1) /0.8751D0/
+       data vval(1,10) /-4.1032D-2/
+       ehg176=ehg128(z,d,nc,vc,a,xi,lo,hi,c,v,nv,vval)
+       end
+      subroutine lowesa(trl,n,d,tau,nsing,delta1,delta2)
+      integer d,dka,dkb,execnt,n,nsing,tau
+      double precision alpha,d1a,d1b,d2a,d2b,delta1,delta2,trl
+      external ehg141
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      call ehg141(trl,n,1,tau,d,nsing,dka,d1a,d2a)
+      call ehg141(trl,n,2,tau,d,nsing,dkb,d1b,d2b)
+      alpha=dfloat(tau-dka)/dfloat(dkb-dka)
+      delta1=(1-alpha)*d1a+alpha*d1b
+      delta2=(1-alpha)*d2a+alpha*d2b
+      return
+      end
+      subroutine ehg191(m,z,l,d,n,nf,nv,ncmax,vc,a,xi,lo,hi,c,v,nvmax,vv
+     +al2,lf,lq)
+      integer lq1,d,execnt,i,i1,i2,j,m,n,nc,ncmax,nf,nv,nvmax,p,vc
+      integer lq(nvmax,nf),a(ncmax),c(vc,ncmax),hi(ncmax),lo(ncmax)
+      double precision l(m,n),lf(0:d,nvmax,nf),v(nvmax,d),vval2(0:d,nvma
+     +x),xi(ncmax),z(m,d),zi(8)
+      double precision ehg128
+      external ehg128
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      do 3 j=1,n
+         do 4 i2=1,nv
+            do 5 i1=0,d
+               vval2(i1,i2)=0
+    5       continue
+    4    continue
+         do 6 i=1,nv
+c           linear search for i in Lq
+            lq1=lq(i,1)
+            lq(i,1)=j
+            p=nf
+c           top of while loop
+    7       if(.not.(lq(i,p).ne.j))goto 8
+               p=p-1
+               goto 7
+c           bottom of while loop
+    8       lq(i,1)=lq1
+            if(lq(i,p).eq.j)then
+               do 9 i1=0,d
+                  vval2(i1,i)=lf(i1,i,p)
+    9          continue
+            end if
+    6    continue
+         do 10 i=1,m
+            do 11 i1=1,d
+               zi(i1)=z(i,i1)
+   11       continue
+            l(i,j)=ehg128(zi,d,ncmax,vc,a,xi,lo,hi,c,v,nvmax,vval2)
+   10    continue
+    3 continue
+      return
+      end
+      subroutine ehg196(tau,d,f,trl)
+      integer d,dka,dkb,execnt,tau
+      double precision alpha,f,trl,trla,trlb
+      external ehg197
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      call ehg197(1,tau,d,f,dka,trla)
+      call ehg197(2,tau,d,f,dkb,trlb)
+      alpha=dfloat(tau-dka)/dfloat(dkb-dka)
+      trl=(1-alpha)*trla+alpha*trlb
+      return
+      end
+      subroutine ehg197(deg,tau,d,f,dk,trl)
+      integer d,deg,dk,tau
+      double precision trl, f
+      dk = 0
+      if(deg.eq.1) dk=d+1
+      if(deg.eq.2) dk=dfloat((d+2)*(d+1))/2.d0
+      g1 = (-0.08125d0*d+0.13d0)*d+1.05d0
+      trl = dk*(1+max(0.d0,(g1-f)/f))
+      return
+      end
+      subroutine ehg192(y,d,n,nf,nv,nvmax,vval,lf,lq)
+      integer d,execnt,i,i1,i2,j,n,nf,nv,nvmax
+      integer lq(nvmax,nf)
+      DOUBLE PRECISION i3
+      DOUBLE PRECISION lf(0:d,nvmax,nf),vval(0:d,nvmax),y(n)
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      do 3 i2=1,nv
+         do 4 i1=0,d
+            vval(i1,i2)=0
+    4    continue
+    3 continue
+      do 5 i=1,nv
+         do 6 j=1,nf
+            i3=y(lq(i,j))
+            do 7 i1=0,d
+               vval(i1,i)=vval(i1,i)+i3*lf(i1,i,j)
+    7       continue
+    6    continue
+    5 continue
+      return
+      end
+      DOUBLE PRECISION function ehg128(z,d,ncmax,vc,a,xi,lo,hi,c,v,nvmax
+     +,vval)
+      logical i10,i2,i3,i4,i5,i6,i7,i8,i9
+      integer d,execnt,i,i1,i11,i12,ig,ii,j,lg,ll,m,nc,ncmax,nt,nv,nvmax
+     +,ur,vc
+      integer a(ncmax),c(vc,ncmax),hi(ncmax),lo(ncmax),t(20)
+      DOUBLE PRECISION ge,gn,gs,gw,gpe,gpn,gps,gpw,h,phi0,phi1,psi0,psi1
+     +,s,sew,sns,v0,v1,xibar
+      DOUBLE PRECISION g(0:8,256),g0(0:8),g1(0:8),v(nvmax,d),vval(0:d,nv
+     +max),xi(ncmax),z(d)
+      external ehg182,ehg184
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+c     locate enclosing cell
+      nt=1
+      t(nt)=1
+      j=1
+c     top of while loop
+    3 if(.not.(a(j).ne.0))goto 4
+         nt=nt+1
+c     bug fix 2006-07-18 (thanks, btyner@gmail.com)
+         if(z(a(j)).le.xi(j))then
+            i1=lo(j)
+         else
+            i1=hi(j)
+         end if
+         t(nt)=i1
+         if(.not.(nt.lt.20))then
+            call ehg182(181)
+         end if
+         j=t(nt)
+         goto 3
+c     bottom of while loop
+    4 continue
+c     tensor
+      do 5 i12=1,vc
+         do 6 i11=0,d
+            g(i11,i12)=vval(i11,c(i12,j))
+    6    continue
+    5 continue
+      lg=vc
+      ll=c(1,j)
+      ur=c(vc,j)
+      do 7 i=d,1,-1
+         h=(z(i)-v(ll,i))/(v(ur,i)-v(ll,i))
+         if(h.lt.-.001D0)then
+            call ehg184('eval ',z,d,1)
+            call ehg184('lowerlimit ',v(ll,1),d,nvmax)
+         else
+            if(1.001D0.lt.h)then
+               call ehg184('eval ',z,d,1)
+               call ehg184('upperlimit ',v(ur,1),d,nvmax)
+            end if
+         end if
+         if(-.001D0.le.h)then
+            i2=(h.le.1.001D0)
+         else
+            i2=.false.
+         end if
+         if(.not.i2)then
+            call ehg182(122)
+         end if
+         lg=DFLOAT(lg)/2.D0
+         do 8 ig=1,lg
+c           Hermite basis
+            phi0=(1-h)**2*(1+2*h)
+            phi1=h**2*(3-2*h)
+            psi0=h*(1-h)**2
+            psi1=h**2*(h-1)
+            g(0,ig)=phi0*g(0,ig)+phi1*g(0,ig+lg)+(psi0*g(i,ig)+psi1*g(i,
+     +ig+lg))*(v(ur,i)-v(ll,i))
+            do 9 ii=1,i-1
+               g(ii,ig)=phi0*g(ii,ig)+phi1*g(ii,ig+lg)
+    9       continue
+    8    continue
+    7 continue
+      s=g(0,1)
+c     blending
+      if(d.eq.2)then
+c        ----- North -----
+         v0=v(ll,1)
+         v1=v(ur,1)
+         do 10 i11=0,d
+            g0(i11)=vval(i11,c(3,j))
+   10    continue
+         do 11 i11=0,d
+            g1(i11)=vval(i11,c(4,j))
+   11    continue
+         xibar=v(ur,2)
+         m=nt-1
+c        top of while loop
+   12    if(m.eq.0)then
+            i4=.true.
+         else
+            if(a(t(m)).eq.2)then
+               i3=(xi(t(m)).eq.xibar)
+            else
+               i3=.false.
+            end if
+            i4=i3
+         end if
+         if(.not.(.not.i4))goto 13
+            m=m-1
+c           voidp junk
+            goto 12
+c        bottom of while loop
+   13    if(m.ge.1)then
+            m=hi(t(m))
+c           top of while loop
+   14       if(.not.(a(m).ne.0))goto 15
+               if(z(a(m)).le.xi(m))then
+                  m=lo(m)
+               else
+                  m=hi(m)
+               end if
+               goto 14
+c           bottom of while loop
+   15       if(v0.lt.v(c(1,m),1))then
+               v0=v(c(1,m),1)
+               do 16 i11=0,d
+                  g0(i11)=vval(i11,c(1,m))
+   16          continue
+            end if
+            if(v(c(2,m),1).lt.v1)then
+               v1=v(c(2,m),1)
+               do 17 i11=0,d
+                  g1(i11)=vval(i11,c(2,m))
+   17          continue
+            end if
+         end if
+         h=(z(1)-v0)/(v1-v0)
+c        Hermite basis
+         phi0=(1-h)**2*(1+2*h)
+         phi1=h**2*(3-2*h)
+         psi0=h*(1-h)**2
+         psi1=h**2*(h-1)
+         gn=phi0*g0(0)+phi1*g1(0)+(psi0*g0(1)+psi1*g1(1))*(v1-v0)
+         gpn=phi0*g0(2)+phi1*g1(2)
+c        ----- South -----
+         v0=v(ll,1)
+         v1=v(ur,1)
+         do 18 i11=0,d
+            g0(i11)=vval(i11,c(1,j))
+   18    continue
+         do 19 i11=0,d
+            g1(i11)=vval(i11,c(2,j))
+   19    continue
+         xibar=v(ll,2)
+         m=nt-1
+c        top of while loop
+   20    if(m.eq.0)then
+            i6=.true.
+         else
+            if(a(t(m)).eq.2)then
+               i5=(xi(t(m)).eq.xibar)
+            else
+               i5=.false.
+            end if
+            i6=i5
+         end if
+         if(.not.(.not.i6))goto 21
+            m=m-1
+c           voidp junk
+            goto 20
+c        bottom of while loop
+   21    if(m.ge.1)then
+            m=lo(t(m))
+c           top of while loop
+   22       if(.not.(a(m).ne.0))goto 23
+               if(z(a(m)).le.xi(m))then
+                  m=lo(m)
+               else
+                  m=hi(m)
+               end if
+               goto 22
+c           bottom of while loop
+   23       if(v0.lt.v(c(3,m),1))then
+               v0=v(c(3,m),1)
+               do 24 i11=0,d
+                  g0(i11)=vval(i11,c(3,m))
+   24          continue
+            end if
+            if(v(c(4,m),1).lt.v1)then
+               v1=v(c(4,m),1)
+               do 25 i11=0,d
+                  g1(i11)=vval(i11,c(4,m))
+   25          continue
+            end if
+         end if
+         h=(z(1)-v0)/(v1-v0)
+c        Hermite basis
+         phi0=(1-h)**2*(1+2*h)
+         phi1=h**2*(3-2*h)
+         psi0=h*(1-h)**2
+         psi1=h**2*(h-1)
+         gs=phi0*g0(0)+phi1*g1(0)+(psi0*g0(1)+psi1*g1(1))*(v1-v0)
+         gps=phi0*g0(2)+phi1*g1(2)
+c        ----- East -----
+         v0=v(ll,2)
+         v1=v(ur,2)
+         do 26 i11=0,d
+            g0(i11)=vval(i11,c(2,j))
+   26    continue
+         do 27 i11=0,d
+            g1(i11)=vval(i11,c(4,j))
+   27    continue
+         xibar=v(ur,1)
+         m=nt-1
+c        top of while loop
+   28    if(m.eq.0)then
+            i8=.true.
+         else
+            if(a(t(m)).eq.1)then
+               i7=(xi(t(m)).eq.xibar)
+            else
+               i7=.false.
+            end if
+            i8=i7
+         end if
+         if(.not.(.not.i8))goto 29
+            m=m-1
+c           voidp junk
+            goto 28
+c        bottom of while loop
+   29    if(m.ge.1)then
+            m=hi(t(m))
+c           top of while loop
+   30       if(.not.(a(m).ne.0))goto 31
+               if(z(a(m)).le.xi(m))then
+                  m=lo(m)
+               else
+                  m=hi(m)
+               end if
+               goto 30
+c           bottom of while loop
+   31       if(v0.lt.v(c(1,m),2))then
+               v0=v(c(1,m),2)
+               do 32 i11=0,d
+                  g0(i11)=vval(i11,c(1,m))
+   32          continue
+            end if
+            if(v(c(3,m),2).lt.v1)then
+               v1=v(c(3,m),2)
+               do 33 i11=0,d
+                  g1(i11)=vval(i11,c(3,m))
+   33          continue
+            end if
+         end if
+         h=(z(2)-v0)/(v1-v0)
+c        Hermite basis
+         phi0=(1-h)**2*(1+2*h)
+         phi1=h**2*(3-2*h)
+         psi0=h*(1-h)**2
+         psi1=h**2*(h-1)
+         ge=phi0*g0(0)+phi1*g1(0)+(psi0*g0(2)+psi1*g1(2))*(v1-v0)
+         gpe=phi0*g0(1)+phi1*g1(1)
+c        ----- West -----
+         v0=v(ll,2)
+         v1=v(ur,2)
+         do 34 i11=0,d
+            g0(i11)=vval(i11,c(1,j))
+   34    continue
+         do 35 i11=0,d
+            g1(i11)=vval(i11,c(3,j))
+   35    continue
+         xibar=v(ll,1)
+         m=nt-1
+c        top of while loop
+   36    if(m.eq.0)then
+            i10=.true.
+         else
+            if(a(t(m)).eq.1)then
+               i9=(xi(t(m)).eq.xibar)
+            else
+               i9=.false.
+            end if
+            i10=i9
+         end if
+         if(.not.(.not.i10))goto 37
+            m=m-1
+c           voidp junk
+            goto 36
+c        bottom of while loop
+   37    if(m.ge.1)then
+            m=lo(t(m))
+c           top of while loop
+   38       if(.not.(a(m).ne.0))goto 39
+               if(z(a(m)).le.xi(m))then
+                  m=lo(m)
+               else
+                  m=hi(m)
+               end if
+               goto 38
+c           bottom of while loop
+   39       if(v0.lt.v(c(2,m),2))then
+               v0=v(c(2,m),2)
+               do 40 i11=0,d
+                  g0(i11)=vval(i11,c(2,m))
+   40          continue
+            end if
+            if(v(c(4,m),2).lt.v1)then
+               v1=v(c(4,m),2)
+               do 41 i11=0,d
+                  g1(i11)=vval(i11,c(4,m))
+   41          continue
+            end if
+         end if
+         h=(z(2)-v0)/(v1-v0)
+c        Hermite basis
+         phi0=(1-h)**2*(1+2*h)
+         phi1=h**2*(3-2*h)
+         psi0=h*(1-h)**2
+         psi1=h**2*(h-1)
+         gw=phi0*g0(0)+phi1*g1(0)+(psi0*g0(2)+psi1*g1(2))*(v1-v0)
+         gpw=phi0*g0(1)+phi1*g1(1)
+c        NS
+         h=(z(2)-v(ll,2))/(v(ur,2)-v(ll,2))
+c        Hermite basis
+         phi0=(1-h)**2*(1+2*h)
+         phi1=h**2*(3-2*h)
+         psi0=h*(1-h)**2
+         psi1=h**2*(h-1)
+         sns=phi0*gs+phi1*gn+(psi0*gps+psi1*gpn)*(v(ur,2)-v(ll,2))
+c        EW
+         h=(z(1)-v(ll,1))/(v(ur,1)-v(ll,1))
+c        Hermite basis
+         phi0=(1-h)**2*(1+2*h)
+         phi1=h**2*(3-2*h)
+         psi0=h*(1-h)**2
+         psi1=h**2*(h-1)
+         sew=phi0*gw+phi1*ge+(psi0*gpw+psi1*gpe)*(v(ur,1)-v(ll,1))
+         s=(sns+sew)-s
+      end if
+      ehg128=s
+      return
+      end
+      integer function ifloor(x)
+      DOUBLE PRECISION x
+      ifloor=x
+      if(ifloor.gt.x) ifloor=ifloor-1
+      end
+      DOUBLE PRECISION functionDSIGN(a1,a2)
+      DOUBLE PRECISION a1, a2
+      DSIGN=DABS(a1)
+      if(a2.ge.0)DSIGN=-DSIGN
+      end
+      subroutine ehg136(u,lm,m,n,d,nf,f,x,psi,y,rw,kernel,k,dist,eta,b,o
+     +d,o,ihat,w,rcond,sing,dd,tdeg,cdeg,s)
+      integer identi,d,dd,execnt,i,i1,ihat,info,j,k,kernel,l,lm,m,n,nf,o
+     +d,sing,tdeg
+      integer cdeg(8),psi(n)
+      double precision f,i2,rcond,scale,tol
+      double precision o(m,n),sigma(15),e(15,15),g(15,15),b(nf,k),dist(n
+     +),eta(nf),dgamma(15),q(8),qraux(15),rw(n),s(0:od,m),u(lm,d),w(nf),
+     +work(15),x(n,d),y(n)
+      external ehg127,ehg182,dqrsl
+      double precision ddot
+      external ddot
+      save execnt
+      data execnt /0/
+c     V -> g
+c     U -> e
+c     Identity -> identi
+c     L -> o
+c     X -> b
+      execnt=execnt+1
+      if(.not.(k.le.nf-1))then
+         call ehg182(104)
+      end if
+      if(.not.(k.le.15))then
+         call ehg182(105)
+      end if
+      do 3 identi=1,n
+         psi(identi)=identi
+    3 continue
+      do 4 l=1,m
+         do 5 i1=1,d
+            q(i1)=u(l,i1)
+    5    continue
+         call ehg127(q,n,d,nf,f,x,psi,y,rw,kernel,k,dist,eta,b,od,w,rcon
+     +d,sing,sigma,e,g,dgamma,qraux,work,tol,dd,tdeg,cdeg,s(0,l))
+         if(ihat.eq.1)then
+c           $L sub {l,l} =
+c           V sub {1,:} SIGMA sup {+} U sup T
+c           (Q sup T W e sub i )$
+            if(.not.(m.eq.n))then
+               call ehg182(123)
+            end if
+c           find $i$ such that $l = psi sub i$
+            i=1
+c           top of while loop
+    6       if(.not.(l.ne.psi(i)))goto 7
+               i=i+1
+               if(.not.(i.lt.nf))then
+                  call ehg182(123)
+               end if
+               goto 6
+c           bottom of while loop
+    7       do 8 i1=1,nf
+               eta(i1)=0
+    8       continue
+            eta(i)=w(i)
+c           $eta = Q sup T W e sub i$
+            call dqrsl(b,nf,nf,k,qraux,eta,eta,eta,eta,eta,eta,1000,info
+     +)
+c           $gamma = U sup T eta sub {1:k}$
+            do 9 i1=1,k
+               dgamma(i1)=0
+    9       continue
+            do 10 j=1,k
+               i2=eta(j)
+               do 11 i1=1,k
+                  dgamma(i1)=dgamma(i1)+i2*e(j,i1)
+   11          continue
+   10       continue
+c           $gamma = SIGMA sup {+} gamma$
+            do 12 j=1,k
+               if(tol.lt.sigma(j))then
+                  dgamma(j)=dgamma(j)/sigma(j)
+               else
+                  dgamma(j)=0.d0
+               end if
+   12       continue
+c           voidp junk
+c           voidp junk
+            o(l,1)=ddot(k,g(1,1),15,dgamma,1)
+         else
+            if(ihat.eq.2)then
+c              $L sub {l,:} =
+c              V sub {1,:} SIGMA sup {+}
+c              ( U sup T Q sup T ) W $
+               do 13 i1=1,n
+                  o(l,i1)=0
+   13          continue
+               do 14 j=1,k
+                  do 15 i1=1,nf
+                     eta(i1)=0
+   15             continue
+                  do 16 i1=1,k
+                     eta(i1)=e(i1,j)
+   16             continue
+                  call dqrsl(b,nf,nf,k,qraux,eta,eta,work,work,work,work
+     +,10000,info)
+                  if(tol.lt.sigma(j))then
+                     scale=1.d0/sigma(j)
+                  else
+                     scale=0.d0
+                  end if
+                  do 17 i1=1,nf
+                     eta(i1)=eta(i1)*(scale*w(i1))
+   17             continue
+                  do 18 i=1,nf
+                     o(l,psi(i))=o(l,psi(i))+g(1,j)*eta(i)
+   18             continue
+   14          continue
+            end if
+         end if
+    4 continue
+      return
+      end
+      subroutine ehg139(v,nvmax,nv,n,d,nf,f,x,pi,psi,y,rw,trl,kernel,k,d
+     +ist,phi,eta,b,od,w,diagl,vval2,ncmax,vc,a,xi,lo,hi,c,vhit,rcond,si
+     +ng,dd,tdeg,cdeg,lq,lf,setlf,s)
+      logical setlf
+      integer identi,d,dd,execnt,i,i2,i3,i5,i6,ii,ileaf,info,j,k,kernel,
+     +l,n,nc,ncmax,nf,nleaf,nv,nvmax,od,sing,tdeg,vc
+      integer lq(nvmax,nf),a(ncmax),c(vc,ncmax),cdeg(8),hi(ncmax),leaf(2
+     +56),lo(ncmax),phi(n),pi(n),psi(n),vhit(nvmax)
+      DOUBLE PRECISION f,i1,i4,i7,rcond,scale,term,tol,trl
+      DOUBLE PRECISION lf(0:d,nvmax,nf),sigma(15),u(15,15),e(15,15),b(nf
+     +,k),diagl(n),dist(n),eta(nf),DGAMMA(15),q(8),qraux(15),rw(n),s(0:o
+     +d,nv),v(nvmax,d),vval2(0:d,nv),w(nf),work(15),x(n,d),xi(ncmax),y(n
+     +),z(8)
+      external ehg127,ehg182,DQRSL,ehg137
+      DOUBLE PRECISION ehg128
+      external ehg128
+      DOUBLE PRECISION DDOT
+      external DDOT
+      save execnt
+      data execnt /0/
+c     V -> e
+c     Identity -> identi
+c     X -> b
+      execnt=execnt+1
+c     l2fit with trace(L)
+      if(.not.(k.le.nf-1))then
+         call ehg182(104)
+      end if
+      if(.not.(k.le.15))then
+         call ehg182(105)
+      end if
+      if(trl.ne.0)then
+         do 3 i5=1,n
+            diagl(i5)=0
+    3    continue
+         do 4 i6=1,nv
+            do 5 i5=0,d
+               vval2(i5,i6)=0
+    5       continue
+    4    continue
+      end if
+      do 6 identi=1,n
+         psi(identi)=identi
+    6 continue
+      do 7 l=1,nv
+         do 8 i5=1,d
+            q(i5)=v(l,i5)
+    8    continue
+         call ehg127(q,n,d,nf,f,x,psi,y,rw,kernel,k,dist,eta,b,od,w,rcon
+     +d,sing,sigma,u,e,DGAMMA,qraux,work,tol,dd,tdeg,cdeg,s(0,l))
+         if(trl.ne.0)then
+c           invert $psi$
+            do 9 i5=1,n
+               phi(i5)=0
+    9       continue
+            do 10 i=1,nf
+               phi(psi(i))=i
+   10       continue
+            do 11 i5=1,d
+               z(i5)=v(l,i5)
+   11       continue
+            call ehg137(z,vhit(l),leaf,nleaf,d,nv,nvmax,ncmax,vc,a,xi,lo
+     +,hi,c,v)
+            do 12 ileaf=1,nleaf
+               do 13 ii=lo(leaf(ileaf)),hi(leaf(ileaf))
+                  i=phi(pi(ii))
+                  if(i.ne.0)then
+                     if(.not.(psi(i).eq.pi(ii)))then
+                        call ehg182(194)
+                     end if
+                     do 14 i5=1,nf
+                        eta(i5)=0
+   14                continue
+                     eta(i)=w(i)
+c                    $eta = Q sup T W e sub i$
+                     call DQRSL(b,nf,nf,k,qraux,eta,work,eta,eta,work,wo
+     +rk,1000,info)
+                     do 15 j=1,k
+                        if(tol.lt.sigma(j))then
+                           i4=DDOT(k,u(1,j),1,eta,1)/sigma(j)
+                        else
+                           i4=0.D0
+                        end if
+                       DGAMMA(j)=i4
+   15                continue
+                     do 16 j=1,d+1
+c                       bug fix 2006-07-15 for k=1, od>1.   (thanks btyner@gmail.com)
+                        if(j.le.k)then
+                           vval2(j-1,l)=DDOT(k,e(j,1),15,DGAMMA,1)
+                        else
+                           vval2(j-1,l)=0
+                        end if
+   16                continue
+                     do 17 i5=1,d
+                        z(i5)=x(pi(ii),i5)
+   17                continue
+                     term=ehg128(z,d,ncmax,vc,a,xi,lo,hi,c,v,nvmax,vval2
+     +)
+                     diagl(pi(ii))=diagl(pi(ii))+term
+                     do 18 i5=0,d
+                        vval2(i5,l)=0
+   18                continue
+                  end if
+   13          continue
+   12       continue
+         end if
+         if(setlf)then
+c           $Lf sub {:,l,:} = V SIGMA sup {+} U sup T Q sup T W$
+            if(.not.(k.ge.d+1))then
+               call ehg182(196)
+            end if
+            do 19 i5=1,nf
+               lq(l,i5)=psi(i5)
+   19       continue
+            do 20 i6=1,nf
+               do 21 i5=0,d
+                  lf(i5,l,i6)=0
+   21          continue
+   20       continue
+            do 22 j=1,k
+               do 23 i5=1,nf
+                  eta(i5)=0
+   23          continue
+               do 24 i5=1,k
+                  eta(i5)=u(i5,j)
+   24          continue
+               call DQRSL(b,nf,nf,k,qraux,eta,eta,work,work,work,work,10
+     +000,info)
+               if(tol.lt.sigma(j))then
+                  scale=1.D0/sigma(j)
+               else
+                  scale=0.D0
+               end if
+               do 25 i5=1,nf
+                  eta(i5)=eta(i5)*(scale*w(i5))
+   25          continue
+               do 26 i=1,nf
+                  i7=eta(i)
+                  do 27 i5=0,d
+                     if(i5.lt.k)then
+                        lf(i5,l,i)=lf(i5,l,i)+e(1+i5,j)*i7
+                     else
+                        lf(i5,l,i)=0
+                     end if
+   27             continue
+   26          continue
+   22       continue
+         end if
+    7 continue
+      if(trl.ne.0)then
+         if(n.le.0)then
+            trl=0.D0
+         else
+            i3=n
+            i1=diagl(i3)
+            do 28 i2=i3-1,1,-1
+               i1=diagl(i2)+i1
+   28       continue
+            trl=i1
+         end if
+      end if
+      return
+      end
+      subroutine dqrdc(x,ldx,n,p,qraux,jpvt,work,job)
+      integer ldx,n,p,job
+      integer jpvt(1)
+      double precision x(ldx,1),qraux(1),work(1)
+c
+c     dqrdc uses householder transformations to compute the qr
+c     factorization of an n by p matrix x.  column pivoting
+c     based on the 2-norms of the reduced columns may be
+c     performed at the users option.
+c
+c     on entry
+c
+c        x       double precision(ldx,p), where ldx .ge. n.
+c                x contains the matrix whose decomposition is to be
+c                computed.
+c
+c        ldx     integer.
+c                ldx is the leading dimension of the array x.
+c
+c        n       integer.
+c                n is the number of rows of the matrix x.
+c
+c        p       integer.
+c                p is the number of columns of the matrix x.
+c
+c        jpvt    integer(p).
+c                jpvt contains integers that control the selection
+c                of the pivot columns.  the k-th column x(k) of x
+c                is placed in one of three classes according to the
+c                value of jpvt(k).
+c
+c                   if jpvt(k) .gt. 0, then x(k) is an initial
+c                                      column.
+c
+c                   if jpvt(k) .eq. 0, then x(k) is a free column.
+c
+c                   if jpvt(k) .lt. 0, then x(k) is a final column.
+c
+c                before the decomposition is computed, initial columns
+c                are moved to the beginning of the array x and final
+c                columns to the end.  both initial and final columns
+c                are frozen in place during the computation and only
+c                free columns are moved.  at the k-th stage of the
+c                reduction, if x(k) is occupied by a free column
+c                it is interchanged with the free column of largest
+c                reduced norm.  jpvt is not referenced if
+c                job .eq. 0.
+c
+c        work    double precision(p).
+c                work is a work array.  work is not referenced if
+c                job .eq. 0.
+c
+c        job     integer.
+c                job is an integer that initiates column pivoting.
+c                if job .eq. 0, no pivoting is done.
+c                if job .ne. 0, pivoting is done.
+c
+c     on return
+c
+c        x       x contains in its upper triangle the upper
+c                triangular matrix r of the qr factorization.
+c                below its diagonal x contains information from
+c                which the orthogonal part of the decomposition
+c                can be recovered.  note that if pivoting has
+c                been requested, the decomposition is not that
+c                of the original matrix x but that of x
+c                with its columns permuted as described by jpvt.
+c
+c        qraux   double precision(p).
+c                qraux contains further information required to recover
+c                the orthogonal part of the decomposition.
+c
+c        jpvt    jpvt(k) contains the index of the column of the
+c                original matrix that has been interchanged into
+c                the k-th column, if pivoting was requested.
+c
+c     linpack. this version dated 08/14/78 .
+c     g.w. stewart, university of maryland, argonne national lab.
+c
+c     dqrdc uses the following functions and subprograms.
+c
+c     blas daxpy,ddot,dscal,dswap,dnrm2
+c     fortran dabs,dmax1,min0,dsqrt
+c
+c     internal variables
+c
+      integer j,jp,l,lp1,lup,maxj,pl,pu
+      double precision maxnrm,dnrm2,tt
+      double precision ddot,nrmxl,t
+      logical negj,swapj
+c
+c
+      pl = 1
+      pu = 0
+      if (job .eq. 0) go to 60
+c
+c        pivoting has been requested.  rearrange the columns
+c        according to jpvt.
+c
+         do 20 j = 1, p
+            swapj = jpvt(j) .gt. 0
+            negj = jpvt(j) .lt. 0
+            jpvt(j) = j
+            if (negj) jpvt(j) = -j
+            if (.not.swapj) go to 10
+               if (j .ne. pl) call dswap(n,x(1,pl),1,x(1,j),1)
+               jpvt(j) = jpvt(pl)
+               jpvt(pl) = j
+               pl = pl + 1
+   10       continue
+   20    continue
+         pu = p
+         do 50 jj = 1, p
+            j = p - jj + 1
+            if (jpvt(j) .ge. 0) go to 40
+               jpvt(j) = -jpvt(j)
+               if (j .eq. pu) go to 30
+                  call dswap(n,x(1,pu),1,x(1,j),1)
+                  jp = jpvt(pu)
+                  jpvt(pu) = jpvt(j)
+                  jpvt(j) = jp
+   30          continue
+               pu = pu - 1
+   40       continue
+   50    continue
+   60 continue
+c
+c     compute the norms of the free columns.
+c
+      if (pu .lt. pl) go to 80
+      do 70 j = pl, pu
+         qraux(j) = dnrm2(n,x(1,j),1)
+         work(j) = qraux(j)
+   70 continue
+   80 continue
+c
+c     perform the householder reduction of x.
+c
+      lup = min0(n,p)
+      do 200 l = 1, lup
+         if (l .lt. pl .or. l .ge. pu) go to 120
+c
+c           locate the column of largest norm and bring it
+c           into the pivot position.
+c
+            maxnrm = 0.0d0
+            maxj = l
+            do 100 j = l, pu
+               if (qraux(j) .le. maxnrm) go to 90
+                  maxnrm = qraux(j)
+                  maxj = j
+   90          continue
+  100       continue
+            if (maxj .eq. l) go to 110
+               call dswap(n,x(1,l),1,x(1,maxj),1)
+               qraux(maxj) = qraux(l)
+               work(maxj) = work(l)
+               jp = jpvt(maxj)
+               jpvt(maxj) = jpvt(l)
+               jpvt(l) = jp
+  110       continue
+  120    continue
+         qraux(l) = 0.0d0
+         if (l .eq. n) go to 190
+c
+c           compute the householder transformation for column l.
+c
+            nrmxl = dnrm2(n-l+1,x(l,l),1)
+            if (nrmxl .eq. 0.0d0) go to 180
+               if (x(l,l) .ne. 0.0d0) nrmxl = dsign(nrmxl,x(l,l))
+               call dscal(n-l+1,1.0d0/nrmxl,x(l,l),1)
+               x(l,l) = 1.0d0 + x(l,l)
+c
+c              apply the transformation to the remaining columns,
+c              updating the norms.
+c
+               lp1 = l + 1
+               if (p .lt. lp1) go to 170
+               do 160 j = lp1, p
+                  t = -ddot(n-l+1,x(l,l),1,x(l,j),1)/x(l,l)
+                  call daxpy(n-l+1,t,x(l,l),1,x(l,j),1)
+                  if (j .lt. pl .or. j .gt. pu) go to 150
+                  if (qraux(j) .eq. 0.0d0) go to 150
+                     tt = 1.0d0 - (dabs(x(l,j))/qraux(j))**2
+                     tt = dmax1(tt,0.0d0)
+                     t = tt
+                     tt = 1.0d0 + 0.05d0*tt*(qraux(j)/work(j))**2
+                     if (tt .eq. 1.0d0) go to 130
+                        qraux(j) = qraux(j)*dsqrt(t)
+                     go to 140
+  130                continue
+                        qraux(j) = dnrm2(n-l,x(l+1,j),1)
+                        work(j) = qraux(j)
+  140                continue
+  150             continue
+  160          continue
+  170          continue
+c
+c              save the transformation.
+c
+               qraux(l) = x(l,l)
+               x(l,l) = -nrmxl
+  180       continue
+  190    continue
+  200 continue
+      return
+      end
+      integer function idamax(n,dx,incx)
+c
+c     finds the index of element having max. absolute value.
+c     jack dongarra, linpack, 3/11/78.
+c
+      double precision dx(1),dmax
+      integer i,incx,ix,n
+c
+      idamax = 0
+      if( n .lt. 1 ) return
+      idamax = 1
+      if(n.eq.1)return
+      if(incx.eq.1)go to 20
+c
+c        code for increment not equal to 1
+c
+      ix = 1
+      dmax = dabs(dx(1))
+      ix = ix + incx
+      do 10 i = 2,n
+         if(dabs(dx(ix)).le.dmax) go to 5
+         idamax = i
+         dmax = dabs(dx(ix))
+    5    ix = ix + incx
+   10 continue
+      return
+c
+c        code for increment equal to 1
+c
+   20 dmax = dabs(dx(1))
+      do 30 i = 2,n
+         if(dabs(dx(i)).le.dmax) go to 30
+         idamax = i
+         dmax = dabs(dx(i))
+   30 continue
+      return
+      end
+      subroutine lowesb(xx,yy,ww,diagl,infl,iv,liv,lv,wv)
+      logical infl,setlf
+      integer execnt
+      integer iv(*)
+      DOUBLE PRECISION trl
+      DOUBLE PRECISION diagl(*),wv(*),ww(*),xx(*),yy(*)
+      external ehg131,ehg182,ehg183
+      integer ifloor
+      external ifloor
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      if(.not.(iv(28).ne.173))then
+         call ehg182(174)
+      end if
+      if(iv(28).ne.172)then
+         if(.not.(iv(28).eq.171))then
+            call ehg182(171)
+         end if
+      end if
+      iv(28)=173
+      if(infl)then
+         trl=1.D0
+      else
+         trl=0.D0
+      end if
+      setlf=(iv(27).ne.iv(25))
+      call ehg131(xx,yy,ww,trl,diagl,iv(20),iv(29),iv(3),iv(2),iv(5),iv(
+     +17),iv(4),iv(6),iv(14),iv(19),wv(1),iv(iv(7)),iv(iv(8)),iv(iv(9)),
+     +iv(iv(10)),iv(iv(22)),iv(iv(27)),wv(iv(11)),iv(iv(23)),wv(iv(13)),
+     +wv(iv(12)),wv(iv(15)),wv(iv(16)),wv(iv(18)),ifloor(iv(3)*wv(2)),wv
+     +(3),wv(iv(26)),wv(iv(24)),wv(4),iv(30),iv(33),iv(32),iv(41),iv(iv(
+     +25)),wv(iv(34)),setlf)
+      if(iv(14).lt.iv(6)+DFLOAT(iv(4))/2.D0)then
+         call ehg183('Warning. k-d tree limited by memory; nvmax=',iv(14
+     +),1,1)
+      else
+         if(iv(17).lt.iv(5)+2)then
+            call ehg183('Warning. k-d tree limited by memory. ncmax=',iv
+     +(17),1,1)
+         end if
+      end if
+      return
+      end
+      subroutine lowesd(versio,iv,liv,lv,v,d,n,f,ideg,nvmax,setlf)
+      logical setlf
+      integer bound,d,execnt,i,i1,i2,ideg,j,liv,lv,n,ncmax,nf,nvmax,vc,v
+     +ersio
+      integer iv(liv)
+      double precision f
+      double precision v(lv)
+      external ehg182
+      integer ifloor
+      external ifloor
+      save execnt
+      data execnt /0/
+c     version -> versio
+      execnt=execnt+1
+      if(.not.(versio.eq.106))then
+         call ehg182(100)
+      end if
+      iv(28)=171
+      iv(2)=d
+      iv(3)=n
+      vc=2**d
+      iv(4)=vc
+      if(.not.(0.lt.f))then
+         call ehg182(120)
+      end if
+      nf=min(n,ifloor(n*f))
+      iv(19)=nf
+      iv(20)=1
+      if(ideg.eq.0)then
+         i1=1
+      else
+         if(ideg.eq.1)then
+            i1=d+1
+         else
+            if(ideg.eq.2)then
+               i1=dfloat((d+2)*(d+1))/2.d0
+            end if
+         end if
+      end if
+      iv(29)=i1
+      iv(21)=1
+      iv(14)=nvmax
+      ncmax=nvmax
+      iv(17)=ncmax
+      iv(30)=0
+      iv(32)=ideg
+      if(.not.(ideg.ge.0))then
+         call ehg182(195)
+      end if
+      if(.not.(ideg.le.2))then
+         call ehg182(195)
+      end if
+      iv(33)=d
+      do 3 i2=41,49
+         iv(i2)=ideg
+    3 continue
+      iv(7)=50
+      iv(8)=iv(7)+ncmax
+      iv(9)=iv(8)+vc*ncmax
+      iv(10)=iv(9)+ncmax
+      iv(22)=iv(10)+ncmax
+c     initialize permutation
+      j=iv(22)-1
+      do 4 i=1,n
+         iv(j+i)=i
+    4 continue
+      iv(23)=iv(22)+n
+      iv(25)=iv(23)+nvmax
+      if(setlf)then
+         iv(27)=iv(25)+nvmax*nf
+      else
+         iv(27)=iv(25)
+      end if
+      bound=iv(27)+n
+      if(.not.(bound-1.le.liv))then
+         call ehg182(102)
+      end if
+      iv(11)=50
+      iv(13)=iv(11)+nvmax*d
+      iv(12)=iv(13)+(d+1)*nvmax
+      iv(15)=iv(12)+ncmax
+      iv(16)=iv(15)+n
+      iv(18)=iv(16)+nf
+      iv(24)=iv(18)+iv(29)*nf
+      iv(34)=iv(24)+(d+1)*nvmax
+      if(setlf)then
+         iv(26)=iv(34)+(d+1)*nvmax*nf
+      else
+         iv(26)=iv(34)
+      end if
+      bound=iv(26)+nf
+      if(.not.(bound-1.le.lv))then
+         call ehg182(103)
+      end if
+      v(1)=f
+      v(2)=0.05d0
+      v(3)=0.d0
+      v(4)=1.d0
+      return
+      end
+      subroutine lowese(iv,liv,lv,wv,m,z,s)
+      integer execnt,m
+      integer iv(*)
+      double precision s(m),wv(*),z(m,1)
+      external ehg133,ehg182
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      if(.not.(iv(28).ne.172))then
+         call ehg182(172)
+      end if
+      if(.not.(iv(28).eq.173))then
+         call ehg182(173)
+      end if
+      call ehg133(iv(3),iv(2),iv(4),iv(14),iv(5),iv(17),iv(iv(7)),iv(iv(
+     +8)),iv(iv(9)),iv(iv(10)),wv(iv(11)),wv(iv(13)),wv(iv(12)),m,z,s)
+      return
+      end
+      subroutine lowesf(xx,yy,ww,iv,liv,lv,wv,m,z,l,ihat,s)
+      logical i1
+      integer execnt,ihat,m,n
+      integer iv(*)
+      double precision l(m,*),s(m),wv(*),ww(*),xx(*),yy(*),z(m,1)
+      external ehg182,ehg136
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      if(171.le.iv(28))then
+         i1=(iv(28).le.174)
+      else
+         i1=.false.
+      end if
+      if(.not.i1)then
+         call ehg182(171)
+      end if
+      iv(28)=172
+      if(.not.(iv(14).ge.iv(19)))then
+         call ehg182(186)
+      end if
+      call ehg136(z,m,m,iv(3),iv(2),iv(19),wv(1),xx,iv(iv(22)),yy,ww,iv(
+     +20),iv(29),wv(iv(15)),wv(iv(16)),wv(iv(18)),0,l,ihat,wv(iv(26)),wv
+     +(4),iv(30),iv(33),iv(32),iv(41),s)
+      return
+      end
+      subroutine lowesl(iv,liv,lv,wv,m,z,l)
+      integer execnt,m,n
+      integer iv(*)
+      double precision l(m,*),wv(*),z(m,1)
+      external ehg182,ehg191
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      if(.not.(iv(28).ne.172))then
+         call ehg182(172)
+      end if
+      if(.not.(iv(28).eq.173))then
+         call ehg182(173)
+      end if
+      if(.not.(iv(26).ne.iv(34)))then
+         call ehg182(175)
+      end if
+      call ehg191(m,z,l,iv(2),iv(3),iv(19),iv(6),iv(17),iv(4),iv(iv(7)),
+     +wv(iv(12)),iv(iv(10)),iv(iv(9)),iv(iv(8)),wv(iv(11)),iv(14),wv(iv(
+     +24)),wv(iv(34)),iv(iv(25)))
+      return
+      end
+      subroutine lowesr(yy,iv,liv,lv,wv)
+      integer execnt
+      integer iv(*)
+      DOUBLE PRECISION wv(*),yy(*)
+      external ehg182,ehg192
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      if(.not.(iv(28).ne.172))then
+         call ehg182(172)
+      end if
+      if(.not.(iv(28).eq.173))then
+         call ehg182(173)
+      end if
+      call ehg192(yy,iv(2),iv(3),iv(19),iv(6),iv(14),wv(iv(13)),wv(iv(34
+     +)),iv(iv(25)))
+      return
+      end
+      subroutine lowesw(res,n,rw,pi)
+      integer identi,execnt,i,i1,n,nh
+      integer pi(n)
+      double precision cmad,rsmall
+      double precision res(n),rw(n)
+      external ehg106
+      integer ifloor
+      external ifloor
+      double precision d1mach
+      external d1mach
+      save execnt
+      data execnt /0/
+c     Identity -> identi
+      execnt=execnt+1
+c     tranliterated from Devlin's ratfor
+c     find median of absolute residuals
+      do 3 i1=1,n
+         rw(i1)=dabs(res(i1))
+    3 continue
+      do 4 identi=1,n
+         pi(identi)=identi
+    4 continue
+      nh=ifloor(dfloat(n)/2.d0)+1
+c     partial sort to find 6*mad
+      call ehg106(1,n,nh,1,rw,pi,n)
+      if((n-nh)+1.lt.nh)then
+         call ehg106(1,nh-1,nh-1,1,rw,pi,n)
+         cmad=3*(rw(pi(nh))+rw(pi(nh-1)))
+      else
+         cmad=6*rw(pi(nh))
+      end if
+      rsmall=d1mach(1)
+      if(cmad.lt.rsmall)then
+         do 5 i1=1,n
+            rw(i1)=1
+    5    continue
+      else
+         do 6 i=1,n
+            if(cmad*0.999d0.lt.rw(i))then
+               rw(i)=0
+            else
+               if(cmad*0.001d0.lt.rw(i))then
+                  rw(i)=(1-(rw(i)/cmad)**2)**2
+               else
+                  rw(i)=1
+               end if
+            end if
+    6    continue
+      end if
+      return
+      end
+      subroutine lowesp(n,y,yhat,pwgts,rwgts,pi,ytilde)
+      integer identi,execnt,i2,i3,i5,m,n
+      integer pi(n)
+      double precision c,i1,i4,mad
+      double precision pwgts(n),rwgts(n),y(n),yhat(n),ytilde(n)
+      external ehg106
+      integer ifloor
+      external ifloor
+      save execnt
+      data execnt /0/
+c     Identity -> identi
+      execnt=execnt+1
+c     median absolute deviation
+      do 3 i5=1,n
+         ytilde(i5)=dabs(y(i5)-yhat(i5))*dsqrt(pwgts(i5))
+    3 continue
+      do 4 identi=1,n
+         pi(identi)=identi
+    4 continue
+      m=ifloor(dfloat(n)/2.d0)+1
+      call ehg106(1,n,m,1,ytilde,pi,n)
+      if((n-m)+1.lt.m)then
+         call ehg106(1,m-1,m-1,1,ytilde,pi,n)
+         mad=(ytilde(pi(m-1))+ytilde(pi(m)))/2
+      else
+         mad=ytilde(pi(m))
+      end if
+c     magic constant
+      c=(6*mad)**2/5
+      do 5 i5=1,n
+         ytilde(i5)=1-((y(i5)-yhat(i5))**2*pwgts(i5))/c
+    5 continue
+      do 6 i5=1,n
+         ytilde(i5)=ytilde(i5)*dsqrt(rwgts(i5))
+    6 continue
+      if(n.le.0)then
+         i4=0.d0
+      else
+         i3=n
+         i1=ytilde(i3)
+         do 7 i2=i3-1,1,-1
+            i1=ytilde(i2)+i1
+    7    continue
+         i4=i1
+      end if
+      c=n/i4
+c     pseudovalues
+      do 8 i5=1,n
+         ytilde(i5)=yhat(i5)+(c*rwgts(i5))*(y(i5)-yhat(i5))
+    8 continue
+      return
+      end
+      subroutine ehg124(ll,uu,d,n,nv,nc,ncmax,vc,x,pi,a,xi,lo,hi,c,v,vhi
+     +t,nvmax,fc,fd,dd)
+      logical i1,i2,i3,leaf
+      integer d,dd,execnt,fc,i4,inorm2,k,l,ll,m,n,nc,ncmax,nv,nvmax,p,u,
+     +uu,vc,lower,upper,check,offset
+      integer a(ncmax),c(vc,ncmax),hi(ncmax),lo(ncmax),pi(n),vhit(nvmax)
+      DOUBLE PRECISION diam,fd
+      DOUBLE PRECISION diag(8),sigma(8),v(nvmax,d),x(n,d),xi(ncmax)
+      external ehg125,ehg106,ehg129
+      integer IDAMAX
+      external IDAMAX
+      save execnt
+      data execnt /0/
+      execnt=execnt+1
+      p=1
+      l=ll
+      u=uu
+      lo(p)=l
+      hi(p)=u
+c     top of while loop
+    3 if(.not.(p.le.nc))goto 4
+         do 5 i4=1,dd
+            diag(i4)=v(c(vc,p),i4)-v(c(1,p),i4)
+    5    continue
+         diam=0
+         do 6 inorm2=1,dd
+            diam=diam+diag(inorm2)**2
+    6    continue
+         diam=DSQRT(diam)
+         if((u-l)+1.le.fc)then
+            i1=.true.
+         else
+            i1=(diam.le.fd)
+         end if
+         if(i1)then
+            leaf=.true.
+         else
+            if(ncmax.lt.nc+2)then
+               i2=.true.
+            else
+               i2=(nvmax.lt.nv+DFLOAT(vc)/2.D0)
+            end if
+            leaf=i2
+         end if
+         if(.not.leaf)then
+            call ehg129(l,u,dd,x,pi,n,sigma)
+            k=IDAMAX(dd,sigma,1)
+            m=DFLOAT(l+u)/2.D0
+            call ehg106(l,u,m,1,x(1,k),pi,n)
+
+c bug fix from btyner@gmail.com 2006-07-20
+      offset = 0
+    7 if(((m+offset).ge.u).or.((m+offset).lt.l))then
+         goto 8
+      else
+        if(offset.lt.0)then
+          lower = l
+          check = m + offset
+          upper = check
+        else
+          lower = m + offset + 1
+          check = lower
+          upper = u
+        end if
+        call ehg106(lower,upper,check,1,x(1,k),pi,n)
+        if(x(pi(m + offset),k).eq.x(pi(m+offset+1),k))then
+          offset = (-offset)
+          if(offset.ge.0)then
+            offset = offset + 1
+          end if
+      goto 7
+        else
+          m = m + offset
+          goto 8
+        end if
+      end if
+
+    8       if(v(c(1,p),k).eq.x(pi(m),k))then
+               leaf=.true.
+            else
+               leaf=(v(c(vc,p),k).eq.x(pi(m),k))
+            end if
+         end if
+         if(leaf)then
+            a(p)=0
+         else
+            a(p)=k
+            xi(p)=x(pi(m),k)
+c           left son
+            nc=nc+1
+            lo(p)=nc
+            lo(nc)=l
+            hi(nc)=m
+c           right son
+            nc=nc+1
+            hi(p)=nc
+            lo(nc)=m+1
+            hi(nc)=u
+            call ehg125(p,nv,v,vhit,nvmax,d,k,xi(p),2**(k-1),2**(d-k),c(
+     +1,p),c(1,lo(p)),c(1,hi(p)))
+         end if
+         p=p+1
+         l=lo(p)
+         u=hi(p)
+         goto 3
+c     bottom of while loop
+    4 return
+      end
+      subroutine ehg129(l,u,d,x,pi,n,sigma)
+      integer d,execnt,i,k,l,n,u
+      integer pi(n)
+      DOUBLE PRECISION machin,alpha,beta,t
+      DOUBLE PRECISION sigma(d),x(n,d)
+      DOUBLE PRECISION D1MACH
+      external D1MACH
+      save machin,execnt
+      data execnt /0/
+c     MachInf -> machin
+      execnt=execnt+1
+      if(execnt.eq.1)then
+         machin=D1MACH(2)
+      end if
+      do 3 k=1,d
+         alpha=machin
+         beta=-machin
+         do 4 i=l,u
+            t=x(pi(i),k)
+            alpha=min(alpha,x(pi(i),k))
+            beta=max(beta,t)
+    4    continue
+         sigma(k)=beta-alpha
+    3 continue
+      return
+      end
+      subroutine ehg137(z,kappa,leaf,nleaf,d,nv,nvmax,ncmax,vc,a,xi,lo,h
+     +i,c,v)
+      integer d,execnt,nc,ncmax,nleaf,p,stackt
+      integer a(ncmax),hi(ncmax),leaf(256),lo(ncmax),pstack(20)
+      DOUBLE PRECISION xi(ncmax),z(d)
+      external ehg182
+      save execnt
+      data execnt /0/
+c     stacktop -> stackt
+      execnt=execnt+1
+c     find leaf cells affected by $z$
+      stackt=0
+      p=1
+      nleaf=0
+c     top of while loop
+    3 if(.not.(0.lt.p))goto 4
+         if(a(p).eq.0)then
+c           leaf
+            nleaf=nleaf+1
+            leaf(nleaf)=p
+c           Pop
+            if(stackt.ge.1)then
+               p=pstack(stackt)
+            else
+               p=0
+            end if
+            stackt=max(0,stackt-1)
+         else
+            if(z(a(p)).eq.xi(p))then
+c              Push
+               stackt=stackt+1
+               if(.not.(stackt.le.20))then
+                  call ehg182(187)
+               end if
+               pstack(stackt)=hi(p)
+               p=lo(p)
+            else
+               if(z(a(p)).le.xi(p))then
+                  p=lo(p)
+               else
+                  p=hi(p)
+               end if
+            end if
+         end if
+         goto 3
+c     bottom of while loop
+    4 if(.not.(nleaf.le.256))then
+         call ehg182(185)
+      end if
+      return
+      end

Added: trunk/Lib/sandbox/pyloess/sandbox/src/misc.c
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/misc.c	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/misc.c	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,334 @@
+#include "S.h"
+#include "loess.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+static double
+fmin(double a, double b)
+{
+    return(a < b ? a : b);
+}
+
+static double
+fmax(double a, double b)
+{
+    return(a > b ? a : b);
+}
+
+
+
+
+void
+anova(loess *one, loess *two,
+      struct anova_struct *out)
+{
+    double  one_d1, one_d2, one_s, two_d1, two_d2, two_s,
+            rssdiff, d1diff, tmp, pf();
+    int     max_enp;
+
+    one_d1 = one->outputs.one_delta;
+    one_d2 = one->outputs.two_delta;
+    one_s = one->outputs.s;
+    two_d1 = two->outputs.one_delta;
+    two_d2 = two->outputs.two_delta;
+    two_s = two->outputs.s;
+
+    rssdiff = fabs(one_s * one_s * one_d1 - two_s * two_s * two_d1);
+    d1diff = fabs(one_d1 - two_d1);
+    out->dfn = d1diff * d1diff / fabs(one_d2 - two_d2);
+    max_enp = (one->outputs.enp > two->outputs.enp);
+    tmp = max_enp ? one_d1 : two_d1;
+    out->dfd = tmp * tmp / (max_enp ? one_d2 : two_d2);
+    tmp = max_enp ? one_s : two_s;
+    out->F_value = (rssdiff / d1diff) / (tmp * tmp);
+    out->Pr_F = 1 - pf(out->F_value, out->dfn, out->dfd);
+}
+
+void
+pointwise(predicted *pre, int m, double coverage,
+          struct ci_struct *ci)
+{
+    double    t_dist, limit, fit, qt();
+    int    i;
+
+    ci->fit = (double *) malloc(m * sizeof(double));
+    ci->upper = (double *) malloc(m * sizeof(double));
+    ci->lower = (double *) malloc(m * sizeof(double));
+
+    t_dist = qt(1 - (1 - coverage)/2, pre->df);
+    for(i = 0; i < m; i++) {
+        limit = pre->se_fit[i] * t_dist;
+        ci->fit[i] = fit = pre->fit[i];
+        ci->upper[i] = fit + limit;
+        ci->lower[i] = fit - limit;
+    }
+}
+
+void
+pw_free_mem(struct ci_struct *ci)
+{
+    free(ci->fit);
+    free(ci->upper);
+    free(ci->lower);
+}
+
+double
+pf(double q, double df1, double df2)
+{
+    double    ibeta();
+    return(ibeta(q*df1/(df2+q*df1), df1/2, df2/2));
+}
+
+double
+qt(double p, double df)
+{
+    double    t, invibeta();
+    t = invibeta(fabs(2*p-1), 0.5, df/2);
+    return((p>0.5?1:-1) * sqrt(t*df/(1-t)));
+}
+
+/**********************************************************************/
+ /*
+ * Incomplete beta function.
+ * Reference:  Abramowitz and Stegun, 26.5.8.
+ * Assumptions: 0 <= x <= 1; a,b > 0.
+ */
+#define DOUBLE_EPS      2.2204460492503131E-16
+#define IBETA_LARGE     1.0e30
+#define IBETA_SMALL     1.0e-30
+
+double
+ibeta(double x, double a, double b)
+{
+    int flipped = 0, i, k, count;
+    double I, temp, pn[6], ak, bk, next, prev, factor, val;
+
+    if (x <= 0)
+        return(0);
+    if (x >= 1)
+        return(1);
+
+    /* use ibeta(x,a,b) = 1-ibeta(1-x,b,a) */
+    if ((a+b+1)*x > (a+1)) {
+        flipped = 1;
+        temp = a;
+        a = b;
+        b = temp;
+        x = 1 - x;
+        }
+
+    pn[0] = 0.0;
+    pn[2] = pn[3] = pn[1] = 1.0;
+    count = 1;
+    val = x/(1.0-x);
+    bk = 1.0;
+    next = 1.0;
+    do {
+        count++;
+        k = count/2;
+        prev = next;
+        if (count%2 == 0)
+            ak = -((a+k-1.0)*(b-k)*val)/((a+2.0*k-2.0)*(a+2.0*k-1.0));
+        else
+            ak = ((a+b+k-1.0)*k*val)/((a+2.0*k)*(a+2.0*k-1.0));
+            pn[4] = bk*pn[2] + ak*pn[0];
+            pn[5] = bk*pn[3] + ak*pn[1];
+            next = pn[4] / pn[5];
+            for (i=0; i<=3; i++)
+                pn[i] = pn[i+2];
+            if (fabs(pn[4]) >= IBETA_LARGE)
+                for (i=0; i<=3; i++)
+                    pn[i] /= IBETA_LARGE;
+            if (fabs(pn[4]) <= IBETA_SMALL)
+                for (i=0; i<=3; i++)
+                    pn[i] /= IBETA_SMALL;
+        } while (fabs(next-prev) > DOUBLE_EPS*prev);
+        factor = a*log(x) + (b-1)*log(1-x);
+        factor -= gamma(a+1) + gamma(b) - gamma(a+b);
+        I = exp(factor) * next;
+        return(flipped ? 1-I : I);
+}
+
+/*
+ * Rational approximation to inverse Gaussian distribution.
+ * Absolute error is bounded by 4.5e-4.
+ * Reference: Abramowitz and Stegun, page 933.
+ * Assumption: 0 < p < 1.
+ */
+
+static double num[] = {
+        2.515517,
+        0.802853,
+        0.010328
+};
+
+static double den[] = {
+        1.000000,
+        1.432788,
+        0.189269,
+        0.001308
+};
+
+double
+invigauss_quick(double p)
+{
+    int lower;
+    double t, n, d, q;
+
+    if(p == 0.5)
+        return(0);
+    lower = p < 0.5;
+    p = lower ? p : 1 - p;
+    t = sqrt(-2 * log(p));
+    n = (num[2]*t + num[1])*t + num[0];
+    d = ((den[3]*t + den[2])*t + den[1])*t + den[0];
+    q = lower ? n/d - t : t - n/d;
+    return(q);
+}
+
+/*
+ * Inverse incomplete beta function.
+ * Assumption: 0 <= p <= 1, a,b > 0.
+ */
+
+double
+invibeta(double p, double a, double b)
+{
+    int i;
+    double ql, qr, qm, qdiff;
+    double pl, pr, pm, pdiff;
+    double invibeta_quick(), ibeta();
+
+/*        MEANINGFUL(qm);*/
+    qm = 0;
+    if(p == 0 || p == 1)
+        return(p);
+
+    /* initialize [ql,qr] containing the root */
+    ql = qr = invibeta_quick(p, a, b);
+    pl = pr = ibeta(ql, a, b);
+    if(pl == p)
+        return(ql);
+    if(pl < p)
+        while(1) {
+            qr += 0.05;
+            if(qr >= 1) {
+                pr = qr = 1;
+                break;
+                }
+            pr = ibeta(qr, a, b);
+            if(pr == p)
+                return(pr);
+            if(pr > p)
+                break;
+        }
+    else
+        while(1) {
+            ql -= 0.05;
+            if(ql <= 0) {
+                pl = ql = 0;
+                break;
+                }
+            pl = ibeta(ql, a, b);
+            if(pl == p)
+                return(pl);
+            if(pl < p)
+                break;
+        }
+
+    /* a few steps of bisection */
+    for(i = 0; i < 5; i++) {
+        qm = (ql + qr) / 2;
+        pm = ibeta(qm, a, b);
+        qdiff = qr - ql;
+        pdiff = pm - p;
+        if(fabs(qdiff) < DOUBLE_EPS*qm || fabs(pdiff) < DOUBLE_EPS)
+            return(qm);
+        if(pdiff < 0) {
+            ql = qm;
+            pl = pm;
+        } else {
+            qr = qm;
+            pr = pm;
+        }
+    }
+
+    /* a few steps of secant */
+    for(i = 0; i < 40; i++) {
+        qm = ql + (p-pl)*(qr-ql)/(pr-pl);
+        pm = ibeta(qm, a, b);
+        qdiff = qr - ql;
+        pdiff = pm - p;
+        if(fabs(qdiff) < 2*DOUBLE_EPS*qm || fabs(pdiff) < 2*DOUBLE_EPS)
+            return(qm);
+        if(pdiff < 0) {
+            ql = qm;
+            pl = pm;
+        } else {
+            qr = qm;
+            pr = pm;
+        }
+    }
+
+    /* no convergence */
+    return(qm);
+}
+
+/*
+ * Quick approximation to inverse incomplete beta function,
+ * by matching first two moments with the Gaussian distribution.
+ * Assumption: 0 < p < 1, a,b > 0.
+ */
+
+double
+invibeta_quick(double p, double a, double b)
+{
+    double x, m, s, fmax(), fmin(), invigauss_quick();
+
+    x = a + b;
+    m = a / x;
+    s = sqrt((a*b) / (x*x*(x+1)));
+    return(fmax(0.0, fmin(1.0, invigauss_quick(p)*s + m)));
+}
+
+int
+max(int a, int b)
+{
+    return(a > b ? a : b);
+}
+
+typedef double doublereal;
+typedef int integer;
+
+void
+Recover(char *a, int *b)
+{
+    printf(a);
+    exit(1);
+}
+
+void
+Warning(char *a, int *b)
+{
+    printf(a);
+}
+
+/*  d1mach may be replaced by Fortran code:
+    mail netlib@netlib.bell-labs.com
+    send d1mach from core.
+*/
+
+#include <float.h>
+
+doublereal F77_SUB(d1mach) (integer *i)
+{
+switch(*i){
+    case 1: return DBL_MIN;
+    case 2: return DBL_MAX;
+    case 3: return DBL_EPSILON/FLT_RADIX;
+    case 4: return DBL_EPSILON;
+    case 5: return log10(FLT_RADIX);
+    default: Recover("Invalid argument to d1mach()", 0L);
+    }
+}
+

Added: trunk/Lib/sandbox/pyloess/sandbox/src/predict.c
===================================================================
--- trunk/Lib/sandbox/pyloess/sandbox/src/predict.c	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/sandbox/src/predict.c	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,172 @@
+#include "S.h"
+#include "loess.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+predict(double *eval, int m, loess *lo, predicted *pre,
+        int se)
+{
+    int    size_info[3];
+    void    pred_();
+
+    pre->fit = (double *) malloc(m * sizeof(double));
+    pre->se_fit = (double *) malloc(m * sizeof(double));
+    pre->residual_scale = lo->outputs.s;
+    pre->df = (lo->outputs.one_delta * lo->outputs.one_delta) /
+lo->outputs.two_delta;
+
+    size_info[0] = lo->inputs.p;
+    size_info[1] = lo->inputs.n;
+    size_info[2] = m;
+
+    pred_(lo->inputs.y, lo->inputs.x, eval, size_info, &lo->outputs.s,
+          lo->inputs.weights,
+          lo->outputs.robust,
+          &lo->model.span,
+          &lo->model.degree,
+          &lo->model.normalize,
+          lo->model.parametric,
+          lo->model.drop_square,
+          &lo->control.surface,
+          &lo->control.cell,
+          &lo->model.family,
+          lo->kd_tree.parameter,
+          lo->kd_tree.a,
+          lo->kd_tree.xi,
+          lo->kd_tree.vert,
+          lo->kd_tree.vval,
+          lo->outputs.divisor,
+          &se,
+          pre->fit,
+          pre->se_fit);
+}
+
+void
+pred_(double *y, double *x_, double *new_x, int *size_info, double *s,
+      double *weights, double *robust, double *span, int *degree,
+      int *normalize, int *parametric, int *drop_square, char **surface,
+      double *cell, char **family, int *parameter, int *a, double *xi,
+      double *vert, double *vval, double *divisor, int *se, double *fit,
+      double *se_fit)
+{
+    double  *x, *x_tmp, *x_evaluate, *L, new_cell, z, tmp, *fit_tmp,
+            *temp, sum, mean;
+    int    N, D, M, sum_drop_sqr = 0, sum_parametric = 0,
+	        nonparametric = 0, *order_parametric, *order_drop_sqr;
+    int     i, j, k, p, cut, comp();
+
+    D = size_info[0];
+    N = size_info[1];
+    M = size_info[2];
+
+    x = (double *) malloc(N * D * sizeof(double));
+    x_tmp = (double *) malloc(N * D * sizeof(double));
+    x_evaluate = (double *) malloc(M * D * sizeof(double));
+    L = (double *) malloc(N * M * sizeof(double));
+    order_parametric = (int *) malloc(D * sizeof(int));
+    order_drop_sqr = (int *) malloc(D * sizeof(int));
+    temp = (double *) malloc(N * D * sizeof(double));
+
+    for(i = 0; i < (N * D); i++)
+        x_tmp[i] = x_[i];
+    for(i = 0; i < D; i++) {
+        k = i * M;
+        for(j = 0; j < M; j++) {
+            p = k + j;
+            new_x[p] = new_x[p] / divisor[i];
+        }
+    }
+    if(!strcmp(*surface, "direct") || se) {
+        for(i = 0; i < D; i++) {
+            k = i * N;
+            for(j = 0; j < N; j++) {
+                p = k + j;
+                x_tmp[p] = x_[p] / divisor[i];
+            }
+		}
+	}
+	j = D - 1;
+	for(i = 0; i < D; i++) {
+        sum_drop_sqr = sum_drop_sqr + drop_square[i];
+        sum_parametric = sum_parametric + parametric[i];
+        if(parametric[i])
+            order_parametric[j--] = i;
+		else
+            order_parametric[nonparametric++] = i;
+	}
+    for(i = 0; i < D; i++) {
+        order_drop_sqr[i] = 2 - drop_square[order_parametric[i]];
+		k = i * M;
+		p = order_parametric[i] * M;
+        for(j = 0; j < M; j++)
+			x_evaluate[k + j] = new_x[p + j];
+		k = i * N;
+		p = order_parametric[i] * N;
+        for(j = 0; j < N; j++)
+            x[k + j] = x_tmp[p + j];
+    }
+	for(i = 0; i < N; i++)
+		robust[i] = weights[i] * robust[i];
+
+	if(!strcmp(*surface, "direct")) {
+	    if(*se) {
+	        loess_dfitse(y, x, x_evaluate, weights, robust,
+                         !strcmp(*family, "gaussian"), span, degree,
+                         &nonparametric, order_drop_sqr, &sum_drop_sqr,
+                         &D, &N, &M, fit, L);
+        }
+	    else {
+		    loess_dfit(y, x, x_evaluate, robust, span, degree,
+                       &nonparametric, order_drop_sqr, &sum_drop_sqr,
+		               &D, &N, &M, fit);
+        }
+    }
+	else {
+	    loess_ifit(parameter, a, xi, vert, vval, &M, x_evaluate, fit);
+	    if(*se) {
+            new_cell = (*span) * (*cell);
+            fit_tmp = (double *) malloc(M * sizeof(double));
+	        loess_ise(y, x, x_evaluate, weights, span, degree,
+			&nonparametric, order_drop_sqr, &sum_drop_sqr,
+			&new_cell, &D, &N, &M, fit_tmp, L);
+			free(fit_tmp);
+        }
+    }
+	if(*se) {
+	    for(i = 0; i < N; i++) {
+	        k = i * M;
+	        for(j = 0; j < M; j++) {
+		        p = k + j;
+		        L[p] = L[p] / weights[i];
+		        L[p] = L[p] * L[p];
+            }
+		}
+		for(i = 0; i < M; i++) {
+		    tmp = 0;
+			for(j = 0; j < N; j++)
+		        tmp = tmp + L[i + j * M];
+			se_fit[i] = (*s) * sqrt(tmp);
+		}
+	}
+	free(x);
+	free(x_tmp);
+	free(x_evaluate);
+	free(L);
+	free(order_parametric);
+	free(order_drop_sqr);
+	free(temp);
+}
+
+void
+pred_free_mem(predicted *pre)
+{
+	free(pre->fit);
+	free(pre->se_fit);
+}
+
+
+
+
+
+

Added: trunk/Lib/sandbox/pyloess/setup.py
===================================================================
--- trunk/Lib/sandbox/pyloess/setup.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/setup.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+__version__ = '1.0'
+__revision__ = "$Revision: 2811 $"
+__date__     = '$Date: 2007-03-02 06:30:02 -0500 (Fri, 02 Mar 2007) $'
+
+import os
+from os.path import join
+
+def configuration(parent_package='',top_path=None):
+    from numpy.distutils.misc_util import Configuration
+    confgr = Configuration('pyloess',parent_package,top_path)
+    confgr.add_extension('_lowess',
+                         sources=[join('src', 'f_lowess.pyf'),
+                                  join('src', 'lowess.f'),]
+                         )
+    confgr.add_extension('_stl',
+                         sources=[join('src', 'f_stl.pyf'),
+                                  join('src', 'stl.f')],
+                         )
+    confgr.add_data_dir('tests')
+    return confgr
+
+if __name__ == "__main__":
+    from numpy.distutils.core import setup
+    config = configuration(top_path='').todict() 
+    setup(**config)
\ No newline at end of file

Added: trunk/Lib/sandbox/pyloess/src/f_lowess.pyf
===================================================================
--- trunk/Lib/sandbox/pyloess/src/f_lowess.pyf	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/src/f_lowess.pyf	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,38 @@
+!    -*- f90 -*-
+! Note: the context of this file is case sensitive.
+
+python module _lowess ! in 
+    interface  ! in :_lowess
+        subroutine lowess(x,y,n,f,nsteps,delta,ys,rw,res) ! in :_lowess:lowess.f
+            double precision dimension(n), intent(in) :: x
+            double precision dimension(n),depend(n), intent(in) :: y
+            integer optional,check(len(x)>=n),depend(x) :: n=len(x)
+            double precision  intent(in) :: f
+            integer intent(in) :: nsteps
+            double precision intent(in) :: delta
+            double precision dimension(n),depend(n), intent(out) :: ys
+            double precision dimension(n),depend(n), intent(out) :: rw
+            double precision dimension(n),depend(n), intent(out) :: res
+        end subroutine lowess
+        subroutine lowest(x,y,n,xs,ys,nleft,nright,w,userw,rw,ok) ! in :_lowess:lowess.f
+            double precision dimension(n) :: x
+            double precision dimension(n),depend(n) :: y
+            integer optional,check(len(x)>=n),depend(x) :: n=len(x)
+            double precision :: xs
+            double precision :: ys
+            integer :: nleft
+            integer :: nright
+            double precision dimension(n),depend(n) :: w
+            logical :: userw
+            double precision dimension(n),depend(n) :: rw
+            logical :: ok
+        end subroutine lowest
+        subroutine ssort(a,n) ! in :_lowess:lowess.f
+            real dimension(n) :: a
+            integer optional,check(len(a)>=n),depend(a) :: n=len(a)
+        end subroutine ssort
+    end interface 
+end python module _lowess
+
+! This file was auto-generated with f2py (version:2_3522).
+! See http://cens.ioc.ee/projects/f2py2e/

Added: trunk/Lib/sandbox/pyloess/src/f_stl.pyf
===================================================================
--- trunk/Lib/sandbox/pyloess/src/f_stl.pyf	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/src/f_stl.pyf	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,129 @@
+!    -*- f90 -*-
+! Note: the context of this file is case sensitive.
+
+python module _stl ! in 
+    interface  ! in :_stl
+        subroutine stl(y,n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,nljump,ni,no,rw,season,trend,work) ! in :_stl:stl.f
+            double precision dimension(n), intent(in) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            integer :: np
+            integer :: ns
+            integer :: nt
+            integer :: nl
+            integer :: isdeg
+            integer :: itdeg
+            integer :: ildeg
+            integer :: nsjump
+            integer :: ntjump
+            integer :: nljump
+            integer :: ni
+            integer :: no
+            double precision dimension(n),depend(n), intent(out) :: rw
+            double precision dimension(n),depend(n), intent(out) :: season
+            double precision dimension(n),depend(n), intent(out) :: trend
+            double precision dimension(n+2*np,5),depend(n,np), intent(out) :: work
+        end subroutine stl
+        subroutine ess(y,n,len_bn,ideg,njump,userw,rw,ys,res) ! in :_stl:stl.f
+            double precision dimension(n) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            integer :: len_bn
+            integer :: ideg
+            integer :: njump
+            logical :: userw
+            double precision dimension(n),depend(n) :: rw
+            double precision dimension(n),depend(n) :: ys
+            double precision dimension(n),depend(n) :: res
+        end subroutine ess
+        subroutine est(y,n,len_bn,ideg,xs,ys,nleft,nright,w,userw,rw,ok) ! in :_stl:stl.f
+            double precision dimension(n) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            integer :: len_bn
+            integer :: ideg
+            double precision :: xs
+            double precision :: ys
+            integer :: nleft
+            integer :: nright
+            double precision dimension(n),depend(n) :: w
+            logical :: userw
+            double precision dimension(n),depend(n) :: rw
+            logical :: ok
+        end subroutine est
+        subroutine fts(x,n,np,trend,work) ! in :_stl:stl.f
+            double precision dimension(n) :: x
+            integer optional,check(len(x)>=n),depend(x) :: n=len(x)
+            integer :: np
+            double precision dimension(n),depend(n) :: trend
+            double precision dimension(n),depend(n) :: work
+        end subroutine fts
+        subroutine ma(x,n,len_bn,ave) ! in :_stl:stl.f
+            double precision dimension(n) :: x
+            integer optional,check(len(x)>=n),depend(x) :: n=len(x)
+            integer :: len_bn
+            double precision dimension(n),depend(n) :: ave
+        end subroutine ma
+        subroutine onestp(y,n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,nljump,ni,userw,rw,season,trend,work) ! in :_stl:stl.f
+            double precision dimension(n), intent(in) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            integer intent(in) :: np
+            integer intent(in) :: ns
+            integer intent(in) :: nt
+            integer intent(in) :: nl
+            integer intent(in) :: isdeg
+            integer intent(in) :: itdeg
+            integer intent(in) :: ildeg
+            integer intent(in) :: nsjump
+            integer intent(in) :: ntjump
+            integer intent(in) :: nljump
+            integer intent(in) :: ni
+            logical intent(in) :: userw
+            double precision dimension(n),depend(n), intent(out) :: rw
+            double precision dimension(n),depend(n), intent(out) :: season
+            double precision dimension(n),depend(n), intent(out) :: trend
+            double precision dimension(n+2*np,5),depend(n,np), intent(out) :: work
+        end subroutine onestp
+        subroutine rwts(y,n,fit,rw) ! in :_stl:stl.f
+            double precision dimension(n) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            double precision dimension(n),depend(n) :: fit
+            double precision dimension(n),depend(n) :: rw
+        end subroutine rwts
+        subroutine ss(y,n,np,ns,isdeg,nsjump,userw,rw,season,work1,work2,work3,work4) ! in :_stl:stl.f
+            double precision dimension(n) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            integer :: np
+            integer :: ns
+            integer :: isdeg
+            integer :: nsjump
+            logical :: userw
+            double precision dimension(n),depend(n) :: rw
+            double precision dimension(n+2*np),depend(n,np) :: season
+            double precision dimension(n),depend(n) :: work1
+            double precision dimension(n),depend(n) :: work2
+            double precision dimension(n),depend(n) :: work3
+            double precision dimension(n),depend(n) :: work4
+        end subroutine ss
+        subroutine stlez(y,n,np,ns,isdeg,itdeg,robust,no,rw,season,trend,work) ! in :_stl:stl.f
+            double precision dimension(n) :: y
+            integer optional,check(len(y)>=n),depend(y) :: n=len(y)
+            integer :: np
+            integer :: ns
+            integer :: isdeg
+            integer :: itdeg
+            logical :: robust
+            integer :: no
+            double precision dimension(n),depend(n) :: rw
+            double precision dimension(n),depend(n) :: season
+            double precision dimension(n),depend(n) :: trend
+            double precision dimension(n+2*np,7),depend(n,np) :: work
+        end subroutine stlez
+        subroutine psort(a,n,ind,ni) ! in :_stl:stl.f
+            double precision dimension(n) :: a
+            integer optional,check(len(a)>=n),depend(a) :: n=len(a)
+            integer dimension(ni) :: ind
+            integer optional,check(len(ind)>=ni),depend(ind) :: ni=len(ind)
+        end subroutine psort
+    end interface 
+end python module _stl
+
+! This file was auto-generated with f2py (version:2_3522).
+! See http://cens.ioc.ee/projects/f2py2e/

Added: trunk/Lib/sandbox/pyloess/src/lowess.f
===================================================================
--- trunk/Lib/sandbox/pyloess/src/lowess.f	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/src/lowess.f	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,615 @@
+* wsc@research.bell-labs.com Mon Dec 30 16:55 EST 1985
+* W. S. Cleveland
+* Bell Laboratories
+* Murray Hill NJ 07974
+* 
+* outline of this file:
+*    lines 1-72   introduction
+*        73-177   documentation for lowess
+*       178-238   ratfor version of lowess
+*       239-301   documentation for lowest
+*       302-350   ratfor version of lowest
+*       351-end   test driver and fortran version of lowess and lowest
+* 
+*   a multivariate version is available by "send dloess from a"
+* 
+*              COMPUTER PROGRAMS FOR LOCALLY WEIGHTED REGRESSION
+* 
+*             This package consists  of  two  FORTRAN  programs  for
+*        smoothing    scatterplots   by   robust   locally   weighted
+*        regression, or lowess.   The  principal  routine  is  LOWESS
+*        which   computes   the  smoothed  values  using  the  method
+*        described in The Elements of Graphing Data, by William S.
+*        Cleveland    (Wadsworth,    555 Morego   Street,   Monterey,
+*        California 93940).
+* 
+*             LOWESS calls a support routine, LOWEST, the code for
+*        which is included. LOWESS also calls a routine  SORT,  which
+*        the user must provide.
+* 
+*             To reduce the computations, LOWESS  requires  that  the
+*        arrays  X  and  Y,  which  are  the  horizontal and vertical
+*        coordinates, respectively, of the scatterplot, be such  that
+*        X  is  sorted  from  smallest  to  largest.   The  user must
+*        therefore use another sort routine which will sort X  and  Y
+*        according  to X.
+*             To summarize the scatterplot, YS,  the  fitted  values,
+*        should  be  plotted  against X.   No  graphics  routines are
+*        available in the package and must be supplied by the user.
+* 
+*             The FORTRAN code for the routines LOWESS and LOWEST has
+*        been   generated   from   higher   level   RATFOR   programs
+*        (B. W. Kernighan, ``RATFOR:  A Preprocessor for  a  Rational
+*        Fortran,''  Software Practice and Experience, Vol. 5 (1975),
+*        which are also included.
+* 
+*             The following are data and output from LOWESS that  can
+*        be  used  to check your implementation of the routines.  The
+*        notation (10)v means 10 values of v.
+* 
+* 
+* 
+* 
+*        X values:
+*          1  2  3  4  5  (10)6  8  10  12  14  50
+* 
+*        Y values:
+*           18  2  15  6  10  4  16  11  7  3  14  17  20  12  9  13  1  8  5  19
+* 
+* 
+*        YS values with F = .25, NSTEPS = 0, DELTA = 0.0
+*         13.659  11.145  8.701  9.722  10.000  (10)11.300  13.000  6.440  5.596
+*           5.456  18.998
+* 
+*        YS values with F = .25, NSTEPS = 0 ,  DELTA = 3.0
+*          13.659  12.347  11.034  9.722  10.511  (10)11.300  13.000  6.440  5.596
+*            5.456  18.998
+* 
+*        YS values with F = .25, NSTEPS = 2, DELTA = 0.0
+*          14.811  12.115  8.984  9.676  10.000  (10)11.346  13.000  6.734  5.744
+*            5.415  18.998
+* 
+* 
+* 
+* 
+*                                   LOWESS
+* 
+* 
+* 
+*        Calling sequence
+* 
+*        CALL LOWESS(X,Y,N,F,NSTEPS,DELTA,YS,RW,RES)
+* 
+*        Purpose
+* 
+*        LOWESS computes the smooth of a scatterplot of Y  against  X
+*        using  robust  locally  weighted regression.  Fitted values,
+*        YS, are computed at each of the  values  of  the  horizontal
+*        axis in X.
+* 
+*        Argument description
+* 
+*              X = Input; abscissas of the points on the
+*                  scatterplot; the values in X must be ordered
+*                  from smallest to largest.
+*              Y = Input; ordinates of the points on the
+*                  scatterplot.
+*              N = Input; dimension of X,Y,YS,RW, and RES.
+*              F = Input; specifies the amount of smoothing; F is
+*                  the fraction of points used to compute each
+*                  fitted value; as F increases the smoothed values
+*                  become smoother; choosing F in the range .2 to
+*                  .8 usually results in a good fit; if you have no
+*                  idea which value to use, try F = .5.
+*         NSTEPS = Input; the number of iterations in the robust
+*                  fit; if NSTEPS = 0, the nonrobust fit is
+*                  returned; setting NSTEPS equal to 2 should serve
+*                  most purposes.
+*          DELTA = input; nonnegative parameter which may be used
+*                  to save computations; if N is less than 100, set
+*                  DELTA equal to 0.0; if N is greater than 100 you
+*                  should find out how DELTA works by reading the
+*                  additional instructions section.
+*             YS = Output; fitted values; YS(I) is the fitted value
+*                  at X(I); to summarize the scatterplot, YS(I)
+*                  should be plotted against X(I).
+*             RW = Output; robustness weights; RW(I) is the weight
+*                  given to the point (X(I),Y(I)); if NSTEPS = 0,
+*                  RW is not used.
+*            RES = Output; residuals; RES(I) = Y(I)-YS(I).
+* 
+* 
+*        Other programs called
+* 
+*               LOWEST
+*               SSORT
+* 
+*        Additional instructions
+* 
+*        DELTA can be used to save computations.   Very  roughly  the
+*        algorithm  is  this:   on the initial fit and on each of the
+*        NSTEPS iterations locally weighted regression fitted  values
+*        are computed at points in X which are spaced, roughly, DELTA
+*        apart; then the fitted values at the  remaining  points  are
+*        computed  using  linear  interpolation.   The  first locally
+*        weighted regression (l.w.r.) computation is carried  out  at
+*        X(1)  and  the  last  is  carried  out at X(N).  Suppose the
+*        l.w.r. computation is carried out at  X(I).   If  X(I+1)  is
+*        greater  than  or  equal  to  X(I)+DELTA,  the  next  l.w.r.
+*        computation is carried out at X(I+1).   If  X(I+1)  is  less
+*        than X(I)+DELTA, the next l.w.r.  computation is carried out
+*        at the largest X(J) which is greater than or equal  to  X(I)
+*        but  is not greater than X(I)+DELTA.  Then the fitted values
+*        for X(K) between X(I)  and  X(J),  if  there  are  any,  are
+*        computed  by  linear  interpolation  of the fitted values at
+*        X(I) and X(J).  If N is less than 100 then DELTA can be  set
+*        to  0.0  since  the  computation time will not be too great.
+*        For larger N it is typically not necessary to carry out  the
+*        l.w.r.  computation for all points, so that much computation
+*        time can be saved by taking DELTA to be  greater  than  0.0.
+*        If  DELTA =  Range  (X)/k  then,  if  the  values  in X were
+*        uniformly  scattered  over  the  range,  the   full   l.w.r.
+*        computation  would be carried out at approximately k points.
+*        Taking k to be 50 often works well.
+* 
+*        Method
+* 
+*        The fitted values are computed by using the nearest neighbor
+*        routine  and  robust locally weighted regression of degree 1
+*        with the tricube weight function.  A few additional features
+*        have  been  added.  Suppose r is FN truncated to an integer.
+*        Let  h  be  the  distance  to  the  r-th  nearest   neighbor
+*        from X(I).   All  points within h of X(I) are used.  Thus if
+*        the r-th nearest neighbor is exactly the  same  distance  as
+*        other  points,  more  than r points can possibly be used for
+*        the smooth at  X(I).   There  are  two  cases  where  robust
+*        locally  weighted regression of degree 0 is actually used at
+*        X(I).  One case occurs when  h  is  0.0.   The  second  case
+*        occurs  when  the  weighted  standard error of the X(I) with
+*        respect to the weights w(j) is  less  than  .001  times  the
+*        range  of the X(I), where w(j) is the weight assigned to the
+*        j-th point of X (the tricube  weight  times  the  robustness
+*        weight)  divided by the sum of all of the weights.  Finally,
+*        if the w(j) are all zero for the smooth at X(I), the  fitted
+*        value is taken to be Y(I).
+* 
+* 
+* 
+* 
+*  subroutine lowess(x,y,n,f,nsteps,delta,ys,rw,res)
+*  real x(n),y(n),ys(n),rw(n),res(n)
+*  logical ok
+*  if (n<2){ ys(1) = y(1); return }
+*  ns = max0(min0(ifix(f*float(n)),n),2)  # at least two, at most n points
+*  for(iter=1; iter<=nsteps+1; iter=iter+1){      # robustness iterations
+*         nleft = 1; nright = ns
+*         last = 0        # index of prev estimated point
+*         i = 1   # index of current point
+*         repeat{
+*                 while(nright<n){
+*  # move nleft, nright to right if radius decreases
+*                         d1 = x(i)-x(nleft)
+*                         d2 = x(nright+1)-x(i)
+*  # if d1<=d2 with x(nright+1)==x(nright), lowest fixes
+*                         if (d1<=d2) break
+*  # radius will not decrease by move right
+*                         nleft = nleft+1
+*                         nright = nright+1
+*                         }
+*                 call lowest(x,y,n,x(i),ys(i),nleft,nright,res,iter>1,rw,ok)
+*  # fitted value at x(i)
+*                 if (!ok) ys(i) = y(i)
+*  # all weights zero - copy over value (all rw==0)
+*                 if (last<i-1) { # skipped points -- interpolate
+*                         denom = x(i)-x(last)    # non-zero - proof?
+*                         for(j=last+1; j<i; j=j+1){
+*                                 alpha = (x(j)-x(last))/denom
+*                                 ys(j) = alpha*ys(i)+(1.0-alpha)*ys(last)
+*                                 }
+*                         }
+*                 last = i        # last point actually estimated
+*                 cut = x(last)+delta     # x coord of close points
+*                 for(i=last+1; i<=n; i=i+1){     # find close points
+*                         if (x(i)>cut) break     # i one beyond last pt within cut
+*                         if(x(i)==x(last)){      # exact match in x
+*                                 ys(i) = ys(last)
+*                                 last = i
+*                                 }
+*                         }
+*                 i=max0(last+1,i-1)
+*  # back 1 point so interpolation within delta, but always go forward
+*                 } until(last>=n)
+*         do i = 1,n      # residuals
+*                 res(i) = y(i)-ys(i)
+*         if (iter>nsteps) break  # compute robustness weights except last time
+*         do i = 1,n
+*                 rw(i) = abs(res(i))
+*         call sort(rw,n)
+*         m1 = 1+n/2; m2 = n-m1+1
+*         cmad = 3.0*(rw(m1)+rw(m2))      # 6 median abs resid
+*         c9 = .999*cmad; c1 = .001*cmad
+*         do i = 1,n {
+*                 r = abs(res(i))
+*                 if(r<=c1) rw(i)=1.      # near 0, avoid underflow
+*                 else if(r>c9) rw(i)=0.  # near 1, avoid underflow
+*                 else rw(i) = (1.0-(r/cmad)**2)**2
+*                 }
+*         }
+*  return
+*  end
+* 
+* 
+* 
+* 
+*                                   LOWEST
+* 
+* 
+* 
+*        Calling sequence
+* 
+*        CALL LOWEST(X,Y,N,XS,YS,NLEFT,NRIGHT,W,USERW,RW,OK)
+* 
+*        Purpose
+* 
+*        LOWEST is a support routine for LOWESS and  ordinarily  will
+*        not  be  called  by  the  user.   The  fitted  value, YS, is
+*        computed  at  the  value,  XS,  of  the   horizontal   axis.
+*        Robustness  weights,  RW,  can  be employed in computing the
+*        fit.
+* 
+*        Argument description
+* 
+* 
+*              X = Input; abscissas of the points on the
+*                  scatterplot; the values in X must be ordered
+*                  from smallest to largest.
+*              Y = Input; ordinates of the points on the
+*                  scatterplot.
+*              N = Input; dimension of X,Y,W, and RW.
+*             XS = Input; value of the horizontal axis at which the
+*                  smooth is computed.
+*             YS = Output; fitted value at XS.
+*          NLEFT = Input; index of the first point which should be
+*                  considered in computing the fitted value.
+*         NRIGHT = Input; index of the last point which should be
+*                  considered in computing the fitted value.
+*              W = Output; W(I) is the weight for Y(I) used in the
+*                  expression for YS, which is the sum from
+*                  I = NLEFT to NRIGHT of W(I)*Y(I); W(I) is
+*                  defined only at locations NLEFT to NRIGHT.
+*          USERW = Input; logical variable; if USERW is .TRUE., a
+*                  robust fit is carried out using the weights in
+*                  RW; if USERW is .FALSE., the values in RW are
+*                  not used.
+*             RW = Input; robustness weights.
+*             OK = Output; logical variable; if the weights for the
+*                  smooth are all 0.0, the fitted value, YS, is not
+*                  computed and OK is set equal to .FALSE.; if the
+*                  fitted value is computed OK is set equal to
+* 
+* 
+*        Method
+* 
+*        The smooth at XS is computed using (robust) locally weighted
+*        regression of degree 1.  The tricube weight function is used
+*        with h equal to the maximum of XS-X(NLEFT) and X(NRIGHT)-XS.
+*        Two  cases  where  the  program  reverts to locally weighted
+*        regression of degree 0 are described  in  the  documentation
+*        for LOWESS.
+* 
+* 
+* 
+* 
+*  subroutine lowest(x,y,n,xs,ys,nleft,nright,w,userw,rw,ok)
+*  real x(n),y(n),w(n),rw(n)
+*  logical userw,ok
+*  range = x(n)-x(1)
+*  h = amax1(xs-x(nleft),x(nright)-xs)
+*  h9 = .999*h
+*  h1 = .001*h
+*  a = 0.0        # sum of weights
+*  for(j=nleft; j<=n; j=j+1){     # compute weights (pick up all ties on right)
+*         w(j)=0.
+*         r = abs(x(j)-xs)
+*         if (r<=h9) {    # small enough for non-zero weight
+*                 if (r>h1) w(j) = (1.0-(r/h)**3)**3
+*                 else      w(j) = 1.
+*                 if (userw) w(j) = rw(j)*w(j)
+*                 a = a+w(j)
+*                 }
+*         else if(x(j)>xs)break   # get out at first zero wt on right
+*         }
+*  nrt=j-1        # rightmost pt (may be greater than nright because of ties)
+*  if (a<=0.0) ok = FALSE
+*  else { # weighted least squares
+*         ok = TRUE
+*         do j = nleft,nrt
+*                 w(j) = w(j)/a   # make sum of w(j) == 1
+*         if (h>0.) {     # use linear fit
+*                 a = 0.0
+*                 do j = nleft,nrt
+*                         a = a+w(j)*x(j) # weighted center of x values
+*                 b = xs-a
+*                 c = 0.0
+*                 do j = nleft,nrt
+*                         c = c+w(j)*(x(j)-a)**2
+*                 if(sqrt(c)>.001*range) {
+*  # points are spread out enough to compute slope
+*                         b = b/c
+*                         do j = nleft,nrt
+*                                 w(j) = w(j)*(1.0+b*(x(j)-a))
+*                         }
+*                 }
+*         ys = 0.0
+*         do j = nleft,nrt
+*                 ys = ys+w(j)*y(j)
+*         }
+*  return
+*  end
+* 
+* 
+* 
+c  test driver for lowess
+c  for expected output, see introduction
+      double precision x(20), y(20), ys(20), rw(20), res(20)
+      data x /1,2,3,4,5,10*6,8,10,12,14,50/
+      data y /18,2,15,6,10,4,16,11,7,3,14,17,20,12,9,13,1,8,5,19/
+      call lowess(x,y,20,.25,0,0.,ys,rw,res)
+      write(6,*) ys
+      call lowess(x,y,20,.25,0,3.,ys,rw,res)
+      write(6,*) ys
+      call lowess(x,y,20,.25,2,0.,ys,rw,res)
+      write(6,*) ys
+      end
+c**************************************************************
+c  Fortran output from ratfor
+c
+      subroutine lowess(x, y, n, f, nsteps, delta, ys, rw, res)
+      integer n, nsteps
+      double precision x(n), y(n), f, delta, ys(n), rw(n), res(n)
+      integer nright, i, j, iter, last, mid(2), ns, nleft
+      double precision cut, cmad, r, d1, d2
+      double precision c1, c9, alpha, denom, dabs
+      logical ok
+      if (n .ge. 2) goto 1
+         ys(1) = y(1)
+         return
+c at least two, at most n points
+   1  ns = max(min(int(f*dble(n)), n), 2)
+      iter = 1
+         goto  3
+   2     iter = iter+1
+   3     if (iter .gt. nsteps+1) goto  22
+c robustness iterations
+         nleft = 1
+         nright = ns
+c index of prev estimated point
+         last = 0
+c index of current point
+         i = 1
+   4        if (nright .ge. n) goto  5
+c move nleft, nright to right if radius decreases
+               d1 = x(i)-x(nleft)
+c if d1<=d2 with x(nright+1)==x(nright), lowest fixes
+               d2 = x(nright+1)-x(i)
+               if (d1 .le. d2) goto  5
+c radius will not decrease by move right
+               nleft = nleft+1
+               nright = nright+1
+               goto  4
+c fitted value at x(i)
+   5        call lowest(x, y, n, x(i), ys(i), nleft, nright, res, iter
+     +     .gt. 1, rw, ok)
+            if (.not. ok) ys(i) = y(i)
+c all weights zero - copy over value (all rw==0)
+            if (last .ge. i-1) goto 9
+               denom = x(i)-x(last)
+c skipped points -- interpolate
+c non-zero - proof?
+               j = last+1
+                  goto  7
+   6              j = j+1
+   7              if (j .ge. i) goto  8
+                  alpha = (x(j)-x(last))/denom
+                  ys(j) = alpha*ys(i)+(1.D0-alpha)*ys(last)
+                  goto  6
+   8           continue
+c last point actually estimated
+   9        last = i
+c x coord of close points
+            cut = x(last)+delta
+            i = last+1
+               goto  11
+  10           i = i+1
+  11           if (i .gt. n) goto  13
+c find close points
+               if (x(i) .gt. cut) goto  13
+c i one beyond last pt within cut
+               if (x(i) .ne. x(last)) goto 12
+                  ys(i) = ys(last)
+c exact match in x
+                  last = i
+  12           continue
+               goto  10
+c back 1 point so interpolation within delta, but always go forward
+  13        i = max(last+1, i-1)
+  14        if (last .lt. n) goto  4
+c residuals
+         do  15 i = 1, n
+            res(i) = y(i)-ys(i)
+  15        continue
+         if (iter .gt. nsteps) goto  22
+c compute robustness weights except last time
+         do  16 i = 1, n
+            rw(i) = dabs(res(i))
+  16        continue
+         call ssort(rw,n)
+         mid(1) = n/2+1
+         mid(2) = n-mid(1)+1
+c 6 median abs resid
+         cmad = 3.D0*(rw(mid(1))+rw(mid(2)))
+         c9 = .999999D0*cmad
+         c1 = .000001D0*cmad
+         do  21 i = 1, n
+            r = dabs(res(i))
+            if (r .gt. c1) goto 17
+               rw(i) = 1.D0
+c near 0, avoid underflow
+               goto  20
+  17           if (r .le. c9) goto 18
+                  rw(i) = 0.D0
+c near 1, avoid underflow
+                  goto  19
+  18              rw(i) = (1.D0-(r/cmad)**2.D0)**2.D0
+  19        continue
+  20        continue
+  21        continue
+         goto  2
+  22  return
+      end
+      
+      
+      subroutine lowest(x, y, n, xs, ys, nleft, nright, w, userw
+     +, rw, ok)
+      integer n
+      integer nleft, nright
+      double precision x(n), y(n), xs, ys, w(n), rw(n)
+      logical userw, ok
+      integer nrt, j
+      double precision dabs, a, b, c, h, r
+      double precision h1, dsqrt, h9, max, range
+      range = x(n)-x(1)
+      h = max(xs-x(nleft), x(nright)-xs)
+      h9 = .999999D0*h
+      h1 = .000001D0*h
+c sum of weights
+      a = 0.D0
+      j = nleft
+         goto  2
+   1     j = j+1
+   2     if (j .gt. n) goto  7
+c compute weights (pick up all ties on right)
+         w(j) = 0.D0
+         r = dabs(x(j)-xs)
+         if (r .gt. h9) goto 5
+            if (r .le. h1) goto 3
+               w(j) = (1.D0-(r/h)**3.D0)**3.D0
+c small enough for non-zero weight
+               goto  4
+   3           w(j) = 1.D0
+   4        if (userw) w(j) = rw(j)*w(j)
+            a = a+w(j)
+            goto  6
+   5        if (x(j) .gt. xs) goto  7
+c get out at first zero wt on right
+   6     continue
+         goto  1
+c rightmost pt (may be greater than nright because of ties)
+   7  nrt = j-1
+      if (a .gt. 0.D0) goto 8
+         ok = .false.
+         goto  16
+   8     ok = .true.
+c weighted least squares
+         do  9 j = nleft, nrt
+c make sum of w(j) == 1
+            w(j) = w(j)/a
+   9        continue
+         if (h .le. 0.D0) goto 14
+            a = 0.D0
+c use linear fit
+            do  10 j = nleft, nrt
+c weighted center of x values
+               a = a+w(j)*x(j)
+  10           continue
+            b = xs-a
+            c = 0.D0
+            do  11 j = nleft, nrt
+               c = c+w(j)*(x(j)-a)**2
+  11           continue
+            if (dsqrt(c) .le. .0000001D0*range) goto 13
+               b = b/c
+c points are spread out enough to compute slope
+               do  12 j = nleft, nrt
+                  w(j) = w(j)*(b*(x(j)-a)+1.D0)
+  12              continue
+  13        continue
+  14     ys = 0.D0
+         do  15 j = nleft, nrt
+            ys = ys+w(j)*y(j)
+  15        continue
+  16  return
+      end
+
+      
+      subroutine ssort(a,n)
+
+C Sorting by Hoare method, C.A.C.M. (1961) 321, modified by Singleton
+C C.A.C.M. (1969) 185.
+	  double precision a(n)
+	  integer iu(16), il(16)
+      integer p
+
+      i =1
+      j = n
+      m = 1
+  5   if (i.ge.j) goto 70
+c first order a(i),a(j),a((i+j)/2), and use median to split the data
+ 10   k=i
+      ij=(i+j)/2
+      t=a(ij)
+      if(a(i) .le. t) goto 20
+      a(ij)=a(i)
+      a(i)=t
+      t=a(ij)
+ 20   l=j
+      if(a(j).ge.t) goto 40
+      a(ij)=a(j)
+      a(j)=t
+      t=a(ij)
+      if(a(i).le.t) goto 40
+      a(ij)=a(i)
+      a(i)=t
+      t=a(ij)
+      goto 40
+ 30   a(l)=a(k)
+      a(k)=tt
+ 40   l=l-1
+      if(a(l) .gt. t) goto 40
+      tt=a(l)
+c split the data into a(i to l) .lt. t, a(k to j) .gt. t
+ 50   k=k+1
+      if(a(k) .lt. t) goto 50
+      if(k .le. l) goto 30
+      p=m
+      m=m+1
+c split the larger of the segments
+      if (l-i .le. j-k) goto 60
+      il(p)=i
+      iu(p)=l
+      i=k
+      goto 80
+ 60   il(p)=k
+      iu(p)=j
+      j=l
+      goto 80
+ 70   m=m-1
+      if(m .eq. 0) return
+      i =il(m)
+      j=iu(m)
+c short sections are sorted by bubble sort
+ 80   if (j-i .gt. 10) goto 10
+      if (i .eq. 1) goto 5
+      i=i-1
+ 90   i=i+1
+      if(i .eq. j) goto 70
+      t=a(i+1)
+      if(a(i) .le. t) goto 90
+      k=i
+ 100  a(k+1)=a(k)
+      k=k-1
+      if(t .lt. a(k)) goto 100
+      a(k+1)=t
+      goto 90
+
+      end      
\ No newline at end of file

Added: trunk/Lib/sandbox/pyloess/src/stl.f
===================================================================
--- trunk/Lib/sandbox/pyloess/src/stl.f	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/src/stl.f	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,554 @@
+      subroutine stl(y,n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,
+     &nljump,ni,no,rw,season,trend,work)
+      integer n, np, ns, nt, nl, isdeg, itdeg, ildeg, nsjump, ntjump, 
+     &nljump, ni, no, k
+      integer newns, newnt, newnl, newnp
+      double precision y(n), rw(n), season(n), trend(n), work(n+2*np,5)
+      logical userw
+      userw = .false.
+      k = 0
+      do 23000 i = 1,n
+          trend(i) = 0.D0
+23000 continue
+      newns = max(3,ns)
+      newnt = max(3,nt)
+      newnl = max(3,nl)
+      newnp = max(2,np)
+      if(.not.(mod(newns,2) .eq. 0))goto 23002
+      newns = newns + 1
+23002 continue
+      if(.not.(mod(newnt,2) .eq. 0))goto 23004
+      newnt = newnt + 1
+23004 continue
+      if(.not.(mod(newnl,2) .eq. 0))goto 23006
+      newnl = newnl + 1
+23006 continue
+23008 continue
+      call onestp(y,n,newnp,newns,newnt,newnl,isdeg,itdeg,ildeg,nsjump,
+     &ntjump,nljump,ni,userw,rw,season, trend, work)
+      k = k+1
+      if(.not.(k .gt. no))goto 23011
+      goto 23010
+23011 continue
+      do 23013 i = 1,n
+          work(i,1) = trend(i)+season(i)
+23013 continue
+      call rwts(y,n,work(1,1),rw)
+      userw = .true.
+23009 goto 23008
+23010 continue
+      if(.not.(no .le. 0))goto 23015
+      do 23017 i = 1,n
+          rw(i) = 1.D0
+23017 continue
+23015 continue
+      return
+      end
+      
+      
+      subroutine ess(y,n,len,ideg,njump,userw,rw,ys,res)
+      integer n, len, ideg, njump, newnj, nleft, nright, nsh, k, i, j
+      double precision y(n), rw(n), ys(n), res(n), delta
+      logical ok, userw
+      if(.not.(n .lt. 2))goto 23019
+      ys(1) = y(1)
+      return
+23019 continue
+      newnj = min(njump, n-1)
+      if(.not.(len .ge. n))goto 23021
+      nleft = 1
+      nright = n
+      do 23023 i = 1,n,newnj 
+      call est(y,n,len,ideg,dble(i),ys(i),nleft,nright,res,userw,rw,ok)
+      if(.not.( .not. ok))goto 23025
+      ys(i) = y(i)
+23025 continue
+23023 continue
+      goto 23022
+23021 continue
+      if(.not.(newnj .eq. 1))goto 23027
+      nsh = (len+1)/2
+      nleft = 1
+      nright = len
+      do 23029 i = 1,n 
+      if(.not.(i .gt. nsh  .and.  nright .ne. n))goto 23031
+      nleft = nleft+1
+      nright = nright+1
+23031 continue
+      call est(y,n,len,ideg,dble(i),ys(i),nleft,nright,res,userw,rw,ok)
+      if(.not.( .not. ok))goto 23033
+      ys(i) = y(i)
+23033 continue
+23029 continue
+      goto 23028
+23027 continue
+      nsh = (len+1)/2
+      do 23035 i = 1,n,newnj 
+      if(.not.(i .lt. nsh))goto 23037
+      nleft = 1
+      nright = len
+      goto 23038
+23037 continue
+      if(.not.(i .ge. n-nsh+1))goto 23039
+      nleft = n-len+1
+      nright = n
+      goto 23040
+23039 continue
+      nleft = i-nsh+1
+      nright = len+i-nsh
+23040 continue
+23038 continue
+      call est(y,n,len,ideg,dble(i),ys(i),nleft,nright,res,userw,rw,ok)
+      if(.not.( .not. ok))goto 23041
+      ys(i) = y(i)
+23041 continue
+23035 continue
+23028 continue
+23022 continue
+      if(.not.(newnj .ne. 1))goto 23043
+      do 23045 i = 1,n-newnj,newnj 
+      delta = (ys(i+newnj)-ys(i))/dble(newnj)
+      do 23047 j = i+1,i+newnj-1
+      ys(j) = ys(i)+delta*dble(j-i)
+23047 continue
+23045 continue
+      k = ((n-1)/newnj)*newnj+1
+      if(.not.(k .ne. n))goto 23049
+      call est(y,n,len,ideg,dble(n),ys(n),nleft,nright,res,userw,rw,ok)
+      if(.not.( .not. ok))goto 23051
+      ys(n) = y(n)
+23051 continue
+      if(.not.(k .ne. n-1))goto 23053
+      delta = (ys(n)-ys(k))/dble(n-k)
+      do 23055 j = k+1,n-1
+      ys(j) = ys(k)+delta*dble(j-k)
+23055 continue
+23053 continue
+23049 continue
+23043 continue
+      return
+      end
+      
+      
+      subroutine est(y,n,len,ideg,xs,ys,nleft,nright,w,userw,rw,ok)
+      integer n, len, ideg, nleft, nright, j
+      double precision y(n), w(n), rw(n), xs, ys, range, h, h1, h9, a, 
+     &b, c, r
+      logical userw,ok
+      range = dble(n)-dble(1)
+      h = max(xs-dble(nleft),dble(nright)-xs)
+      if(.not.(len .gt. n))goto 23057
+      h = h+dble((len-n)/2)
+23057 continue
+      h9 = .999999D0*h
+      h1 = .000001D0*h
+      a = 0.D0
+      do 23059 j = nleft,nright 
+      w(j) = 0.D0
+      r = dabs(dble(j)-xs)
+      if(.not.(r .le. h9))goto 23061
+      if(.not.(r .le. h1))goto 23063
+      w(j) = 1.D0
+      goto 23064
+23063 continue
+      w(j) = (1.D0-(r/h)**3.D0)**3.D0
+23064 continue
+      if(.not.(userw))goto 23065
+      w(j) = rw(j)*w(j)
+23065 continue
+      a = a+w(j)
+23061 continue
+23059 continue
+      if(.not.(a .le. 0.D0))goto 23067
+      ok = .false.
+      goto 23068
+23067 continue
+      ok = .true.
+      do 23069 j = nleft,nright
+      w(j) = w(j)/a
+23069 continue
+      if(.not.((h .gt. 0.D0) .and. (ideg .gt. 0)))goto 23071
+      a = 0.D0
+      do 23073 j = nleft,nright
+      a = a+w(j)*dble(j)
+23073 continue
+      b = xs-a
+      c = 0.D0
+      do 23075 j = nleft,nright
+      c = c+w(j)*(dble(j)-a)**2.D0
+23075 continue
+      if(.not.(sqrt(c) .gt. .001*range))goto 23077
+      b = b/c
+      do 23079 j = nleft,nright
+      w(j) = w(j)*(b*(dble(j)-a)+1.D0)
+23079 continue
+23077 continue
+23071 continue
+      ys = 0.D0
+      do 23081 j = nleft,nright
+      ys = ys+w(j)*y(j)
+23081 continue
+23068 continue
+      return
+      end
+      
+      
+      subroutine fts(x,n,np,trend,work)
+      integer n, np
+      double precision x(n), trend(n), work(n)
+      call ma(x,n,np,trend)
+      call ma(trend,n-np+1,np,work)
+      call ma(work,n-2*np+2,3,trend)
+      return
+      end
+      
+      
+      subroutine ma(x, n, len, ave)
+      integer n, len, i, j, k, m, newn
+      double precision x(n), ave(n), flen, v
+      newn = n-len+1
+      flen = dble(len)
+      v = 0.D0
+      do 23083 i = 1,len
+      v = v+x(i)
+23083 continue
+      ave(1) = v/flen
+      if(.not.(newn .gt. 1))goto 23085
+      k = len
+      m = 0
+      do 23087 j = 2, newn 
+      k = k+1
+      m = m+1
+      v = v-x(m)+x(k)
+      ave(j) = v/flen
+23087 continue
+23085 continue
+      return
+      end
+      
+      
+      subroutine onestp(y,n,np,ns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,
+     &nljump,ni,userw,rw,season,trend,work)
+      integer n,ni,np,ns,nt,nsjump,ntjump,nl,nljump,isdeg,itdeg,ildeg
+      double precision y(n),rw(n),season(n),trend(n),work(n+2*np,5)
+      logical userw
+      do 23089 j = 1,ni 
+      do 23091 i = 1,n
+      work(i,1) = y(i)-trend(i)
+23091 continue
+      call ss(work(1,1),n,np,ns,isdeg,nsjump,userw,rw,work(1,2),work(1,
+     &3),work(1,4),work(1,5),season)
+      call fts(work(1,2),n+2*np,np,work(1,3),work(1,1))
+      call ess(work(1,3),n,nl,ildeg,nljump,.false.,work(1,4),work(1,1),
+     &work(1,5))
+      do 23093 i = 1,n
+      season(i) = work(np+i,2)-work(i,1)
+23093 continue
+      do 23095 i = 1,n
+      work(i,1) = y(i)-season(i)
+23095 continue
+      call ess(work(1,1),n,nt,itdeg,ntjump,userw,rw,trend,work(1,3))
+23089 continue
+      return
+      end
+      
+      
+      subroutine rwts(y,n,fit,rw)
+      integer mid(2), n
+      double precision y(n), fit(n), rw(n), cmad, c9, c1, r
+      do 23097 i = 1,n
+      rw(i) = dabs(y(i)-fit(i))
+23097 continue
+      mid(1) = n/2+1
+      mid(2) = n-mid(1)+1
+      call psort(rw,n,mid,2)
+      cmad = 3.D0*(rw(mid(1))+rw(mid(2)))
+      c9 = .999999D0*cmad
+      c1 = .000001D0*cmad
+      do 23099 i = 1,n 
+      r = dabs(y(i)-fit(i))
+      if(.not.(r .le. c1))goto 23101
+      rw(i) = 1.
+      goto 23102
+23101 continue
+      if(.not.(r .le. c9))goto 23103
+      rw(i) = (1.D0-(r/cmad)**2.D0)**2.D0
+      goto 23104
+23103 continue
+      rw(i) = 0.D0
+23104 continue
+23102 continue
+23099 continue
+      return
+      end
+      
+      
+      subroutine ss(y,n,np,ns,isdeg,nsjump,userw,rw,season,work1,work2,
+     &work3,work4)
+      integer n, np, ns, isdeg, nsjump, nright, nleft, i, j, k
+      double precision y(n), rw(n), season(n+2*np), work1(n), work2(n), 
+     &work3(n), work4(n), xs
+      logical userw,ok
+      j=1
+23105 if(.not.(j .le. np))goto 23107
+      k = (n-j)/np+1
+      do 23108 i = 1,k
+      work1(i) = y((i-1)*np+j)
+23108 continue
+      if(.not.(userw))goto 23110
+      do 23112 i = 1,k
+      work3(i) = rw((i-1)*np+j)
+23112 continue
+23110 continue
+      call ess(work1,k,ns,isdeg,nsjump,userw,work3,work2(2),work4)
+      xs = 0.D0
+      nright = min0(ns,k)
+      call est(work1,k,ns,isdeg,xs,work2(1),1,nright,work4,userw,work3,
+     &ok)
+      if(.not.( .not. ok))goto 23114
+      work2(1) = work2(2)
+23114 continue
+      xs = dble(k+1)
+      nleft = max0(1,k-ns+1)
+      call est(work1,k,ns,isdeg,xs,work2(k+2),nleft,k,work4,userw,work3,
+     &ok)
+      if(.not.( .not. ok))goto 23116
+      work2(k+2) = work2(k+1)
+23116 continue
+      do 23118 m = 1,k+2
+      season((m-1)*np+j) = work2(m)
+23118 continue
+       j=j+1
+      goto 23105
+23107 continue
+      return
+      end
+      
+      
+      subroutine stlez(y, n, np, ns, isdeg, itdeg, robust, no, rw, 
+     &season, trend, work)
+      logical robust
+      integer n, i, j, np, ns, no, nt, nl, ni, nsjump, ntjump, nljump, 
+     &newns, newnp
+      integer isdeg, itdeg, ildeg
+      double precision y(n), rw(n), season(n), trend(n), work(n+2*np,7)
+      double precision maxs, mins, maxt, mint, maxds, maxdt, difs, dift
+      ildeg = itdeg
+      newns = max(3,ns)
+      if(.not.(mod(newns,2) .eq. 0))goto 23120
+      newns = newns+1
+23120 continue
+      newnp = max(2,np)
+      nt = (1.5*newnp)/(1 - 1.5/newns) + 0.5
+      nt = max(3,nt)
+      if(.not.(mod(nt,2) .eq. 0))goto 23122
+      nt = nt+1
+23122 continue
+      nl = newnp
+      if(.not.(mod(nl,2) .eq. 0))goto 23124
+      nl = nl+1
+23124 continue
+      if(.not.(robust))goto 23126
+      ni = 1
+      goto 23127
+23126 continue
+      ni = 2
+23127 continue
+      nsjump = max(1,int(dble(newns)/10.D0 + 0.9D0))
+      ntjump = max(1,int(dble(nt)/10.D0 + 0.9D0))
+      nljump = max(1,int(dble(nl)/10.D0 + 0.9D0))
+      do 23128 i = 1,n
+      trend(i) = 0.D0
+23128 continue
+      call onestp(y,n,newnp,newns,nt,nl,isdeg,itdeg,ildeg,nsjump,ntjump,
+     &nljump,ni,.false.,rw,season,trend,work)
+      no = 0
+      if(.not.(robust))goto 23130
+      j=1
+23132 if(.not.(j .le. 15))goto 23134
+      do 23135 i = 1,n
+      work(i,6) = season(i)
+      work(i,7) = trend(i)
+      work(i,1) = trend(i)+season(i)
+23135 continue
+      call rwts(y,n,work(1,1),rw)
+      call onestp(y, n, newnp, newns, nt, nl, isdeg, itdeg, ildeg, 
+     &nsjump,ntjump, nljump, ni, .true., rw, season, trend, work)
+      no = no+1
+      maxs = work(1,6)
+      mins = work(1,6)
+      maxt = work(1,7)
+      mint = work(1,7)
+      maxds = dabs(work(1,6) - season(1))
+      maxdt = dabs(work(1,7) - trend(1))
+      do 23137 i = 2,n
+      if(.not.(maxs .lt. work(i,6)))goto 23139
+      maxs = work(i,6)
+23139 continue
+      if(.not.(maxt .lt. work(i,7)))goto 23141
+      maxt = work(i,7)
+23141 continue
+      if(.not.(mins .gt. work(i,6)))goto 23143
+      mins = work(i,6)
+23143 continue
+      if(.not.(mint .gt. work(i,7)))goto 23145
+      mint = work(i,7)
+23145 continue
+      difs = dabs(work(i,6) - season(i))
+      dift = dabs(work(i,7) - trend(i))
+      if(.not.(maxds .lt. difs))goto 23147
+      maxds = difs
+23147 continue
+      if(.not.(maxdt .lt. dift))goto 23149
+      maxdt = dift
+23149 continue
+23137 continue
+      if(.not.((maxds/(maxs-mins) .lt. .01)  .and.  
+     &    (maxdt/(maxt-mint) .lt. .01)))goto 23151
+      goto 23134
+23151 continue
+       j=j+1
+      goto 23132
+23134 continue
+23130 continue
+      if(.not.( .not. robust))goto 23153
+      do 23155 i = 1,n
+      rw(i) = 1.D0
+23155 continue
+23153 continue
+      return
+      end
+      
+      
+      subroutine psort(a,n,ind,ni)
+      double precision a(n)
+      integer n,ind(ni),ni
+      integer indu(16),indl(16),iu(16),il(16),p,jl,ju,i,j,m,k,ij,l
+      double precision t,tt
+      if(.not.(n .lt. 0 .or. ni .lt. 0))goto 23157
+      return
+23157 continue
+      if(.not.(n .lt. 2  .or.  ni .eq. 0))goto 23159
+      return
+23159 continue
+      jl = 1
+      ju = ni
+      indl(1) = 1
+      indu(1) = ni
+      i = 1
+      j = n
+      m = 1
+23161 continue
+      if(.not.(i .lt. j))goto 23164
+      go to 10
+23164 continue
+23166 continue
+      m = m-1
+      if(.not.(m .eq. 0))goto 23169
+      goto 23163
+23169 continue
+      i = il(m)
+      j = iu(m)
+      jl = indl(m)
+      ju = indu(m)
+      if(.not.(jl .le. ju))goto 23171
+23173 if(.not.(j-i .gt. 10))goto 23174
+10    k = i
+      ij = (i+j)/2
+      t = a(ij)
+      if(.not.(a(i) .gt. t))goto 23175
+      a(ij) = a(i)
+      a(i) = t
+      t = a(ij)
+23175 continue
+      l = j
+      if(.not.(a(j) .lt. t))goto 23177
+      a(ij) = a(j)
+      a(j) = t
+      t = a(ij)
+      if(.not.(a(i) .gt. t))goto 23179
+      a(ij) = a(i)
+      a(i) = t
+      t = a(ij)
+23179 continue
+23177 continue
+23181 continue
+      l = l-1
+      if(.not.(a(l) .le. t))goto 23184
+      tt = a(l)
+23186 continue
+      k = k+1
+23187 if(.not.(a(k) .ge. t))goto 23186
+      if(.not.(k .gt. l))goto 23189
+      goto 23183
+23189 continue
+      a(l) = a(k)
+      a(k) = tt
+23184 continue
+23182 goto 23181
+23183 continue
+      indl(m) = jl
+      indu(m) = ju
+      p = m
+      m = m+1
+      if(.not.(l-i .le. j-k))goto 23191
+      il(p) = k
+      iu(p) = j
+      j = l
+23193 continue
+      if(.not.(jl .gt. ju))goto 23196
+      goto 23167
+23196 continue
+      if(.not.(ind(ju) .le. j))goto 23198
+      goto 23195
+23198 continue
+      ju = ju-1
+23194 goto 23193
+23195 continue
+      indl(p) = ju+1
+      goto 23192
+23191 continue
+      il(p) = i
+      iu(p) = l
+      i = k
+23200 continue
+      if(.not.(jl .gt. ju))goto 23203
+      goto 23167
+23203 continue
+      if(.not.(ind(jl) .ge. i))goto 23205
+      goto 23202
+23205 continue
+      jl = jl+1
+23201 goto 23200
+23202 continue
+      indu(p) = jl-1
+23192 continue
+      goto 23173
+23174 continue
+      if(.not.(i .eq. 1))goto 23207
+      goto 23168
+23207 continue
+      i = i-1
+23209 continue
+      i = i+1
+      if(.not.(i .eq. j))goto 23212
+      goto 23211
+23212 continue
+      t = a(i+1)
+      if(.not.(a(i) .gt. t))goto 23214
+      k = i
+23216 continue
+      a(k+1) = a(k)
+      k = k-1
+23217 if(.not.(t .ge. a(k)))goto 23216
+      a(k+1) = t
+23214 continue
+23210 goto 23209
+23211 continue
+23171 continue
+23167 goto 23166
+23168 continue
+23162 goto 23161
+23163 continue
+      return
+      end

Added: trunk/Lib/sandbox/pyloess/tests/__init__.py
===================================================================
--- trunk/Lib/sandbox/pyloess/tests/__init__.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/tests/__init__.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,7 @@
+"""
+Test suite for lowess, stl.
+"""
+__author__ = "Pierre GF Gerard-Marchant"
+__version__ = '1.0'
+__revision__ = "$Revision: 150 $"
+__date__     = '$Date: 2007-02-28 23:42:16 -0500 (Wed, 28 Feb 2007) $'

Added: trunk/Lib/sandbox/pyloess/tests/co2_data
===================================================================
--- trunk/Lib/sandbox/pyloess/tests/co2_data	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/tests/co2_data	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,87 @@
+315.58 316.39 316.79 317.82 
+318.39 318.22 316.68 315.01 
+314.02 313.55 315.02 315.75 
+316.52 317.1 317.79 319.22 
+320.08 319.7 318.27 315.99 
+314.24 314.05 315.05 316.23 
+316.92 317.76 318.54 319.49 
+320.64 319.85 318.7 316.96 
+315.17 315.47 316.19 317.17 
+318.12 318.72 319.79 320.68 
+321.28 320.89 319.79 317.56 
+316.46 315.59 316.85 317.87 
+318.87 319.25 320.13 321.49 
+322.34 321.62 319.85 317.87 
+316.36 316.24 317.13 318.46 
+319.57 320.23 320.89 321.54 
+322.2 321.9 320.42 318.6 
+316.73 317.15 317.94 318.91 
+319.73 320.78 321.23 322.49 
+322.59 322.35 321.61 319.24 
+318.23 317.76 319.36 319.5 
+320.35 321.4 322.22 323.45 
+323.8 323.5 322.16 320.09 
+318.26 317.66 319.47 320.7 
+322.06 322.23 322.78 324.1 
+324.63 323.79 322.34 320.73 
+319 318.99 320.41 321.68 
+322.3 322.89 323.59 324.65 
+325.3 325.15 323.88 321.8 
+319.99 319.86 320.88 322.36 
+323.59 324.23 325.34 326.33 
+327.03 326.24 325.39 323.16 
+321.87 321.31 322.34 323.74 
+324.61 325.58 326.55 327.81 
+327.82 327.53 326.29 324.66 
+323.12 323.09 324.01 325.1 
+326.12 326.62 327.16 327.94 
+329.15 328.79 327.53 325.65 
+323.6 323.78 325.13 326.26 
+326.93 327.84 327.96 329.93 
+330.25 329.24 328.13 326.42 
+324.97 325.29 326.56 327.73 
+328.73 329.7 330.46 331.7 
+332.66 332.22 331.02 329.39 
+327.58 327.27 328.3 328.81 
+329.44 330.89 331.62 332.85 
+333.29 332.44 331.35 329.58 
+327.58 327.55 328.56 329.73 
+330.45 330.98 331.63 332.88 
+333.63 333.53 331.9 330.08 
+328.59 328.31 329.44 330.64 
+331.62 332.45 333.36 334.46 
+334.84 334.29 333.04 330.88 
+329.23 328.83 330.18 331.5 
+332.8 333.22 334.54 335.82 
+336.45 335.97 334.65 332.4 
+331.28 330.73 332.05 333.54 
+334.65 335.06 336.32 337.39 
+337.66 337.56 336.24 334.39 
+332.43 332.22 333.61 334.78 
+335.88 336.43 337.61 338.53 
+339.06 338.92 337.39 335.72 
+333.64 333.65 335.07 336.53 
+337.82 338.19 339.89 340.56 
+341.22 340.92 339.26 337.27 
+335.66 335.54 336.71 337.79 
+338.79 340.06 340.93 342.02 
+342.65 341.8 340.01 337.94 
+336.17 336.28 337.76 339.05 
+340.18 341.04 342.16 343.01 
+343.64 342.91 341.72 339.52 
+337.75 337.68 339.14 340.37 
+341.32 342.45 343.05 344.91 
+345.77 345.3 343.98 342.41 
+339.89 340.03 341.19 342.87 
+343.74 344.55 345.28 347 
+347.37 346.74 345.36 343.19 
+340.97 341.2 342.76 343.96 
+344.82 345.82 347.24 348.09 
+348.66 347.9 346.27 344.21 
+342.88 342.58 343.99 345.31 
+345.98 346.72 347.63 349.24 
+349.83 349.1 347.52 345.43 
+344.48 343.89 345.29 346.54 
+347.66 348.07 349.12 350.55 
+351.34 350.8 349.1 347.54 
+346.2 346.2 347.44 348.67 

Added: trunk/Lib/sandbox/pyloess/tests/co2_results_double
===================================================================
--- trunk/Lib/sandbox/pyloess/tests/co2_results_double	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/tests/co2_results_double	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,7 @@
+ -0.131254643360572       0.517069428110988        1.08182067584919        2.13326637358770        2.73375546874132        2.23997776835891       0.929699515256501       -1.11444707420409       -2.67573821245580       -2.87856330488736       -1.90209785853191      -0.960288396846844      -0.127309599506098       0.519123971628999        1.09845833595895        2.15377745092389        2.74178279831138        2.24390654627401       0.927034947716549       -1.11840574881049       -2.69421608102192       -2.89832584564760       -1.91246650303411      -0.960459432315943      -0.123323614572555       0.521218070743582        1.11513416618278        2.17432369186148        2.74984228497017        2.24786402897563       0.924395632660881       -1.12234432639115       -2.71267900802084       -2.91807776589179       -1.92282884807142      -0.960626468256293      -0.119335930046407       0.523313128694124        1.13181021448592        2.19487004452363        2.75790177699876        2.25182151436214       0.921756317605213       -1.12628287349056       -2.73114187405725       -2.93782932476804       -1.93319053133537      -0.960792260330621      -0.115346419561576       0.525409317286149        1.14848669811335        2.21541273077976        2.76595350089103        2.25576409079413       0.919094952776809       -1.13025072305144       -2.74964129524388       -2.95762143862511       -1.94359676941072      -0.961001887200727      -0.111663528494415       0.527041806941144        1.16591699949743        2.23572475782599        2.77558209490346        2.26100862164176       0.916135515605680       -1.13521851311631       -2.76853269649236       -2.97819389766126       -1.95447404199440      -0.961469922313078      -0.107860654017195       0.528789664565914        1.18345805341101        2.25613699562502        2.78530035789200        2.26632885561176       0.913237815703161       -1.14013859201476       -2.78739041267661       -2.99874290502888       -1.96533809630523      -0.961929689327584      -0.104054461617129       0.530539382987096        1.20099951099456        2.27654943992924        2.79501863022095        2.27164909425196       0.910340115800643       -1.14505866933551       -2.80624812570546       -3.01929207422557       -1.97620247742963      -0.962391060045031      -0.100251149809378       0.532282176944238        1.21853000024234        2.29694352384120        2.80471115010115        2.27693520990275       0.907399922368041       -1.15002684464570       -2.82515954118310       -3.03989522748933       -1.98712112423937      -0.962900372915200      -9.657142836469074E-002  0.534498365407295        1.23663732630217        2.31763175742248        2.81524537246355        2.28255222950951       0.904114205312311       -1.15622306722147       -2.84480538227602       -3.06114244925604       -1.99798435060416      -0.963119381070332      -9.277853340694056E-002  0.536818220007927        1.25483881112409        2.33840092971464        2.82584731348562        2.28822285505067       0.900867981465680       -1.16239113573849       -2.86443440846052       -3.08237920554798       -2.00884346092780      -0.963336241276855      -8.898545859310647E-002  0.539138117293329        1.27304020145945        2.35917005259441        2.83644925016947        2.29389347842271       0.897621757619049       -1.16855899932509       -2.88406302478419       -3.10361326189795       -2.01969758122834      -0.963539280350215      -8.516973153606598E-002  0.541497365991697        1.29129764237755        2.38001852337338        2.84715383206899        2.29969629210904       0.894537269185294       -1.17453457130906       -2.90346879331549       -3.12459976725524       -2.03027944733590      -0.963462846700087      -8.318137128004088E-002  0.543878489204072        1.30556339626621        2.40086196051427        2.86349649009386        2.30662073374580       0.887792197369512       -1.18505484118622       -2.92012438706208       -3.14478006706923       -2.03869306366509      -0.962605359946822      -8.131952325850622E-002  0.546127682709739        1.31969180297595        2.42157577340269        2.87971724679271        2.31343828536589       0.880955246846406       -1.19565053554695       -2.93683895106848       -3.16500456560729       -2.04713610718260      -0.961766931458097      -7.946636457773126E-002  0.548371989282220        1.33381912516008        2.44228903304709        2.89593798152913        2.32025582600477       0.874118296323300       -1.20624598994303       -2.95355303514557       -3.18522530648506       -2.05557211530886      -0.960907763364043      -7.757876207755750E-002  0.550679154240705        1.34803772029682        2.46313591470192        2.91233468733382        2.32730163521162       0.867561911867873       -1.21650906054413       -2.96988291770040       -3.20502042283162       -2.06354107589496      -0.959566493512336      -7.730219052307574E-002  0.550357935231823        1.35866963091892        2.48275195707344        2.93421989150165        2.33628089748756       0.856814006163955       -1.23047890110198       -2.98132949467161       -3.22331217432112       -2.07013703786751      -0.958710477392881      -7.712537096548630E-002  0.549926745420134        1.36918135193231        2.50225440094597        2.95599808828023        2.34516971366972       0.845992215661742       -1.24450607549849       -2.99281685452186       -3.24163247691575       -2.07674931917128      -0.957864064655987      -7.695143884179889E-002  0.549494111512313        1.37969307218733        2.52175684968569        2.97777629555155        2.35405853509826       0.835170425159529       -1.25853325141979       -3.00430421742168       -3.25995284087020       -2.08336172014513      -0.957018509640572      -7.677910249098863E-002  0.549056980809610        1.39019739462547        2.54124599510881        2.99953529400655        2.36292081968353       0.824314769787128       -1.27259985902399       -3.01583657881712       -3.27831926911595       -2.09002125120596      -0.956215270085997      -7.659034326116144E-002  0.548303305832745        1.40189817662095        2.56059404473287        3.02216449393333        2.37249493004545       0.812882095499132       -1.28748162695347       -3.02788580296873       -3.29720423678765       -2.09686072038062      -0.955524593494270      -7.628314748519592E-002  0.547660207647820        1.41370167565417        2.58003235634854        3.04487150080557        2.38213274135591       0.801499016162785       -1.30232615353693       -3.03991013937994       -3.31607228287846       -2.10369123413391      -0.954828406701153      -7.597388672782887E-002  0.547018261938728        1.42550541465766        2.59947079083601        3.06757851345117        2.39177055555305       0.790115936826438       -1.31717061821239       -3.05193435197517       -3.33493973126345       -2.11052067629153      -0.954130057562446      -7.566137287494026E-002  0.546380413810568        1.43731409572749        2.61891435943207        3.09029085224759        2.40141467672878       0.778740145296439       -1.33200480401653       -3.06394529463410       -3.35378911923031       -2.11732726754918      -0.953403895217910      -7.602451339366684E-002  0.546239431030685        1.44876402506477        2.63888506323516        3.11434437457380        2.41097132000011       0.766666985700136       -1.34824458585656       -3.07630256711981       -3.37247512859970       -2.12367610934446      -0.952323810467218      -7.635206537097822E-002  0.546127432756093        1.46023633487122        2.65887223673730        3.13840845582895        2.42053368947150       0.754594719575008       -1.36448616515093       -3.08866432798535       -3.39116569389385       -2.13002957460944      -0.951247011186959      -7.668156481946027E-002  0.546014308367871        1.47170833992158        2.67885925398630        3.16247252933391        2.43009605506780       0.742522453449881       -1.38072769771166       -3.10102599538363       -3.40985565045688       -2.13638191587943      -0.950167084869187      -7.700593418790123E-002  0.545910597459656        1.48319404185191        2.69886726639568        3.18656489627965        2.43969768454088       0.730500421637537       -1.39690705311059       -3.11331354277110       -3.42846020971871       -2.14263758255784      -0.948981962890397     
+   315.551939725323        315.644481572339        315.737023419355        315.831019342046        315.925015264737        316.017871370006        316.110727475274        316.202019778800        316.293312082325        316.398957194298        316.504602306271        316.616296186514        316.727990066757        316.807925805088        316.887861543420        316.931141044518        316.974420545617        317.009107349720        317.043794153822        317.079929437763        317.116064721703        317.145706993755        317.175349265808        317.217323426682        317.259297587556        317.333560803835        317.407824020115        317.503177240388        317.598530460661        317.693263457235        317.787996453809        317.877822068571        317.967647683333        318.050567993525        318.133488303716        318.210189243932        318.286890184147        318.358269704290        318.429649224433        318.490571336492        318.551493448551        318.604564508711        318.657635568871        318.704397175047        318.751158781223        318.799682725764        318.848206670306        318.893484228360        318.938761786415        318.971518019974        319.004274253534        319.036061188978        319.067848124423        319.111286397250        319.154724670078        319.201719446166        319.248714222255        319.284772974631        319.320831727008        319.357168859719        319.393505992430        319.440776405357        319.488046818284        319.536228132110        319.584409445937        319.624345612089        319.664281778242        319.706243792973        319.748205807704        319.801823191447        319.855440575190        319.916163786446        319.976886997702        320.047187868720        320.117488739738        320.196045022062        320.274601304387        320.342956883518        320.411312462648        320.477813606563        320.544314750478        320.619464561199        320.694614371920        320.767508281146        320.840402190372        320.894032842931        320.947663495491        321.000026728028        321.052389960566        321.121797898971        321.191205837375        321.260278580623        321.329351323871        321.385910769388        321.442470214905        321.490940957730        321.539411700554        321.589024066796        321.638636433037        321.692886430859        321.747136428681        321.807410271409        321.867684114138        321.932598715622        321.997513317105        322.066533621897        322.135553926688        322.222083283889        322.308612641090        322.397868000686        322.487123360281        322.560303090986        322.633482821692        322.714287308585        322.795091795478        322.908260930562        323.021430065647        323.150533438384        323.279636811122        323.406616081944        323.533595352765        323.665482985268        323.797370617771        323.924810654343        324.052250690915        324.157171357403        324.262092023892        324.359777947874        324.457463871855        324.556286968541        324.655110065228        324.752623165413        324.850136265599        324.960022466940        325.069908668282        325.197416497441        325.324924326600        325.446490625083        325.568056923567        325.666280376633        325.764503829700        325.848864548032        325.933225266364        326.017071987071        326.100918707778        326.175668162728        326.250417617679        326.323939678717        326.397461739755        326.484110353133        326.570758966511        326.668917429334        326.767075892157        326.861808991717        326.956542091276        327.033335451432        327.110128811587        327.191444480573        327.272760149559        327.385077493485        327.497394837411        327.629431366801        327.761467896192        327.914194748308        328.066921600425        328.248121894823        328.429322189222        328.638637270929        328.847952352636        329.060521894823        329.273091437010        329.451251567944        329.629411698878        329.765631868200        329.901852037522        329.994517707214        330.087183376907        330.156606311731        330.226029246556        330.265626534325        330.305223822094        330.323366805201        330.341509788308        330.368464497079        330.395419205849        330.433097452678        330.470775699507        330.495675736625        330.520575773744        330.540523844711        330.560471915678        330.599888688797        330.639305461916        330.698128574083        330.756951686250        330.830811600114        330.904671513979        330.997038064963        331.089404615948        331.204868521107        331.320332426266        331.430668355679        331.541004285091        331.626799906690        331.712595528288        331.781599415280        331.850603302271        331.910793078141        331.970982854011        332.037661841837        332.104340829664        332.188600437080        332.272860044496        332.384631494404        332.496402944312        332.631585554655        332.766768164998        332.918152479767        333.069536794536        333.229342023138        333.389147251741        333.545866305444        333.702585359147        333.848586388998        333.994587418849        334.126660196019        334.258732973190        334.387671725906        334.516610478623        334.648009639758        334.779408800893        334.902725346625        335.026041892356        335.139417944176        335.252793995995        335.361458254357        335.470122512718        335.573790214812        335.677457916906        335.779511353252        335.881564789598        335.989359512658        336.097154235719        336.218065610003        336.338976984288        336.476357256642        336.613737528996        336.769402814510        336.925068100023        337.091013012734        337.256957925444        337.420581414309        337.584204903175        337.740545944728        337.896886986282        338.042603733218        338.188320480154        338.310523251021        338.432726021888        338.544130098184        338.655534174480        338.765442959544        338.875351744608        338.966731194332        339.058110644055        339.128072537222        339.198034430388        339.268379466158        339.338724501929        339.424039477127        339.509354452325        339.599580850248        339.689807248171        339.786401591064        339.882995933956        339.997126144263        340.111256354571        340.235990611348        340.360724868124        340.473730387176        340.586735906228        340.689158181393        340.791580456557        340.900727360221        341.009874263885        341.154872396777        341.299870529668        341.483472761808        341.667074993948        341.868242153109        342.069409312271        342.264456214578        342.459503116885        342.650449487265        342.841395857645        343.021253454262        343.201111050878        343.354468577260        343.507826103641        343.637191865892        343.766557628142        343.886350911358        344.006144194574        344.115057152717        344.223970110859        344.323751742253        344.423533373646        344.526471089294        344.629408804942        344.735184447806        344.840960090669        344.940830075417        345.040700060165        345.142825602093        345.244951144021        345.353258414239        345.461565684457        345.561742598325        345.661919512192        345.747183300792        345.832447089391        345.918321519461        346.004195949531        346.100779004480        346.197362059429        346.299593561791        346.401825064153        346.512186102756        346.622547141358        346.744061652652        346.865576163946        346.988500888955        347.111425613964        347.232657355122        347.353889096279        347.483494160462        347.613099224645        347.764657761497        347.916216298350        348.111704887568        348.307193476786        348.500459990222        348.693726503657        348.890983069679        349.088239635700        349.291727004359        349.495214373018        349.702691602918     
+  0.947488031764416       0.882390707609878       0.998157647188866       0.952418608947733       0.817270789273660       0.996885051409493       0.728085695102151       0.990851982305767       0.637884911652333       0.990072880709515       0.595762565698863       0.972711816092563       0.965856676712861       0.841499815568552       0.886523232980042       0.965146976116641       0.741668277822855       0.591837991311972       0.792193970670084       0.997641002602193       0.912710251366073       0.928807209498480       0.898237850232544       0.999266296612623       0.851886377313259       0.964215762668314       0.999965289268365       0.908641401475467       0.823260760767501       0.977611315847939       0.999974349583762       0.889567351166186       0.981488117858243       0.692616403426253       0.999799300554367       0.989320449671225       0.986825156618664       0.919534533638257       0.884225650135546       0.999760151806573       0.994414971601326       0.997951916161087       0.887100740140224       0.999562269234954       0.585920531538786       0.853141175940922       0.991037805096357       0.992152573567451       0.999332011617492       0.823545047162815       0.996443576352900       0.874206648004056       0.504419990571978       0.857988673199827       0.880110420364086       0.900473538757466       0.945823442689414       0.988574826041659       0.857348906652125       0.987735219949253       0.834849581142526       0.860603669548175       0.876631518580033       0.867738652432744       0.925070932274631       0.999566920332460       0.942733182253283       0.997254316870668       0.848459702866706       0.718212115789131       0.994416519154735       0.997261147415274       0.940630243662637       0.914072981316579       0.985177959596764       0.996989902230292       0.495901708774148       0.831373909694944       0.811585411032084       0.972422902327099       0.546506568978507       0.945466147984970       0.265167252870300       0.780073398100054       0.624172807601586       0.994702160557937       0.990471279156271       0.926205743368332       0.992289442371609       0.968178822977318       0.986639627303399       0.999350711154713       0.840996129164800       0.182032780051221       0.999420135756517       0.915674903525654       0.282483995465186       0.974733431424663       0.985662777337056       0.967728208260297       0.988995028275044       0.798827379975444       0.595406669550792       0.993177956795018       0.926237360222123       0.999240100281311       0.831292225438565       0.594676637874432       0.984614780462075       0.993177780480680       0.955256473058929       0.879741440104462       0.939025147345531       0.939963934618185       0.914610953158321       0.994504016810673       0.913917505780136       0.891820062027726       0.646946420306272       0.986077202293310       0.949554346292742       0.999015136479037       0.804778629910955       0.987191788882639       0.949946668384419       0.900620180118301       0.872239965517043       0.995495686190679       0.824647797345363       0.944362118100568       0.781994122827541       0.995249330421569       0.940627092330763       0.986553210751971       0.895606345391544       0.839413763311823       0.721710696426580       0.897831775256494       0.929067967094475       0.938208550669446       0.861961823764060       0.696886207592241       0.971019508447038       0.989448569084288       0.965598560947786       0.981922340009845       0.701411404420612       0.104600308707135       0.983164500996082       0.998017240668145       0.982302668213245       0.935061774348980       0.846669208371132       0.988816946876684       0.886186572312611       0.891383147444920       0.985965748104140       0.961108151167829       0.327083058925475       0.917596615233765       0.984060890087786       0.217730716921630       0.508169585980581       0.804407334152152       0.941039626571956       0.889349173772447       0.920662880643609       0.989464185236220       0.997605465838400       0.979297066753547       0.957172016172363       0.932132506038552       0.949575189698423       0.946393910886845       0.854301739303652       0.324800555892071       0.583488485913683       0.793620289936204       0.957643066851486       0.515647886050300       7.587988206706671E-002  0.996867521589717       0.997314974002783       0.989598664164471       0.999803995476453       0.791306381858096       0.999556931659123       0.812664089299613       0.999670698308111       0.900955932641992       0.992430774756580       0.976684805319769       0.975935960902469       0.839419982497541       0.541881541911152       0.650753760709872       0.920590438442358       0.885607859732216       0.993861723237700       0.983788524221900       0.863800866013731       0.980691997132225       0.995615856317590       0.998035099067158       0.999811714758427       0.964988924043206       0.941495533701261       0.985448935005877       0.989091806279382       0.984726628049543       0.983865840183017       0.978314689920389       0.989713063012797       0.748690231413388       0.850392645437634       0.926729817273933       0.964055523221987       0.858174179764269       0.971942532484567       0.975564067037686       0.973059960674606       0.982890313458071       0.974544248477077       0.880302225261198       0.823633420842541       0.939346535967996       0.952335555793629       0.972133528480918       0.882069362488227       0.957244691296426       0.931996655132657       0.998759581996794       0.730520403082927       0.987445088111139       0.943077947728455       0.830796266171339       0.995962582309898       0.976397067467406       0.999842741306551       0.994396191911193       0.980866711135284       0.974783154853931       0.958741105591158       0.887673550805615       0.821573436078837       0.981655775478357       0.994525598973073       0.902253799209502       0.820031864288388       0.927527981444656       0.969506633058071       0.993067476133660       0.762049414169121       0.976744402242804       0.321074631755019       0.996577589308699       0.999892202223984       0.867305592691854       0.999769688520615       0.999590503549087       0.998317218746979       0.990283611839627       0.984615565457175       0.873629200967010       0.925085621757581       0.649935802425659       0.752761503409992       0.915204684728773       0.822061098076671       0.999993666123134       0.794484496418216       0.679678268772147       0.512279128327064       0.907667460096379       0.998334986500622       0.999989606657796       0.932594465060915       0.824912191750586       0.668096805665421       0.994350905307304       0.999882062973145       0.932293050204642       0.953093150199542       0.980705662019545       0.892601959093755       0.945217594123708       0.991556051414152       0.930916373128400       0.850512922777617       0.994452949956122       0.554705372831289       0.997552734207715       0.889705207453044       0.867636913380303       0.733054431000601       0.189343181073062       0.826890203083248       0.999990059425219       0.873347393089944       0.937402781828196       0.991024201719805       0.960198320684717       0.931895807744739       0.836099661156904       0.994896965661127       0.999555521329668       0.925705142591297       0.999705976575668       0.337357688658303       0.927201512426989       0.997233493771151       0.996180780623039       0.965115513480998       0.945214504620896       0.400652424056755       0.978910246416990       0.988197843822846       0.983488981782400       0.944786229818726       0.898731539524064       0.958107295811193       0.997020194126272       0.975042358663448       0.949058616986090       0.966457179198796       0.971509076915235       0.866937202889720       0.990404613199697       0.992862121865960       0.985910200969520       0.978506742931891       0.892033009545154       0.536045358478198       0.994294000448681       0.991893801076137       0.999776834875325       0.943669866205371       0.887873440548549       0.835155315552832       0.865672193714240       0.957628043010181       0.958717440718235       0.765411016459182       0.998796714540848       0.872204491067018       0.752159100110003       0.982845533894251       0.980718422156039     
+           2
+ -0.131254643360572       0.517069428110988        1.08182067584919        2.13326637358770        2.73375546874132        2.23997776835891       0.929699515256501       -1.11444707420409       -2.67573821245580       -2.87856330488736       -1.90209785853191      -0.960288396846844      -0.127309599506098       0.519123971628999        1.09845833595895        2.15377745092389        2.74178279831138        2.24390654627401       0.927034947716549       -1.11840574881049       -2.69421608102192       -2.89832584564760       -1.91246650303411      -0.960459432315943      -0.123323614572555       0.521218070743582        1.11513416618278        2.17432369186148        2.74984228497017        2.24786402897563       0.924395632660881       -1.12234432639115       -2.71267900802084       -2.91807776589179       -1.92282884807142      -0.960626468256293      -0.119335930046407       0.523313128694124        1.13181021448592        2.19487004452363        2.75790177699876        2.25182151436214       0.921756317605213       -1.12628287349056       -2.73114187405725       -2.93782932476804       -1.93319053133537      -0.960792260330621      -0.115346419561576       0.525409317286149        1.14848669811335        2.21541273077976        2.76595350089103        2.25576409079413       0.919094952776809       -1.13025072305144       -2.74964129524388       -2.95762143862511       -1.94359676941072      -0.961001887200727      -0.111663528494415       0.527041806941144        1.16591699949743        2.23572475782599        2.77558209490346        2.26100862164176       0.916135515605680       -1.13521851311631       -2.76853269649236       -2.97819389766126       -1.95447404199440      -0.961469922313078      -0.107860654017195       0.528789664565914        1.18345805341101        2.25613699562502        2.78530035789200        2.26632885561176       0.913237815703161       -1.14013859201476       -2.78739041267661       -2.99874290502888       -1.96533809630523      -0.961929689327584      -0.104054461617129       0.530539382987096        1.20099951099456        2.27654943992924        2.79501863022095        2.27164909425196       0.910340115800643       -1.14505866933551       -2.80624812570546       -3.01929207422557       -1.97620247742963      -0.962391060045031      -0.100251149809378       0.532282176944238        1.21853000024234        2.29694352384120        2.80471115010115        2.27693520990275       0.907399922368041       -1.15002684464570       -2.82515954118310       -3.03989522748933       -1.98712112423937      -0.962900372915200      -9.657142836469074E-002  0.534498365407295        1.23663732630217        2.31763175742248        2.81524537246355        2.28255222950951       0.904114205312311       -1.15622306722147       -2.84480538227602       -3.06114244925604       -1.99798435060416      -0.963119381070332      -9.277853340694056E-002  0.536818220007927        1.25483881112409        2.33840092971464        2.82584731348562        2.28822285505067       0.900867981465680       -1.16239113573849       -2.86443440846052       -3.08237920554798       -2.00884346092780      -0.963336241276855      -8.898545859310647E-002  0.539138117293329        1.27304020145945        2.35917005259441        2.83644925016947        2.29389347842271       0.897621757619049       -1.16855899932509       -2.88406302478419       -3.10361326189795       -2.01969758122834      -0.963539280350215      -8.516973153606598E-002  0.541497365991697        1.29129764237755        2.38001852337338        2.84715383206899        2.29969629210904       0.894537269185294       -1.17453457130906       -2.90346879331549       -3.12459976725524       -2.03027944733590      -0.963462846700087      -8.318137128004088E-002  0.543878489204072        1.30556339626621        2.40086196051427        2.86349649009386        2.30662073374580       0.887792197369512       -1.18505484118622       -2.92012438706208       -3.14478006706923       -2.03869306366509      -0.962605359946822      -8.131952325850622E-002  0.546127682709739        1.31969180297595        2.42157577340269        2.87971724679271        2.31343828536589       0.880955246846406       -1.19565053554695       -2.93683895106848       -3.16500456560729       -2.04713610718260      -0.961766931458097      -7.946636457773126E-002  0.548371989282220        1.33381912516008        2.44228903304709        2.89593798152913        2.32025582600477       0.874118296323300       -1.20624598994303       -2.95355303514557       -3.18522530648506       -2.05557211530886      -0.960907763364043      -7.757876207755750E-002  0.550679154240705        1.34803772029682        2.46313591470192        2.91233468733382        2.32730163521162       0.867561911867873       -1.21650906054413       -2.96988291770040       -3.20502042283162       -2.06354107589496      -0.959566493512336      -7.730219052307574E-002  0.550357935231823        1.35866963091892        2.48275195707344        2.93421989150165        2.33628089748756       0.856814006163955       -1.23047890110198       -2.98132949467161       -3.22331217432112       -2.07013703786751      -0.958710477392881      -7.712537096548630E-002  0.549926745420134        1.36918135193231        2.50225440094597        2.95599808828023        2.34516971366972       0.845992215661742       -1.24450607549849       -2.99281685452186       -3.24163247691575       -2.07674931917128      -0.957864064655987      -7.695143884179889E-002  0.549494111512313        1.37969307218733        2.52175684968569        2.97777629555155        2.35405853509826       0.835170425159529       -1.25853325141979       -3.00430421742168       -3.25995284087020       -2.08336172014513      -0.957018509640572      -7.677910249098863E-002  0.549056980809610        1.39019739462547        2.54124599510881        2.99953529400655        2.36292081968353       0.824314769787128       -1.27259985902399       -3.01583657881712       -3.27831926911595       -2.09002125120596      -0.956215270085997      -7.659034326116144E-002  0.548303305832745        1.40189817662095        2.56059404473287        3.02216449393333        2.37249493004545       0.812882095499132       -1.28748162695347       -3.02788580296873       -3.29720423678765       -2.09686072038062      -0.955524593494270      -7.628314748519592E-002  0.547660207647820        1.41370167565417        2.58003235634854        3.04487150080557        2.38213274135591       0.801499016162785       -1.30232615353693       -3.03991013937994       -3.31607228287846       -2.10369123413391      -0.954828406701153      -7.597388672782887E-002  0.547018261938728        1.42550541465766        2.59947079083601        3.06757851345117        2.39177055555305       0.790115936826438       -1.31717061821239       -3.05193435197517       -3.33493973126345       -2.11052067629153      -0.954130057562446      -7.566137287494026E-002  0.546380413810568        1.43731409572749        2.61891435943207        3.09029085224759        2.40141467672878       0.778740145296439       -1.33200480401653       -3.06394529463410       -3.35378911923031       -2.11732726754918      -0.953403895217910      -7.602451339366684E-002  0.546239431030685        1.44876402506477        2.63888506323516        3.11434437457380        2.41097132000011       0.766666985700136       -1.34824458585656       -3.07630256711981       -3.37247512859970       -2.12367610934446      -0.952323810467218      -7.635206537097822E-002  0.546127432756093        1.46023633487122        2.65887223673730        3.13840845582895        2.42053368947150       0.754594719575008       -1.36448616515093       -3.08866432798535       -3.39116569389385       -2.13002957460944      -0.951247011186959      -7.668156481946027E-002  0.546014308367871        1.47170833992158        2.67885925398630        3.16247252933391        2.43009605506780       0.742522453449881       -1.38072769771166       -3.10102599538363       -3.40985565045688       -2.13638191587943      -0.950167084869187      -7.700593418790123E-002  0.545910597459656        1.48319404185191        2.69886726639568        3.18656489627965        2.43969768454088       0.730500421637537       -1.39690705311059       -3.11331354277110       -3.42846020971871       -2.14263758255784      -0.948981962890397     
+   315.551939725323        315.644481572339        315.737023419355        315.831019342046        315.925015264737        316.017871370006        316.110727475274        316.202019778800        316.293312082325        316.398957194298        316.504602306271        316.616296186514        316.727990066757        316.807925805088        316.887861543420        316.931141044518        316.974420545617        317.009107349720        317.043794153822        317.079929437763        317.116064721703        317.145706993755        317.175349265808        317.217323426682        317.259297587556        317.333560803835        317.407824020115        317.503177240388        317.598530460661        317.693263457235        317.787996453809        317.877822068571        317.967647683333        318.050567993525        318.133488303716        318.210189243932        318.286890184147        318.358269704290        318.429649224433        318.490571336492        318.551493448551        318.604564508711        318.657635568871        318.704397175047        318.751158781223        318.799682725764        318.848206670306        318.893484228360        318.938761786415        318.971518019974        319.004274253534        319.036061188978        319.067848124423        319.111286397250        319.154724670078        319.201719446166        319.248714222255        319.284772974631        319.320831727008        319.357168859719        319.393505992430        319.440776405357        319.488046818284        319.536228132110        319.584409445937        319.624345612089        319.664281778242        319.706243792973        319.748205807704        319.801823191447        319.855440575190        319.916163786446        319.976886997702        320.047187868720        320.117488739738        320.196045022062        320.274601304387        320.342956883518        320.411312462648        320.477813606563        320.544314750478        320.619464561199        320.694614371920        320.767508281146        320.840402190372        320.894032842931        320.947663495491        321.000026728028        321.052389960566        321.121797898971        321.191205837375        321.260278580623        321.329351323871        321.385910769388        321.442470214905        321.490940957730        321.539411700554        321.589024066796        321.638636433037        321.692886430859        321.747136428681        321.807410271409        321.867684114138        321.932598715622        321.997513317105        322.066533621897        322.135553926688        322.222083283889        322.308612641090        322.397868000686        322.487123360281        322.560303090986        322.633482821692        322.714287308585        322.795091795478        322.908260930562        323.021430065647        323.150533438384        323.279636811122        323.406616081944        323.533595352765        323.665482985268        323.797370617771        323.924810654343        324.052250690915        324.157171357403        324.262092023892        324.359777947874        324.457463871855        324.556286968541        324.655110065228        324.752623165413        324.850136265599        324.960022466940        325.069908668282        325.197416497441        325.324924326600        325.446490625083        325.568056923567        325.666280376633        325.764503829700        325.848864548032        325.933225266364        326.017071987071        326.100918707778        326.175668162728        326.250417617679        326.323939678717        326.397461739755        326.484110353133        326.570758966511        326.668917429334        326.767075892157        326.861808991717        326.956542091276        327.033335451432        327.110128811587        327.191444480573        327.272760149559        327.385077493485        327.497394837411        327.629431366801        327.761467896192        327.914194748308        328.066921600425        328.248121894823        328.429322189222        328.638637270929        328.847952352636        329.060521894823        329.273091437010        329.451251567944        329.629411698878        329.765631868200        329.901852037522        329.994517707214        330.087183376907        330.156606311731        330.226029246556        330.265626534325        330.305223822094        330.323366805201        330.341509788308        330.368464497079        330.395419205849        330.433097452678        330.470775699507        330.495675736625        330.520575773744        330.540523844711        330.560471915678        330.599888688797        330.639305461916        330.698128574083        330.756951686250        330.830811600114        330.904671513979        330.997038064963        331.089404615948        331.204868521107        331.320332426266        331.430668355679        331.541004285091        331.626799906690        331.712595528288        331.781599415280        331.850603302271        331.910793078141        331.970982854011        332.037661841837        332.104340829664        332.188600437080        332.272860044496        332.384631494404        332.496402944312        332.631585554655        332.766768164998        332.918152479767        333.069536794536        333.229342023138        333.389147251741        333.545866305444        333.702585359147        333.848586388998        333.994587418849        334.126660196019        334.258732973190        334.387671725906        334.516610478623        334.648009639758        334.779408800893        334.902725346625        335.026041892356        335.139417944176        335.252793995995        335.361458254357        335.470122512718        335.573790214812        335.677457916906        335.779511353252        335.881564789598        335.989359512658        336.097154235719        336.218065610003        336.338976984288        336.476357256642        336.613737528996        336.769402814510        336.925068100023        337.091013012734        337.256957925444        337.420581414309        337.584204903175        337.740545944728        337.896886986282        338.042603733218        338.188320480154        338.310523251021        338.432726021888        338.544130098184        338.655534174480        338.765442959544        338.875351744608        338.966731194332        339.058110644055        339.128072537222        339.198034430388        339.268379466158        339.338724501929        339.424039477127        339.509354452325        339.599580850248        339.689807248171        339.786401591064        339.882995933956        339.997126144263        340.111256354571        340.235990611348        340.360724868124        340.473730387176        340.586735906228        340.689158181393        340.791580456557        340.900727360221        341.009874263885        341.154872396777        341.299870529668        341.483472761808        341.667074993948        341.868242153109        342.069409312271        342.264456214578        342.459503116885        342.650449487265        342.841395857645        343.021253454262        343.201111050878        343.354468577260        343.507826103641        343.637191865892        343.766557628142        343.886350911358        344.006144194574        344.115057152717        344.223970110859        344.323751742253        344.423533373646        344.526471089294        344.629408804942        344.735184447806        344.840960090669        344.940830075417        345.040700060165        345.142825602093        345.244951144021        345.353258414239        345.461565684457        345.561742598325        345.661919512192        345.747183300792        345.832447089391        345.918321519461        346.004195949531        346.100779004480        346.197362059429        346.299593561791        346.401825064153        346.512186102756        346.622547141358        346.744061652652        346.865576163946        346.988500888955        347.111425613964        347.232657355122        347.353889096279        347.483494160462        347.613099224645        347.764657761497        347.916216298350        348.111704887568        348.307193476786        348.500459990222        348.693726503657        348.890983069679        349.088239635700        349.291727004359        349.495214373018        349.702691602918     
+  0.947488031764416       0.882390707609878       0.998157647188866       0.952418608947733       0.817270789273660       0.996885051409493       0.728085695102151       0.990851982305767       0.637884911652333       0.990072880709515       0.595762565698863       0.972711816092563       0.965856676712861       0.841499815568552       0.886523232980042       0.965146976116641       0.741668277822855       0.591837991311972       0.792193970670084       0.997641002602193       0.912710251366073       0.928807209498480       0.898237850232544       0.999266296612623       0.851886377313259       0.964215762668314       0.999965289268365       0.908641401475467       0.823260760767501       0.977611315847939       0.999974349583762       0.889567351166186       0.981488117858243       0.692616403426253       0.999799300554367       0.989320449671225       0.986825156618664       0.919534533638257       0.884225650135546       0.999760151806573       0.994414971601326       0.997951916161087       0.887100740140224       0.999562269234954       0.585920531538786       0.853141175940922       0.991037805096357       0.992152573567451       0.999332011617492       0.823545047162815       0.996443576352900       0.874206648004056       0.504419990571978       0.857988673199827       0.880110420364086       0.900473538757466       0.945823442689414       0.988574826041659       0.857348906652125       0.987735219949253       0.834849581142526       0.860603669548175       0.876631518580033       0.867738652432744       0.925070932274631       0.999566920332460       0.942733182253283       0.997254316870668       0.848459702866706       0.718212115789131       0.994416519154735       0.997261147415274       0.940630243662637       0.914072981316579       0.985177959596764       0.996989902230292       0.495901708774148       0.831373909694944       0.811585411032084       0.972422902327099       0.546506568978507       0.945466147984970       0.265167252870300       0.780073398100054       0.624172807601586       0.994702160557937       0.990471279156271       0.926205743368332       0.992289442371609       0.968178822977318       0.986639627303399       0.999350711154713       0.840996129164800       0.182032780051221       0.999420135756517       0.915674903525654       0.282483995465186       0.974733431424663       0.985662777337056       0.967728208260297       0.988995028275044       0.798827379975444       0.595406669550792       0.993177956795018       0.926237360222123       0.999240100281311       0.831292225438565       0.594676637874432       0.984614780462075       0.993177780480680       0.955256473058929       0.879741440104462       0.939025147345531       0.939963934618185       0.914610953158321       0.994504016810673       0.913917505780136       0.891820062027726       0.646946420306272       0.986077202293310       0.949554346292742       0.999015136479037       0.804778629910955       0.987191788882639       0.949946668384419       0.900620180118301       0.872239965517043       0.995495686190679       0.824647797345363       0.944362118100568       0.781994122827541       0.995249330421569       0.940627092330763       0.986553210751971       0.895606345391544       0.839413763311823       0.721710696426580       0.897831775256494       0.929067967094475       0.938208550669446       0.861961823764060       0.696886207592241       0.971019508447038       0.989448569084288       0.965598560947786       0.981922340009845       0.701411404420612       0.104600308707135       0.983164500996082       0.998017240668145       0.982302668213245       0.935061774348980       0.846669208371132       0.988816946876684       0.886186572312611       0.891383147444920       0.985965748104140       0.961108151167829       0.327083058925475       0.917596615233765       0.984060890087786       0.217730716921630       0.508169585980581       0.804407334152152       0.941039626571956       0.889349173772447       0.920662880643609       0.989464185236220       0.997605465838400       0.979297066753547       0.957172016172363       0.932132506038552       0.949575189698423       0.946393910886845       0.854301739303652       0.324800555892071       0.583488485913683       0.793620289936204       0.957643066851486       0.515647886050300       7.587988206706671E-002  0.996867521589717       0.997314974002783       0.989598664164471       0.999803995476453       0.791306381858096       0.999556931659123       0.812664089299613       0.999670698308111       0.900955932641992       0.992430774756580       0.976684805319769       0.975935960902469       0.839419982497541       0.541881541911152       0.650753760709872       0.920590438442358       0.885607859732216       0.993861723237700       0.983788524221900       0.863800866013731       0.980691997132225       0.995615856317590       0.998035099067158       0.999811714758427       0.964988924043206       0.941495533701261       0.985448935005877       0.989091806279382       0.984726628049543       0.983865840183017       0.978314689920389       0.989713063012797       0.748690231413388       0.850392645437634       0.926729817273933       0.964055523221987       0.858174179764269       0.971942532484567       0.975564067037686       0.973059960674606       0.982890313458071       0.974544248477077       0.880302225261198       0.823633420842541       0.939346535967996       0.952335555793629       0.972133528480918       0.882069362488227       0.957244691296426       0.931996655132657       0.998759581996794       0.730520403082927       0.987445088111139       0.943077947728455       0.830796266171339       0.995962582309898       0.976397067467406       0.999842741306551       0.994396191911193       0.980866711135284       0.974783154853931       0.958741105591158       0.887673550805615       0.821573436078837       0.981655775478357       0.994525598973073       0.902253799209502       0.820031864288388       0.927527981444656       0.969506633058071       0.993067476133660       0.762049414169121       0.976744402242804       0.321074631755019       0.996577589308699       0.999892202223984       0.867305592691854       0.999769688520615       0.999590503549087       0.998317218746979       0.990283611839627       0.984615565457175       0.873629200967010       0.925085621757581       0.649935802425659       0.752761503409992       0.915204684728773       0.822061098076671       0.999993666123134       0.794484496418216       0.679678268772147       0.512279128327064       0.907667460096379       0.998334986500622       0.999989606657796       0.932594465060915       0.824912191750586       0.668096805665421       0.994350905307304       0.999882062973145       0.932293050204642       0.953093150199542       0.980705662019545       0.892601959093755       0.945217594123708       0.991556051414152       0.930916373128400       0.850512922777617       0.994452949956122       0.554705372831289       0.997552734207715       0.889705207453044       0.867636913380303       0.733054431000601       0.189343181073062       0.826890203083248       0.999990059425219       0.873347393089944       0.937402781828196       0.991024201719805       0.960198320684717       0.931895807744739       0.836099661156904       0.994896965661127       0.999555521329668       0.925705142591297       0.999705976575668       0.337357688658303       0.927201512426989       0.997233493771151       0.996180780623039       0.965115513480998       0.945214504620896       0.400652424056755       0.978910246416990       0.988197843822846       0.983488981782400       0.944786229818726       0.898731539524064       0.958107295811193       0.997020194126272       0.975042358663448       0.949058616986090       0.966457179198796       0.971509076915235       0.866937202889720       0.990404613199697       0.992862121865960       0.985910200969520       0.978506742931891       0.892033009545154       0.536045358478198       0.994294000448681       0.991893801076137       0.999776834875325       0.943669866205371       0.887873440548549       0.835155315552832       0.865672193714240       0.957628043010181       0.958717440718235       0.765411016459182       0.998796714540848       0.872204491067018       0.752159100110003       0.982845533894251       0.980718422156039     

Added: trunk/Lib/sandbox/pyloess/tests/co2_results_real
===================================================================
--- trunk/Lib/sandbox/pyloess/tests/co2_results_real	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/tests/co2_results_real	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,7 @@
+ -0.1312545      0.5171010       1.081863       2.133283       2.733717       2.239956      0.9297554      -1.114420      -2.675813      -2.878533      -1.902167     -0.9602861     -0.1273115      0.5191532       1.098498       2.153796       2.741747       2.243891      0.9270887      -1.118383      -2.694288      -2.898298      -1.912531     -0.9604589     -0.1233273      0.5212451       1.115170       2.174344       2.749810       2.247854      0.9244474      -1.122326      -2.712748      -2.918053      -1.922890     -0.9606276     -0.1193415      0.5233380       1.131844       2.194892       2.757873       2.251818      0.9218062      -1.126269      -2.731208      -2.937807      -1.933248     -0.9607950     -0.1153538      0.5254319       1.148517       2.215437       2.765927       2.255767      0.9191428      -1.130242      -2.749705      -2.957601      -1.943650     -0.9610062     -0.1116722      0.5270622       1.165944       2.235751       2.775559       2.261016      0.9161811      -1.135213      -2.768593      -2.978176      -1.954524     -0.9614759     -0.1078705      0.5288079       1.183482       2.256165       2.785280       2.266341      0.9132813      -1.140137      -2.787447      -2.998728      -1.965384     -0.9619374     -0.1040655      0.5305554       1.201020       2.276579       2.795002       2.271666      0.9103814      -1.145061      -2.806301      -3.019279      -1.976244     -0.9624004     -0.1002634      0.5322961       1.218547       2.296975       2.804697       2.276956      0.9074391      -1.150033      -2.825208      -3.039885      -1.987159     -0.9629111     -9.6585110E-02  0.5345098       1.236650       2.317664       2.815235       2.282577      0.9041511      -1.156232      -2.844850      -3.061133      -1.998018     -0.9631324     -9.2793740E-02  0.5368271       1.254847       2.338434       2.825840       2.288252      0.9009027      -1.162404      -2.864474      -3.082371      -2.008873     -0.9633515     -8.9002162E-02  0.5391444       1.273044       2.359204       2.836445       2.293926      0.8976543      -1.168575      -2.884098      -3.103606      -2.019723     -0.9635568     -8.5187905E-02  0.5415012       1.291297       2.380054       2.847153       2.299733      0.8945679      -1.174553      -2.903498      -3.124593      -2.030300     -0.9634821     -8.3201811E-02  0.5438787       1.305556       2.400896       2.863496       2.306658      0.8878226      -1.185068      -2.920140      -3.144774      -2.038712     -0.9626333     -8.1342012E-02  0.5461245       1.319679       2.421609       2.879717       2.313476      0.8809856      -1.195659      -2.936841      -3.164999      -2.047152     -0.9618035     -7.9490878E-02  0.5483653       1.333800       2.442321       2.895938       2.320295      0.8741485      -1.206250      -2.953541      -3.185220      -2.055586     -0.9609529     -7.7605315E-02  0.5506690       1.348012       2.463167       2.912336       2.327341      0.8675922      -1.216508      -2.969857      -3.205015      -2.063553     -0.9596200     -7.7330299E-02  0.5503440       1.358636       2.482778       2.934216       2.336317      0.8568450      -1.230463      -2.981276      -3.223306      -2.070151     -0.9587819     -7.7154912E-02  0.5499091       1.369141       2.502276       2.955991       2.345202      0.8460240      -1.244474      -2.992736      -3.241627      -2.076766     -0.9579533     -7.6982312E-02  0.5494729       1.379645       2.521775       2.977765       2.354088      0.8352031      -1.258486      -3.004196      -3.259947      -2.083381     -0.9571256     -7.6811321E-02  0.5490321       1.390142       2.541260       2.999520       2.362947      0.8243483      -1.272537      -3.015701      -3.278312      -2.090042     -0.9563401     -7.6623864E-02  0.5482746       1.401835       2.560602       3.022145       2.372517      0.8129162      -1.287402      -3.027721      -3.297196      -2.096884     -0.9556683     -7.6317951E-02  0.5476279       1.413630       2.580036       3.044847       2.382150      0.8015336      -1.302230      -3.039716      -3.316063      -2.103717     -0.9549910     -7.6009966E-02  0.5469823       1.425426       2.599469       3.067550       2.391784      0.7901511      -1.317057      -3.051710      -3.334929      -2.110549     -0.9543115     -7.5698733E-02  0.5463407       1.437227       2.618907       3.090258       2.401424      0.7787760      -1.331874      -3.063692      -3.353776      -2.117358     -0.9536040     -7.6063856E-02  0.5461957       1.448669       2.638872       3.114306       2.410975      0.7667037      -1.348096      -3.076017      -3.372460      -2.123710     -0.9525445     -7.6393344E-02  0.5460796       1.460133       2.658854       3.138366       2.420532      0.7546321      -1.364318      -3.088346      -3.391149      -2.130067     -0.9514883     -7.6724812E-02  0.5459623       1.471596       2.678835       3.162424       2.430090      0.7425606      -1.380541      -3.100676      -3.409836      -2.136422     -0.9504288     -7.7051133E-02  0.5458546       1.483073       2.698837       3.186512       2.439687      0.7305394      -1.396702      -3.112931      -3.428438      -2.142681     -0.9492642    
+   315.5519       315.6444       315.7370       315.8309       315.9249       316.0178       316.1107       316.2020       316.2933       316.3990       316.5046       316.6163       316.7279       316.8079       316.8878       316.9311       316.9743       317.0090       317.0437       317.0798       317.1160       317.1457       317.1753       317.2173       317.2592       317.3336       317.4079       317.5032       317.5985       317.6932       317.7880       317.8778       317.9677       318.0505       318.1334       318.2101       318.2868       318.3582       318.4297       318.4905       318.5515       318.6045       318.6576       318.7044       318.7512       318.7997       318.8482       318.8934       318.9387       318.9714       319.0042       319.0360       319.0678       319.1112       319.1547       319.2017       319.2487       319.2848       319.3208       319.3572       319.3935       319.4408       319.4881       319.5362       319.5844       319.6243       319.6643       319.7062       319.7481       319.8018       319.8554       319.9161       319.9768       320.0472       320.1175       320.1960       320.2744       320.3428       320.4112       320.4777       320.5442       320.6194       320.6946       320.7675       320.8404       320.8941       320.9478       321.0001       321.0525       321.1218       321.1912       321.2603       321.3293       321.3860       321.4426       321.4910       321.5395       321.5891       321.6387       321.6929       321.7472       321.8074       321.8677       321.9326       321.9974       322.0666       322.1357       322.2221       322.3085       322.3978       322.4871       322.5602       322.6334       322.7142       322.7951       322.9083       323.0215       323.1505       323.2796       323.4066       323.5336       323.6655       323.7974       323.9248       324.0522       324.1571       324.2621       324.3597       324.4574       324.5563       324.6551       324.7526       324.8501       324.9600       325.0699       325.1974       325.3250       325.4465       325.5681       325.6663       325.7645       325.8489       325.9333       326.0171       326.1010       326.1757       326.2505       326.3240       326.3975       326.4841       326.5707       326.6689       326.7671       326.8619       326.9567       327.0334       327.1101       327.1916       327.2731       327.3853       327.4976       327.6297       327.7618       327.9146       328.0674       328.2484       328.4293       328.6387       328.8480       329.0606       329.2731       329.4512       329.6294       329.7654       329.9015       329.9944       330.0872       330.1566       330.2260       330.2656       330.3052       330.3234       330.3416       330.3688       330.3960       330.4333       330.4705       330.4956       330.5207       330.5406       330.5605       330.5999       330.6394       330.6982       330.7570       330.8309       330.9047       330.9972       331.0897       331.2050       331.3204       331.4307       331.5411       331.6268       331.7126       331.7816       331.8506       331.9108       331.9710       332.0377       332.1044       332.1886       332.2728       332.3846       332.4964       332.6316       332.7668       332.9182       333.0696       333.2294       333.3892       333.5459       333.7026       333.8486       333.9946       334.1266       334.2587       334.3876       334.5166       334.6480       334.7794       334.9027       335.0260       335.1393       335.2527       335.3613       335.4700       335.5737       335.6774       335.7795       335.8816       335.9893       336.0971       336.2180       336.3389       336.4763       336.6138       336.7694       336.9250       337.0909       337.2568       337.4205       337.5841       337.7405       337.8969       338.0427       338.1884       338.3105       338.4326       338.5441       338.6555       338.7655       338.8755       338.9668       339.0580       339.1279       339.1978       339.2682       339.3386       339.4240       339.5094       339.5996       339.6898       339.7864       339.8830       339.9971       340.1111       340.2360       340.3608       340.4738       340.5868       340.6892       340.7917       340.9008       341.0099       341.1549       341.2999       341.4833       341.6667       341.8679       342.0690       342.2645       342.4600       342.6507       342.8414       343.0210       343.2006       343.3539       343.5072       343.6369       343.7666       343.8864       344.0062       344.1151       344.2241       344.3238       344.4236       344.5265       344.6294       344.7352       344.8410       344.9409       345.0409       345.1429       345.2449       345.3532       345.4615       345.5617       345.6619       345.7472       345.8325       345.9183       346.0041       346.1007       346.1973       346.2995       346.4017       346.5121       346.6226       346.7441       346.8656       346.9885       347.1115       347.2327       347.3539       347.4835       347.6131       347.7646       347.9162       348.1116       348.3071       348.4999       348.6928       348.8899       349.0870       349.2884       349.4897       349.7021    
+  0.9473456      0.8820528      0.9981718      0.9523941      0.8169235      0.9968721      0.7275636      0.9908377      0.6374046      0.9900793      0.5952753      0.9727222      0.9657797      0.8412194      0.8863041      0.9650735      0.7412772      0.5911558      0.7918944      0.9976359      0.9126042      0.9287147      0.8981016      0.9992640      0.8516618      0.9641449      0.9999655      0.9084932      0.8229079      0.9775841      0.9999740      0.8893542      0.9814858      0.6921397      0.9997987      0.9893009      0.9868131      0.9194017      0.8840622      0.9997586      0.9944118      0.9979475      0.8869542      0.9995601      0.5853120      0.8529151      0.9910294      0.9921290      0.9993278      0.8233213      0.9964389      0.8739912      0.5036717      0.8577449      0.8799009      0.9003027      0.9457330      0.9885447      0.8570249      0.9877417      0.8345523      0.8603712      0.8764476      0.8674909      0.9248952      0.9995702      0.9426413      0.9972472      0.8482621      0.7178012      0.9944118      0.9972574      0.9405500      0.9139733      0.9851364      0.9969788      0.4954960      0.8312120      0.8113978      0.9723752      0.5457299      0.9453593      0.2643782      0.7797844      0.6239225      0.9947231      0.9904200      0.9260687      0.9922562      0.9681790      0.9866477      0.9993476      0.8408600      0.1812998      0.9994192      0.9156029      0.2818184      0.9746988      0.9856681      0.9676514      0.9889814      0.7985213      0.5947735      0.9931651      0.9261450      0.9992403      0.8309539      0.5941209      0.9845950      0.9931651      0.9551575      0.8795514      0.9389349      0.9398142      0.9144093      0.9944832      0.9138095      0.8916704      0.6464453      0.9860324      0.9495300      0.9990164      0.8044351      0.9871626      0.9498475      0.9004778      0.8719712      0.9955013      0.8243347      0.9442974      0.7816713      0.9952399      0.9405271      0.9865257      0.8954014      0.8391304      0.7213080      0.8975996      0.9288895      0.9381664      0.8617947      0.6964918      0.9709492      0.9894392      0.9655861      0.9818738      0.7010069      0.1039263      0.9831502      0.9979994      0.9821939      0.9348792      0.8464258      0.9887996      0.8859938      0.8913366      0.9858394      0.9611016      0.3264723      0.9174322      0.9840199      0.2168292      0.5075723      0.8040431      0.9408705      0.8893237      0.9207462      0.9894688      0.9976125      0.9792520      0.9570797      0.9320744      0.9494027      0.9463241      0.8543022      0.3240814      0.5827369      0.7932186      0.9575490      0.5153625      7.5613648E-02  0.9968399      0.9972875      0.9896256      0.9998081      0.7909694      0.9995499      0.8123233      0.9996711      0.9008568      0.9924324      0.9765879      0.9759859      0.8392387      0.5412561      0.6502172      0.9204307      0.8854656      0.9938530      0.9838016      0.8638172      0.9807110      0.9956102      0.9980421      0.9998107      0.9649314      0.9413726      0.9854034      0.9891018      0.9846898      0.9838746      0.9782504      0.9896938      0.7482746      0.8501588      0.9267029      0.9640011      0.8578818      0.9719143      0.9755108      0.9730045      0.9828760      0.9745318      0.8800598      0.8233213      0.9392827      0.9522703      0.9719781      0.8818638      0.9571581      0.9319032      0.9987569      0.7301404      0.9874538      0.9430911      0.8306218      0.9959595      0.9763831      0.9998436      0.9944333      0.9808433      0.9747442      0.9586537      0.8875102      0.8213251      0.9816285      0.9945189      0.9021925      0.8195850      0.9273343      0.9694217      0.9929974      0.7616304      0.9767481      0.3199174      0.9965921      0.9998900      0.8672252      0.9997818      0.9995781      0.9983168      0.9902315      0.9846542      0.8739912      0.9251511      0.6491545      0.7521552      0.9149528      0.8217025      0.9999934      0.7942597      0.6791515      0.5116771      0.9076493      0.9983443      0.9999844      0.9324158      0.8247468      0.6679452      0.9943252      0.9998839      0.9321719      0.9530309      0.9806179      0.8923972      0.9451830      0.9915662      0.9311679      0.8502639      0.9944261      0.5542958      0.9975463      0.8896603      0.8676236      0.7327968      0.1887221      0.8266525      0.9999914      0.8732761      0.9370639      0.9911562      0.9603313      0.9317075      0.8358660      0.9948754      0.9995601      0.9256614      0.9997001      0.3365756      0.9271325      0.9972321      0.9962590      0.9649491      0.9452492      0.4000554      0.9789069      0.9881831      0.9834098      0.9445416      0.8983963      0.9580159      0.9970051      0.9750311      0.9486145      0.9663744      0.9714338      0.8667263      0.9904200      0.9929007      0.9858394      0.9784330      0.8917311      0.5354862      0.9942672      0.9918803      0.9998053      0.9436064      0.8876644      0.8348811      0.8652251      0.9573147      0.9585381      0.7653055      0.9986812      0.8698055      0.7505626      0.9830258      0.9803512    
+           2
+ -0.1312545      0.5171010       1.081863       2.133283       2.733717       2.239956      0.9297554      -1.114420      -2.675813      -2.878533      -1.902167     -0.9602861     -0.1273115      0.5191532       1.098498       2.153796       2.741747       2.243891      0.9270887      -1.118383      -2.694288      -2.898298      -1.912531     -0.9604589     -0.1233273      0.5212451       1.115170       2.174344       2.749810       2.247854      0.9244474      -1.122326      -2.712748      -2.918053      -1.922890     -0.9606276     -0.1193415      0.5233380       1.131844       2.194892       2.757873       2.251818      0.9218062      -1.126269      -2.731208      -2.937807      -1.933248     -0.9607950     -0.1153538      0.5254319       1.148517       2.215437       2.765927       2.255767      0.9191428      -1.130242      -2.749705      -2.957601      -1.943650     -0.9610062     -0.1116722      0.5270622       1.165944       2.235751       2.775559       2.261016      0.9161811      -1.135213      -2.768593      -2.978176      -1.954524     -0.9614759     -0.1078705      0.5288079       1.183482       2.256165       2.785280       2.266341      0.9132813      -1.140137      -2.787447      -2.998728      -1.965384     -0.9619374     -0.1040655      0.5305554       1.201020       2.276579       2.795002       2.271666      0.9103814      -1.145061      -2.806301      -3.019279      -1.976244     -0.9624004     -0.1002634      0.5322961       1.218547       2.296975       2.804697       2.276956      0.9074391      -1.150033      -2.825208      -3.039885      -1.987159     -0.9629111     -9.6585110E-02  0.5345098       1.236650       2.317664       2.815235       2.282577      0.9041511      -1.156232      -2.844850      -3.061133      -1.998018     -0.9631324     -9.2793740E-02  0.5368271       1.254847       2.338434       2.825840       2.288252      0.9009027      -1.162404      -2.864474      -3.082371      -2.008873     -0.9633515     -8.9002162E-02  0.5391444       1.273044       2.359204       2.836445       2.293926      0.8976543      -1.168575      -2.884098      -3.103606      -2.019723     -0.9635568     -8.5187905E-02  0.5415012       1.291297       2.380054       2.847153       2.299733      0.8945679      -1.174553      -2.903498      -3.124593      -2.030300     -0.9634821     -8.3201811E-02  0.5438787       1.305556       2.400896       2.863496       2.306658      0.8878226      -1.185068      -2.920140      -3.144774      -2.038712     -0.9626333     -8.1342012E-02  0.5461245       1.319679       2.421609       2.879717       2.313476      0.8809856      -1.195659      -2.936841      -3.164999      -2.047152     -0.9618035     -7.9490878E-02  0.5483653       1.333800       2.442321       2.895938       2.320295      0.8741485      -1.206250      -2.953541      -3.185220      -2.055586     -0.9609529     -7.7605315E-02  0.5506690       1.348012       2.463167       2.912336       2.327341      0.8675922      -1.216508      -2.969857      -3.205015      -2.063553     -0.9596200     -7.7330299E-02  0.5503440       1.358636       2.482778       2.934216       2.336317      0.8568450      -1.230463      -2.981276      -3.223306      -2.070151     -0.9587819     -7.7154912E-02  0.5499091       1.369141       2.502276       2.955991       2.345202      0.8460240      -1.244474      -2.992736      -3.241627      -2.076766     -0.9579533     -7.6982312E-02  0.5494729       1.379645       2.521775       2.977765       2.354088      0.8352031      -1.258486      -3.004196      -3.259947      -2.083381     -0.9571256     -7.6811321E-02  0.5490321       1.390142       2.541260       2.999520       2.362947      0.8243483      -1.272537      -3.015701      -3.278312      -2.090042     -0.9563401     -7.6623864E-02  0.5482746       1.401835       2.560602       3.022145       2.372517      0.8129162      -1.287402      -3.027721      -3.297196      -2.096884     -0.9556683     -7.6317951E-02  0.5476279       1.413630       2.580036       3.044847       2.382150      0.8015336      -1.302230      -3.039716      -3.316063      -2.103717     -0.9549910     -7.6009966E-02  0.5469823       1.425426       2.599469       3.067550       2.391784      0.7901511      -1.317057      -3.051710      -3.334929      -2.110549     -0.9543115     -7.5698733E-02  0.5463407       1.437227       2.618907       3.090258       2.401424      0.7787760      -1.331874      -3.063692      -3.353776      -2.117358     -0.9536040     -7.6063856E-02  0.5461957       1.448669       2.638872       3.114306       2.410975      0.7667037      -1.348096      -3.076017      -3.372460      -2.123710     -0.9525445     -7.6393344E-02  0.5460796       1.460133       2.658854       3.138366       2.420532      0.7546321      -1.364318      -3.088346      -3.391149      -2.130067     -0.9514883     -7.6724812E-02  0.5459623       1.471596       2.678835       3.162424       2.430090      0.7425606      -1.380541      -3.100676      -3.409836      -2.136422     -0.9504288     -7.7051133E-02  0.5458546       1.483073       2.698837       3.186512       2.439687      0.7305394      -1.396702      -3.112931      -3.428438      -2.142681     -0.9492642    
+   315.5519       315.6444       315.7370       315.8309       315.9249       316.0178       316.1107       316.2020       316.2933       316.3990       316.5046       316.6163       316.7279       316.8079       316.8878       316.9311       316.9743       317.0090       317.0437       317.0798       317.1160       317.1457       317.1753       317.2173       317.2592       317.3336       317.4079       317.5032       317.5985       317.6932       317.7880       317.8778       317.9677       318.0505       318.1334       318.2101       318.2868       318.3582       318.4297       318.4905       318.5515       318.6045       318.6576       318.7044       318.7512       318.7997       318.8482       318.8934       318.9387       318.9714       319.0042       319.0360       319.0678       319.1112       319.1547       319.2017       319.2487       319.2848       319.3208       319.3572       319.3935       319.4408       319.4881       319.5362       319.5844       319.6243       319.6643       319.7062       319.7481       319.8018       319.8554       319.9161       319.9768       320.0472       320.1175       320.1960       320.2744       320.3428       320.4112       320.4777       320.5442       320.6194       320.6946       320.7675       320.8404       320.8941       320.9478       321.0001       321.0525       321.1218       321.1912       321.2603       321.3293       321.3860       321.4426       321.4910       321.5395       321.5891       321.6387       321.6929       321.7472       321.8074       321.8677       321.9326       321.9974       322.0666       322.1357       322.2221       322.3085       322.3978       322.4871       322.5602       322.6334       322.7142       322.7951       322.9083       323.0215       323.1505       323.2796       323.4066       323.5336       323.6655       323.7974       323.9248       324.0522       324.1571       324.2621       324.3597       324.4574       324.5563       324.6551       324.7526       324.8501       324.9600       325.0699       325.1974       325.3250       325.4465       325.5681       325.6663       325.7645       325.8489       325.9333       326.0171       326.1010       326.1757       326.2505       326.3240       326.3975       326.4841       326.5707       326.6689       326.7671       326.8619       326.9567       327.0334       327.1101       327.1916       327.2731       327.3853       327.4976       327.6297       327.7618       327.9146       328.0674       328.2484       328.4293       328.6387       328.8480       329.0606       329.2731       329.4512       329.6294       329.7654       329.9015       329.9944       330.0872       330.1566       330.2260       330.2656       330.3052       330.3234       330.3416       330.3688       330.3960       330.4333       330.4705       330.4956       330.5207       330.5406       330.5605       330.5999       330.6394       330.6982       330.7570       330.8309       330.9047       330.9972       331.0897       331.2050       331.3204       331.4307       331.5411       331.6268       331.7126       331.7816       331.8506       331.9108       331.9710       332.0377       332.1044       332.1886       332.2728       332.3846       332.4964       332.6316       332.7668       332.9182       333.0696       333.2294       333.3892       333.5459       333.7026       333.8486       333.9946       334.1266       334.2587       334.3876       334.5166       334.6480       334.7794       334.9027       335.0260       335.1393       335.2527       335.3613       335.4700       335.5737       335.6774       335.7795       335.8816       335.9893       336.0971       336.2180       336.3389       336.4763       336.6138       336.7694       336.9250       337.0909       337.2568       337.4205       337.5841       337.7405       337.8969       338.0427       338.1884       338.3105       338.4326       338.5441       338.6555       338.7655       338.8755       338.9668       339.0580       339.1279       339.1978       339.2682       339.3386       339.4240       339.5094       339.5996       339.6898       339.7864       339.8830       339.9971       340.1111       340.2360       340.3608       340.4738       340.5868       340.6892       340.7917       340.9008       341.0099       341.1549       341.2999       341.4833       341.6667       341.8679       342.0690       342.2645       342.4600       342.6507       342.8414       343.0210       343.2006       343.3539       343.5072       343.6369       343.7666       343.8864       344.0062       344.1151       344.2241       344.3238       344.4236       344.5265       344.6294       344.7352       344.8410       344.9409       345.0409       345.1429       345.2449       345.3532       345.4615       345.5617       345.6619       345.7472       345.8325       345.9183       346.0041       346.1007       346.1973       346.2995       346.4017       346.5121       346.6226       346.7441       346.8656       346.9885       347.1115       347.2327       347.3539       347.4835       347.6131       347.7646       347.9162       348.1116       348.3071       348.4999       348.6928       348.8899       349.0870       349.2884       349.4897       349.7021    
+  0.9473456      0.8820528      0.9981718      0.9523941      0.8169235      0.9968721      0.7275636      0.9908377      0.6374046      0.9900793      0.5952753      0.9727222      0.9657797      0.8412194      0.8863041      0.9650735      0.7412772      0.5911558      0.7918944      0.9976359      0.9126042      0.9287147      0.8981016      0.9992640      0.8516618      0.9641449      0.9999655      0.9084932      0.8229079      0.9775841      0.9999740      0.8893542      0.9814858      0.6921397      0.9997987      0.9893009      0.9868131      0.9194017      0.8840622      0.9997586      0.9944118      0.9979475      0.8869542      0.9995601      0.5853120      0.8529151      0.9910294      0.9921290      0.9993278      0.8233213      0.9964389      0.8739912      0.5036717      0.8577449      0.8799009      0.9003027      0.9457330      0.9885447      0.8570249      0.9877417      0.8345523      0.8603712      0.8764476      0.8674909      0.9248952      0.9995702      0.9426413      0.9972472      0.8482621      0.7178012      0.9944118      0.9972574      0.9405500      0.9139733      0.9851364      0.9969788      0.4954960      0.8312120      0.8113978      0.9723752      0.5457299      0.9453593      0.2643782      0.7797844      0.6239225      0.9947231      0.9904200      0.9260687      0.9922562      0.9681790      0.9866477      0.9993476      0.8408600      0.1812998      0.9994192      0.9156029      0.2818184      0.9746988      0.9856681      0.9676514      0.9889814      0.7985213      0.5947735      0.9931651      0.9261450      0.9992403      0.8309539      0.5941209      0.9845950      0.9931651      0.9551575      0.8795514      0.9389349      0.9398142      0.9144093      0.9944832      0.9138095      0.8916704      0.6464453      0.9860324      0.9495300      0.9990164      0.8044351      0.9871626      0.9498475      0.9004778      0.8719712      0.9955013      0.8243347      0.9442974      0.7816713      0.9952399      0.9405271      0.9865257      0.8954014      0.8391304      0.7213080      0.8975996      0.9288895      0.9381664      0.8617947      0.6964918      0.9709492      0.9894392      0.9655861      0.9818738      0.7010069      0.1039263      0.9831502      0.9979994      0.9821939      0.9348792      0.8464258      0.9887996      0.8859938      0.8913366      0.9858394      0.9611016      0.3264723      0.9174322      0.9840199      0.2168292      0.5075723      0.8040431      0.9408705      0.8893237      0.9207462      0.9894688      0.9976125      0.9792520      0.9570797      0.9320744      0.9494027      0.9463241      0.8543022      0.3240814      0.5827369      0.7932186      0.9575490      0.5153625      7.5613648E-02  0.9968399      0.9972875      0.9896256      0.9998081      0.7909694      0.9995499      0.8123233      0.9996711      0.9008568      0.9924324      0.9765879      0.9759859      0.8392387      0.5412561      0.6502172      0.9204307      0.8854656      0.9938530      0.9838016      0.8638172      0.9807110      0.9956102      0.9980421      0.9998107      0.9649314      0.9413726      0.9854034      0.9891018      0.9846898      0.9838746      0.9782504      0.9896938      0.7482746      0.8501588      0.9267029      0.9640011      0.8578818      0.9719143      0.9755108      0.9730045      0.9828760      0.9745318      0.8800598      0.8233213      0.9392827      0.9522703      0.9719781      0.8818638      0.9571581      0.9319032      0.9987569      0.7301404      0.9874538      0.9430911      0.8306218      0.9959595      0.9763831      0.9998436      0.9944333      0.9808433      0.9747442      0.9586537      0.8875102      0.8213251      0.9816285      0.9945189      0.9021925      0.8195850      0.9273343      0.9694217      0.9929974      0.7616304      0.9767481      0.3199174      0.9965921      0.9998900      0.8672252      0.9997818      0.9995781      0.9983168      0.9902315      0.9846542      0.8739912      0.9251511      0.6491545      0.7521552      0.9149528      0.8217025      0.9999934      0.7942597      0.6791515      0.5116771      0.9076493      0.9983443      0.9999844      0.9324158      0.8247468      0.6679452      0.9943252      0.9998839      0.9321719      0.9530309      0.9806179      0.8923972      0.9451830      0.9915662      0.9311679      0.8502639      0.9944261      0.5542958      0.9975463      0.8896603      0.8676236      0.7327968      0.1887221      0.8266525      0.9999914      0.8732761      0.9370639      0.9911562      0.9603313      0.9317075      0.8358660      0.9948754      0.9995601      0.9256614      0.9997001      0.3365756      0.9271325      0.9972321      0.9962590      0.9649491      0.9452492      0.4000554      0.9789069      0.9881831      0.9834098      0.9445416      0.8983963      0.9580159      0.9970051      0.9750311      0.9486145      0.9663744      0.9714338      0.8667263      0.9904200      0.9929007      0.9858394      0.9784330      0.8917311      0.5354862      0.9942672      0.9918803      0.9998053      0.9436064      0.8876644      0.8348811      0.8652251      0.9573147      0.9585381      0.7653055      0.9986812      0.8698055      0.7505626      0.9830258      0.9803512    

Added: trunk/Lib/sandbox/pyloess/tests/test_pyloess.py
===================================================================
--- trunk/Lib/sandbox/pyloess/tests/test_pyloess.py	2007-03-12 19:46:06 UTC (rev 2843)
+++ trunk/Lib/sandbox/pyloess/tests/test_pyloess.py	2007-03-12 19:47:15 UTC (rev 2844)
@@ -0,0 +1,131 @@
+"""
+Wrapper to lowess and stl routines.
+
+:author: Pierre GF Gerard-Marchant
+:contact: pierregm_at_uga_edu
+:date: $Date: 2007-02-28 02:23:25 -0500 (Wed, 28 Feb 2007) $
+:version: $Id: generic.py 145 2007-02-28 07:23:25Z backtopop $
+"""
+__author__ = "Pierre GF Gerard-Marchant ($Author: backtopop $)"
+__version__ = '1.0'
+__revision__ = "$Revision: 145 $"
+__date__     = '$Date: 2007-02-28 02:23:25 -0500 (Wed, 28 Feb 2007) $'
+
+import os
+
+import numpy
+from numpy import bool_, complex_, float_, int_, str_, object_
+import numpy.core.numeric as numeric
+from numpy.core.records import recarray
+
+from numpy.testing import NumpyTest, NumpyTestCase
+from numpy.testing.utils import build_err_msg, \
+        assert_equal, assert_almost_equal
+
+import pyloess
+reload(pyloess)
+from pyloess import lowess, stl
+
+
+def get_co2data():
+    "Reads CO2 data."
+    filename = os.path.join('tests','co2_data')
+    F = open(filename, 'r')
+    data = []
+    for line in F.readlines():
+        data.append([float(x) for x in line.rstrip().split()])
+    return numpy.concatenate(data)
+
+def get_co2results():
+    "Gets theoretical results of smoothed CO2."
+    filename = os.path.join('tests','co2_results_double')
+    F = open(filename, 'r')
+    result = []
+    for line in F.readlines():
+        result.append(numpy.fromiter((float(x) for x in line.rstrip().split()),
+                                     float_))
+    return result
+
+def set_parameters():
+    "Returns the parameters of the STL on CO2 data."
+    parameters = dict(np=12, ns=35, nt=19, nl=13, no=2, ni=1,
+                      nsjump=4, ntjump=2, nljump=2,
+                      isdeg=1, itdeg=1, ildeg=1)
+    return parameters
+########################################################################
+class test_lowess(NumpyTestCase):
+    "Test class for lowess."
+    #
+    def __init__(self, *args, **kwds):
+        NumpyTestCase.__init__(self, *args, **kwds)
+        X = [ 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8,10,12,14,50]
+        Y = [18, 2,15, 6,10, 4,16,11, 7, 3,14,17,20,12, 9,13, 1, 8, 5,19]
+        self.data = (X, Y)
+    #
+    def test_lowess_1(self):
+        "Tests lowess on typical data. part #1."
+        (X, Y) = self.data
+        YS = [13.659,11.145, 8.701, 9.722,10.000,11.300,11.300,11.300,
+              11.300,11.300,11.300,11.300,11.300,11.300,11.300,13.000, 
+              6.440, 5.596,  5.456,18.998]
+        Z = lowess(X, Y, f=0.25, nsteps=0, delta=0)
+        assert_almost_equal(Z.smooth, YS, decimal=3)
+        assert_almost_equal(Z.residuals+Z.smooth, Y, decimal=3)
+    #
+    def test_lowess_2(self):
+        "Tests lowess on typical data. part #2."
+        (X, Y) = self.data
+        YS = [13.659,12.347,11.034, 9.722,10.511,11.300,11.300,11.300,
+              11.300,11.300,11.300,11.300,11.300,11.300,11.300,13.000, 
+               6.440, 5.596, 5.456,18.998]
+        Z = lowess(X, Y, f=0.25, nsteps=0, delta=3)
+        assert_almost_equal(Z.smooth, YS, decimal=3)
+        assert_almost_equal(Z.residuals+Z.smooth, Y, decimal=3)        
+    #
+    def test_lowess_3(self):
+        "Tests lowess on typical data. part #3."
+        (X, Y) = self.data
+        YS = [14.811,12.115, 8.984, 9.676,10.000,11.346,11.346,11.346,
+              11.346,11.346,11.346,11.346,11.346,11.346,11.346,13.000, 
+               6.734, 5.744, 5.415,18.998 ]
+        Z = lowess(X, Y, f=0.25, nsteps=2, delta=0)
+        assert_almost_equal(Z.smooth, YS, decimal=3)
+        assert_almost_equal(Z.residuals+Z.smooth, Y, decimal=3)        
+
+#-----------------------------------------------------------------------
+class test_stl(NumpyTestCase):
+    "Tests STL."
+    #
+    def __init__(self, *args, **kwds):
+        NumpyTestCase.__init__(self, *args, **kwds)
+        co2_data = get_co2data()
+        co2_results = get_co2results()
+        parameters = set_parameters()
+        self.d = (co2_data, co2_results, parameters)
+    #
+    def test_stl_1(self):
+        "Tests a classic STL."
+        (co2_data, co2_results, parameters) = self.d
+        co2_fitted = stl(co2_data, robust=False, **parameters)
+        assert_almost_equal(co2_fitted.seasonal, co2_results[0], 6)
+        assert_almost_equal(co2_fitted.trend, co2_results[1], 6)
+        assert_almost_equal(co2_fitted.weights, co2_results[2], 6)
+    #
+    def test_stl_2(self):
+        "Tests a robust STL."
+        (co2_data, co2_results, parameters) = self.d
+        co2_fitted = stl(co2_data, robust=True, **parameters)
+        assert_almost_equal(co2_fitted.seasonal, co2_results[4], 6)
+        assert_almost_equal(co2_fitted.trend, co2_results[5], 6)
+        assert_almost_equal(co2_fitted.weights, co2_results[6], 6)
+        
+########################################################################
+if __name__ == '__main__':
+    NumpyTest().run()       
+    #
+    co2_data = get_co2data()
+    co2_results = get_co2results()
+    parameters = set_parameters()
+    co2_fitted = stl(co2_data, robust=False, **parameters)
+    
+



More information about the Scipy-svn mailing list