from __future__ import absolute_import

import numpy as np
from six.moves import zip


def add_params(param_list_left, param_list_right):
    """Add two lists of parameters one by one

    :param param_list_left: list of numpy arrays
    :param param_list_right: list of numpy arrays
    :return: list of numpy arrays
    """
    res = []
    for x, y in zip(param_list_left, param_list_right):
        res.append(x + y)
    return res


def subtract_params(param_list_left, param_list_right):
    """Subtract two lists of parameters

    :param param_list_left: list of numpy arrays
    :param param_list_right: list of numpy arrays
    :return: list of numpy arrays
    """
    res = []
    for x, y in zip(param_list_left, param_list_right):
        res.append(x - y)
    return res


def get_neutral(array_list):
    """Get list of zero-valued numpy arrays for
    specified list of numpy arrays

    :param array_list: list of numpy arrays
    :return: list of zeros of same shape as input
    """
    res = []
    for x in array_list:
        res.append(np.zeros_like(x))
    return res


def divide_by(array_list, num_workers):
    """Divide a list of parameters by an integer num_workers.

    :param array_list:
    :param num_workers:
    :return:
    """
    for i, x in enumerate(array_list):
        array_list[i] /= num_workers
    return array_list

@@ -321,34 +321,35 @@
   %22%22%22%0A    re
-s = %5B%5D%0A   
+turn %5Bx + y
  for x, y in
@@ -391,50 +391,9 @@
 ght)
-:%0A        res.append(x + y)%0A    return res
+%5D
 %0A%0A%0Ad
@@ -631,34 +631,35 @@
   %22%22%22%0A    re
-s = %5B%5D%0A   
+turn %5Bx - y
  for x, y in
@@ -701,50 +701,9 @@
 ght)
-:%0A        res.append(x - y)%0A    return res
+%5D
 %0A%0A%0Ad
@@ -926,91 +926,51 @@
   re
-s = %5B%5D%0A    for x in array_list:%0A        res.append(np.zeros_like(x))%0A    return res
+turn %5Bnp.zeros_like(x) for x in array_list%5D
 %0A%0A%0Ad
@@ -1147,67 +1147,19 @@
     
-for i, x in enumerate(array_list):%0A        array_list%5Bi%5D
+return %5Bx
  /
-=
  num
@@ -1166,26 +1166,24 @@
 _workers
-%0A    retur
+ for x i
 n array_
@@ -1186,9 +1186,10 @@
 ray_list
+%5D
 %0A

convert functional utils to list comprehension