Giter VIP home page Giter VIP logo

Comments (5)

stephenberry avatar stephenberry commented on May 24, 2024

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.

stephenberry avatar stephenberry commented on May 24, 2024

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.

prashant-saxena avatar prashant-saxena commented on May 24, 2024

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.

stephenberry avatar stephenberry commented on May 24, 2024

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.

stephenberry avatar stephenberry commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.