-
Notifications
You must be signed in to change notification settings - Fork 57
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
Overload operators #143
Overload operators #143
Conversation
Why separate domain.hpp into .hpp and .cpp? |
I assumed it was necessary because otherwise the Translate class wouldn’t be declared before DomainBase tries to use it, but perhaps that’s an incorrect assumption? |
It works in |
I assumed you'll just have to add stuff to |
I have no idea - I just assumed I needed to split it so started with that. I’ll quickly try fresh with just the extra bit, but after that I need to get some sleep so will have to come back to this later |
Nope, unfortunately errors out with (All I tried here was just adding the add method to |
I don't know what code you're running exactly but I can say it works in |
I've added virtual
Translate
__add__(
const std::shared_ptr<const pygalmesh::DomainBase> & domain,
const std::array<double, 3> & direction
) const
{
return Translate(domain, direction);
} to the |
I think it should be |
Very possible - I'm thinking in Python land since that's what I'm most familiar with, but it's possible it has to be the C++ operator overloading functions instead, likely worth looking into/trying both to see what works.
Interesting idea. If I'm understanding you correctly that would basically make the operations on a I'm unsure how the current method-stacking logic would be applied from an instance method though. Can a C++ instance method dynamically wrap another instance method? I suppose that has to be possible somehow, although I'm not sure how it'd be done. The Python equivalent would be def translate(self, direction):
old_eval = self.eval
def eval_wrapper(point):
d = point - direction # assuming numpy array
return old_eval(d)
self.eval = eval_wrapper
... # similar for translate_features and get_bounding_sphere_squared_radius but that's reliant on functions being first-class objects that you can just move around and reassign at will. I'll have to have a play over the weekend, and maybe look into C++ a bit more if I've got the time. I feel like this is a decent learning experience, and useful functionality to have, just takes time... Unfortunately I'm wanting to use this in a project, so not finishing/implementing it asap means inevitable reworking for my own project later on, but I'll have to see how it goes. |
I suppose it's always possible to create a specific eval method for each operation (and similarly for the other relevant methods), and manually create a function stack and object stack for the wrappers and the objects they need, and add to those stacks in the modifier methods (e.g. |
Had the grand idea of creating a subclass of Before I had that realisation I attempted to implement a I looked a bit more into nested functions in C++, which seems to be possible using lambdas, although I believe the 'dynamically wrapping an existing method' side of things might not be possible, so another approach is likely required. I would rather avoid the stack approach if at all possible, because it's complicated to implement and understand. I still feel like this should be achievable with some kind of forward declaration of |
Latest attempt is using On the plus side, compiling isn't complaining about |
Is this still being worked on? |
Hi @nschloe, the project I was initially planning on using this for is on the backburner at the moment, and I'm afraid I've forgotten if I was still planning to use this in it once that project resumes (I'm not sure when that will be). Accordingly, I may still do some work on this in future, but don't know for sure, and don't know when that would be either. I'll close the PR for now - I can always re-open it if I come back to it :-) |
PR to implement #142.
Note: currently only includes an attempt at implementing
__add__
, and doesn't compile becauseerror: non-virtual member function marked 'override' hides virtual member function
for basically all the methods indomain.hpp
I clearly don't know much about what I'm doing here, but the process I went with was:
domain.hpp
domain.cpp
instead, and#include "domain.hpp"
in there__add__
inDomainBase
indomain.hpp
, which returns aTranslate
instance and takes in the same signature as theTranslate
constructordomain.cpp
to perform that python operator overloadDefinitely not in a mergeable state yet, but hopefully a step in the right-ish direction.