예제 #1
0
    def _mul_sparse_matrix(self, other):

        expanded_sym = self.tofullcsc()
        if isinstance(other, SparseBase):
            if other.is_symmetric:
                expanded_other = other.tofullcsc()
                result = expanded_sym * expanded_other
                return _convert_matrix_to_symmetric(result,
                                                    check_symmetry=False)
            from pyomo.contrib.pynumero.sparse.block_matrix import BlockMatrix
            if isinstance(other, BlockMatrix):
                raise NotImplementedError("Not supported yet")
                expanded_other = other.tocsc()
                result = expanded_sym * expanded_other
                if expanded_sym.shape[0] == expanded_other.shape[1]:
                    if _is_symmetric_numerically(result):
                        return _convert_matrix_to_symmetric(
                            result, check_symmetry=False)
                return result

            result = expanded_sym * other
            if expanded_sym.shape[0] == other.shape[1]:
                if _is_symmetric_numerically(result):
                    return _convert_matrix_to_symmetric(result,
                                                        check_symmetry=False)
            return result
        if issparse(other):
            raise RuntimeError(
                "Multiplication not supported with scipy matrices")
        raise RuntimeError("Sparse format not recognized {}".format(
            type(other)))
예제 #2
0
    def test_is_symmetric_numerically(self):

        test_m = np.array([[2., 0., 0., 1.], [0., 3., 0., 0.],
                           [0., 0., 4., 0.], [1., 0., 0., 5.]])

        m = COOMatrix(test_m)
        self.assertTrue(_is_symmetric_numerically(m))
        self.assertFalse(_is_symmetric_numerically(self.basic_m))