#ifndef LINEPATHD1_H
#define LINEPATHD1_H

//#include <cassert>
//#include <iostream>

//using namespace std;

//#include <typeop.h>

/*!
\brief  This is a 1D line in N dimensions.

  The function has been templated as FN.
*/
template< typename FN, typename T > 
class linepathD1
{
public:

  /** Dimension. */
  uintc dim;

  /** The function being minimized. */
  FN fn;
  /** The function state. */
  T * xi;
  /** Line constant. */
  T * x0;
  /** Direction. */
  T * di;

  /** Configure the line later. */
  linepathD1
  (
    uintc dim_, 
    FN fn_
  )
    : dim(dim_), fn(fn_), xi(0), x0(0), di(0)
    {}

  linepathD1
  (
    uintc dim_, 
    FN fn_, 
    X xi_, 
    X x0_, 
    X di_ 
  )
    : dim(dim_), fn(fn_), xi(xi_), x0(x0_), di(di_) 
    {}

  /** Have the function fn owned by the line path. */
  linepathD1
  (
    uintc dim_, 
    X xi_, 
    X x0_, 
    X di_ 
  )
    : dim(dim_), xi(xi_), x0(x0_), di(di_) 
    {}

  /** Set xi by t. */
  void eval(T const t)
  {
    for (uint i=0; i<dim; ++i)
      xi[i] = x0[i]+di[i]*t;
//cout << "***";
//cout << printvecfunc(xi,dim) << endl;
  }
  /** Evaluate the function on the line at t. */
  void eval(T& fval, T const t)
    { eval(t); fn(fval); }

  /** Print the current state. */
  ostream & print(ostream & os) const;

};


//-----------------------------------------------
//  Implementation


template< typename FN, typename T > 
ostream & linepathD1<FN,T>::print(ostream & os) const
{
  os << "dim=" << dim << endl;
  //os << "xi[]=" << printvecfunc(xi,dim) << endl;
  os << "xi[]=" << print(xi,xi+dim) << endl;
  //os << "x0[]=" << printvecfunc(x0,dim) << endl;
  os << "x0[]=" << print(x0,x0+dim) << endl;
  //os << "di[]=" << printvecfunc(di,dim) << endl;
  os << "di[]=" << print(di,di+dim) << endl;

  return os;
}






#endif



