コード例 #1
0
ファイル: opennl.c プロジェクト: mik0001/Blender
static void __nlSparseMatrixClear( __NLSparseMatrix* M) {
	NLuint i;
	if(M->storage & __NL_ROWS) {
		for(i=0; i<M->m; i++) {
			__nlRowColumnClear(&(M->row[i]));
		}
	}
	if(M->storage & __NL_COLUMNS) {
		for(i=0; i<M->n; i++) {
			__nlRowColumnClear(&(M->column[i]));
		}
	}
	__NL_CLEAR_ARRAY(NLfloat, M->diag, M->diag_size);	
}
コード例 #2
0
ファイル: opennl.cpp プロジェクト: erli2/parameterization
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;
}
コード例 #3
0
ファイル: opennl.c プロジェクト: mik0001/Blender
static void __nlSparseMatrix_mult_cols(
	__NLSparseMatrix* A, NLfloat* x, NLfloat* y
) {
	NLuint n = A->n;
	NLuint j,ii; 
	__NLRowColumn* Cj = NULL;
	__NLCoeff* c = NULL;
	__NL_CLEAR_ARRAY(NLfloat, y, A->m);
	for(j=0; j<n; j++) {
		Cj = &(A->column[j]);
		for(ii=0; ii<Cj->size; ii++) {
			c = &(Cj->coeff[ii]);
			y[c->index] += c->value * x[j];
		}
	}
}
コード例 #4
0
ファイル: opennl.c プロジェクト: mik0001/Blender
static void __nlSparseMatrix_transpose_mult_rows(
	__NLSparseMatrix* A, NLfloat* x, NLfloat* y
) {
	NLuint m = A->m;
	NLuint n = A->n;
	NLuint i,ij;
	__NLRowColumn* Ri = NULL;
	__NLCoeff* c = NULL;

	__NL_CLEAR_ARRAY(NLfloat, y, n);

	for(i=0; i<m; i++) {
		Ri = &(A->row[i]);
		for(ij=0; ij<Ri->size; ij++) {
			c = &(Ri->coeff[ij]);
			y[c->index] += c->value * x[i];
		}
	}
}
コード例 #5
0
ファイル: opennl.c プロジェクト: mik0001/Blender
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();
}