Skip to content

Commit

Permalink
All the methods should follow this self-referential pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
FadiShawki committed Feb 20, 2024
1 parent 581aba7 commit ec53109
Showing 1 changed file with 48 additions and 19 deletions.
67 changes: 48 additions & 19 deletions environments/python/orbitmines/ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def ray(func: Callable[[Any, ...], Any]) -> Ray:

class Ray2:
def __getattr__(self, name: str) -> Any:
print(f'{name}')
print(f'__getattr__.{name}')
pass
def __setattr__(self, key, value) -> Any:
print(f'{key}={value}')
print(f'__setattr__{key}={value}')
pass

#
Expand Down Expand Up @@ -249,30 +249,54 @@ def size(self, b: Arbitrary) -> Ray:
# duplicate = copy = clone = size.from_perspective_of

@ray
def xor(a, b: Arbitrary) -> Ray: return -(a.xnor(b))
def xor(self) -> Ray: return (
-self.xnor
)
__xor__ \
= xor
@ray
def xnor(a, b: Arbitrary) -> Ray: raise NotImplementedError # TODO: Could be 'is_equivalent' too? or is_orbit
@ray
def nand(a, b: Arbitrary) -> Ray: return -(a & b)
@ray
def nor(a, b: Arbitrary) -> Ray: return -(a | b)

@ray
def add(a, b: Arbitrary) -> Ray: raise NotImplementedError
@ray # TODO: Could be 'is_equivalent' too? or is_orbit
def xnor(self) -> Ray: return (
-self.xor
)
@ray
def nand(self) -> Ray: return (
-self._and
)
@ray
def nor(self): return (
-self._or
)
@ray
def _and(self) -> Ray: return (
-self.nand
)
__and__ = \
_and
@ray
def _or(self) -> Ray: return (
-self.nor
)
__or__ = \
_or

@ray
def add(self) -> Ray: return (
-self.sub
)
__add__ \
= add
@ray
def sub(self) -> Ray: return (
-self.add
)
__sub__ \
= sub

# TODO: -add = sub & others

@ray
def radd(self) -> Ray: return -self.add.perspective
@ray
def sub(a, b: Arbitrary) -> Ray: return -a.add
__sub__ \
= sub
@ray
def pow(a, b: Arbitrary) -> Ray: raise NotImplementedError
__pow__ \
= pow
Expand Down Expand Up @@ -346,9 +370,6 @@ async def __anext__(self) -> Ray: raise NotImplementedError
# def __hash__(self) -> str: raise NotImplementedError
# def __bool__(self) -> bool: raise NotImplementedError

def __and__(a, b: Arbitrary) -> Ray: raise NotImplementedError
def __or__(a, b: Arbitrary) -> Ray: raise NotImplementedError

# def __iadd__(a, b: Arbitrary) -> Ray: return a.assign(a.add(b))
# def __isub__(a, b: Arbitrary) -> Ray: return a.assign(a.sub(b))
# def __imul__(a, b: Arbitrary) -> Ray: return a.assign(a.mul(b))
Expand Down Expand Up @@ -471,7 +492,15 @@ def memoized(self) -> Ray:
print('----------------')
ray = Ray2()
ray.__init__ = lambda self: self

ray.__mul__ = 'test'
setattr(ray, '__mul__', lambda self: self)

# class Ray3(ray):
# mul = times = size \
# = ray__mul__
# pass

print('----------------')
# Ray.__add__ = -Ray.__sub__
# Ray.__sub__ = -Ray.__add__
Expand Down

0 comments on commit ec53109

Please sign in to comment.