示例#1
0
文件: csparse.c 项目: chrfilip/Spice
int *cs_counts(const cs *A, const int *parent, const int *post, int ata) {

	int i, j, k, n, m, J, s, p, q, jleaf, *ATp, *ATi, *maxfirst, *prevleaf, *ancestor,
			*head = NULL, *next = NULL, *colcount, *w, *first, *delta;
	cs *AT;
	if (!CS_CSC (A) || !parent || !post)
		return (NULL); /* check inputs */
	m = A->m;
	n = A->n;
	s = 4 * n + (ata ? (n + m + 1) : 0);
	delta = colcount = (int *) cs_malloc(n, sizeof(int)); /* allocate result */
	w = (int *) cs_malloc(s, sizeof(int)); /* get workspace */
	AT = cs_transpose(A, 0); /* AT = A' */
	if (!AT || !colcount || !w)
		return (cs_idone(colcount, AT, w, 0));
	ancestor = w;
	maxfirst = w + n;
	prevleaf = w + 2 * n;
	first = w + 3 * n;
	for (k = 0; k < s; k++)
		w[k] = -1; /* clear workspace w [0..s-1] */
	for (k = 0; k < n; k++) /* find first [j] */
	{
		j = post[k];
		delta[j] = (first[j] == -1) ? 1 : 0; /* delta[j]=1 if j is a leaf */
		for (; j != -1 && first[j] == -1; j = parent[j])
			first[j] = k;
	}
	ATp = AT->p;
	ATi = AT->i;
	if (ata)
		init_ata(AT, post, w, &head, &next);
	for (i = 0; i < n; i++)
		ancestor[i] = i; /* each node in its own set */
	for (k = 0; k < n; k++) {
		j = post[k]; /* j is the kth node in postordered etree */
		if (parent[j] != -1)
			delta[parent[j]]--; /* j is not a root */
		for (J = HEAD (k,j); J != -1; J = NEXT (J)) /* J=j for LL'=A case */
		{
			for (p = ATp[J]; p < ATp[J + 1]; p++) {
				i = ATi[p];
				q = cs_leaf(i, j, first, maxfirst, prevleaf, ancestor, &jleaf);
				if (jleaf >= 1)
					delta[j]++; /* A(i,j) is in skeleton */
				if (jleaf == 2)
					delta[q]--; /* account for overlap in q */
			}
		}
		if (parent[j] != -1)
			ancestor[j] = parent[j];
	}
	for (j = 0; j < n; j++) /* sum up delta's of each child */
	{
		if (parent[j] != -1)
			colcount[parent[j]] += colcount[j];
	}
	return (cs_idone(colcount, AT, w, 1)); /* success: free workspace */
}
示例#2
0
文件: init.c 项目: moritz31/SkyOs
void init(multiboot_info_t* mb_info, unsigned long magic)
{
    clear_screen();
    init_serial();
    init_ata();
    //initalize the memory manager
    init_memory_manager(mb_info);
    //clean the multiboot info after it isn't needed anymore
    mb_info = NULL;
    
    init_keyboard();
    
    kprintf("Initalizing GDT...\n");
    init_gdt();
    kprintf("Initalizing IDT...\n");
    init_idt();
    init_multitasking();
}