Comments (8)
You can already reuse an expression and evaluate it when needed, however named variables are not supported:
xt::array<double> x, y;
auto exp_res1 = x + y + 3; // exp_res1 type is xfunction<....>, not evaluated
auto exp_res2 = exp_res1 / 2; // exp_res2 type is xfunction<...>, not evaluated
// init x and y
x = arr1;
y = arr2;
// Forces evaluation of exp_res1 in res1. exp_res1 remains unchanged.
xt::xarray<double> res1 = exp_res1;
// changes y
y = arr3;
// Forces evaluation of exp_res1 (with new y) in res2. exp_res1 remains unchanged.
xt::xarray<double> res2 = exp_res1;
// Forces evaluation of exp_res1 (with new y) in res2. exp_res1 remains unchanged.
xt::xarray<double> res3 = exp_res2;
from xtensor.
What happens when x, y is not in scope?
from xtensor.
xfunction
doesn't provide any way to retrieve its arguments, so you have to store references to x and y somewhere, that you can reach from the code that modifies them. I guess it can be problematic if you have sophisticated expressions with dozens of variables.
@SylvainCorlay any thought on implementing named variables ?
from xtensor.
Also something like
xt::xarray<double> res = xt::xfunction("x + y + 3").setp("x", arr1).setp("y", arr2).eval()
res = xt::xfunction("f(x, y) = x + y + 3").setp("x", arr1).setp("y", arr2).eval()
res = xt::xfunction("f(x, y) = x + y + 3").setp(0, arr1).setp(1, arr2).eval()
res = xt::xfunction("f(x, y) = g(x) + h(y) + 3").setf("g", f1).setf("h", f2).setp("x", arr1).setp("y", arr2).eval()
Also have some predefined standard functions
xt::sin, xt::ln, xt::reg, .....
from xtensor.
You're not supposed to call xfunction
constructor by yourself.
So this code:
xt::array<double> res = xt:xfunction("x + y + 3")
should definitely be replaced by:
xt::array<double> res = x + y + 3;
or
auto exp_res = x + y + 3;
if you want to keep the expression for a deferred evaluation.
Besides, building xfunction
based on string expression is not supported. And won't. Never. This library is a computation library, not a parser library. If you need such a feature, feel free to implement it as an aside project, but xtensor
is not the right place where to do it.
Almost all the standard mathematical functions defined in the C++ standard library have their counterpart in xtensor
. Check the xmath.hpp
header and the doc. If you need one that is missing, please open another issue dedicated to this, so we don't mix up unrelated features.
from xtensor.
As mentioned before, what if I do not have x and y when I set up the expression.
from xtensor.
That's the same problem as the first one. The solution is to provide a way to retrieve the arguments of an xfunction
(either with indexed or named getters), not a constructor that parses a string.
from xtensor.
Thanks for this @sirinath I am closing this since it is out of scope at the moment.
from xtensor.
Related Issues (20)
- [Performance] Improve xfunction evaluation in xviews HOT 2
- [Documentation] Convolve and possibly other functions omitted from documentation HOT 1
- [CI] Multiple failures in CI on Clang 16.0.6 MSVC HOT 8
- Implement element preserving `resize` in 1d HOT 9
- assigning a view values from another view HOT 2
- row major xtensor assignment is so slow HOT 2
- Questions on migration from numpy to xtensor. HOT 10
- argmax( x, 0) on a single dimension array returns the wrong index HOT 4
- Missing `ravel_multi_index`
- [Bug] Error when using vstack with mixed shape type HOT 1
- Can't find functions finding the maximum and minimum values and indices of the entire matrix HOT 3
- Adding `xt::reshape` like `reshape` intrinsic in Fortran HOT 11
- View sizes mismatch when assigning view to another view HOT 5
- `xt::real(...)` crashes the program when printed to `cout` HOT 1
- [C++20] Module and Concepts HOT 2
- update for xsimd 12 HOT 2
- arm64 build timing out on test_xblockwise_reducer.cpp HOT 1
- [Performance] Sub-optimal performance on means of strided axes
- Linear algebra operators HOT 1
- Buggy behaviour of non-contiguous xadaptor and scalar assignment
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 xtensor.