コード例 #1
0
ファイル: performance.py プロジェクト: JolanPhilippe/PySke
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))
コード例 #2
0
ファイル: performance.py プロジェクト: JolanPhilippe/PySke
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)
コード例 #3
0
def test_map_empty():
    # pylint: disable=missing-docstring
    slst = SList()
    exp = SList()
    res = slst.map(fun.idt)
    assert res == exp
コード例 #4
0
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
コード例 #5
0
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