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)
- Buggy behaviour of non-contiguous xadaptor and scalar assignment
- saturation arithmetic?
- Tensor View Operations Slower Than Manual Looping
- How can I compile xtensor with gcc-7.5 HOT 5
- Avoiding template explosion on views HOT 4
- Performance issue possibly related to returning C-style adaptor from function HOT 1
- Non-conformant testing of template-template-args c++ standard feature HOT 1
- transpose slower than numpy
- xt::variance crashes HOT 2
- Unexpected value of `xt::get_rank<xt::xtensor_adaptor>`.
- Support for iterating over elements of a specified axis. HOT 2
- Can't check equality of shapes of xtensor_fixed and xscalar
- Output of example in ReadMe file is not matching with the current master HOT 2
- Support of dumping 1D expressions
- *** stack smashing detected ***: terminated
- xtensor::optimize breaks compilation on ARM macOS HOT 2
- Example code from the page "Extending xtensor" gives "incomplete type"? HOT 1
- [CI] GCC 11 Failing on Master HOT 1
- [Question] How can I convert an xtensor xarray into std::vector HOT 8
- Divergence in default rounding of `xt::round()` from `np.round()` HOT 2
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.