mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
Added in a mixin module with an Equality class for mixin use
This commit is contained in:
parent
8f760afa70
commit
f886d2849e
1 changed files with 24 additions and 0 deletions
24
openmc/mixin.py
Normal file
24
openmc/mixin.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import numpy as np
|
||||
|
||||
|
||||
class Equality(object):
|
||||
"""A Class which provides generic __eq__ and __ne__ functionality which
|
||||
can easily be inherited by downstream classes.
|
||||
"""
|
||||
|
||||
def __eq__(self, other):
|
||||
eqval = True
|
||||
if isinstance(other, type(self)):
|
||||
for key, value in self.__dict__.items():
|
||||
if key in other.__dict__:
|
||||
if not np.array_equal(value, other.__dict__.get(key)):
|
||||
eqval = False
|
||||
else:
|
||||
eqval = False
|
||||
else:
|
||||
eqval = False
|
||||
|
||||
return eqval
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
Loading…
Add table
Add a link
Reference in a new issue