-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use builder pattern to simplify the API #3
Comments
Hi, thanks for this comment. I was actually considering this a while ago but soon gave up, secretly hoping that someone will suggest this and therefore force me to think about it again in detail. So, thanks, I guess ;)
Currently, a solver is implemented like this (very, very simplified): #[derive(ArgminSolver)]
struct MySolver {
variable: f64,
base: ArgminBase,
}
impl MySolver {
pub fn new() -> Self {
MySolver {
variable: 1.0,
base: ArgminBase::new(),
}
}
pub fn set_variable(&mut self, var: f64) {
self.variable = var;
}
}
impl ArgminNextIter for MySolver {
// Not important for the purpose of this example
} The impl ArgminSolver for MySolver {
// Associated types and a bunch of methods
// example method
fn set_max_iters(iters: u64) {
self.base.set_max_iters(iters);
}
} I have difficulty seeing where the builder should come in. If there were a I hope this wasn't too confusing. I'm happy to give my explanations another try if they are incomprehensible ;) Greetings from the south ;) |
This seems indeed very difficult, perhaps yet another option would be to split each solver into a struct which executes the optimization (i.e. the ...
let solver = BacktrackingLineSearch::new(operator, cond)
.set_search_direction(vec![-2.0, 0.0])
.set_rho(0.9)?
...;
let executor = Framework::new()
.with_solver(solver)
.max_iters(1000)
.add_logger(ArgminSlogLogger::term())
.run()?; I don't know which one is more sensible, but for now I have no time because of exam time, perhaps in the middle of march :) |
This is an excellent suggestion, thanks a lot! This would solve many problems, in particular it would remove the ugly Good luck with your exams! :) |
When I implemented the codegen crate I was well aware that I'm doing this mostly for vanity reasons and for my ego, but I thought it was serving at least some purpose. It wasn't. While implementing your suggestion it became clear that the old design made everything much more complicated than necessary. Over the last week I've changed the design completely and simplified other parts along the way. Overall many problems I've had with the previous design vanished with the new design. It is still not entirely done but I think the major parts work. Therefore I've merged it into master. I will continue improving the design and documentation over the next days and I will reimplement the tests for the new design. Thanks once again for your suggestion! If you have time and if you are interested, I'd appreciate it if you would contribute! :) |
Glad I could help :) |
Hey, thanks for creating and maintaining this crate :) I only glanced over the examples, but wondered why you don't use the builder pattern. It could simplify setting up a new solver a bit, otherwise the crate is looking really useful. Greetings from Aachen.
The text was updated successfully, but these errors were encountered: