-
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
Data frame: Typed frame vs. type erasure in practice? #214
Comments
Just to add another complication into the mix: For handling physical units, something like |
1. Variant vs type-erasure It depends on the level of genericity / type control you want to give to your API; the function can accept a very generic type, a frame type (in that case it has to be templated), or be enabled depending on some requirement on its generic template parameter: template <class F>
auto do_something(const F& frame);
template <class... Ts>
auto do_something(const xframe<Ts...>& frame);
template <class F, XTL_REQUIRES(is_xframe_expression<F>)>
auto do_something(const F& frame); The combinatoric explosion of the number of types is the drawback of the variant. That's why the code for dynamic variables have not been removed, and I think that at some point I see variant and type erasure as complementary approaches rather than competitors. The first one gives you more static checking and performances, the second one more flexibility. This first one is easier and faster to implement though, since it does not require the implementation of a dynamic expression system. 2. Python Interface I'm afraid that we don't have the choice here. So the idea is to limit the number of type we expose (only frames on variable containers, not expressions, with a limited number of scalar types). Dynamic variables can also be of help here, although we probably don't want to completely erase the scalar types of the data. A dynamic expression system would allow to expose arithmetic operators and so on, and keep the lazy evaluation; without such a system, we need to expose operators that evaluate and return their result. 3. Compatibility between frame objects I agree that xframes involved in an operation could have different types, however in practice you will align the frames before the operations (for performance considerations), so there should not be a lot of different frmae types (the difference should be on the scalar types embedded in the different frames). All expressions in template <class FT1, class FT2, XTL_REQUIRES(is_frame_expression<FT1>, is_frame_expression<FT2>)>
inline auto my_operation(const FT1& frame1, const FT2& frame2)
{
} Regarding 4. Intuitive API The Regarding the addition / removal of a variable to / from an already existing frame, I think it's totally possible to provide an intuitive API for a C++14 user: auto new_frame = existing_frame.add("name", var); Whether variables are moved from one frame to the other, making I think we won't be able to totally mimic a Python API on the C++ side (except for the frame with dynamic variables), however if we restrict the number of types exposed to the Python, building such an API on top of the more generic one should be quite straightforward. |
I am looking at #174 with regards to the suggested typed-frame. I am assuming this would essentially be something like
I think I really like the idea of having a
std::variant
here. In combination withstd::visit
implementing algorithms for this looks very convenient. 👍I have a couple of concerns however, which may be rooted in my lack of understanding of what you are proposing, i.e., do not see this as a criticism of the approach per se:
Does every custom algorithm or function that takes and
xframe
as an argument have to be templated onTs...
?double
orint64_t
, i.e., we have a combinatoric explosion of the number ofxframe
types.xframe
?Considering a Python interface:
How is compatibility between two
xframe
objects handled? We need to support, e.g.,xframe::operator+=(const xframe &other)
.other
that actually has a different content that*this
(within certain limits). For example,*this
might contain some additional variables or coordinates that are not present inother
. If the remaining coordinates and variable names match, an operation is still possible and should be supported.template <class F1, class F2> void myAlg;
)?Again, I am also concerned about the number of instantiations. I assume it could quickly reach hundreds or even thousands in practice when supporting two input frames (at least when doing explicit instantiations such that
xframe
is usable from Python)? Supporting three or more input frames seems totally impossible, unless maybe we just have a singlexframe
type for a variant with all possible supported types (not sure this would still be possible with expressions then, since adding a set of expressions to the list of supported types seems unrealistic?)?Is it possible to provide an intuitive API for the frame type, given that adding/removing variables may change the type?
operator|
, which is very different from Python where we would have something likeframe["data1"] = variable
--- is such an asymmetry between C++ and Python a problem?The text was updated successfully, but these errors were encountered: