Exemple #1
0
def test_predicted_svals():
    '''
    The predicted_svals function shows the predicted singular values.
    '''
    t1 = MockTensor()
    t1.svals = range(5, 0, -1)
    t2 = MockTensor()
    t2.svals = range(10, 0, -2)

    # Weighting one side heavily should make its svals uniquely show up.
    weight = 0.999999
    b = Blend([t1, t2], weights=[weight, 1 - weight], k_values=1)

    # with origin tracking:
    svals = b.predicted_svals(num=5, for_each_tensor=5, track_origin=True)
    for expected, (actual, src) in zip(t1.svals, svals):
        assert_almost_equal(actual / weight, expected)
        eq_(src, 0)

    # without origin tracking
    svals = b.predicted_svals(num=5, for_each_tensor=5)
    for expected, actual in zip(t1.svals, svals):
        assert_almost_equal(actual / weight, expected)

    # Flip it around.
    b.weights = [1 - weight, weight]
    # Note: this is an easy way to transpose the "matrix"
    sval, src = zip(
        *b.predicted_svals(num=5, for_each_tensor=5, track_origin=True))
    for actual, expected in zip(sval, t2.svals):
        assert_almost_equal(actual / weight, expected)
    eq_(src, (1, ) * 5)
Exemple #2
0
def test_predicted_svals():
    '''
    The predicted_svals function shows the predicted singular values.
    '''
    t1 = MockTensor()
    t1.svals = range(5, 0, -1)
    t2 = MockTensor()
    t2.svals = range(10, 0, -2)

    # Weighting one side heavily should make its svals uniquely show up.
    weight = 0.999999
    b = Blend([t1, t2], weights=[weight, 1-weight], k_values=1)

    # with origin tracking:
    svals = b.predicted_svals(num=5, for_each_tensor=5, track_origin=True)
    for expected, (actual, src) in zip(t1.svals, svals):
        assert_almost_equal(actual/weight, expected)
        eq_(src, 0)

    # without origin tracking
    svals = b.predicted_svals(num=5, for_each_tensor=5)
    for expected, actual in zip(t1.svals, svals):
        assert_almost_equal(actual/weight, expected)

    # Flip it around.
    b.weights = [1-weight, weight]
    # Note: this is an easy way to transpose the "matrix"
    sval, src = zip(*b.predicted_svals(num=5, for_each_tensor=5, track_origin=True))
    for actual, expected in zip(sval, t2.svals):
        assert_almost_equal(actual/weight, expected)
    eq_(src, (1,)*5)