static void Main() { SubtractionElement sub = new SubtractionElement(); IntegerElement a = new IntegerElement(); IntegerElement b = new IntegerElement(); a.setText("5"); b.setText("5"); sub.setLhs(a); sub.setRhs(b); Element c; Element d; c = (Element)sub.getLhs(); d = (Element)sub.getRhs(); }
private void ParallelSub(SubtractionElement element) { VisitElement(element.getLhs()); parallelString.Append("-"); VisitElement(element.getRhs()); }
public override void VisitSubtractionElement(SubtractionElement element) { if (element.getRhs() == null) VisitElement(element.getLhs()); else { if (inParallelFor == 1) { ParallelSub(element); return; } else { VisitElement(element.getLhs()); VisitElement(element.getRhs()); if (mat_stack.Count >= 2) { Object obj_rhs = getTopOfStack_Matrix(); Object obj_lhs = getTopOfStack_Matrix(); int rhs_type = GetTypeOfElement((Element)obj_rhs); int lhs_type = GetTypeOfElement((Element)obj_lhs); if (rhs_type == 3 && lhs_type == 3) // check whether both are matrices or not { MatrixVariableDeclaration stk_rhs = (MatrixVariableDeclaration)(obj_rhs); MatrixVariableDeclaration stk_lhs = (MatrixVariableDeclaration)(obj_lhs); MatrixVariableDeclaration final = new MatrixVariableDeclaration(); if (stk_lhs != null && stk_rhs != null) { if (stk_lhs.getType() == stk_rhs.getType()) { IntegerElement lRow = (IntegerElement)(stk_lhs.getRow()); IntegerElement lCol = (IntegerElement)(stk_lhs.getColumn()); IntegerElement rRow = (IntegerElement)(stk_rhs.getRow()); IntegerElement rCol = (IntegerElement)(stk_rhs.getColumn()); int lhs_row = int.Parse(((IntegerElement)(stk_lhs.getRow())).getText()); int lhs_col = int.Parse(((IntegerElement)(stk_lhs.getColumn())).getText()); int rhs_row = int.Parse(((IntegerElement)(stk_rhs.getRow())).getText()); int rhs_col = int.Parse(((IntegerElement)(stk_rhs.getColumn())).getText()); if (lhs_row == rhs_row && lhs_col == rhs_col) { final.setRow(lRow); final.setColumn(lCol); final.setType(stk_lhs.getType()); Console.Write("Subtraction..\n"); Console.Write(element.getLhs().GetType()); string mat_type = stk_lhs.getType(); if (mat_type == "int") { int[,] rhs_elements = stk_rhs.getintValue(); int[,] lhs_elements = stk_lhs.getintValue(); int[,] output = new int[lhs_row, lhs_col]; for (int i = 0; i < lhs_row; i++) { for (int j = 0; j < lhs_col; j++) { output[i, j] = lhs_elements[i, j] - rhs_elements[i, j]; Console.Write(output[i, j]); Console.Write("\t"); } Console.Write("\n"); } bool mat_set = final.setIntMatrix(output); } else if (mat_type == "double") { double[,] rhs_elements = stk_rhs.getdoubleValue(); double[,] lhs_elements = stk_lhs.getdoubleValue(); double[,] output = new double[lhs_row, lhs_col]; for (int i = 0; i < lhs_row; i++) { for (int j = 0; j < lhs_col; j++) { output[i, j] = lhs_elements[i, j] - rhs_elements[i, j]; Console.Write(output[i, j]); Console.Write("\t"); } Console.Write("\n"); } bool mat_set = final.setDoubleMatrix(output); } Object result = (Object)(final); mat_stack.Push(result); } } else { Console.Write("Matrix dimensions does not match.. try again.. \n"); sendres(112, "Matrix dimensions does not match.. try again.. \n"); } } } else if (lhs_type == 2 && rhs_type == 2) { //Double PerformDoubleSubtraction(obj_rhs, obj_lhs); } else if (lhs_type == 1 && rhs_type == 1) { //Int PerformIntSubtraction(obj_rhs, obj_lhs); } else { Console.Write("Scalar and matrix subtraction not possible\n"); sendres(112, "Scalar and matrix subtraction not possible\n"); } } else { Console.Write("Matrix types are different.. try again.. "); sendres(112, "Matrix types are different.. try again.. "); } } } }