In [1]:
from zephyr.Parallel import CommonReducer
import numpy as np

In [2]:
dict0 = {
    'key0': np.array([1,2,3,4,5]),
    'key1': np.array([0,1,0,1,0]),
}
CR0 = CommonReducer(dict0)

dict1 = {
    'key1': np.array([5,4,3,2,1]),
    'key2': 10,
}
CR1 = CommonReducer(dict1)

In [3]:
CR0 + CR1


Out[3]:
{'key0': array([1, 2, 3, 4, 5]), 'key1': array([5, 5, 3, 3, 1]), 'key2': 10}

In [4]:
CR0 - CR1


Out[4]:
{'key1': array([-5, -3, -3, -1, -1])}

In [5]:
CR0 * CR1


Out[5]:
{'key1': array([0, 4, 0, 2, 0])}

In [6]:
CR0 / CR1


Out[6]:
{'key1': array([0, 0, 0, 0, 0])}

In [7]:
CR0.real


Out[7]:
{'key0': array([1, 2, 3, 4, 5]), 'key1': array([0, 1, 0, 1, 0])}

In [8]:
CR1.imag


Out[8]:
{'key1': array([0, 0, 0, 0, 0]), 'key2': 0}

In [9]:
CR0.sum()


Out[9]:
{'key0': 15, 'key1': 2}

In [10]:
CR1.sum()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-55ae269568fc> in <module>()
----> 1 CR1.sum()

/Users/brendan/Projects/zephyr/zephyr/Parallel.pyc in __getattr__(self, attr)
    130                 return CommonReducer({key: getattr(self[key], attr) for key in self.keys()})
    131         else:
--> 132             raise AttributeError('\'CommonReducer\' object has no attribute \'%s\', and it could not be satisfied through cascade lookup'%attr)
    133 
    134         return result

AttributeError: 'CommonReducer' object has no attribute 'sum', and it could not be satisfied through cascade lookup

In [11]:
(CR0 + CR1).sum()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-08321024520e> in <module>()
----> 1 (CR0 + CR1).sum()

/Users/brendan/Projects/zephyr/zephyr/Parallel.pyc in __getattr__(self, attr)
    130                 return CommonReducer({key: getattr(self[key], attr) for key in self.keys()})
    131         else:
--> 132             raise AttributeError('\'CommonReducer\' object has no attribute \'%s\', and it could not be satisfied through cascade lookup'%attr)
    133 
    134         return result

AttributeError: 'CommonReducer' object has no attribute 'sum', and it could not be satisfied through cascade lookup

In [12]:
(CR0 + CR1 + {'key2': np.array([1,2,3])}).sum()


Out[12]:
{'key0': 15, 'key1': 17, 'key2': 36}

In [ ]: