Esempio n. 1
0
def test_stack_4b():
    """

    :return:
    """
    k = 1000
    l = 4 * k
    m = 6 * k

    A = csc_matrix(random(k, l, density=0.1))
    B = csc_matrix(random(k, k, density=0.1))
    C = csc_matrix(random(m, l, density=0.1))
    D = csc_matrix(random(m, k, density=0.1))
    t = time()
    E = hstack((vstack((A, C)), vstack((B, D))))
    print('Scipy\t', time() - t)

    A1 = scipy_to_mat(A)
    B1 = scipy_to_mat(B)
    C1 = scipy_to_mat(C)
    D1 = scipy_to_mat(D)
    t = time()
    E1 = csc_stack_2d_ff([A1, B1, C1, D1], 2, 2)
    print('Csparse3\t', time() - t)
    # print(A1)
    # print(B1)
    # print(C1)
    # print(D1)
    # print(E1)

    stack_test = (E.todense() == E1.todense()).all()

    print('Stacking pass:', stack_test)
    assert stack_test

    return True
Esempio n. 2
0
def test1(check=True):
    np.random.seed(0)
    k = 500
    m, n = k, k

    A = csc_matrix(random(m, n, density=0.01)) + diags(np.ones(n))
    B = csc_matrix(random(m, n, density=0.01)) + diags(np.ones(n))
    x = np.random.random(m)
    xx = np.random.random((m, 5))

    # ---------------------------------------------------------------------
    # Scipy
    # ---------------------------------------------------------------------
    t = time()
    C = A + B
    D = A - B
    F = A * B
    G = C * x
    H = A * 5
    I = A.T
    J = A * xx
    print('Scipy\t', time() - t, 's')

    # ---------------------------------------------------------------------
    # CSparse3
    # ---------------------------------------------------------------------
    A2 = scipy_to_mat(A)
    B2 = scipy_to_mat(B)

    t = time()
    C2 = A2 + B2
    D2 = A2 - B2
    F2 = A2 * B2
    G2 = C2 * x
    H2 = A2 * 5
    I2 = A2.T
    J2 = A2 * xx
    print('CSparse\t', time() - t, 's')

    # ---------------------------------------------------------------------
    # check
    # ---------------------------------------------------------------------
    if check:
        pass_sum = (C.todense() == C2.todense()).all()
        pass_subt = (D.todense() == D2.todense()).all()
        pass_mult = (F.todense() == F2.todense()).all()
        pass_mat_vec = (G == G2).all()
        pass_mat_vec_multiple = (J == J2).all()
        pass_mult_scalar = (H.todense() == H2.todense()).all()
        pass_transpose = (I.todense() == I2.todense()).all()

        # print(F.todense())
        # print(F2)

        assert pass_sum
        assert pass_subt
        assert pass_mult
        assert pass_mat_vec
        assert pass_mat_vec_multiple
        assert pass_mult_scalar
        assert pass_transpose

        print('+\t\t', pass_sum)
        print('-\t\t', pass_subt)
        print('mat mat\t', pass_mult)
        print('mat vec\t', pass_mat_vec)
        print('mat vec multiple\t', pass_mat_vec_multiple)
        print('scalar *', pass_mult_scalar)
        print('Transpose', pass_transpose)