sivaramambikasaran/HODLR_Solver — pull request #2 by dfm (2014-01-31 20:31:51+00:00)
Title: Moving to object oriented structure for matrix definition

This pull request looks *horrifying* if you look at the diff but I actually didn't change very much and I'm getting exactly the same performance!

The original implementation of the `get_Matrix_Element` wasn't quite flexible enough for my purposes so I took a pass at implementing a version using a template class for the kernel. I'd love to hear what you think of this!

The basic idea is that you no longer implement a `get_Matrix_Element` function. Instead, you subclass the `HODLR_Kernel` object and overload the `get_Matrix_Entry` method as follows:

```
#include
#include "HODLR_Kernel.hpp"

using Eigen::VectorXd;

class My_Kernel : public HODLR_Kernel {

public:
My_Kernel (VectorXd times) : times_(times) {};
double get_Matrix_Entry(const unsigned i, const unsigned j) {
double d = times_[i] - times[j];
return exp(-d*d);
};

private:
vector times_;

};
```

Then the creation of the `HODLR_Tree` object becomes:

```
My_Kernel kernel(times);
HODLR_Tree * A = new HODLR_Tree(&kernel, N, nLeaf);
```

Everything else stays the same.

Let me know what you think!