Skip to content

Commit

Permalink
v1.5.3: Optimize equality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
shBLOCK committed Apr 8, 2024
1 parent 1316995 commit 13f5219
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
14 changes: 8 additions & 6 deletions codegen/templates/transform_2d.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ cdef class Transform2D:
"""
if not isinstance(other, Transform2D):
return False
return self.xx == (<Transform2D> other).xx and self.xy == (<Transform2D> other).xy and\
self.yx == (<Transform2D> other).yx and self.yy == (<Transform2D> other).yy and\
self.ox == (<Transform2D> other).ox and self.oy == (<Transform2D> other).oy
cdef Transform2D trans = <Transform2D> other
return self.xx == trans.xx and self.xy == trans.xy and\
self.yx == trans.yx and self.yy == trans.yy and\
self.ox == trans.ox and self.oy == trans.oy

def __ne__(self, object other) -> bool:
"""Perform exact comparison.
Expand All @@ -125,9 +126,10 @@ cdef class Transform2D:
"""
if not isinstance(other, Transform2D):
return True
return self.xx != (<Transform2D> other).xx or self.xy != (<Transform2D> other).xy or \
self.yx != (<Transform2D> other).yx or self.yy != (<Transform2D> other).yy or \
self.ox != (<Transform2D> other).ox or self.oy != (<Transform2D> other).oy
cdef Transform2D trans = <Transform2D> other
return self.xx != trans.xx or self.xy != trans.xy or \
self.yx != trans.yx or self.yy != trans.yy or \
self.ox != trans.ox or self.oy != trans.oy

def is_close(self, Transform2D other, /, py_float rel_tol = DEFAULT_RELATIVE_TOLERANCE, py_float abs_tol = DEFAULT_ABSOLUTE_TOLERANCE) -> bool:
"""Determine if the two transforms are close enough.
Expand Down
18 changes: 10 additions & 8 deletions codegen/templates/transform_3d.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ cdef class Transform3D:
"""
if not isinstance(other, Transform3D):
return False
return self.xx == (<Transform3D> other).xx and self.xy == (<Transform3D> other).xy and self.xz == (<Transform3D> other).xz and\
self.yx == (<Transform3D> other).yx and self.yy == (<Transform3D> other).yy and self.yz == (<Transform3D> other).yz and\
self.zx == (<Transform3D> other).zx and self.zy == (<Transform3D> other).zy and self.zz == (<Transform3D> other).zz and\
self.ox == (<Transform3D> other).ox and self.oy == (<Transform3D> other).oy and self.oz == (<Transform3D> other).oz
cdef Transform3D trans = <Transform3D> other
return self.xx == trans.xx and self.xy == trans.xy and self.xz == trans.xz and\
self.yx == trans.yx and self.yy == trans.yy and self.yz == trans.yz and\
self.zx == trans.zx and self.zy == trans.zy and self.zz == trans.zz and\
self.ox == trans.ox and self.oy == trans.oy and self.oz == trans.oz

def __ne__(self, object other) -> bool:
"""Perform exact comparison.
Expand All @@ -180,10 +181,11 @@ cdef class Transform3D:
"""
if not isinstance(other, Transform3D):
return True
return self.xx != (<Transform3D> other).xx or self.xy != (<Transform3D> other).xy or self.xz != (<Transform3D> other).xz or\
self.yx != (<Transform3D> other).yx or self.yy != (<Transform3D> other).yy or self.yz != (<Transform3D> other).yz or\
self.zx != (<Transform3D> other).zx or self.zy != (<Transform3D> other).zy or self.zz != (<Transform3D> other).zz or\
self.ox != (<Transform3D> other).ox or self.oy != (<Transform3D> other).oy or self.oz != (<Transform3D> other).oz
cdef Transform3D trans = <Transform3D> other
return self.xx != trans.xx or self.xy != trans.xy or self.xz != trans.xz or\
self.yx != trans.yx or self.yy != trans.yy or self.yz != trans.yz or\
self.zx != trans.zx or self.zy != trans.zy or self.zz != trans.zz or\
self.ox != trans.ox or self.oy != trans.oy or self.oz != trans.oz

def is_close(self, Transform3D other, /, py_float rel_tol = DEFAULT_RELATIVE_TOLERANCE, py_float abs_tol = DEFAULT_ABSOLUTE_TOLERANCE) -> bool:
"""Determine if the two transforms are close enough.
Expand Down
6 changes: 4 additions & 2 deletions codegen/templates/vec_class.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ cdef class _VecClassName_:
"""
if not isinstance(other, _VecClassName_):
return False
return #<GEN>: gen_for_each_dim("self.{dim} == other.{dim}", _Dims_, join=" and ")
cdef _VecClassName_ vec = <_VecClassName_> other
return #<GEN>: gen_for_each_dim("self.{dim} == vec.{dim}", _Dims_, join=" and ")

def __ne__(self, object other) -> bool:
"""Perform exact comparison.
Expand All @@ -74,7 +75,8 @@ cdef class _VecClassName_:
"""
if not isinstance(other, _VecClassName_):
return True
return #<GEN>: gen_for_each_dim("self.{dim} != other.{dim}", _Dims_, join=" or ")
cdef _VecClassName_ vec = <_VecClassName_> other
return #<GEN>: gen_for_each_dim("self.{dim} != vec.{dim}", _Dims_, join=" or ")

def is_close(self, _VecClassName_ other, /, py_float rel_tol = DEFAULT_RELATIVE_TOLERANCE, py_float abs_tol = DEFAULT_ABSOLUTE_TOLERANCE) -> bool:
"""Determine if the two vectors are close enough.
Expand Down

0 comments on commit 13f5219

Please sign in to comment.