I’d like some feedback on an idea for argument validation in the github.com:sakrejda/stan-config
repo. There’s a BUILD
file in the repo with instructions that “should” work with cmake (haven’t had lots of computers to test it). The repo has classes for some arguments and tests.
I was playing around with templates for simplifying argument validation and I was wondering if this might make it manageable to put a mechanism into cmdstan
or stan
for argument validation without adding a lot of code. In general you need a per-arg class like CmdStan currently uses, but you pass some template parameters to identify what the argument should be, so in this line:
class num_samples : stan::config::argument<int, num_samples, integer, positive> {
int
should really be taken from num_samples::from
but I’m having some issues with incomplete types.
num_samples
is for CRTP, integer
and
positive` say the argument will throw on construction if it’s not a positive integer.
So basically the logic is move mostly out of the class. Here’s an example class.
#include <stan/config/argument.hpp>
#include <stan/config/argument_traits.hpp>
namespace stan {
namespace config {
class num_samples : stan::config::argument<int, num_samples, integer, positive> {
public:
num_samples();
num_samples(int arg);
typedef int from;
const static std::string description;
const static int default_value;
};
num_samples::num_samples() : num_samples::num_samples(num_samples::default_value) {}
num_samples::num_samples(int arg) : stan::config::argument<int, num_samples, integer, positive>(arg) {}
const std::string num_samples::description = "Integer (n) describing the number of "
"samples to generate from the posterior density. Includes warmup iterations. ";
const int num_samples::default_value = 1000;
}
}
Would this be worth using to simplify argument validation in CmdStan or more broadly?