Ejemplo n.º 1
0
int
sm_block_partition(sm_matrix *A, sm_matrix **L, sm_matrix **R)
{
int cols_visited, rows_visited;
register sm_row *prow;
register sm_col *pcol;
if (A->nrows == 0) {
return 0;
}
for(prow = A->first_row; prow != 0; prow = prow->next_row) {
prow->flag = 0;
}
for(pcol = A->first_col; pcol != 0; pcol = pcol->next_col) {
pcol->flag = 0;
}
cols_visited = rows_visited = 0;
if (visit_row(A, A->first_row, &rows_visited, &cols_visited)) {
return 0;
} else {
*L = sm_alloc();
*R = sm_alloc();
for(prow = A->first_row; prow != 0; prow = prow->next_row) {
if (prow->flag) {
copy_row(*L, prow);
} else {
copy_row(*R, prow);
}
}
return 1;
}
}
Ejemplo n.º 2
0
static int
visit_col(sm_matrix *A, sm_col *pcol, int *rows_visited, int *cols_visited)
{
sm_element *p;
sm_row *prow;
if (! pcol->flag) {
pcol->flag = 1;
(*cols_visited)++;
if (*cols_visited == A->ncols) {
return 1;
}
for(p = pcol->first_row; p != 0; p = p->next_row) {
prow = ((( p->row_num) >= 0 && ( p->row_num) < (A)->rows_size) ? (A)->rows[ p->row_num] : (sm_row *) 0);
if (! prow->flag) {
if (visit_row(A, prow, rows_visited, cols_visited)) {
return 1;
}
}
}
}
return 0;
}
Ejemplo n.º 3
0
int
sm_block_partition(sm_matrix *A, sm_matrix **L, sm_matrix **R)
{
    int cols_visited, rows_visited;
    register sm_row *prow;
    register sm_col *pcol;

    /* Avoid the trivial case */
    if (A->nrows == 0) {
	return 0;
    }

    /* Reset the visited flags for each row and column */
    for(prow = A->first_row; prow != 0; prow = prow->next_row) {
	prow->flag = 0;
    }
    for(pcol = A->first_col; pcol != 0; pcol = pcol->next_col) {
	pcol->flag = 0;
    }

    cols_visited = rows_visited = 0;
    if (visit_row(A, A->first_row, &rows_visited, &cols_visited)) {
	/* we found all of the rows */
	return 0;
    } else {
	*L = sm_alloc();
	*R = sm_alloc();
	for(prow = A->first_row; prow != 0; prow = prow->next_row) {
	    if (prow->flag) {
		copy_row(*L, prow);
	    } else {
		copy_row(*R, prow);
	    }
	}
	return 1;
    }
}