Beispiel #1
0
void nlEndRow() {
    NLRowColumn*    af = &nlCurrentContext->af ;
    NLRowColumn*    al = &nlCurrentContext->al ;
    NLRowColumn*    xl = &nlCurrentContext->xl ;
    NLSparseMatrix* M  = &nlCurrentContext->M  ;
	NLdouble*       b  = nlCurrentContext->b ;
	NLuint          nf = af->size ;
	NLuint          nl = al->size ;
    NLuint current_row = nlCurrentContext->current_row ;
    NLuint i ;
    NLuint j ;
    NLdouble S ;
    nlTransition(NL_STATE_ROW, NL_STATE_MATRIX) ;

    if(nlCurrentContext->normalize_rows) {
        nlNormalizeRow(nlCurrentContext->row_scaling) ;
    } else {
        nlScaleRow(nlCurrentContext->row_scaling) ;
    }

    // if least_squares : we want to solve
    // A'A x = A'b
    //
	if(nlCurrentContext->least_squares) {
		if(!nlCurrentContext->matrix_already_set) {
			for(i=0; i<nf; i++) {
				for(j=0; j<nf; j++) {
					nlSparseMatrixAdd(
						M, af->coeff[i].index, af->coeff[j].index,
						af->coeff[i].value * af->coeff[j].value
					) ;
				}
			}
		}

		S = - nlCurrentContext->right_hand_side ;
        for(j=0; j<nl; j++) {
            S += al->coeff[j].value * xl->coeff[j].value ;
        }
        for(i=0; i<nf; i++) {
			b[af->coeff[i].index] -= af->coeff[i].value * S ;
        }
	} else {
		if(!nlCurrentContext->matrix_already_set) {
			for(i=0; i<nf; i++) {
				nlSparseMatrixAdd(
					M, current_row, af->coeff[i].index, af->coeff[i].value
				) ;
			}
		}
        b[current_row] = -nlCurrentContext->right_hand_side ;
        for(i=0; i<nl; i++) {
            b[current_row] -= al->coeff[i].value * xl->coeff[i].value ;
        }
    }

    nlCurrentContext->current_row++ ;
    nlCurrentContext->right_hand_side = 0.0 ;    
	nlCurrentContext->row_scaling     = 1.0 ;
}
Beispiel #2
0
void nlEndRow() {
    NLRowColumn*    af = &nlCurrentContext->af ;
    NLRowColumn*    al = &nlCurrentContext->al ;
    NLRowColumn*    xl = &nlCurrentContext->xl ;
    NLSparseMatrix* M  = &nlCurrentContext->M  ;
    NLdouble* b        = nlCurrentContext->b ;
    NLuint nf          = af->size ;
    NLuint nl          = al->size ;
    NLuint current_row = nlCurrentContext->current_row ;
    NLuint i ;
    NLuint j ;
    NLdouble S ;
    nlTransition(NL_STATE_ROW, NL_STATE_MATRIX) ;

    if(nlCurrentContext->normalize_rows) {
        nlNormalizeRow(nlCurrentContext->row_scaling) ;
    } else {
        nlScaleRow(nlCurrentContext->row_scaling) ;
    }

    if(nlCurrentContext->least_squares) {
        for(i=0; i<nf; i++) {
            for(j=0; j<nf; j++) {
                nlSparseMatrixAdd(
                    M, af->coeff[i].index, af->coeff[j].index,
                    af->coeff[i].value * af->coeff[j].value
                ) ;
            }
        }
        S = -nlCurrentContext->right_hand_side ;
        for(j=0; j<nl; j++) {
            S += al->coeff[j].value * xl->coeff[j].value ;
        }
        for(i=0; i<nf; i++) {
            b[ af->coeff[i].index ] -= af->coeff[i].value * S ;
        }
    } else {
        for(i=0; i<nf; i++) {
            nlSparseMatrixAdd(
                M, current_row, af->coeff[i].index, af->coeff[i].value
            ) ;
        }
        b[current_row] = nlCurrentContext->right_hand_side ; /* [Bruno] Fixed RHS bug in non-least-squares mode*/
        for(i=0; i<nl; i++) {
            b[current_row] -= al->coeff[i].value * xl->coeff[i].value ;
        }
    }
    nlCurrentContext->current_row++ ;
    nlCurrentContext->right_hand_side = 0.0 ;    
    nlCurrentContext->row_scaling     = 1.0 ;
}