-
Notifications
You must be signed in to change notification settings - Fork 99
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
Need more examples and improved documentation #962
Comments
I agree that more documentation is needed. It is slowly growing and I'll try to make a beginners documentation soon. For the best performance and ease of use, you would just put struct config_t
{
int min{};
int max{};
};
struct coef_t
{
int min{};
int max{};
std::array<float, 20> mean{};
std::vector<float> duration{};
std::vector<int> length{};
// TODO: implement "data"
};
struct state_t
{
coef_t coef{};
};
struct top_level_t
{
config_t config{};
std::map<std::string, state_t> state{};
};
// Now that you have all the structures defined you can read in a file
void some_function()
{
top_level_t top_level{};
std::string buffer{};
auto err = glz::read_file_json(top_level, "model.json", buffer);
if (err) {
std::cerr << glz::format_error(err, buffer) << '\n';
}
else {
// top_level is now populated with all your state information
// top_level.state.at("K") would give you the "K" state
int config_min = top_level.config.min;
// etc.
}
} |
I have not used NumCpp before, but if they follow typical C++ conventions then you should just be able to use their types just like |
Thanks @stephenberry, struct coef_t
{
int min{};
int max{};
std::array<float, 20> mean{};
std::vector<float> duration{};
nc::NdArray<int> length{};
// TODO: implement "data"
}; The error thrown is
Unfortunately, I can't use glaze right now as 2D arrays are not supported. Let me know your plans for the implementation. |
This just means that nc::NdArray cannot be automatically reflected. This is because their class is not aggregate initializable, which it probably should be. When you get reflection issues the next step is to try the glz::meta approach, where you list out the fields explicitly. See the README for more explanation. For multi-dimensional data you need to determine how you want your JSON to be formatted. Glaze has a header for handling the Eigen matrix library you could look at Glaze definitely supports this library, it just depends on whether you need to write a little more code. I can take a look at this next week and add a an extension header for their library if they don't comply with typical interfaces. |
I just realized the eigen code isn't as generic as I thought. I'll work on making that more generic so that other matrix libraries can be easily used with glaze. |
Hello,
From the beginner to intermediate level c/c++ user I'm finding it a bit harder to understand the concept because of fewer examples and no proper documentation. I hope it will be up and running soon. Here is the JSON structure I'm trying to read:
Here is the c++ code
Question 1: How do you get 'config' and 'state' members?
Question 2: If one has to read arrays in nc::NdArray instead of vector, than how do you do it?
Cheers
The text was updated successfully, but these errors were encountered: