Exemplo n.º 1
0
def is_zero_matrix(matrix):
    m_rand = st.subs_random_numbers(matrix, prime=srn_prime)

    for i in xrange(len(m_rand)):
        if not np.allclose(float(m_rand[i]), 0):
            return False
    return True
Exemplo n.º 2
0
    def test_rnd_number_tuples3(self):
        a, b = sp.symbols('a, b', commutative=False)

        term1 = a * b - b * a
        st.warnings.simplefilter("always")
        with st.warnings.catch_warnings(record=True) as cm:
            st.rnd_number_subs_tuples(term1)

        self.assertEqual(len(cm), 1)
        self.assertTrue('not commutative' in str(cm[0].message))

        with st.warnings.catch_warnings(record=True) as cm2:
            st.subs_random_numbers(term1)

        self.assertEqual(len(cm2), 1)
        self.assertTrue('not commutative' in str(cm2[0].message))
Exemplo n.º 3
0
def is_zero_matrix(matrix):
    m_rand = st.subs_random_numbers(matrix, prime=srn_prime)

    for i in range(len(m_rand)):
        if not np.allclose(float(m_rand[i]), 0):
            return False
    return True
Exemplo n.º 4
0
    def nonzero_tuples(self, srn=False, eps=1e-30):
        """
        returns a list of tuples (coeff, idcs) for each index-tuple idcs,
        where the corresponding coeff != 0
        """
        Z = lzip(self.coeff, self.indices)

        if srn == "prime":
            res = [(c, idcs) for (c, idcs) in Z
                   if abs(st.subs_random_numbers(c, prime=True)) > eps]
        elif srn:
            res = [(c, idcs) for (c, idcs) in Z
                   if abs(st.subs_random_numbers(c)) > eps]
        else:
            res = [(c, idcs) for (c, idcs) in Z if c != 0]

        return res
Exemplo n.º 5
0
def is_unit_matrix(matrix):
    assert is_square_matrix(matrix), "Matrix is not a square matrix."
    m, n = matrix.shape
    m_rand = st.subs_random_numbers(matrix, prime=srn_prime)

    for i in xrange(len(m_rand)):
        if i%(m+1)==0:
            if not np.allclose(float(m_rand[i]), 1):
                return False
        else:
            if not np.allclose(float(m_rand[i]), 0):
                return False
    return True
Exemplo n.º 6
0
def is_unit_matrix(matrix):
    assert is_square_matrix(matrix), "Matrix is not a square matrix."
    m, n = matrix.shape
    m_rand = st.subs_random_numbers(matrix, prime=srn_prime)

    for i in range(len(m_rand)):
        if i % (m + 1) == 0:
            if not np.allclose(float(m_rand[i]), 1):
                return False
        else:
            if not np.allclose(float(m_rand[i]), 0):
                return False
    return True
Exemplo n.º 7
0
    def test_unimod_inv4(self):
        path = make_abspath('test_data', 'unimod_matrix_unicycle.pcl')
        with open(path, 'rb') as pfile:
            pdict = pickle.load(pfile)

        PQ = pdict['PQ']
        s = [ symb for symb in PQ.s if str(symb) == "s"][0]
        self.assertTrue(s in PQ.s)

        abc = pdict['abc']
        #kk = pdict['kk']
        #JEh = pdict['JEh']

        inv = nct.unimod_inv(PQ, s, None, abc, max_deg=2)
        res = nct.nc_mul(inv, PQ)
        res2 = nct.right_shift_all(res, s, None, abc)
        res3, tmp = nct.make_all_symbols_commutative(res2)
        res4 = st.subs_random_numbers(res3, prime=True)
        self.assertEqual(res4, sp.eye(3))