Ejemplo n.º 1
0
def reorder_matrix(n, rowind, colptr, icntl=[0, 6], jcntl=[0, 0], weight=[2, 1]):
    """Helper function called by `sloan` and `rcm`.

    It performs the bulk of the work when applying Sloan's method or the
    reverse Cuthill-McKee algorithm to a symmetric sparse matrix.
    """
    # Make room for pattern of the whole matrix and adjust to be 1-based
    icptr = colptr.copy() + 1
    irn = np.empty(2 * (icptr[-1] - 1), dtype=np.int32)
    irn[:icptr[-1] - 1] = rowind.copy() + 1

    # Check data
    info = _mc60.mc60ad(irn, icptr, icntl)

    # Compute supervariables
    nsup, svar, vars = _mc60.mc60bd(irn, icptr)

    # Permute reduced matrix
    permsv = np.empty(nsup, dtype=np.int32)
    pair = np.empty((2, nsup / 2), dtype=np.int32)
    info = _mc60.mc60cd(n, irn, icptr[:nsup + 1], vars[:nsup],
                        jcntl, permsv, weight, pair)

    # Compute profile, maximum wavefront, semi-bandwidth and root-mean-square
    # wavefront of the permuted matrix
    rinfo = _mc60.mc60fd(n, irn, icptr[:nsup + 1], vars[:nsup], permsv)

    # Obtain variable permutation from supervariable permutation
    perm, possv = _mc60.mc60dd(svar, vars[:nsup], permsv)

    # Adjust permutation to make it 0-based
    perm -= 1

    # There are other things to return!
    return (perm, rinfo)
Ejemplo n.º 2
0
    def test_spec_sheet(self):
        """Solve example from the spec sheet.

        Ordering
        http://www.hsl.rl.ac.uk/specs/mc60.pdf
        """
        icntl = np.array([0, 6], dtype=np.int32)  # Abort on error
        jcntl = np.array([0, 0], dtype=np.int32)  # Sloan's alg with auto choice
        weight = np.array([2, 1])                 # Weights in Sloan's alg

        # Store lower triangle of symmetric matrix in csr format (1-based)
        n = 5
        icptr = np.array([1, 6, 8, 9, 10, 11], dtype=np.int32)  # nnz = 10
        irn = np.empty(2 * (icptr[-1] - 1), dtype=np.int32)
        irn[:icptr[-1] - 1] = np.array([1, 2, 3,
                                        4, 5, 2, 3, 3, 4, 5], dtype=np.int32)

        # Check data
        info = _mc60.mc60ad(irn, icptr, icntl)

        # Compute supervariables
        nsup, svar, vars = _mc60.mc60bd(irn, icptr)
        assert nsup == 4
        print 'The number of supervariables is ', nsup

        # Permute reduced matrix
        permsv = np.empty(nsup, dtype=np.int32)
        pair = np.empty((2, nsup / 2), dtype=np.int32)
        info = _mc60.mc60cd(n, irn, icptr[:nsup + 1],
                            vars[:nsup], jcntl, permsv, weight, pair)

        # Compute profile and wavefront
        rinfo = _mc60.mc60fd(n, irn, icptr[:nsup + 1], vars[:nsup], permsv)

        # Obtain variable permutation from supervariable permutation
        perm, possv = _mc60.mc60dd(svar, vars[:nsup], permsv)

        assert np.array_equal(perm, np.array([3, 5, 4, 1, 2], np.int32))
        assert rinfo[0] == 10
Ejemplo n.º 3
0
# Make room for pattern of the whole matrix
irn = np.empty(2 * (icptr[-1] - 1), dtype=np.int32)
irn[:icptr[-1] - 1] = M.ind.copy() + 1

# Check data
info = _mc60.mc60ad(irn, icptr, icntl)

# Compute supervariables
nsup, svar, vars = _mc60.mc60bd(irn, icptr)
print 'The number of supervariables is ', nsup

# Permute reduced matrix
permsv = np.empty(nsup, dtype=np.int32)
pair = np.empty((2, nsup / 2), dtype=np.int32)
info = _mc60.mc60cd(n, irn, icptr[:nsup + 1], vars[:nsup],
                    jcntl, permsv, weight, pair)

# Compute profile and wavefront
rinfo = _mc60.mc60fd(n, irn, icptr[:nsup + 1], vars[:nsup], permsv)

# Obtain variable permutation from supervariable permutation
perm, possv = _mc60.mc60dd(svar, vars[:nsup], permsv)

np.set_printoptions(precision=3, linewidth=80, threshold=10, edgeitems=3)
print 'The variable permutation is ', perm
print 'The profile is ', rinfo[0]
print 'The maximum wavefront is ', rinfo[1]
print 'The semibandwidth is ', rinfo[2]
print 'The root-mean-square wavefront is ', rinfo[3]

try: