/*!
 * @file svd.h
 * @brief svd object
 *
 * @date 2003.10.30
 *
 * Copyright 2003 Takashi Suehiro
 */
#include <stdio.h>
// nr/svd
#include <nrutil.h>
#include <nr.h>

#ifndef SVD_H
#define SVD_H
/*!
 * @class SVD
 * @brief class for svd object
 *
 */
class SVD
{
 public:
  //! row = 1..m, m <= m_max,  column = 1..n
  SVD(int m_max, int n);
  ~SVD();
  //! row = 1..m m <= m_max
  int set_m(int m);
  //! 0 <= idx < m_max, converted to (idx + 1)
  //! j[i], i = 0..(n-1 or greater)
  int put_row(int idx, double * jb);
  //! ys[i], i = 0..(m-1 or greater)
  int put_ys(double * ys);
  int put_row_and_y(int idx, double y, double * jb);
  int do_svdcmp();
  int do_round_off(double lim);
  int do_svbksb();
  //! x[i], i = 0..(n-1 or greater)
  int get_sv(double * w);
  int get_result(double * x);

 private:
  //! m_max * m_max NR matrix, input matrix
  double ** anr;
  //! m_max * m_max NR matrix
  double ** unr;
  //! n * n NR matrix
  double ** vnr;
  //! n NR vector
  double * wnr;
  //! n NR vector
  double * xnr;
  //! m NR vector
  double * ynr;
  //! maxmum row
  int mm_max;
  //! current m
  int mm_cur;
  //! column
  int nn;
};

#endif
