Skip to content
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

Implement == for cdef class LBNode and LBSlice #4204

Closed
RudolfWeeber opened this issue Apr 6, 2021 · 1 comment · Fixed by #4268
Closed

Implement == for cdef class LBNode and LBSlice #4204

RudolfWeeber opened this issue Apr 6, 2021 · 1 comment · Fixed by #4268

Comments

@RudolfWeeber
Copy link
Contributor

Nodes and slcies shoudl be considered equal, if the index/slice is equal

Otherwise

lb_nodes1 = [some list of lb node objects retrieved by index]
lb_nodes2 = [some list of lb nodes overlapping with lb_nodes1 also retrieved by index]
all_nodes =set(lb_nodes1+lbnodes2)

can have duplicate entries

This would be solved by implementing __eq__().

Particle handles might also be affected.

@jngrad
Copy link
Member

jngrad commented May 25, 2021

Suitable task for @KaiserMartin @stekajack

@kodiakhq kodiakhq bot closed this as completed in #4268 Jun 3, 2021
kodiakhq bot added a commit that referenced this issue Jun 3, 2021
Resolves #4204

Description of changes:

- implemented __eq__() for LBFluidRoutines() . Now logical lbf[index, index, index] == lbf[index, index, index] give expected results.

- modified default __hash__() so that the comparisons are done based on node indices rather than the name attribute. This is done because hash will give different names to pointers so 2 different handles to the same node would be considered not equal. Now they are considered equal so that set(list_of_nodes, also_list_of_nodes) is possible and cannot have duplicate entries now.

- implemented __iter__() for LBSlice class. now given a slice object, one can directly access nodes in any iteration context (using generator functionality for this). Therefore LBSlice object can now be transformed in to for example a list of nodes. This enables smth like set(list(LBSlice), list_of_nodes) to work correctly. 

- However set(LBSice, list_of_nodes) will NOT work!  This is deliberate because LBSlice as implemented, cannot in general be used as a node and as such it made more sense to first ask for an explicit conversion to a iterable_of_nodes before doing logical comparisons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants