Exemplo n.º 1
0
static void __nlSparseMatrix_square(
	__NLSparseMatrix* AtA, __NLSparseMatrix *A
) {
	NLuint m = A->m;
	NLuint n = A->n;
	NLuint i, j0, j1;
	__NLRowColumn *Ri = NULL;
	__NLCoeff *c0 = NULL, *c1 = NULL;
	float value;

	__nlSparseMatrixConstruct(AtA, n, n, A->storage);

	for(i=0; i<m; i++) {
		Ri = &(A->row[i]);

		for(j0=0; j0<Ri->size; j0++) {
			c0 = &(Ri->coeff[j0]);
			for(j1=0; j1<Ri->size; j1++) {
				c1 = &(Ri->coeff[j1]);

				value = c0->value*c1->value;
				__nlSparseMatrixAdd(AtA, c0->index, c1->index, value);
			}
		}
	}
}
Exemplo n.º 2
0
static void __nlBeginMatrix() {
	NLuint i;
	NLuint n = 0;
	NLenum storage = __NL_ROWS;

	__nlTransition(__NL_STATE_SYSTEM, __NL_STATE_MATRIX);

	if (!__nlCurrentContext->solve_again) {
		for(i=0; i<__nlCurrentContext->nb_variables; i++) {
			if(!__nlCurrentContext->variable[i].locked)
				__nlCurrentContext->variable[i].index = n++;
			else
				__nlCurrentContext->variable[i].index = ~0;
		}

		__nlCurrentContext->n = n;

		/* a least squares problem results in a symmetric matrix */
		if(__nlCurrentContext->least_squares)
			__nlCurrentContext->symmetric = NL_TRUE;

		if(__nlCurrentContext->symmetric)
			storage = (storage | __NL_SYMMETRIC);

		/* SuperLU storage does not support symmetric storage */
		storage = (storage & ~__NL_SYMMETRIC);

		__nlSparseMatrixConstruct(&__nlCurrentContext->M, n, n, storage);
		__nlCurrentContext->alloc_M = NL_TRUE;

		__nlCurrentContext->x = __NL_NEW_ARRAY(NLfloat, n);
		__nlCurrentContext->alloc_x = NL_TRUE;
		
		__nlCurrentContext->b = __NL_NEW_ARRAY(NLfloat, n);
		__nlCurrentContext->alloc_b = NL_TRUE;
	}
	else {
		/* need to recompute b only, A is not constructed anymore */
		__NL_CLEAR_ARRAY(NLfloat, __nlCurrentContext->b, __nlCurrentContext->n);
	}

	__nlVariablesToVector();

	__nlRowColumnConstruct(&__nlCurrentContext->af);
	__nlCurrentContext->alloc_af = NL_TRUE;
	__nlRowColumnConstruct(&__nlCurrentContext->al);
	__nlCurrentContext->alloc_al = NL_TRUE;

	__nlCurrentContext->current_row = 0;
}
Exemplo n.º 3
0
static void __nlBeginMatrix() {
	NLuint i;
	NLuint m = 0, n = 0;
	NLenum storage = __NL_ROWS;
	__NLContext *context = __nlCurrentContext;

	__nlTransition(__NL_STATE_SYSTEM, __NL_STATE_MATRIX);

	if (!context->solve_again) {
		for(i=0; i<context->nb_variables; i++) {
			if(context->variable[i].locked) {
				context->variable[i].index = ~0;
				context->variable[i].a = __NL_NEW(__NLRowColumn);
				__nlRowColumnConstruct(context->variable[i].a);
			}
			else
				context->variable[i].index = n++;
		}

		m = (context->nb_rows == 0)? n: context->nb_rows;

		context->m = m;
		context->n = n;

		__nlSparseMatrixConstruct(&context->M, m, n, storage);
		context->alloc_M = NL_TRUE;

		context->b = __NL_NEW_ARRAY(NLfloat, m*context->nb_rhs);
		context->alloc_b = NL_TRUE;

		context->x = __NL_NEW_ARRAY(NLfloat, n*context->nb_rhs);
		context->alloc_x = NL_TRUE;
	}
	else {
		/* need to recompute b only, A is not constructed anymore */
		__NL_CLEAR_ARRAY(NLfloat, context->b, context->m*context->nb_rhs);
	}

	__nlVariablesToVector();
}