-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Vector results #5
Comments
It's an interesting idea. I'll think about it. I'm afraid of blowing up the complexity of the language... I really don't want argument-list-expansion (like python's "*args" and "**kwargs") or vector slicing because I feel like it pushes the language a bit too far beyond its typical use-case. |
I also feel like this kind of capability is already "sort-of supported" because custom functions can do anything. It would be easy to define a custom function "A" that stores vector results in an external storage location and produces NaN (or maybe an ID related to the external storage) as its return value, then custom function "B" would continue to operate on that external location and probably produce the reduction as its return value. It's quite a hack and doesn't compose well, but it might be "good enough". If I see real-life use cases for this, I will probably consider a general implementation, like what you're suggesting. |
@likebike, thanks a lot for your comments and suggestion. Your idea to return ref on vector makes sense. What I'm going to do is to take your lib as a basis and try to implement higher level language and evaluation engine inspired by Excel Formula language and in particular Apache POI but without spreadsheet burden. I have little experience with Rust, though .. it can take a while. |
I added a unit test which performs some vector operations with some custom functions. You might be able to use it as an example: Line 112 in 4b2b034
It might be a bit cryptic. Let me know if you have questions. |
Great, thanks @likebike ! |
Wouldn't the following work? Add a generic param For the |
@arnodb I thought about doing that, but I assumed it wouldn't be adequate, since I do more than those four aritmetic operations. I also do Exponentiation, Modulo, Comparison, Logarithms, Rounding, Trigonometry, Absolute-Value, Sign, etc etc etc. Do you know a way that I could achieve all those results just by adding more trait bounds? I guess I could define new traits for all those extra capabilities, and then implement those new traits for all the advanced number types. I guess I just thought it was more direct to avoid that. |
That gives a broader view of the problem to solve. I confess I integrated First of all, exponentiation, logarithm, trigonometry are functions that take I suppose the modulus falls into the same bucket as the Maybe the first question to ask yourself is at which point do you know the type you are working with. I mean, in simple arithmetic, everything is a function (a trait to implement if you prefer). Like Rust, the point is to check at the very moment you know the Could this check be static is another big design question :-). If you want it to be static then you need to know This comment is too long, hope it gives you ideas. |
If you have some spare time, can you please tell me if you found any part of the transition from meval to fasteval difficult? Are there things you miss that meval does better than fasteval? Have you been able to notice any performance difference from the switch? |
That was awesomely easy. One single commit:
Thanks to a slightly better design, I removed an unnecessary The only thing that puzzled me was the strongly fixed capacity of the slab. I would have expected something like a vector that can grow until there is nothing left to parse. In my case everything is parsed on startup. But I worked around that by exposing different constructors. The only thing is that it could be hard to determine what capacity is necessary. |
I'm happy to see that you were able to migrate such a large project so easily. A few notes:
Right, fasteval achieves most of its performance advantage by pre-allocating all of its stuff, rather than performing many small allocations. That's why the size needs to be known ahead of time. It also helps with safety: https://docs.rs/fasteval/0.2.4/fasteval/#safety ...But I can understand that sometimes this requirement is a hassle and confusing. I'll consider adding a 'GrowableSlab' or something which would behave slower than a pre-allocated slab, but with more intuitive behavior. Thanks so much for your feedback! |
Edit: https://doc.rust-lang.org/std/collections/index.html shows, as expected, O(1) for almost all operations with
Is it that slower to use |
At the moment supported evaluation results is
Result<f64,Error>
, will be enhanced with Advanced Number Types (Complex Numbers, Rational Numbers, Arbitrary Precision Numbers, Big Integers + Crypto), but is it even possible to have something likeResult<Vec<T>,Error>
? I imagine to have custom functions that can perform map or iteration operations over some data not just reduction.The text was updated successfully, but these errors were encountered: