Coder Social home page Coder Social logo

Comments (5)

VinGarcia avatar VinGarcia commented on July 20, 2024

The current implementation of memory management on lists is not very efficient =/. I belive the best way to fix this would be to implement a special type of list made for only for integers, floats, etc that internally would count as a single std::vector.

We could create a special type such as "TokenIntList" etc, for these cases. However, I currently don't have time to spare =/.

If you want to submit a PR for this it would be welcome, but it might be a little complicated 🤔 .

from cparse.

zxpatric avatar zxpatric commented on July 20, 2024

Let me see if the naive is acceptable speed wise and how complicated it is to implement TokenIntList. Is there a way that calculator::calculate can cache the equation interpretation so it doesn't have to parse it every time for every tuple? For exmaple, a^2+bc. If there are 3 vectors for a, b, c and each tuple with one element from a, b, c will be called through calculator::calculate("a^2+bc", &vars). My concern is the parsing time of the equation can be long but can also be saved since it needs to be done only once. Any sight on this?

from cparse.

zxpatric avatar zxpatric commented on July 20, 2024

Got it. may dig deep into this function and use rpn for naive iteration.

packToken calculator::calculate(const char* expr, TokenMap vars,
const char* delim, const char** rest) {
// Convert to RPN with Dijkstra's Shunting-yard algorithm.
RAII_TokenQueue_t rpn = calculator::toRPN(expr, vars, delim, rest);

TokenBase* ret = calculator::calculate(rpn, vars);

return packToken(resolve_reference(ret));
}

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

About your first comment: If you compile the expression, i.e. create an instance of the calculator class the parsing is made only on the first time. Then for each consecutive call to eval() it will only execute the code in the context provided by the TokenMap passed as argument and not parse it.

If this was your concern then I might have misunderstood you.

You can see how to do that on the Getting Started page of the Wiki:

The easiest way to do it would be like this:

TokenMap vars;
calculator C("my_var = x / 4 + 3");

vars["x"] = 8;
std::cout << C.eval(vars) << std::endl; // 5

vars["x"] = 16;
std::cout << C.eval(vars) << std::endl; // 7

Is this the issue you needed to fix?, If so you can close this issue.

from cparse.

zxpatric avatar zxpatric commented on July 20, 2024

Thanks VinGarcia. I did went that way. The speed is o...k for large amount although if there are possibilities to support vectorized operation, the best.

from cparse.

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.