Пример #1
0
    def on_open(self):
        """Handle new websocket connection."""
        this.request = WSGIRequest(self.ws.environ)
        this.ws = self
        this.send = self.send
        this.reply = self.reply
        this.error = self.error

        self.logger = self.ws.logger
        self.remote_ids = collections.defaultdict(set)

        # self._tx_buffer collects outgoing messages which must be sent in order
        self._tx_buffer = {}
        # track the head of the queue (buffer) and the next msg to be sent
        self._tx_buffer_id_gen = itertools.cycle(irange(sys.maxint))
        self._tx_next_id_gen = itertools.cycle(irange(sys.maxint))
        # start by waiting for the very first message
        self._tx_next_id = next(self._tx_next_id_gen)

        this.remote_addr = self.remote_addr = \
            '{0[REMOTE_ADDR]}:{0[REMOTE_PORT]}'.format(
                self.ws.environ,
            )
        this.subs = {}
        self.logger.info('+ %s OPEN', self)
        self.send('o')
        self.send('a["{\\"server_id\\":\\"0\\"}"]')
Пример #2
0
    def on_open(self):
        """Handle new websocket connection."""
        this.request = WSGIRequest(self.ws.environ)
        this.ws = self
        this.send = self.send
        this.reply = self.reply

        self.logger = self.ws.logger
        self.remote_ids = collections.defaultdict(set)

        # `_tx_buffer` collects outgoing messages which must be sent in order
        self._tx_buffer = {}
        # track the head of the queue (buffer) and the next msg to be sent
        self._tx_buffer_id_gen = itertools.cycle(irange(sys.maxsize))
        self._tx_next_id_gen = itertools.cycle(irange(sys.maxsize))
        # start by waiting for the very first message
        self._tx_next_id = next(self._tx_next_id_gen)

        this.remote_addr = self.remote_addr = \
            '{0[REMOTE_ADDR]}:{0[REMOTE_PORT]}'.format(
                self.ws.environ,
            )
        this.subs = {}
        safe_call(self.logger.info, '+ %s OPEN', self)
        self.send('o')
        self.send('a["{\\"server_id\\":\\"0\\"}"]')
Пример #3
0
def coloring(m, inv_row_p, inv_col_p):
    # The permutation must give a matrix in Hessenberg form
    row_major, col_major = get_permuted_sp_matrices(m, inv_row_p, inv_col_p)
    ncols = col_major.shape[1]
    # Initially all column colors are set to the invalid "color" -1
    column_colors = np.full(ncols, -1, np.int32)
    # If color i is available: color_available[i] is 1, otherwise 0
    # Initially, "color" 0 is available 
    color_available = np.ones(1, np.int8)
    # Iterate through the columns backwards, from right to left
    for c in reversed(irange(ncols)):
        # All rows containing c
        for r in rows_in_col(col_major, c):
            # All other columns in those rows, c's "neighbors"
            cols = cols_in_row(row_major, r)
            idx = np.flatnonzero(cols==c)
            # cols in r: [ left | c | right]
            # only the right index set has been processed so far
            right = cols[idx+1:]
            used_colors = column_colors[right]
            color_available[used_colors] = 0
        #print('Colors available:\n%s' % color_available)
        index = np.flatnonzero(color_available)[0]
        column_colors[c] = index
        # introduce new "color" if index == color_available.size-1 
        color_available = np.ones(max(index+2, color_available.size), np.int8)
    print('Colors:\n%s' % column_colors)
    # chromatic number >= max nonzeros in a row
    lb_chromatic_number = np.max(np.diff(row_major.indptr))
    color_count = color_available.size-1
    print('Color count: %d (>=%d)' % (color_count, lb_chromatic_number))
    return  column_colors, color_count
Пример #4
0
def coloring(m, inv_row_p, inv_col_p):
    # The permutation must give a matrix in Hessenberg form
    row_major, col_major = get_permuted_sp_matrices(m, inv_row_p, inv_col_p)
    ncols = col_major.shape[1]
    # Initially all column colors are set to the invalid "color" -1
    column_colors = np.full(ncols, -1, np.int32)
    # If color i is available: color_available[i] is 1, otherwise 0
    # Initially, "color" 0 is available
    color_available = np.ones(1, np.int8)
    # Iterate through the columns backwards, from right to left
    for c in reversed(irange(ncols)):
        # All rows containing c
        for r in rows_in_col(col_major, c):
            # All other columns in those rows, c's "neighbors"
            cols = cols_in_row(row_major, r)
            idx = np.flatnonzero(cols == c)
            # cols in r: [ left | c | right]
            # only the right index set has been processed so far
            right = cols[idx + 1:]
            used_colors = column_colors[right]
            color_available[used_colors] = 0
        #print('Colors available:\n%s' % color_available)
        index = np.flatnonzero(color_available)[0]
        column_colors[c] = index
        # introduce new "color" if index == color_available.size-1
        color_available = np.ones(max(index + 2, color_available.size),
                                  np.int8)
    print('Colors:\n%s' % column_colors)
    # chromatic number >= max nonzeros in a row
    lb_chromatic_number = np.max(np.diff(row_major.indptr))
    color_count = color_available.size - 1
    print('Color count: %d (>=%d)' % (color_count, lb_chromatic_number))
    return column_colors, color_count
Пример #5
0
def min_degree_ordering(m, row_p, col_p, rbeg, rend, cbeg, cend):
    dbg_show_permuted_matrix(m, row_p, col_p)
    for rbeg in irange(rbeg, rend):
        # get the rows and cols in the active submatrix (asm)
        rows, cols = row_p[rbeg:rend], col_p[cbeg:cend]
        r, cmask = find_row_with_min_count(m, rows, cols)
        rmask = rows==r
        row_p[rbeg:rend] = stable_partition(rows, rmask)
        col_p[cbeg:cend] = stable_partition(cols, cmask)
        dbg_step(slice(rbeg,rend),slice(cbeg,cend),row_p,col_p,m,r,rmask,cmask)
        cbeg += np.count_nonzero(cmask)
Пример #6
0
def min_degree_ordering(m, row_p, col_p, rbeg, rend, cbeg, cend):
    dbg_show_permuted_matrix(m, row_p, col_p)
    for rbeg in irange(rbeg, rend):
        # get the rows and cols in the active submatrix (asm)
        rows, cols = row_p[rbeg:rend], col_p[cbeg:cend]
        r, cmask = find_row_with_min_count(m, rows, cols)
        rmask = rows == r
        row_p[rbeg:rend] = stable_partition(rows, rmask)
        col_p[cbeg:cend] = stable_partition(cols, cmask)
        dbg_step(slice(rbeg, rend), slice(cbeg, cend), row_p, col_p, m, r,
                 rmask, cmask)
        cbeg += np.count_nonzero(cmask)
Пример #7
0
def set_min_degree_order_and_coloring(bsp):
    # Checking whether the blocks are in lower triangular form
    set_inverse_permutations(bsp)
    get_permuted_block_profiles(bsp) # profiles are currently ignored
    # Unpacking bsp
    m, row_p, col_p = bsp.csr_mat, bsp.row_permutation, bsp.col_permutation  
    # Apply minimum degree ordering to each block on the diagonal (i,i)    
    for i in irange(bsp.n_rblx):
        min_degree_ordering(m, row_p, col_p, *get_block_boundaries(bsp, i, i))
    set_inverse_permutations(bsp)
    bsp.coloring, bsp.color_count = coloring( m, bsp.inverse_row_perm, 
                                                 bsp.inverse_col_perm )
Пример #8
0
def itr_col_indices(m):
    assert isinstance(m, sp.csr_matrix)
    for row in irange(m.shape[0]):
        yield m.indices[m.indptr[row]:m.indptr[row+1]]
Пример #9
0
def itr_nonzero_indices(m):
    assert isinstance(m, sp.csr_matrix)    
    for row in irange(m.shape[0]):
        for col in m.indices[m.indptr[row]:m.indptr[row+1]]:
            yield row, col