# Path: sampyl/state.py
# class State(collections.OrderedDict):
#     """ State object for storing parameter values.
#         
#         Inherits from OrderedDict.
# 
#     """
# 
#     def tovector(self):
#         """ Return the parameter values as a flat vector. """
#         return np.hstack(self.values())
# 
#     def fromvector(self, vec):
#         """ Update the state using a numpy array. 
# 
#             :param vec: np.array for updating the state.
#         """
#         var_sizes = self.size()
#         i = 0
#         for var in self:
#             self[var] = np.squeeze(vec[i:(i+var_sizes[var])])
#             i += var_sizes[var]
#         return self
# 
#     def freeze(self):
#         """ Return a immutable tuple of the state values."""
#         return tuple(self.tovector())
# 
#     @staticmethod
#     def init_fromvector(vec, state):
#         ""
#         vals = []
#         var_sizes = state.size()
#         i = 0
#         for var in state:
#             vals.append(np.squeeze(vec[i:(i+var_sizes[var])]))
#             i += var_sizes[var]
#         return State(zip(state.keys(), vals))
# 
#     @staticmethod
#     def fromfunc(func):
#         """ Initialize a State from the arguments of a function """
#         var_names = func_var_names(func)
#         return State.fromkeys(var_names)
# 
#     def size(self):
#         return State([(var, np.size(self[var])) for var in self])
# 
#     def __add__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__add__')
#         elif isinstance(other, collections.Iterable):
#             return handle_iterable(self, other, '__add__')
#         else:
#             raise TypeError("Addition not supported for State and {}".format(other))
# 
#     def __sub__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__sub__')
#         elif isinstance(other, collections.Iterable):
#             return handle_iterable(self, other, '__sub__')
#         else:
#             raise TypeError("Subtraction not supported for State and {}".format(other))
# 
#     def __mul__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__mul__')
#         else:
#             raise TypeError("Multiplication not supported for State and {}".format(other))
# 
#     def __truediv__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__truediv__')
#         else:
#             raise TypeError("Division not supported for State and {}".format(other))
# 
#     def __radd__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             # Commutative, so nothing changes
#             return self + other
#         else:
#             raise TypeError("Can only broadcast from the left.")
# 
#     def __rmul__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             # Commutative, so nothing changes
#             return self * other
#         else:
#             raise TypeError("Can only broadcast from the left.")
# 
#     def __rsub__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__rsub__')
#         elif isinstance(other, collections.Iterable):
#             return handle_iterable(self, other, '__rsub__')
#         else:
#             raise TypeError("Subtraction not supported for State and {}".format(other))
# 
#     def __rtruediv__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__truediv__')
#         else:
#             raise TypeError("Division not supported for State and {}".format(other))


from ..core import np
from ..state import State

state1 = State([('x', 1)])
state2 = State([('x', np.array([1, 2, 3]))])
state3 = State([('x', np.array([1,2,3])), ('y', 1)])
state4 = State([('x', np.array([2.]))])
state5 = State([('x', np.array([2,1,4])), ('y', 2)])

def test_add_states():
    new = state3 + state5
    print(new)

# Path: sampyl/state.py
# class State(collections.OrderedDict):
#     """ State object for storing parameter values.
#         
#         Inherits from OrderedDict.
# 
#     """
# 
#     def tovector(self):
#         """ Return the parameter values as a flat vector. """
#         return np.hstack(self.values())
# 
#     def fromvector(self, vec):
#         """ Update the state using a numpy array. 
# 
#             :param vec: np.array for updating the state.
#         """
#         var_sizes = self.size()
#         i = 0
#         for var in self:
#             self[var] = np.squeeze(vec[i:(i+var_sizes[var])])
#             i += var_sizes[var]
#         return self
# 
#     def freeze(self):
#         """ Return a immutable tuple of the state values."""
#         return tuple(self.tovector())
# 
#     @staticmethod
#     def init_fromvector(vec, state):
#         ""
#         vals = []
#         var_sizes = state.size()
#         i = 0
#         for var in state:
#             vals.append(np.squeeze(vec[i:(i+var_sizes[var])]))
#             i += var_sizes[var]
#         return State(zip(state.keys(), vals))
# 
#     @staticmethod
#     def fromfunc(func):
#         """ Initialize a State from the arguments of a function """
#         var_names = func_var_names(func)
#         return State.fromkeys(var_names)
# 
#     def size(self):
#         return State([(var, np.size(self[var])) for var in self])
# 
#     def __add__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__add__')
#         elif isinstance(other, collections.Iterable):
#             return handle_iterable(self, other, '__add__')
#         else:
#             raise TypeError("Addition not supported for State and {}".format(other))
# 
#     def __sub__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__sub__')
#         elif isinstance(other, collections.Iterable):
#             return handle_iterable(self, other, '__sub__')
#         else:
#             raise TypeError("Subtraction not supported for State and {}".format(other))
# 
#     def __mul__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__mul__')
#         else:
#             raise TypeError("Multiplication not supported for State and {}".format(other))
# 
#     def __truediv__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__truediv__')
#         else:
#             raise TypeError("Division not supported for State and {}".format(other))
# 
#     def __radd__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             # Commutative, so nothing changes
#             return self + other
#         else:
#             raise TypeError("Can only broadcast from the left.")
# 
#     def __rmul__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             # Commutative, so nothing changes
#             return self * other
#         else:
#             raise TypeError("Can only broadcast from the left.")
# 
#     def __rsub__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__rsub__')
#         elif isinstance(other, collections.Iterable):
#             return handle_iterable(self, other, '__rsub__')
#         else:
#             raise TypeError("Subtraction not supported for State and {}".format(other))
# 
#     def __rtruediv__(self, other):
#         if isinstance(other, int) or isinstance(other, float):
#             return handle_number(self, other, '__truediv__')
#         else:
#             raise TypeError("Division not supported for State and {}".format(other))


# Path: sampyl/tests/test_state.py
from ..core import np
from ..state import State


state1 = State([('x', 1)])
state2 = State([('x', np.array([1, 2, 3]))])
state3 = State([('x', np.array([1,2,3])), ('y', 1)])
state4 = State([('x', np.array([2.]))])
state5 = State([('x', np.array([2,1,4])), ('y', 2)])

def test_add_states():
    new = state3 + state5
    print(new)

    assert(type(new) == State)