/*
Performs a linear regression of the Function; returns the pair
[ a, b]
where f(x) = a*x + b
if the optional arguments _first_ and _last_ are provided, they
represent the indices of the first and last elements.
*/
static VALUE function_reglin(int argc, VALUE *argv, VALUE self)
{
long len = function_sanity_check(self);
const double *x = Dvector_Data_for_Read(get_x_vector(self),NULL);
const double *y = Dvector_Data_for_Read(get_y_vector(self),NULL);
VALUE ret = rb_funcall(cDvector, idNew, 1, INT2NUM(2));
double * dat = Dvector_Data_for_Write(ret, NULL);
long nb;
if(argc == 2) {
long f = NUM2LONG(argv[0]);
long l = NUM2LONG(argv[1]);
if(f < 0)
f = len + f;
if(l < 0)
l = len + l;
x += f;
y += f;
nb = l - f;
}
else if(argc == 0) {
nb = len;
}
else {
rb_raise(rb_eArgError, "reglin should have 0 or 2 parameters");
}
reglin(x,y,nb,dat,dat+1);
return ret;
}