Comments (5)
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.
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.
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.
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.
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)
- exception on simple calculatorexample
- Segmentation fault on bad inputs
- terminating with uncaught exception of type syntax_error: Invalid operator: - HOT 4
- Token names cannot have UTF8 characters HOT 4
- Project doesn't install anything HOT 10
- Syntax errors cause crashes HOT 21
- Hexadecimal number computation HOT 4
- calculator ignores variable HOT 3
- Consider adding a namespace to cparse code HOT 6
- Program treats "." in numeric "0.x" as an operator and throw an exception! HOT 5
- Thread Safety HOT 4
- Is not operator supported? HOT 1
- Warning c4099 is everywhere. HOT 3
- Invalid operators, but with ALL operators HOT 1
- It doesn't compile in Windows and Linux, am I doing something wrong? HOT 3
- Buffer-overflow (out-of-bounds read) occured in two positions HOT 1
- cparse/builtin-features/operators.inc HOT 9
- Solved. Errors with Linux emulator using GCC. HOT 22
- TokenMap value change to None,when using getChild() HOT 6
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 cparse.