int main(int argc, char ** argv) { char op; char mStr[1024]; matrix ans, m1, m2; int sc = 0; if(argc > 1){ op = getOp(argv[1]); } else { printf("Which operation: "); op = getOp(NULL); } printf("First matrix:\n"); scanf("%s", mStr); m1 = MatrixInit(mStr); if(op == 'a' || op == 's' || op == 'm'){ printf("Second matrix:\n"); scanf("%s", mStr); m2 = MatrixInit(mStr); } else if(op == 'c') { printf("Scalar multiple:\n"); scanf("%d", &sc); } switch(op){ case 'a': ans = MatrixAdd(m1, m2); break; case 's': ans = MatrixSub(m1, m2); break; case 'm': ans = MatrixMul(m1, m2); break; case 'i': ans = MatrixInv(m1); break; case 'c': ans = MatrixSMul(m1, i2f(sc)); break; default: printf("Something went very wrong.\n"); return 1; } printf("Answer:\n"); MatrixPrint(ans); MatrixFree(m1); MatrixFree(ans); if(op == 'a' || op == 's' || op == 'm'){ MatrixFree(m2); } return 0; }
ParkingLot * InitParkingLot( FILE * mapconfig, int col, int row, int floors, int accesses ) { char *** matrix; int *vertices, *ramps; ParkingLot * parkinglot; vertices = (int*)malloc(sizeof(int)); VerifyMalloc( (Item) vertices ); ramps = (int*)malloc(sizeof(int)); VerifyMalloc( (Item) ramps ); parkinglot = (ParkingLot*) malloc( sizeof(ParkingLot) ); VerifyMalloc((Item) parkinglot); parkinglot->freespots = 0; matrix = MatrixInit(vertices, ramps, mapconfig, col, row, floors); /*Creates string cointaining the map - its a 3d string */ parkinglot->graphdecoder = GraphDecoderInit(matrix, col, row, floors, *vertices, &(parkinglot->freespots) ); /*Creates array cointaining the Decoder for the graph positions*/ parkinglot->g = GraphInit(*vertices, matrix, parkinglot->graphdecoder, col, row); parkinglot->accesseshead = InitAccesses(accesses, parkinglot->graphdecoder, *vertices); parkinglot->parkedcarshead = ListInit(); parkinglot->queuehead = ListInit(); /**PrintGraph(GetGraph(parkinglot), *vertices); */ /*prints the graph in the parkinglot */ FreeMatrix(matrix, col, row); free(vertices); free(ramps); return (parkinglot); }
void MatrixStackInit(MatrixStack *stack) { for (int i = 0; i < stack->size; i++) { MatrixInit(&stack->matrix[i*16]); } stack->position = 0; }
void MatrixStackSetMaxSize (MatrixStack *stack, int size){ stack->size = (size + 1); if (stack->matrix != NULL) { free (stack->matrix); } s32 stackSize = stack->size; stack->matrix = (float*) malloc ((stackSize<<4)*sizeof(float)); for (s32 i = 0; i < stackSize; ++i){ MatrixInit (&stack->matrix[i<<4]); } --stack->size; }
void MatrixStackSetMaxSize (MatrixStack *stack, int size) { int i; stack->size = (size + 1); if (stack->matrix != NULL) { free (stack->matrix); } stack->matrix = new s32[stack->size*16*sizeof(s32)]; for (i = 0; i < stack->size; i++) { MatrixInit (&stack->matrix[i*16]); } stack->size--; }
void MatrixStackSetMaxSize (MatrixStack *stack, int size) { int i; stack->size = size; if (stack->matrix != NULL) { free (stack->matrix); } stack->matrix = (float*) malloc (stack->size*16*sizeof(float)); for (i = 0; i < stack->size; i++) { MatrixInit (&stack->matrix[i*16]); } stack->size--; }
InteractiveResultsTable* InteractiveResultsTableInit(const ulong rows, const ulong columns, BOOL error) { ushort tester = 0; InteractiveResultsTable *table = (InteractiveResultsTable*) malloc(sizeof(InteractiveResultsTable)); if (!table){ printf("InteractiveResultsTableInit ERROR %s\n", strerror(errno)); return NULL; } if (!error) tester+=1; table->m_results = MatrixInit(rows, (columns/*+tester*/)); table->m_operation = NOT_CALCULATED; table->m_precsion = 0; table->m_total = 0; table->m_solution; return table; }
void SkJS::InitializeDisplayables(const SkBitmap& bitmap, JSContext *cx, JSObject *obj, JSObject *proto) { SkJSDisplayable::gCanvas = new SkCanvas(bitmap); SkJSDisplayable::gPaint = new SkPaint(); #if SK_USE_CONDENSED_INFO == 0 GenerateTables(); #else SkASSERT(0); // !!! compressed version hasn't been implemented #endif AddInit(cx, obj, proto); AddCircleInit(cx, obj, proto); AddOvalInit(cx, obj, proto); AddPathInit(cx, obj, proto); AddRectangleInit(cx, obj, proto); AddRoundRectInit(cx, obj, proto); // AfterInit(cx, obj, proto); ApplyInit(cx, obj, proto); // AnimateInit(cx, obj, proto); // AnimateColorInit(cx, obj, proto); AnimateFieldInit(cx, obj, proto); // AnimateRotateInit(cx, obj, proto); // AnimateScaleInit(cx, obj, proto); // AnimateTranslateInit(cx, obj, proto); BitmapInit(cx, obj, proto); // BaseBitmapInit(cx, obj, proto); // BeforeInit(cx, obj, proto); BitmapShaderInit(cx, obj, proto); BlurInit(cx, obj, proto); ClipInit(cx, obj, proto); ColorInit(cx, obj, proto); CubicToInit(cx, obj, proto); DashInit(cx, obj, proto); DataInit(cx, obj, proto); // DimensionsInit(cx, obj, proto); DiscreteInit(cx, obj, proto); DrawToInit(cx, obj, proto); EmbossInit(cx, obj, proto); EventInit(cx, obj, proto); // FontInit(cx, obj, proto); // FocusInit(cx, obj, proto); ImageInit(cx, obj, proto); IncludeInit(cx, obj, proto); // InputInit(cx, obj, proto); LineInit(cx, obj, proto); LinearGradientInit(cx, obj, proto); LineToInit(cx, obj, proto); MatrixInit(cx, obj, proto); MoveInit(cx, obj, proto); MoveToInit(cx, obj, proto); OvalInit(cx, obj, proto); PathInit(cx, obj, proto); PaintInit(cx, obj, proto); DrawPointInit(cx, obj, proto); PolyToPolyInit(cx, obj, proto); PolygonInit(cx, obj, proto); PolylineInit(cx, obj, proto); PostInit(cx, obj, proto); QuadToInit(cx, obj, proto); RadialGradientInit(cx, obj, proto); RandomInit(cx, obj, proto); RectToRectInit(cx, obj, proto); RectangleInit(cx, obj, proto); RemoveInit(cx, obj, proto); ReplaceInit(cx, obj, proto); RotateInit(cx, obj, proto); RoundRectInit(cx, obj, proto); ScaleInit(cx, obj, proto); SetInit(cx, obj, proto); SkewInit(cx, obj, proto); // 3D_CameraInit(cx, obj, proto); // 3D_PatchInit(cx, obj, proto); SnapshotInit(cx, obj, proto); // StrokeInit(cx, obj, proto); TextInit(cx, obj, proto); TextOnPathInit(cx, obj, proto); TextToPathInit(cx, obj, proto); TranslateInit(cx, obj, proto); // UseInit(cx, obj, proto); }
void MatrixStackInit(MatrixStack *stack){ for (s32 i = 0, stackSize = stack->size; i < stackSize; i++){ MatrixInit(&stack->matrix[i<<4]); } stack->position = 0; }
int main() { Matrix hX1; Matrix hX2; Matrix hX3; int16u i, j; int32s rand_int; float64 rand_double; float64 X1[X1_ROW][X1_COL]; float64 X2[X2_ROW][X2_COL]; float64 X3[X1_ROW][X2_COL]; MatrixInit(&hX1, X1_ROW, X1_COL, X1); MatrixInit(&hX2, X2_ROW, X2_COL, X2); MatrixInit(&hX3, X1_ROW, X2_COL, X3); srand(123); for(i=0; i<X1_ROW; i++) { for(j=0; j<X1_COL; j++) { rand_int = rand(); rand_double = rand_int / 31415926.53589795; X1[i][j] = rand_double; rand_int = rand(); rand_double = rand_int / 31415926.53589795; X2[j][i] = rand_double; } } //hw_MatrixMul(&hX1, &hX2, &hX3); sw_MatrixInverse(&hX1, &hX3); #if 1 for (i = 0; i < X1_ROW; i++) { for (j = 0; j < X2_COL; j++) { printf(" %f",X3[i][j]); } printf("\r\n"); } #endif #if 0 for (i = 0; i < X1_ROW; i++) { for (j = 0; j < X1_COL; j++) { printf(" %f",X1[i][j]); } printf("\r\n"); } #endif #if 0 for (i = 0; i < X2_ROW; i++) { for (j = 0; j < X2_COL; j++) { printf(" %f",X2[i][j]); } printf("\r\n"); } #endif return 0; }
void semantics(ASTnode* ASTroot){ firstMatrix=1; if(ASTroot==NULL){ return; } int z,noTraverse=0; ASTnode *rows,*l; token bufToken; SymbolTable *tmp; SymbolTableEntryNode *t; int p=0; if(sflag==0){ //first time, main function so create a symbol table for main function sflag=1; S[0]=createSymbolTable(size, NULL, "MAIN");//parentTable of Main is NULL symbolStack=createSymbolStack(); pushSymbolStack(S[0],symbolStack); p=1; counter++; } switch(ASTroot->label){ //Symbol Table creates only in 1, 61, 64 //Symbol table populates in 1:functionDef,31:declarationStmt case 1://make a new symbol table, this would be the scope unless an END is encountered, functionDef InsertSymbolTable(topSymbolStack(symbolStack), ASTroot); S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),ASTroot->array[1]->t.lexeme); pushSymbolStack(S[counter],symbolStack); InsertSymbolTableFun(topSymbolStack(symbolStack), ASTroot);//for input and output arguments of function p=1; counter++; break; case 2://ifstmt S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),"IF"); pushSymbolStack(S[counter],symbolStack); p=1; counter++; break; case 3: noTraverse=1; if(strcmp(topSymbolStack(symbolStack)->symbolTableName,ASTroot->array[0]->t.lexeme)==0){//checking for Recursion semanticError(3,ASTroot->array[0]->t); return; } //check for input parameter list and function signature- input and output tmp=topSymbolStack(symbolStack); while(tmp!=NULL){ z=SearchHashTable(tmp, ASTroot->array[0]->t.lexeme); if(z!=-1) break; else tmp=tmp->parentTable; } if(tmp==NULL){ semanticError(1,ASTroot->t); break; }//declaration of FunId is checked here itself t=findSymbolTableNode(tmp->table[z].next,ASTroot->array[0]->t.lexeme); if(t->type.fid.outputSize!=typeCounter){ semanticError(5,ASTroot->array[0]->t); break; } else{ for(z=0; z<=t->type.fid.outputSize; z++){ if(t->type.fid.output[z]!=type[z]){ semanticError(5,ASTroot->array[0]->t); noTraverse=1; break;//from for } } typeCounter=-1;//successfully implemented. } l=ASTroot->array[1]; for(z=0; z<=t->type.fid.inputSize; z++){ if(l==NULL){ semanticError(5,ASTroot->array[0]->t);//number of output parameters noTraverse=1; break; } if(t->type.fid.input[z]!=findTypeVar(l->array[0])){ semanticError(14,ASTroot->array[0]->t);//type Mismatch noTraverse=1; break; } l=l->array[1]; } break; case 11://else stmt S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),"ELSE"); pushSymbolStack(S[counter],symbolStack); p=1; counter++; break; case 26:if(ASTroot->array[0]->label==67){ t=getSymbolTableNode(ASTroot->array[1]); t->type.id.initialized=1; } case 27: break; case 28: break; //it should not come case 29: break; case 30: break; case 31://declaration stmt InsertSymbolTable(topSymbolStack(symbolStack), ASTroot); return; break; case 51://Assignment noTraverse=1; typeCounter=-1; if(ASTroot->array[1]->label==3){//function call statement if(ASTroot->array[0]->label==54){//single list if(outputCheck1(ASTroot->array[0])==0)//send leaf directly return; //1- it should already have been declared, 2-if so, then it's type should be recorded } else{ //send l if(outputCheck(ASTroot->array[0])==0) return; } semantics(ASTroot->array[1]); } if(ASTroot->array[1]->label==60){//size stmt //1- check if ID is declared, 2- What is the type of ID, 3- Compare with the return type if(!isDeclared(ASTroot->array[1]->array[0])){ semanticError(1,ASTroot->array[1]->array[0]->t); return; } z=findType(ASTroot->array[1]->array[0],0); if(z==57){ if(outputCheck(ASTroot->array[0])==0){//it will populate type of LHS if declared, else returns 0 return; } else{//declared if(!(typeCounter==0&&type[0]==57)) semanticError(6,ASTroot->array[0]->t); return; } } else if(z==58){ if(outputCheck(ASTroot->array[0])==0){//it will populate type of LHS if declared, else returns 0 return; } else{//declared if(!(typeCounter==1&&type[0]==55&&type[1]==55)) semanticError(6,ASTroot->array[0]->t); return; } } else { semanticError(8,ASTroot->array[1]->array[0]->t);//Size contains other that String and Matrix } } if(ASTroot->array[1]->label==37){//Arithmetic Expression l=ASTroot->array[0]; z=findType(l,1); if(l->label==54){ if(z==57){ if(ASTroot->array[1]->array[1]==NULL){ if(ASTroot->array[1]->array[0]->array[1]==NULL){ if(findTypeVar(ASTroot->array[1]->array[0]->array[0])==57){//initialization StringInit(ASTroot->array[0],ASTroot->array[1]->array[0]->array[0]->t.lexeme); return; } } } } else if(z==58){//lhs is matrix firstMatrix=1; if(ASTroot->array[1]->array[1]==NULL){ if(ASTroot->array[1]->array[0]->array[1]==NULL){ if((ASTroot->array[1]->array[0]->array[0]->label)==44){//initialization MatrixInit(ASTroot->array[0],ASTroot->array[1]->array[0]->array[0]); return; } } } } } if(z==-1) break; typeCounter++; type[typeCounter]=z; if((z=findTypeAE(ASTroot->array[1]))!=type[typeCounter]){ bufToken.lineNumber=l->t.lineNumber; semanticError(10,bufToken); break; } //valid Arithmetic expression //debug(); t= getSymbolTableNode(ASTroot->array[0]); t->type.id.initialized=1; typeCounter=-1; } break; case 52://go to case 54 case 54: if(!isDeclared(ASTroot)) semanticError(1,ASTroot->t); break; case 75:// AND case 76:// OR case 77:// LT case 78:// LE case 79:// EQ case 80:// GT case 81:// GE case 82:// NE case 83:// NOTbooleanExpressionSemantics(ASTnode* BE) noTraverse=1; if(booleanExpressionSemantics(ASTroot)==0){ semanticError(10,bufToken); } default: break; }//end of switch int i; if(noTraverse==0){ for( i=0; i<ASTroot->arraySize; i++){ if(ASTroot->array[i]!=NULL){ semantics(ASTroot->array[i]); } } } if(p){ //if popping SymbolTable is a function, then check if it's output parameter are accurately initialised or not tmp=popSymbolStack(symbolStack); if(strcmp(tmp->symbolTableName,"MAIN")!=0&&strcmp(tmp->symbolTableName,"IF")!=0&&strcmp(tmp->symbolTableName,"ELSE")!=0){//it is a function int i; for(i=0; i<tmp->outputParameter; i++){ t=outputParameterInitCheck(tmp,tmp->outputParameterLexeme[i]); if(t->type.id.initialized!=1) { semanticError(13,ASTroot->array[1]->t); break; } } } } }//end of function
int main(){ ulong i,j; LinearSystem *system; Matrix * matrix = MatrixInit(3,4); /* for(i=0; i < matrix->m_rows; i++) for(j=0; j < matrix->m_columns; j++) matrix->m_data[i][j] = (3.14 * (i+(j+1)) * 2) / 10; */ // ONLY TEST --------- matrix->m_data[0][0] = 1; matrix->m_data[0][1] = 1; matrix->m_data[0][2] = 2; matrix->m_data[0][3] = 9; matrix->m_data[1][0] = 0; matrix->m_data[1][1] = 2; matrix->m_data[1][2] = -7; matrix->m_data[1][3] = -17; matrix->m_data[2][0] = 3; matrix->m_data[2][1] = 6; matrix->m_data[2][2] = -5; matrix->m_data[2][3] = 0; // ----------------------- MatrixShow(matrix); system = LinearSystemInit(matrix, TRUE); MatrixShow(system->m_systemMatrix); MatrixDelete(matrix); //LinearSystemSetIndependentTermsVector(system, 0.1,0.2,0.3,0.5,0.4,0.03); MatrixShow(system->m_systemMatrix); LinearSystemGaussJordan(system); MatrixShow(system->m_solutionMatrix); LinearSystemDelete(system); Polynomial *pol = PolynomialInit(2); PolynomialSetConstants(pol, 1.0, 0.0,-3.0); OrderedPair *pair = (OrderedPair*) malloc(sizeof(OrderedPair)); pair->m_x = 1; pair->m_y = 2; printf("Intervals %lf %lf\n", pair->m_x, pair->m_y); PolynomialResultsTable *table = PolynomialRootBissection(pol,pair,10,0.01); //printf("%lu %lf\n",table->m_results->m_iterator, table->m_results[1].m_data[1]); if (table){ puts("\n Bissecao \n\n"); PolynomialResultsTableShow(table); PolynomialResultsTableDelete(table); } Polynomial *pol2 = PolynomialInit(3); PolynomialSetConstants(pol2,1.0,0.0,(-9.0),3.0); PolynomialShow(pol2); pair->m_x = 0; pair->m_y = 1; table = PolynomialRootSecant(pol2, pair , 10, 0.0005); puts("\n SECANTE \n\n"); PolynomialResultsTableShow(table); printf("\nRoot founded is: %lf\n", *table->m_root); PolynomialResultsTableDelete(table); PolynomialShow(pol); PolynomialDelete(pol); free(pair); PolynomialDelete(pol2); return 0; }
int main(void) { char mStr[1024]; matrix *ans, *m1, *m2; int sc = 0; printf("Which operation: "); char op = tolower(getchar()); while(op != '+' || op != '-' || op != '*' || op != '/' || op != 'i') { puts(opErr); op = tolower(getchar()); } printf("First matrix:\n"); scanf("%s", mStr); m1 = MatrixInit(mStr); MatrixPrint(m1); if(op == 'a' || op == 's' || op == 'm') { printf("Second matrix:\n"); scanf("%s", mStr); m2 = MatrixInit(mStr); MatrixPrint(m2); } else if(op == 'c') { printf("Scalar multiple:\n"); scanf("%d", &sc); } switch(op) { case 'a': ans = MatrixAdd(m1, m2); break; case 's': ans = MatrixSub(m1, m2); break; case 'm': ans = MatrixMul(m1, m2); break; case 'i': ans = MatrixInv(m1); break; case 'c': ans = MatrixSMul(m1, sc); break; default: printf("Something went very wrong.\n"); return 1; } printf("Answer:\n"); MatrixPrint(ans); MatrixFree(m1); MatrixFree(ans); if(op == 'a' || op == 's' || op == 'm') { MatrixFree(m2); } return 0; }