def norm(vec: DSList): """ Computes the norm of the argument vector. :param vec: DSList :return: float """ return math.sqrt(vec.map(sqr).reduce(add, 0))
def smul(scalar: float, vec: DSList): """ Compute the product of a scalar and a vector :param scalar: float :param vec: DSList :return: DSList """ return vec.map(lambda num: scalar*num)
def test_map_empty(): # pylint: disable=missing-docstring slst = SList() exp = SList() res = slst.map(fun.idt) assert res == exp
def test_map_id(): # pylint: disable=missing-docstring slst = SList([1, 2, 3]) exp = SList([1, 2, 3]) res = slst.map(fun.idt) assert res == exp
def test_map_reduce_non_empty(): # pylint: disable=missing-docstring slst = SList([1, 2, 3, 4]) res = slst.map_reduce(fun.incr, operator.add, 0) exp = slst.map(fun.incr).reduce(operator.add) assert res == exp