# Good C, C++ library for efficient grid search / tuples, ideally with bindings to Eigen

I have a $$q$$-dimensional grid, known at run, not compile-time, that has $$50$$ points in each direction and hence $$50^3$$ combinations that I would like to first build and then call a function with each point as its single argument, to store the output in a data structure that has a pointer to the argument.

Is there a good way to implement this in C++ by using perhaps a library that is optimised to handle such tasks? Ideally with good bindings to Eigen but I can hack that together myself if need be. More formally:

My problem is now to populate the vector of grid points with each lambda ranging from $$0.95$$ to $$1$$ in steps of $$0.001$$ so that I have a model of the Cartesian coordinate system $$[0.95,1] \times [0.95,1] \times[0.95,1] \in \mathbb{R}^{3}$$.

My first attempt at a solution would be this:

class grid_point{
grid_point(int q){

lambda = VectorXf::Zeros(q);
}

private:
VectorXd lambda;
float likelihood;
}


And then instantiate vector<grid_point> my_grid(num_steps); where num_steps = pow(50,3). I suppose this question here is similar but it implements a bunch of nested for loops. I am wondering if there are packages that implement this natively possibly as part of the STL or in some custom package that people on this site are using. Performing grid search must be a well-trodden path in many disciplines.

I may be able to use the library <algorithm> but to me this feels like I am reinventing the wheel as I am sure there must be more efficient ways to

1. generate all tuples that span my model of $$\mathbb{R} ^{3}$$
2. and then call a function with a single parameter on it to write its output into grid_point.

Many thanks, All!

Seems like this question is not getting much interest. But here is an update on what can be done:

My current sense is to build it from scratch as above and somehow try to find use of this methodology here enter link description here.

• What does "traverse" mean in your context? Is all you want to do "read each element once"? – Wolfgang Bangerth Apr 17 '19 at 22:01
• Hi @WolfgangBangerth thank you for your interest! I have clarified your question in my edited version. Please let me know if there are more ways to make it clearer! – Hirek Apr 18 '19 at 11:24
• You have less than a million point, which makes your problem quite small. You don’t need a package, certainly not an optimized one, you can just do it yourself. – Kirill Apr 19 '19 at 18:09