Blame multifit/work.c

Packit 67cb25
/* multifit/work.c
Packit 67cb25
 * 
Packit 67cb25
 * Copyright (C) 2000, 2007, 2009 Brian Gough
Packit 67cb25
 * 
Packit 67cb25
 * This program is free software; you can redistribute it and/or modify
Packit 67cb25
 * it under the terms of the GNU General Public License as published by
Packit 67cb25
 * the Free Software Foundation; either version 3 of the License, or (at
Packit 67cb25
 * your option) any later version.
Packit 67cb25
 * 
Packit 67cb25
 * This program is distributed in the hope that it will be useful, but
Packit 67cb25
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 67cb25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 67cb25
 * General Public License for more details.
Packit 67cb25
 * 
Packit 67cb25
 * You should have received a copy of the GNU General Public License
Packit 67cb25
 * along with this program; if not, write to the Free Software
Packit 67cb25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
#include <config.h>
Packit 67cb25
#include <gsl/gsl_errno.h>
Packit 67cb25
#include <gsl/gsl_multifit.h>
Packit 67cb25
Packit 67cb25
gsl_multifit_linear_workspace *
Packit 67cb25
gsl_multifit_linear_alloc (const size_t nmax, const size_t pmax)
Packit 67cb25
{
Packit 67cb25
  gsl_multifit_linear_workspace *w;
Packit 67cb25
Packit 67cb25
  w = calloc (1, sizeof (gsl_multifit_linear_workspace));
Packit 67cb25
Packit 67cb25
  if (w == 0)
Packit 67cb25
    {
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for multifit_linear struct",
Packit 67cb25
                     GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->nmax = nmax;                     /* max number of observations */
Packit 67cb25
  w->pmax = pmax;                     /* max number of parameters */
Packit 67cb25
  w->n = 0;
Packit 67cb25
  w->p = 0;
Packit 67cb25
  w->rcond = 0.0;
Packit 67cb25
Packit 67cb25
  w->A = gsl_matrix_alloc (nmax, pmax);
Packit 67cb25
Packit 67cb25
  if (w->A == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for A", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->Q = gsl_matrix_alloc (pmax, pmax);
Packit 67cb25
Packit 67cb25
  if (w->Q == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for Q", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->QSI = gsl_matrix_alloc (pmax, pmax);
Packit 67cb25
Packit 67cb25
  if (w->QSI == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for QSI", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->S = gsl_vector_alloc (pmax);
Packit 67cb25
Packit 67cb25
  if (w->S == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for S", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->t = gsl_vector_alloc (nmax);
Packit 67cb25
Packit 67cb25
  if (w->t == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for t", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->xt = gsl_vector_calloc (pmax);
Packit 67cb25
Packit 67cb25
  if (w->xt == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for xt", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  w->D = gsl_vector_calloc (pmax);
Packit 67cb25
Packit 67cb25
  if (w->D == 0)
Packit 67cb25
    {
Packit 67cb25
      gsl_multifit_linear_free(w);
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for D", GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  return w;
Packit 67cb25
}
Packit 67cb25
Packit 67cb25
void
Packit 67cb25
gsl_multifit_linear_free (gsl_multifit_linear_workspace * w)
Packit 67cb25
{
Packit 67cb25
  RETURN_IF_NULL (w);
Packit 67cb25
Packit 67cb25
  if (w->A)
Packit 67cb25
    gsl_matrix_free (w->A);
Packit 67cb25
Packit 67cb25
  if (w->Q)
Packit 67cb25
    gsl_matrix_free (w->Q);
Packit 67cb25
Packit 67cb25
  if (w->QSI)
Packit 67cb25
    gsl_matrix_free (w->QSI);
Packit 67cb25
Packit 67cb25
  if (w->S)
Packit 67cb25
    gsl_vector_free (w->S);
Packit 67cb25
Packit 67cb25
  if (w->t)
Packit 67cb25
    gsl_vector_free (w->t);
Packit 67cb25
Packit 67cb25
  if (w->xt)
Packit 67cb25
    gsl_vector_free (w->xt);
Packit 67cb25
Packit 67cb25
  if (w->D)
Packit 67cb25
    gsl_vector_free (w->D);
Packit 67cb25
Packit 67cb25
  free (w);
Packit 67cb25
}
Packit 67cb25