Comments (5)
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 config
and state
members in a struct.
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.
}
}
from glaze.
Question 2: If one has to read arrays in nc::NdArray instead of vector, than how do you do it?
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 std::vector
, std::array
, etc. Glaze uses C++20 concepts to determine how types should be parsed without requiring additional dependencies. So, try to read and write from nc::NdArray
and if you run into issues let me know and I can probably add some concepts to support them.
from glaze.
Thanks @stephenberry,
When changing this structure's member length to nc::NdArray
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
D:\projects\glaze\include\glaze\reflection\to_tuple.hpp(82,38): error C3448: the number of identifiers must match the
number of array elements or members in a structured binding declaration
Unfortunately, I can't use glaze right now as 2D arrays are not supported. Let me know your plans for the implementation.
from glaze.
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/ext/eigen.hpp
. And you can always write your own custom serialization/deserialization. Just look in the docs folder for the associated documentation.
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.
from glaze.
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.
from glaze.
Related Issues (20)
- The executable glaze_ide is built but not installed HOT 2
- Add support for unions (like variants) HOT 9
- Document current support and add more support for JSON Merge Patch
- `validate_json` returns `syntax_error` if buffer contains non-ASCII chars HOT 3
- Support 0 and 1 as boolean values HOT 1
- Bazel support HOT 2
- ASIO REPE example bad file descriptor error HOT 2
- minify_json compiler errors when including header directly HOT 5
- Function signatures inconsistency between write_file_json and read_file_json HOT 2
- Stack overflow when returning intermediate object to serialize in_addr HOT 6
- Bug: Malformed JSON string produced HOT 10
- Build and test for 32-bit in Actions
- std::pair arrays roundtrip
- `float` member issue with `clang++-15` and `g++-12` HOT 3
- `json_test.cpp(7840): warning C4267: '=': conversion from 'size_t' to 'uint16_t', possible loss of data` HOT 1
- glz::reader/glz::writer for incremental reading/writing HOT 4
- Partial read for BEVE
- glz::raw without quotes question HOT 1
- Binary serialization of hidden members HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glaze.