/*
Vnd:  n-dimensional vector class with conjugate gradient Ax=b solver
Author:  Aaron Dwyer, 2003
Note:  This class hasn't been rigorously tested outside of my physics simulations and therefore its correctness is in no way gauranteed.  If anyone does determine it has problems (or doesn't) I'd be glad to hear about it.
*/

#ifndef __VND_H__
#define __VND_H__

struct Vnd;

typedef void(*MatrixTimesVector)(void *userData, Vnd &dest, const Vnd &x);

struct Vnd
{
	Vnd();
	Vnd(int nParam);
	~Vnd();
	void SetSize(int size);
	
	void SetZero();
	
	void SetAll(double s);

	static void Add(Vnd &dest, Vnd &lhs, Vnd &rhs);
	static void AddTo(Vnd &lhs, Vnd &rhs);
	static void AddScaled(Vnd &dest, Vnd &lhs, double s, Vnd &rhs);
	static void AddScaledTo(Vnd &lhs, double s, Vnd &rhs);
	static void Subtract(Vnd &dest, const Vnd &lhs, Vnd &rhs);
	static void Scale(Vnd &dest, double lhs, Vnd &rhs);
	static void Scale(double lhs, Vnd &rhs);
	static double Dot(Vnd &lhs, Vnd &rhs);
	static double DotSelf(Vnd &v);
	static void Copy(Vnd &dest, Vnd &source);

	static void ConjugateGradient(MatrixTimesVector matrixTimesVector, void *userData, Vnd &x, const Vnd &b, int maxIterations, double epsilon);

	int n;
	double *vec;
};

#endif
