private bool InitGaTables() { _log.Append("Initializing GA Data..."); labelStatus.Text = _log.ToString(); Application.DoEvents(); try { GMacLookupTables.Choose(1, 1); _log.AppendLine("Done").AppendLine(); labelStatus.Text = _log.ToString(); Application.DoEvents(); return(true); } catch (Exception e) { _log.AppendLine("Failed").AppendLine(e.Message).AppendLine(); labelStatus.Text = _log.ToString(); Application.DoEvents(); return(false); } }
private static string PatternsRangeSample() { Composer.Clear(); Composer.AppendLine("PatternsBetween(3, 12):"); AddPatternsListToComposer(BitUtils.PatternsBetween(3, 12)); Composer.AppendLineAtNewLine(PageSeparator).AppendLine(); Composer.AppendLine("PatternsBetween(12, 3):"); AddPatternsListToComposer(BitUtils.PatternsBetween(12, 3)); Composer.AppendLineAtNewLine(PageSeparator).AppendLine(); Composer.AppendLine("OnesPermutations(5, 2):"); AddPatternsListToComposer(BitUtils.OnesPermutations(5, 2)); Composer.AppendLineAtNewLine(PageSeparator).AppendLine(); Composer.AppendLine("OnesPermutations(5, 3):"); AddPatternsListToComposer(BitUtils.OnesPermutations(5, 3)); Composer.AppendLineAtNewLine(PageSeparator).AppendLine(); Composer.AppendLine("ZerosPermutations(5, 2):"); AddPatternsListToComposer(BitUtils.ZerosPermutations(5, 2)); Composer.AppendLineAtNewLine(PageSeparator).AppendLine(); Composer.AppendLine("ZerosPermutations(5, 3):"); AddPatternsListToComposer(BitUtils.ZerosPermutations(5, 3)); Composer.AppendLineAtNewLine(PageSeparator).AppendLine(); return(Composer.ToString()); }
private string GenerateClassCode() { var composer = new LinearComposer(); composer.AppendLineAtNewLine(GenerateDeclareCoefsText()); composer.AppendLineAtNewLine(GenerateAbstractCoefsText()); composer.AppendAtNewLine( MainCodeTemplate, "mv_class_name", ClassData.ClassName, "mv_class_id", ClassData.ClassId, "frame", CurrentFrameName, "double", GMacLanguage.ScalarTypeName, "iszero_code", GenerateIsZeroCode(), "norm2_code", GenerateNorm2Code(), "isequal_cases", GenerateAbstractMethodCases("IsEqual"), "op_cases", GenerateAbstractMethodCases("OP"), "gp_cases", GenerateAbstractMethodCases("GP"), "lcp_cases", GenerateAbstractMethodCases("LCP"), "rcp_cases", GenerateAbstractMethodCases("RCP"), "sp_cases", GenerateAbstractMethodCases("SP"), "add_cases", GenerateAbstractMethodCases("Add"), "subtract_cases", GenerateAbstractMethodCases("Subtract") ); return(composer.ToString()); }
/// <summary> /// Generate a string containing some statistics about the final text inside /// the files of this composer /// </summary> /// <returns></returns> public string GenerateStatistics() { var composer = new LinearComposer(); composer .AppendLineAtNewLine("Composer Log:") .AppendLineAtNewLine(_log.ToString()) .AppendLine(); var totalLines = 0; var totalCharacters = 0; foreach (var pair in _fileComposersDictionary) { int linesCount, charsCount; composer.AppendAtNewLine( pair.Value.GenerateStatistics(RootFolder, FilesEncoding, out linesCount, out charsCount) ); totalLines += linesCount; totalCharacters += charsCount; } composer .AppendLine() .AppendAtNewLine("Total Files: ") .AppendLine(_fileComposersDictionary.Count.ToString("###,###,###,###")) .AppendAtNewLine("Total Lines: ") .AppendLine(totalLines.ToString("###,###,###,###")) .AppendAtNewLine("Total Characters: ") .AppendLine(totalCharacters.ToString("###,###,###,###")); return(composer.ToString()); }
public override string ToString() { var textBuilder = new LinearComposer(); ToString(textBuilder); return(textBuilder.ToString()); }
public string ToTextTree() { var log = new LinearComposer(); ToTextTree(log); return(log.ToString()); }
public string GenerateCode(ISyntaxTreeElement syntaxElement) { TextComposer.Clear(); syntaxElement.AcceptVisitor(this); return(TextComposer.ToString()); }
public string SectionsTreeToText() { var log = new LinearComposer(); SectionsTreeToText(log); return(log.ToString()); }
private string GenerateProductMethodCode(string macroName, out string resultClassName) { SetBaseMacro(CurrentFrame.Macro(macroName)); var computationsText = GenerateComputationsCode(); //The result is zero if (MacroCodeGenerator.CodeBlock.NonZeroOutputVariables.Any() == false) { //The result is the zero multivector if (BaseMacro.OutputType.IsValidMultivectorType) { resultClassName = MvLibraryGenerator.MultivectorClassesData[0].ClassName; return("return Zero;"); } //The result is the scalar zero resultClassName = GMacLanguage.ScalarTypeName; return("return " + GMacLanguage.ScalarZero + ";"); } //The result is not zero string resultDeclarationText; if (BaseMacro.OutputType.IsValidMultivectorType) { var grades = MacroCodeGenerator .CodeBlock .NonZeroOutputVariables .Select(v => v.ValueAccess.GetBasisBlade().Grade) .Distinct(); var id = grades.Sum(grade => 1 << grade); resultClassName = MvLibraryGenerator.MultivectorClassesData[id].ClassName; resultDeclarationText = "var result = new " + resultClassName + "();"; } else { resultClassName = GMacLanguage.ScalarTypeName; resultDeclarationText = "var result = " + GMacLanguage.ScalarZero + ";"; } var composer = new LinearComposer(); composer .AppendLineAtNewLine(resultDeclarationText) .AppendLine() .AppendLineAtNewLine(computationsText) .AppendAtNewLine("return result;"); return(composer.ToString()); }
public string Execute() { var composer = new LinearComposer(); foreach (var test in this) { composer .AppendLineAtNewLine(test.Execute()) .AppendLine(); } return(composer.ToString()); }
public static string InitializeGMac() { var log = new LinearComposer(); try { log.Append("Initializing GA Data..."); GMacLookupTables.Choose(1, 1); log.AppendLine("Done").AppendLine(); log.Append("Initializing GMac Resources..."); if (Directory.Exists(IconsPath) == false) { Directory.CreateDirectory(IconsPath); } SaveIcon(Resources.BasisVector64, "BasisVector64"); SaveIcon(Resources.Compile64, "Compile64"); SaveIcon(Resources.Constant64, "Constant64"); SaveIcon(Resources.Filter64, "Filter64"); SaveIcon(Resources.Frame64, "Frame64"); SaveIcon(Resources.GMacAST64, "GMacAST64"); SaveIcon(Resources.GMac_Icon64, "GMac_Icon64"); SaveIcon(Resources.Idea64, "Idea64"); SaveIcon(Resources.Input64, "Input64"); SaveIcon(Resources.Macro64, "Macro64"); SaveIcon(Resources.Namespace64, "Namespace64"); SaveIcon(Resources.Output64, "Output64"); SaveIcon(Resources.Scalar64, "Scalar64"); SaveIcon(Resources.Structure64, "Structure64"); SaveIcon(Resources.Subspace64, "Subspace64"); SaveIcon(Resources.Transform64, "Transform64"); log.AppendLine("Done").AppendLine(); log.Append("Initializing Symbolic Engine..."); MathematicaScalar.Create(SymbolicUtils.Cas, "0"); log.AppendLine("Done").AppendLine(); } catch (Exception e) { log.AppendLine("Failed").AppendLine(e.Message).AppendLine(); } return(log.ToString()); }
/// <summary> /// Set final text to the text generated from the linear composer and clear the linear composer /// </summary> /// <returns></returns> public TextFileComposer FinalizeText() { if (IsFinalized) { return(this); } FinalText = _textComposer.ToString(); _textComposer = null; IsFinalized = true; return(this); }
public void SaveScript(string filePath) { var composer = new LinearComposer(); composer .AppendLine("[shortcuts]") .AppendLine(Ipr.Shortcuts) .AppendLine("[namespaces]") .AppendLine(OpenedNamespaces.Concatenate(Environment.NewLine)) .AppendLine() .AppendLine("[members]") .AppendLine(ScriptClassMembersText) .AppendLine("[script]") .AppendLine(ScriptText); File.WriteAllText(filePath, composer.ToString()); }
//private void ComputeTableSize() //{ //} public override string ToString() { var rowHeadersWidth = RowsInfo.Max(r => r.Header.Length); var colHeadersWidth = ColumnsInfo.Max(c => c.Header.Length); var maxItemWidth = Math.Max(rowHeadersWidth, colHeadersWidth); for (var c = 0; c < Columns; c++) { for (var r = 0; r < Rows; r++) { if (maxItemWidth < Items[r, c].Length) { maxItemWidth = Items[r, c].Length; } } } var composer = new LinearComposer(); //Add column headers composer.Append(FormatItem("", maxItemWidth)); for (var c = 0; c < Columns; c++) { composer.Append(FormatItem(ColumnsInfo[c].Header, maxItemWidth)); } composer.AppendLine(); //Add rows for (var r = 0; r < Rows; r++) { composer.Append(FormatItem(RowsInfo[r].Header, maxItemWidth)); for (var c = 0; c < Columns; c++) { composer.Append(FormatItem(Items[r, c], maxItemWidth)); } composer.AppendLine(); } return(composer.ToString()); }
private string GenerateIsEqualMethod() { var codeText = GenerateIsEqualMethodCode(); var template = new ParametricComposer("#", "#", BilinearTemplateText); var composer = new LinearComposer(); composer.Append( template, "result_type", "bool", "op_name", "IsEqual", "mv_class_name", CalcClassData.ClassName, "code", codeText ); return(composer.ToString()); }
/// <summary> /// This method generates a full report regarding any errors in the structure /// of this AST /// </summary> /// <returns></returns> public string VerifyAst() { var composer = new LinearComposer(); //Chack for macros without a command body foreach (var macro in this.Macros()) { if (macro.SymbolBody == null) { composer .AppendAtNewLine("Macro <") .Append(macro.SymbolAccessName) .AppendLine("> Has null Command Body!"); } } return(composer.ToString()); }
public override string ToString() { var composer = new LinearComposer(); composer .AppendLineAtNewLine(@"<TR>") .IncreaseIndentation(); foreach (var cell in _cells) { composer.AppendLineAtNewLine(cell.ToString()); } composer .DecreaseIndentation() .AppendAtNewLine(@"</TR>"); return(composer.ToString()); }
private string GenerateProductMethod(string macroName) { string resultClassName; var codeText = GenerateProductMethodCode(macroName, out resultClassName); var template = new ParametricComposer("#", "#", BilinearTemplateText); var composer = new LinearComposer(); composer.Append( template, "result_type", resultClassName, "op_name", BaseMacro.Name, "mv_class_name", CalcClassData.ClassName, "code", codeText ); return(composer.ToString()); }
public override string ToString() { var s = new LinearComposer(); s.Append(ProgressId.ToString("D6")).Append(": ").Append(FullTimingText); s.AppendLineAtNewLine(FullTitle); if (String.IsNullOrEmpty(Details) == false) { s.AppendLineAtNewLine() .AppendLineAtNewLine("Begin Details") .IncreaseIndentation() .AppendAtNewLine(Details) .DecreaseIndentation() .AppendLineAtNewLine("End Details"); } return(s.ToString()); }
private string GenerateSubtractMethod() { var resultId = ClassData.ClassId | CalcClassData.ClassId; var resultClassData = MvLibraryGenerator.MultivectorClassesData[resultId]; var codeText = GenerateSubtractMethodCode(resultClassData); var template = new ParametricComposer("#", "#", BilinearTemplateText); var composer = new LinearComposer(); composer.Append( template, "result_type", resultClassData.ClassName, "op_name", "Subtract", "mv_class_name", CalcClassData.ClassName, "code", codeText ); return(composer.ToString()); }
private string GenerateClassCode() { var macroNames = new[] { DefaultMacro.EuclideanBinary.OuterProduct, DefaultMacro.MetricBinary.GeometricProduct, DefaultMacro.MetricBinary.LeftContractionProduct, DefaultMacro.MetricBinary.RightContractionProduct, DefaultMacro.MetricBinary.ScalarProduct }; var composer = new LinearComposer(); if (MvLibraryGenerator.MacroGenDefaults.AllowGenerateMacroCode) { foreach (var macroName in macroNames) { composer.AppendAtNewLine( GenerateProductMethod(macroName) ); } } composer.AppendAtNewLine( GenerateAddMethod() ); composer.AppendAtNewLine( GenerateSubtractMethod() ); composer.AppendAtNewLine( GenerateIsEqualMethod() ); return(composer.ToString()); }
public override string ToString() { var textComposer = new LinearComposer(); var idStack = new Stack <ulong>(); var nodeStack = new Stack <IGMacBinaryTreeNode <T> >(); idStack.Push(0ul); nodeStack.Push(this); while (nodeStack.Count > 0) { var id = idStack.Pop(); var node = nodeStack.Pop(); var level = TreeDepth - node.TreeDepth; if (node.IsLeafNode) { textComposer .AppendAtNewLine("<") .Append(id.PatternToString(level)) .Append("> ") .Append("".PadRight(level * 2, ' ')) .Append("Leaf { ") .Append(node.Value.ToString()) .AppendLine(" }"); continue; } if (node.TreeDepth == TreeDepth) { textComposer .AppendAtNewLine("<") .Append("".PadRight(TreeDepth, '-')) .Append("> ") .AppendLine("Root"); } else { textComposer .AppendAtNewLine("<") .Append( id .PatternToString(TreeDepth) .Substring(0, level) .PadRight(TreeDepth, '-') ) .Append("> ") .Append("".PadRight(level * 2, ' ')) .AppendLine("Node"); } if (node.HasChildNode1) { idStack.Push(id | node.ChildNode1.BitMask); nodeStack.Push(node.ChildNode1); } if (node.HasChildNode0) { idStack.Push(id); nodeStack.Push(node.ChildNode0); } } return(textComposer.ToString()); }
public string ToTreeString() { var textComposer = new LinearComposer(); var levelStack = new Stack <int>(); var idStack = new Stack <int>(); var nodeStack = new Stack <IGaTreeMultivectorNode>(); levelStack.Push(0); idStack.Push(0); nodeStack.Push(this); while (nodeStack.Count > 0) { var level = levelStack.Pop(); var id = idStack.Pop(); var node = nodeStack.Pop(); var leafNode = node as GaTreeMultivectorLeaf; if (!ReferenceEquals(leafNode, null)) { textComposer .AppendAtNewLine("".PadLeft(level * 2, ' ')) .Append("Leaf <") .Append(id.PatternToString(level)) .Append("> { ") .Append(id.BasisBladeName()) .Append(" = ") .Append(leafNode.Value.ExpressionText) .AppendLine(" }"); continue; } if (node.IsRoot) { textComposer .AppendAtNewLine("".PadLeft(level * 2, ' ')) .AppendLine("Multivector"); } else { textComposer .AppendAtNewLine("".PadLeft(level * 2, ' ')) .Append("Node <") .Append(id.PatternToString(level)) .AppendLine(">"); } var rightChild = node.GetRightChild(); if (!ReferenceEquals(rightChild, null)) { levelStack.Push(level + 1); idStack.Push(id); nodeStack.Push(rightChild); } var leftChild = node.GetLeftChild(); if (!ReferenceEquals(leftChild, null)) { levelStack.Push(level + 1); idStack.Push((1 << level) | id); nodeStack.Push(leftChild); } } return(textComposer.ToString()); }
public string Execute() { var randGen = new GMacRandomGenerator(10); var textComposer = new LinearComposer(); var numFrame = GaNumFrame.CreateConformal(5); var symFrame = GaSymFrame.CreateConformal(5); var numMv1 = randGen.GetNumMultivectorFull(numFrame.GaSpaceDimension); var numMv2 = randGen.GetNumMultivectorFull(numFrame.GaSpaceDimension); var symMv1 = numMv1.ToSymbolic(); var symMv2 = numMv2.ToSymbolic(); var symMvGp = symFrame.Gp[symMv1, symMv2]; //textComposer.AppendLineAtNewLine("Symbolic Multivector 1: ").AppendLine(symMv1); //textComposer.AppendLineAtNewLine("Numeric Multivector 1: ").AppendLine(numMv1); //textComposer.AppendLineAtNewLine("Symbolic Multivector 2: ").AppendLine(symMv2); //textComposer.AppendLineAtNewLine("Numeric Multivector 2: ").AppendLine(numMv2); //textComposer.AppendLineAtNewLine("Symbolic Gp: ").AppendLine(symMvGp); //textComposer.AppendLineAtNewLine("Numeric GP: ").AppendLine(numMvGp); numFrame.SetProductsImplementation(GaBilinearProductImplementation.Computed); GaNumMultivector.ResetAddFactorsCallCount(); var numMvGp = numFrame.Gp[numMv1, numMv2]; var callsCount = GaNumMultivector.AddFactorsCallCount; var diff = symMvGp.ToNumeric() - numMvGp; diff.Simplify(); GaNumMultivector.ResetAddFactorsCallCount(); textComposer .AppendLineAtNewLine("Difference, Computed Tree: ") .AppendLine(callsCount) .AppendLine(diff); numFrame.SetProductsImplementation(GaBilinearProductImplementation.LookupArray); GaNumMultivector.ResetAddFactorsCallCount(); numMvGp = numFrame.Gp[numMv1, numMv2]; callsCount = GaNumMultivector.AddFactorsCallCount; //var factorsCount = ((GaNumMapBilinearArray) numFrame.Gp).FactorsCount; diff = symMvGp.ToNumeric() - numMvGp; diff.Simplify(); GaNumMultivector.ResetAddFactorsCallCount(); textComposer .AppendLineAtNewLine("Difference, Lookup Array: ") .AppendLine(callsCount) //.AppendLine(factorsCount) .AppendLine(diff); numFrame.SetProductsImplementation(GaBilinearProductImplementation.LookupHash); GaNumMultivector.ResetAddFactorsCallCount(); numMvGp = numFrame.Gp[numMv1, numMv2]; callsCount = GaNumMultivector.AddFactorsCallCount; //factorsCount = ((GaNumMapBilinearHash)numFrame.Gp).FactorsCount; diff = symMvGp.ToNumeric() - numMvGp; diff.Simplify(); GaNumMultivector.ResetAddFactorsCallCount(); textComposer .AppendLineAtNewLine("Difference, Lookup Hash: ") .AppendLine(callsCount) //.AppendLine(factorsCount) .AppendLine(diff); numFrame.SetProductsImplementation(GaBilinearProductImplementation.LookupTree); GaNumMultivector.ResetAddFactorsCallCount(); numMvGp = numFrame.Gp[numMv1, numMv2]; callsCount = GaNumMultivector.AddFactorsCallCount; //factorsCount = ((GaNumMapBilinearTree)numFrame.Gp).FactorsCount; diff = symMvGp.ToNumeric() - numMvGp; diff.Simplify(); GaNumMultivector.ResetAddFactorsCallCount(); textComposer .AppendLineAtNewLine("Difference, Lookup Tree: ") .AppendLine(callsCount) //.AppendLine(factorsCount) .AppendLine(diff); numFrame.SetProductsImplementation(GaBilinearProductImplementation.LookupCoefSums); GaNumMultivector.ResetAddFactorsCallCount(); numMvGp = numFrame.Gp[numMv1, numMv2]; callsCount = GaNumMultivector.AddFactorsCallCount; //factorsCount = ((GaNumMapBilinearCoefSums)numFrame.Gp).FactorsCount; diff = symMvGp.ToNumeric() - numMvGp; diff.Simplify(); GaNumMultivector.ResetAddFactorsCallCount(); textComposer .AppendLineAtNewLine("Difference, Lookup CoefSums: ") .AppendLine(callsCount) //.AppendLine(factorsCount) .AppendLine(diff); return(textComposer.ToString()); }