Matrix and Vector in nr


windmaomao
02-13-2003, 03:20 PM
actually i don't see any good using matrix and vector in nr. Instead in my opinion, they should use a wrapper matrix/vector class internally and leave the calling procedure like this

void Spline(int n, DP * input, DP * output)
{
whatever internal vector you want to wrap on the input or output data;
TNT a(input); // just an example
a[1]
}

This gives the user a lot flexiablility and i don't see lot penety here.

For example, i have a data set *x[12], if i want to call nr, i have to first use TNT to wrap it, then use nr vector to wrap it. Or i can just copy the data to nr vector which i don't want to do at any circumstance. And i don't know why nr vector is not designed as a wrapper. ( The way they're doing is neither fortran style or c++ style, very complicated)

OOP or generic code is good, but it has to be flexible; At least i don't feel STL vector is flexible enough for scientific computing. Vector, a math word, what's the point if it can't be used for math stuff in general.

windmaomao
02-14-2003, 04:02 PM
one of the solutions to my previous probelm is:
add two functions to nr vector

class NRVec {
public:
NRVec();
~NRVec();
void attach(T* const a, int n)
{
if (v != 0) delete[] (v);
nn=n; v=a;
}
void detach() { v=0; nn=0; }
// Detach has to be called before the memory it attached to releases.
}

e.g

vector<double> a(3);
NRVec b;
b.attach(a.begin(),3);
nr_func(b);
b.detach();

Please let me know if someone has better solutions. The above one is very dangrous since NRVec don't use reference counting.