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)
- calculate serialize size before serialization and serialize to pre-allocated memory HOT 4
- Option to use partial with char* or char[] HOT 7
- data_must_be_null_terminated issue HOT 7
- Raw char buffer handling HOT 2
- Built-in support for type control HOT 3
- reflection fails with custom serializer for std::chrono types on clang/gcc HOT 7
- How do I write an enum as a raw string? HOT 1
- compile error with error_on_missing_keys HOT 1
- old GCC 11.4.0 compiler support HOT 8
- Link to NDJSON website looks sus... HOT 2
- [ICE] `msvc 17.8` (`glaze 2.8.1`) HOT 1
- Numeric variant deduction type
- Write_binary/read_binary support for the "json_t" interface HOT 6
- is_[json_type] concepts in glz:: namespace
- Compilation error when structure have more than 32 fields HOT 1
- How to pass glz::read_json to a std::function? HOT 1
- Support std::variant<...,std::variant<...> > HOT 2
- repe::registry needs to handle throws on function calls
- Tuple routines not working as expected HOT 1
- Does glaze handle structs with static 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.