void evaluateASTNodeFactor(ASTNode *node){ MatList *p; switch (node->subType) { case FactorParen: case FactorFuncExp: /*just clone the result*/ node->mat = cloneMatrix(node->l->mat); break; case FactorNumber: node->mat = createSingletonMatrix(node->l->scalarValue); break; case FactorID: strcpy(node->identifier, node->l->identifier); p = outMatList(node->identifier); if (strcmp(p->identifier,node->identifier)==0){ node->mat = cloneMatrix(p->mat);} break; case FactorBracketedMatrix: node->mat = cloneMatrix(node->l->mat); break; /* some work left undone */ default: break; } return; }
void evaluateASTNodeArg(ASTNode *node){ MatList *p; switch (node->subType) { case ArgNumber: node->mat = createSingletonMatrix(node->l->scalarValue); break; case ArgID: strcpy(node->identifier, node->l->identifier); p = outMatList(node->identifier); if (strcmp(p->identifier,node->identifier)==0){ node->mat = cloneMatrix(p->mat);} get_submatrix = 1; break; case ArgVectorExp: node->l->mat = createBracketedMatrix(node->l->start,node->l->step,node->l->end); node->mat = cloneMatrix(node->l->mat); get_submatrix = 1; break; case ArgColon: node->mat = createEyeMatrix(0); //changeOneElementOfMatrix(node->mat,1,1,COLONLABEL);/*COLONLABEL = 0 */ break; default: break; } return; }
void evaluateASTNodeExpression(ASTNode *node){ MatList *p; Matrix result; ASTNode *argNode[10]; Number figure; switch (node->subType) { case ExpSimpleAssign: p = intoMatList(node->l->identifier,node->r->mat); matrixList->mat = cloneMatrix(p->mat); displayInternalInfoOfMatlist(p); node->mat = cloneMatrix(node->r->mat); break; case ExpPartAssign: /* Still not written*/ p = checkMatList(node->l->identifier); argNode[0] = getNthArgFromArgList(node->r,1); argNode[1] = getNthArgFromArgList(node->r,2); figure = readOneElementOfMatrix(node->a->mat,1,1); matrixList->mat = createEyeMatrix(1); changeOneElementOfMatrix(matrixList->mat,1,1,figure); changeOneElementOfMatrix(p->mat,(int)readOneElementOfMatrix(argNode[0]->mat,1,1),(int)readOneElementOfMatrix(argNode[1]->mat,1,1),figure); printf("%s(%d,%d) = \n",p->identifier,(int)readOneElementOfMatrix(argNode[0]->mat,1,1),(int)readOneElementOfMatrix(argNode[1]->mat,1,1)); printf("%f\n",figure); break; case ExpSimpleExp: /*just clone the result*/ node->mat = cloneMatrix(node->l->mat); matrixList->mat = cloneMatrix(node->mat); displayMatrix(node->mat); break; default: break; } return; }
void evaluateASTNodeBracketedMatrix(ASTNode *node){ switch (node->subType) { case DefaultSubType: node->mat = cloneMatrix(node->l->mat); break; default: break; } return; }
void GS(Matrix u, double tolerance, int maxit) { int it=0; Matrix b = cloneMatrix(u); Matrix e = cloneMatrix(u); Matrix v = cloneMatrix(u); int* sizes, *displ; splitVector(u->rows-2, 2*max_threads(), &sizes, &displ); copyVector(b->as_vec, u->as_vec); fillVector(u->as_vec, 0.0); double max = tolerance+1; while (max > tolerance && ++it < maxit) { copyVector(e->as_vec, u->as_vec); copyVector(u->as_vec, b->as_vec); for (int color=0;color<2;++color) { for (int i=1;i<u->cols-1;++i) { #pragma omp parallel { int cnt=displ[get_thread()*2+color]+1; for (int j=0;j<sizes[get_thread()*2+color];++j, ++cnt) { u->data[i][cnt] += v->data[i][cnt-1]; u->data[i][cnt] += v->data[i][cnt+1]; u->data[i][cnt] += v->data[i-1][cnt]; u->data[i][cnt] += v->data[i+1][cnt]; u->data[i][cnt] /= 4.0; v->data[i][cnt] = u->data[i][cnt]; } } } } axpy(e->as_vec, u->as_vec, -1.0); max = sqrt(innerproduct(e->as_vec, e->as_vec)); } printf("number of iterations %i %f\n", it, max); freeMatrix(b); freeMatrix(e); freeMatrix(v); free(sizes); free(displ); }
void evaluateASTNodeSubMatrixListRow(ASTNode *node){ switch (node->subType) { case SubMatrixListRowSingle: node->mat = cloneMatrix(node->l->mat); break; case SubMatrixListRowMultiple: node->mat = cmbMatrixListRow(node->l->mat,node->r->mat); break; default: break; } return; }
void evaluateASTNodeSubMatrix(ASTNode *node){ switch (node->subType) { case SubMatrixVectorExp: #ifdef DEBUGGING_ON printf("evaluate SubMatrixVectorExp!\n"); #endif node->l->mat = createBracketedMatrix(node->l->start,node->l->step,node->l->end); node->mat = cloneMatrix(node->l->mat); break; case SubMatrixID: node->mat = callFunc(node->l->identifier, node->r); break; case SubMatrixNumber: node->mat = createSingletonMatrix(node->l->scalarValue); break; default: break; } return; }
void evaluateASTNodeSimpleExp(ASTNode *node){ switch (node->subType) { case SimpleExpTerm: /*just clone the result*/ node->mat = cloneMatrix(node->l->mat); break; case SimpleExpPlus: node->mat = addMatrix(node->l->mat, node->r->mat); break; case SimpleExpMinus: node->mat = minusMatrix(node->l->mat, node->r->mat); break; case SimpleExpPower: node->mat = powerMatrix(node->l->mat, (int)readOneElementOfMatrix(node->r->mat,1,1)); break; default: break; } return; }
void evaluateASTNodeTerm(ASTNode *node){ switch (node->subType) { case TermFactor: /*just clone the result*/ node->mat = cloneMatrix(node->l->mat); break; case TermTimes: node->mat = multiplyMatrix(node->l->mat, node->r->mat); break; case TermDivide: node->mat = divideMatrix(node->l->mat, node->r->mat); break; case TermMod: node->mat = modMatrix(node->l->mat, node->r->mat); break; case TermTurn: node->mat = turnMatrix(node->l->mat); break; default: break; } return; }
AUD_Error gmm_clone( void **phGmmHandle, void *hSrcGmmHandle, AUD_Int8s *pName ) { AUD_ASSERT( phGmmHandle && hSrcGmmHandle ); AUD_ASSERT( *phGmmHandle == NULL ); AUD_Int32s ret = 0; GmmModel *pState = NULL; pState = (GmmModel*)calloc( sizeof(GmmModel), 1 ); if ( pState == NULL ) { *phGmmHandle = NULL; return AUD_ERROR_OUTOFMEMORY; } GmmModel *pSrcModel = (GmmModel*)hSrcGmmHandle; if ( pName == NULL ) { snprintf( (char*)pState->arGmmName, MAX_GMMNAME_LENGTH, "%s", (char*)pSrcModel->arGmmName ); } else { snprintf( (char*)pState->arGmmName, MAX_GMMNAME_LENGTH, "%s", (char*)pName ); } pState->numMix = pSrcModel->numMix; pState->width = pSrcModel->width; pState->step = pState->width; pState->means.rows = pState->numMix; pState->means.cols = pState->step; pState->means.dataType = AUD_DATATYPE_INT32S; ret = createMatrix( &(pState->means) ); AUD_ASSERT( ret == 0 ); ret = cloneMatrix( &(pState->means), &(pSrcModel->means) ); AUD_ASSERT( ret == 0 ); pState->cvars.rows = pState->numMix; pState->cvars.cols = pState->step; pState->cvars.dataType = AUD_DATATYPE_INT64S; ret = createMatrix( &(pState->cvars) ); AUD_ASSERT( ret == 0 ); ret = cloneMatrix( &(pState->cvars), &(pSrcModel->cvars) ); AUD_ASSERT( ret == 0 ); pState->weights.len = pState->numMix; pState->weights.dataType = AUD_DATATYPE_DOUBLE; ret = createVector( &(pState->weights) ); AUD_ASSERT( ret == 0 ); ret = cloneVector( &(pState->weights), &(pSrcModel->weights) ); AUD_ASSERT( ret == 0 ); pState->dets.len = pState->numMix; pState->dets.dataType = AUD_DATATYPE_DOUBLE; ret = createVector( &(pState->dets) ); AUD_ASSERT( ret == 0 ); ret = cloneVector( &(pState->dets), &(pSrcModel->dets) ); AUD_ASSERT( ret == 0 ); *phGmmHandle = pState; return AUD_ERROR_NONE; }
AUD_Error gmm_init( void **phGmmHandle, AUD_Int8s *pModelName, AUD_Int32s numMix, AUD_Int32s featDim, AUD_Vector *pWeights, AUD_Matrix *pMeans, AUD_Matrix *pCvars ) { AUD_ASSERT( phGmmHandle && pModelName && pWeights && pMeans && pCvars ); AUD_ASSERT( *phGmmHandle == NULL ); AUDLOG( "init model: %s\n", pModelName ); AUD_Int32s ret = 0; GmmModel *pState = NULL; pState = (GmmModel*)calloc( sizeof(GmmModel), 1 ); if ( pState == NULL ) { *phGmmHandle = NULL; return AUD_ERROR_OUTOFMEMORY; } strncpy( (char*)pState->arGmmName, (char*)pModelName, MAX_GMMNAME_LENGTH - 1 ); pState->arGmmName[strlen( (char*)pModelName )] = '\0'; pState->numMix = numMix; pState->width = featDim; pState->step = pState->width; pState->means.rows = pState->numMix; pState->means.cols = pState->step; pState->means.dataType = AUD_DATATYPE_INT32S; ret = createMatrix( &(pState->means) ); AUD_ASSERT( ret == 0 ); if ( pMeans != NULL ) { ret = cloneMatrix( &(pState->means), pMeans ); AUD_ASSERT( ret == 0 ); } pState->cvars.rows = pState->numMix; pState->cvars.cols = pState->step; pState->cvars.dataType = AUD_DATATYPE_INT64S; ret = createMatrix( &(pState->cvars) ); AUD_ASSERT( ret == 0 ); if ( pCvars != NULL ) { ret = cloneMatrix( &(pState->cvars), pCvars ); AUD_ASSERT( ret == 0 ); } pState->weights.len = pState->numMix; pState->weights.dataType = AUD_DATATYPE_DOUBLE; ret = createVector( &(pState->weights) ); AUD_ASSERT( ret == 0 ); if ( pWeights != NULL ) { ret = cloneVector( &(pState->weights), pWeights ); AUD_ASSERT( ret == 0 ); } pState->dets.len = pState->numMix; pState->dets.dataType = AUD_DATATYPE_DOUBLE; ret = createVector( &(pState->dets) ); AUD_ASSERT( ret == 0 ); calcdet( &(pState->cvars), &(pState->weights), &(pState->dets) ); *phGmmHandle = pState; return AUD_ERROR_NONE; }