当前位置: 首页>>代码示例>>C#>>正文


C# Specification.OutputCppOrC方法代码示例

本文整理汇总了C#中Specification.OutputCppOrC方法的典型用法代码示例。如果您正苦于以下问题:C# Specification.OutputCppOrC方法的具体用法?C# Specification.OutputCppOrC怎么用?C# Specification.OutputCppOrC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Specification的用法示例。


在下文中一共展示了Specification.OutputCppOrC方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDualCode

 /// <summary>
 /// Returns the code for dualization wrt to whole space using metric <c>M</c>.
 /// The code is composed of calls to functions generated by <c>WriteGmvDualParts()</c>.
 /// 
 /// This function uses <c>cdg.m_gmvDualPartFuncNames</c>, but only to check whether a
 /// geometric product of some group with the pseudoscalar will get non-zero results in some
 /// other group.
 /// 
 /// The returned code is only the body. The function declaration is not included.
 /// </summary>
 /// <param name="S">Specification of algebra (used for general multivector type, output language).</param>
 /// <param name="cgd">Used for <c>m_gmvDualPartFuncNames</c>.</param>
 /// <param name="FT">Floating point type.</param>
 /// <param name="M">The metric of the dual.</param>
 /// <param name="FAI">Info about function arguments</param>
 /// <param name="resultName">Name of variable where the result goes (in the generated code).</param>
 /// <param name="dual">When true, 'dual' is generated, otherwise, 'undual' is generated.</param>
 /// <returns>code for the requested product type.</returns>
 public static string GetDualCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, 
     G25.Metric M, G25.CG.Shared.FuncArgInfo[] FAI, string resultName, bool dual)
 {
     if (S.OutputCppOrC())
         return GetDualCodeCppOrC(S, cgd, FT, M, FAI, resultName, dual);
     else return GetDualCodeCSharpOrJava(S, cgd, FT, M, FAI, resultName, dual);
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:25,代码来源:dual_parts.cs

示例2: WriteSetMatrix

        public static void WriteSetMatrix(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som, bool transpose)
        {
            int NB_ARGS = 1;
            string[] argTypes = new string[NB_ARGS];
            string[] argNames = new string[NB_ARGS];
            argTypes[0] = FT.type;
            argNames[0] = "M";

            // construct image values
            RefGA.Multivector[] imageValue = new RefGA.Multivector[som.DomainVectors.Length];
            for (int d = 0; d < som.DomainVectors.Length; d++)
            {
                //imageValue[d] = RefGA.Multivector.ZERO;
                RefGA.BasisBlade[] IV = new RefGA.BasisBlade[som.RangeVectors.Length];
                for (int r = 0; r < som.RangeVectors.Length; r++)
                {
                    int matrixIdx = (transpose) ? (d * som.RangeVectors.Length + r) : (r * som.DomainVectors.Length + d);
                    string entryName = argNames[0] + "[" + matrixIdx + "]";
                    IV[r] = new RefGA.BasisBlade(som.RangeVectors[r].bitmap, 1.0, entryName);
                }
                imageValue[d] = new RefGA.Multivector(IV);
            }

            string typeName = FT.GetMangledName(S, som.Name);
            string funcName = GetFunctionName(S, typeName, "set", "_setMatrix");
            if (transpose) funcName = funcName + "Transpose";

            //argNames[0] = "*" + argNames[0]; // quick hack: add pointer to name instead of type!
            G25.fgs F = new G25.fgs(funcName, funcName, "", argTypes, argNames, new String[] { FT.type }, null, null, null); // null, null = metricName, comment, options
            F.InitArgumentPtrFromTypeNames(S);
            if (S.OutputCppOrC())
                F.m_argumentPtr[0] = true;
            else F.m_argumentArr[0] = true;
            bool computeMultivectorValue = false;
            G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, NB_ARGS, FT, S.m_GMV.Name, computeMultivectorValue);

            G25.CG.Shared.FuncArgInfo returnArgument = null;
            if (S.OutputC())
                returnArgument = new G25.CG.Shared.FuncArgInfo(S, F, -1, FT, som.Name, computeMultivectorValue);

            // setup instructions
            List<G25.CG.Shared.Instruction> I = new List<G25.CG.Shared.Instruction>();
            {
                bool mustCast = false;
                int nbTabs = 1;
                string dstName = (S.OutputC()) ? G25.fgs.RETURN_ARG_NAME : SmvUtil.THIS;
                bool dstPtr = S.OutputCppOrC();
                bool declareDst = false;
                for (int g = 1; g < som.Domain.Length; g++)
                {
                    for (int c = 0; c < som.DomainForGrade(g).Length; c++)
                    {
                        G25.SMVOM smvOM = som.DomainSmvForGrade(g)[c];
                        RefGA.BasisBlade domainBlade = som.DomainForGrade(g)[c];
                        RefGA.Multivector value = new RefGA.Multivector(new RefGA.BasisBlade(domainBlade, 0)); // copy the scalar part, ditch the basis blade
                        for (uint v = 0; v < som.DomainVectors.Length; v++)
                        {
                            if ((domainBlade.bitmap & som.DomainVectors[v].bitmap) != 0)
                            {
                                value = RefGA.Multivector.op(value, imageValue[v]);
                            }
                        }

                        I.Add(new G25.CG.Shared.CommentInstruction(nbTabs, "Set image of " + domainBlade.ToString(S.m_basisVectorNames)));
                        I.Add(new G25.CG.Shared.AssignInstruction(nbTabs, smvOM, FT, mustCast, value, dstName, dstPtr, declareDst));
                    }
                }

            }

            Comment comment = new Comment("Sets " + typeName + " from a " + (transpose ? "transposed " : "") + "matrix.");
            bool writeDecl = (S.OutputC());
            bool staticFunc = false;
            G25.CG.Shared.Functions.WriteFunction(S, cgd, F, S.m_inlineSet, staticFunc, "void", funcName, returnArgument, FAI, I, comment, writeDecl);
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:75,代码来源:om_init.cs

示例3: WriteSetIdentity

        /// <summary>
        /// Writes a function to set an SOM struct/class to identity
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Results go here. Also intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT"></param>
        /// <param name="som"></param>
        public static void WriteSetIdentity(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            StringBuilder declSB = cgd.m_declSB;
            StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB;

            if (S.OutputC())
                declSB.AppendLine();
            defSB.AppendLine();

            string typeName = FT.GetMangledName(S, som.Name);
            string funcName = GetFunctionName(S, typeName, "setIdentity", "_setIdentity");

            bool mustCast = false;

            G25.fgs F = new G25.fgs(funcName, funcName, "", null, null, new String[] { FT.type }, null, null, null); // null, null = metricName, comment, options
            F.InitArgumentPtrFromTypeNames(S);
            bool computeMultivectorValue = false;

            G25.CG.Shared.FuncArgInfo returnArgument = null;
            if (S.OutputC())
                returnArgument = new G25.CG.Shared.FuncArgInfo(S, F, -1, FT, som.Name, computeMultivectorValue);

            // setup instructions
            List<G25.CG.Shared.Instruction> I = new List<G25.CG.Shared.Instruction>();
            {
                int nbTabs = 1;
                mustCast = false;
                string valueName = (S.OutputC()) ? G25.fgs.RETURN_ARG_NAME : SmvUtil.THIS;
                bool valuePtr = S.OutputCppOrC();
                bool declareValue = false;
                for (int g = 1; g < som.Domain.Length; g++)
                {
                    for (int c = 0; c < som.DomainForGrade(g).Length; c++)
                    {
                        G25.SMVOM smvOM = som.DomainSmvForGrade(g)[c];
                        I.Add(new G25.CG.Shared.AssignInstruction(nbTabs, smvOM, FT, mustCast, new RefGA.Multivector(som.DomainForGrade(g)[c]), valueName, valuePtr, declareValue));
                    }
                }
            }

            Comment comment = new Comment("Sets " + typeName + " to identity.");
            bool writeDecl = S.OutputC();
            bool staticFunc = false;
            G25.CG.Shared.Functions.WriteFunction(S, cgd, F, S.m_inlineSet, staticFunc, "void", funcName, returnArgument, new G25.CG.Shared.FuncArgInfo[0], I, comment, writeDecl);
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:52,代码来源:om_init.cs

示例4: WriteSetCopy

        public static void WriteSetCopy(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            StringBuilder declSB = cgd.m_declSB;
            StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB;

            if (S.OutputC())
                declSB.AppendLine();
            defSB.AppendLine();

            string typeName = FT.GetMangledName(S, som.Name);
            string funcName = GetFunctionName(S, typeName, "set", "_set");

            bool mustCast = false;

            const int NB_ARGS = 1;
            string srcName = "src";
            bool srcPtr = S.OutputC();
            G25.fgs F = new G25.fgs(funcName, funcName, "", new String[] { som.Name }, new String[] { srcName }, new String[] { FT.type }, null, null, null); // null, null = metricName, comment, options
            F.InitArgumentPtrFromTypeNames(S);
            bool computeMultivectorValue = false;
            G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, NB_ARGS, FT, S.m_GMV.Name, computeMultivectorValue);

            G25.CG.Shared.FuncArgInfo returnArgument = null;
            if (S.OutputC())
                returnArgument = new G25.CG.Shared.FuncArgInfo(S, F, -1, FT, som.Name, computeMultivectorValue);

            // setup instructions
            List<G25.CG.Shared.Instruction> I = new List<G25.CG.Shared.Instruction>();
            {
                int nbTabs = 1;
                mustCast = false;
                string dstName = (S.OutputC()) ? G25.fgs.RETURN_ARG_NAME : SmvUtil.THIS;
                bool dstPtr = (S.OutputCppOrC());
                bool declareDst = false;
                for (int g = 1; g < som.Domain.Length; g++)
                {
                    for (int c = 0; c < som.DomainForGrade(g).Length; c++)
                    {
                        G25.SMVOM smvOM = som.DomainSmvForGrade(g)[c];
                        RefGA.Multivector srcValue = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, smvOM, srcName, srcPtr);
                        I.Add(new G25.CG.Shared.AssignInstruction(nbTabs, smvOM, FT, mustCast, srcValue, dstName, dstPtr, declareDst));
                    }
                }
            }

            Comment comment = new Comment("Copies " + typeName + "."); ;
            bool writeDecl = (S.OutputC());
            bool staticFunc = false;
            G25.CG.Shared.Functions.WriteFunction(S, cgd, F, S.m_inlineSet, staticFunc, "void", funcName, returnArgument, FAI, I, comment, writeDecl);
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:50,代码来源:om_init.cs

示例5: WriteOMtoOMcopy

        public static void WriteOMtoOMcopy(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, OM srcOm, OM dstOm)
        {
            StringBuilder declSB = cgd.m_declSB;
            StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB;
            string srcTypeName = FT.GetMangledName(S, srcOm.Name);
            string dstTypeName = FT.GetMangledName(S, dstOm.Name);
            bool writeDecl = S.OutputC();

            string funcName = GetFunctionName(S, (S.OutputC() ? "" : dstTypeName), "set", srcTypeName + "_to_" + dstTypeName);

            // do we inline this func?
            string inlineStr = G25.CG.Shared.Util.GetInlineString(S, S.m_inlineSet, " ");
            string dstArgStr = (S.OutputC()) ? (dstTypeName + " *dst, ") : "";
            string refStr = (S.OutputC()) ? "*" : ((S.OutputCpp()) ? "&" : "");
            string CONST = (S.OutputCppOrC()) ? "const " : "";

            string funcDecl = inlineStr + "void " + funcName + "(" + dstArgStr + CONST + srcTypeName + " " + refStr + "src)";

            // write comment, function declaration
            Comment comment = new Comment("Copies a " + srcTypeName + " to a " + dstTypeName + "\n" +
                "Warning 1: coordinates which cannot be represented are silenty lost.\n" +
                "Warning 2: coordinates which are not present in 'src' are set to zero in 'dst'.\n");
            if (writeDecl)
            {
                comment.Write(declSB, S, 0);
                declSB.Append(funcDecl);
                declSB.AppendLine(";");
            }

            if (S.OutputCSharpOrJava())
                comment.Write(defSB, S, 0);

            defSB.Append(funcDecl);
            {
                defSB.AppendLine(" {");

                Dictionary<Tuple<int, int, int>, Tuple<int, int, double>> D = dstOm.getMapping(srcOm);

                StringBuilder copySB = new StringBuilder();
                List<string> setToZero = new List<string>();

                string matrixStr = (S.OutputC()) ? "m" : "m_m";
                string dstMatrixStr = (S.OutputC()) ? "dst->" + matrixStr : matrixStr;
                string ptrStr = (S.OutputC()) ? "->" : ".";

                // For all grades of som, for all columns, for all rows, check D, get entry, set; otherwise set to null
                // Do not use foreach() on D because we want to fill in coordinates in their proper order.
                for (int gradeIdx = 1; gradeIdx < dstOm.Domain.Length; gradeIdx++)
                {
                    for (int somRangeIdx = 0; somRangeIdx < dstOm.Range[gradeIdx].Length; somRangeIdx++)
                    {
                        for (int somDomainIdx = 0; somDomainIdx < dstOm.Domain[gradeIdx].Length; somDomainIdx++)
                        {
                            Tuple<int, int, int> key = new Tuple<int, int, int>(gradeIdx, somDomainIdx, somRangeIdx);

                            int somMatrixIdx = dstOm.getCoordinateIndex(gradeIdx, somDomainIdx, somRangeIdx);
                            string dstString = dstMatrixStr + gradeIdx + "[" + somMatrixIdx + "] = ";
                            if (D.ContainsKey(key))
                            {
                                Tuple<int, int, double> value = D[key];
                                int gomMatrixIdx = srcOm.getCoordinateIndex(gradeIdx, value.Value1, value.Value2);
                                double multiplier = value.Value3;
                                string multiplierString = (multiplier == 1.0) ? "" : (FT.DoubleToString(S, multiplier) + " * ");

                                copySB.AppendLine("\t" + dstString + multiplierString + " src" + ptrStr + matrixStr + gradeIdx + "[" + gomMatrixIdx + "];");
                            }
                            else
                            {
                                setToZero.Add(dstString);
                            }
                        }
                    }
                }

                // append copy statements
                defSB.Append(copySB);

                // append statements to set coordinates to zero
                if (setToZero.Count > 0)
                {
                    int cnt = 0;
                    defSB.Append("\t");
                    foreach (string str in setToZero)
                    {
                        defSB.Append(str);
                        cnt++;
                        if (cnt > 8)
                        {
                            cnt = 0;
                            defSB.AppendLine("");
                            defSB.Append("\t\t");
                        }
                    }
                    defSB.AppendLine(FT.DoubleToString(S, 0.0) + ";");
                }

                defSB.AppendLine("}");
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:99,代码来源:om_init.cs

示例6: WriteFunction

        public static void WriteFunction(
            Specification S, G25.CG.Shared.CGdata cgd, G25.fgs F,
            bool inline, bool staticFunc, string returnType, string functionName,
            FuncArgInfo returnArgument, FuncArgInfo[] arguments,
            System.Collections.Generic.List<Instruction> instructions, Comment comment)
        {
            bool writeDecl = S.OutputCppOrC();

            WriteFunction(S, cgd, F, inline, staticFunc, returnType, functionName, returnArgument, arguments, instructions, comment, writeDecl);
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:10,代码来源:functions.cs

示例7: WriteGmvGpParts

        /// <summary>
        /// Writes pieces of code to <c>cgd</c> which compute the geometric product of general multivectors,
        /// on a group by group basis. The function is output language aware.
        /// </summary>
        /// <param name="S">Specification (used for output language, GMV).</param>
        /// <param name="cgd">Result goes here, and <c>cgd.m_gmvGPpartFuncNames</c> is set.</param>
        public static void WriteGmvGpParts(Specification S, CGdata cgd)
        {
            G25.GMV gmv = S.m_GMV;

            string name1 = "A";
            string name2 = "B";
            string name3 = "C";
            bool ptr = true;
            int allGroups = -1;
            bool mustCast = false;
            int nbBaseTabs = (S.OutputCSharpOrJava()) ? 1 : 0;
            int nbCodeTabs = 1 + nbBaseTabs;
            bool writeZeros = false;

            // get two symbolic multivectors (with different symbolic names):
            RefGA.Multivector[] M1 = null, M2 = null;
            if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
            {
                M1 = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, name1, ptr, allGroups);
                M2 = G25.CG.Shared.Symbolic.GMVtoSymbolicMultivector(S, gmv, name2, ptr, allGroups);
            }

            foreach (G25.FloatType FT in S.m_floatTypes)
            {
                bool fromOutsideRuntimeNamespace = true;
                string runtimeComputeGpFuncName = GetRuntimeComputeGpFuncName(S, FT, fromOutsideRuntimeNamespace);

                int metricId = 0;
                foreach (G25.Metric M in S.m_metric)
                {
                    // map from code fragment to name of function
                    Dictionary<string, string> generatedCode = new Dictionary<string, string>();

                    for (int g1 = 0; g1 < gmv.NbGroups; g1++)
                    {
                        for (int g2 = 0; g2 < gmv.NbGroups; g2++)
                        {
                            RefGA.Multivector M3 = null;
                            if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                            {
                                M3 = RefGA.Multivector.gp(M1[g1], M2[g2], M.m_metric);
                                // round value if required by metric
                                if (M.m_round) M3 = M3.Round(1e-14);
                            }

                            for (int gd = 0; gd < gmv.NbGroups; gd++)
                            {
                                // get function name
                                string funcName = GetGPpartFunctionName(S, FT, M, g1, g2, gd);

                                // get assignment code
                                string code = ""; // empty string means 'no code for this combo of g1, g2, gd and metric'.

                                if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                { // code for full expansion
                                    int dstBaseIdx = 0;
                                    code = G25.CG.Shared.CodeUtil.GenerateGMVassignmentCode(S, FT, mustCast, gmv, name3, gd, dstBaseIdx, M3, nbCodeTabs, writeZeros);
                                    // replace '=' with '+='
                                    code = code.Replace("=", "+=");
                                }
                                else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                { // code for runtime geometric product
                                    string EMP = (S.OutputCppOrC()) ? "&" : "";

                                    if (!S.m_GMV.IsZeroGP(g1, g2, gd))
                                    {
                                        fromOutsideRuntimeNamespace = true;
                                        string runtimeGpTableName = GetRuntimeGpTableName(S, M, g1, g2, gd, fromOutsideRuntimeNamespace);
                                        if (S.OutputCSharpOrJava())
                                        {
                                            string initFunc = S.OutputJava() ? "initRuntimeGpTable" : "InitRuntimeGpTable";

                                            code = "\t\tif(" + runtimeGpTableName + " == null) " +
                                              runtimeGpTableName + " = " + initFunc + "(" + metricId + ", " + g1 + ", " + g2 + ", " + gd + ");\n\t";
                                        }
                                        code += "\t" + runtimeComputeGpFuncName + "(" + name1 + ", " + name2 + ", " + name3 +
                                            ", " + EMP + runtimeGpTableName + ", " + metricId + ", " + g1 + ", " + g2 + ", " + gd + ");\n";
                                    }
                                }

                                // set the function names of parts of the geometric product
                                cgd.m_gmvGPpartFuncNames[new Tuple<string, string, string>(FT.type, M.m_name, funcName)] = (code.Length > 0);

                                if (code.Length > 0)
                                {
                                    // check if code was already generated, and, if so, reuse it
                                    if ((S.m_gmvCodeGeneration == GMV_CODE.EXPAND) && generatedCode.ContainsKey(code))
                                    {
                                        // ready generated: call that function
                                        code = new string('\t', nbCodeTabs) + generatedCode[code] + "(" + name1 + ", " + name2 + ", " + name3 + ");\n";
                                    }
                                    else
                                    {
                                        // not generated yet: remember code -> function
//.........这里部分代码省略.........
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:gp_parts.cs

示例8: GetExpandCode

 /// <summary>
 /// Generates 'expand general multivector code'. This code makes the general multivector
 /// available as a list of pointers to grade parts.
 /// 
 /// Used internally by <c>WriteGmvGpParts()</c>,
 /// but also by e.g. <c>DualParts.GetDualCode()</c>.
 /// </summary>
 /// <param name="S">Used for output language and dimension of space.</param>
 /// <param name="cgd">Currently not used.</param>
 /// <param name="FT">Code for this float type is generated.</param>
 /// <param name="FAI">Used to determine whether an argument is scalar or general multivector.</param>
 /// <param name="resultIsScalar">The expand code also contains code to allocate coordinates of the result.
 /// When a scalar is going to be returned, only '1' needs to be allocated, otherwise <c>2^S.m_dimension</c>
 /// coordinates should be allocated.</param>
 /// <param name="initResultToZero">Whether to set the result coordinates 'c' to 0.</param>
 /// <returns></returns>
 public static string GetExpandCode(Specification S, G25.CG.Shared.CGdata cgd, 
     G25.FloatType FT, G25.CG.Shared.FuncArgInfo[] FAI, bool resultIsScalar, bool initResultToZero)
 {
     if (S.OutputCppOrC())
         return GetExpandCodeCppOrC(S, cgd, FT, FAI, resultIsScalar, initResultToZero);
     else return GetExpandCodeCSharpOrJava(S, cgd, FT, FAI, resultIsScalar, initResultToZero);
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:23,代码来源:gp_parts.cs

示例9: GetUnaryToggleSignCode

 /// <summary>
 /// Returns the code for any negation, reversion, conjugation or grade involution function of general multivectors.
 /// The code is composed of calls to functions generated by <c>WriteCASNparts()</c>.
 /// 
 /// The returned code is only the body. The function declaration is not included.
 /// </summary>
 /// <param name="S">Specification of algebra (used for output language).</param>
 /// <param name="cgd">Currently not used.</param>
 /// <param name="FT">Floating point type.</param>
 /// <param name="T">What function to generate</param>
 /// <param name="FAI">Info about function arguments</param>
 /// <param name="resultName">Name of variable where the result goes (in the generated code).</param>
 /// <returns>code for the requested product type.</returns>
 public static string GetUnaryToggleSignCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, 
     UnaryToggleSignType T,
     G25.CG.Shared.FuncArgInfo[] FAI, string resultName)
 {
     if (S.OutputCppOrC())
         return GetUnaryToggleSignCodeCppOrC(S, cgd, FT, T, FAI, resultName);
     else return GetUnaryToggleSignCodeCSharpOrJava(S, cgd, FT, T, FAI, resultName);
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:21,代码来源:copy_add_sub_neg_parts.cs

示例10: GetGradeCode

 /// <summary>
 /// Returns the code for grade selection for general multivectors.
 /// The code is composed of calls to functions generated by WriteCASNparts().
 /// 
 /// The returned code is only the body. The function declaration is not included.
 /// </summary>
 /// <param name="S">Specification of algebra (used for output language).</param>
 /// <param name="cgd">Used to resolve dependecy (<c>grade()</c> function).</param>
 /// <param name="FT">Floating point type.</param>
 /// <param name="gradeIdx">Grade of function (use -1 for user-specified)</param>
 /// <param name="FAI">Info about function arguments</param>
 /// <param name="resultName">Name of variable where the result goes (in the generated code).</param>
 /// <param name="groupBitmapName">Name of the (integer) variable which holds the groupBitmap.</param>
 /// <returns>code for the requested product type.</returns>
 public static string GetGradeCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
     int gradeIdx,
     G25.CG.Shared.FuncArgInfo[] FAI, string resultName, string groupBitmapName)
 {
     if (S.OutputCppOrC())
         return GetGradeCodeCppOrC(S, cgd, FT, gradeIdx, FAI, resultName, groupBitmapName);
     else return GetGradeCodeCSharpOrJava(S, cgd, FT, gradeIdx, FAI, resultName, groupBitmapName);
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:22,代码来源:copy_add_sub_neg_parts.cs

示例11: GetAddSubtractHpCode

 /// <summary>
 /// Returns the code addition/subtraction/hadamard product of two general multivectors. 
 /// The code is composed of calls to functions generated by <c>WriteCASNparts()</c>.
 /// 
 /// The returned code is only the body. The function declaration is not included.
 /// </summary>
 /// <param name="S">Specification of algebra (used for general multivector type, output language).</param>
 /// <param name="cgd">Currently not used.</param>
 /// <param name="FT">Floating point type.</param>
 /// <param name="funcType">Whether to generate addition, subtraction or Hadamard product code.</param>
 /// <param name="FAI">Info about function arguments.</param>
 /// <param name="resultName">Name of variable where the result goes (in the generated code).</param>
 /// <returns>code for the requested product type.</returns>
 public static string GetAddSubtractHpCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, 
     ADD_SUB_HP_TYPE funcType,
     G25.CG.Shared.FuncArgInfo[] FAI, string resultName)
 {
     if (S.OutputCppOrC())
         return GetAddSubtractHpCode_C_CPP(S, cgd, FT, funcType, FAI, resultName);
     else return GetAddSubtractHpCode_CSharp_Java(S, cgd, FT, funcType, FAI, resultName);
 }
开发者ID:Sciumo,项目名称:gaigen,代码行数:21,代码来源:copy_add_sub_neg_parts.cs

示例12: WriteDualParts


//.........这里部分代码省略.........
                foreach (G25.Metric M in S.m_metric)
                {
                    if (M.m_metric.IsDegenerate()) continue; // do not generate code for degenerate metrics

                    for (int g1 = 0; g1 < gmv.NbGroups; g1++)
                    {
                        for (int d = 1; d >= 0; d--) // d = 1 -> generate dual, d = 0 -> generate undual
                        {
                            // get value of operation, name of function:
                            RefGA.Multivector value = null;
                            if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                            {
                                try
                                {
                                    value = (d == 0) ? RefGA.Multivector.Undual(M1[g1], M.m_metric) : RefGA.Multivector.Dual(M1[g1], M.m_metric);
                                }
                                catch (Exception)
                                {
                                    cgd.AddError(new G25.UserException("Non-invertable pseudoscalar. Do not generate (un)dual functions for degenerate metrics."));
                                    return;
                                }
                                if (M.m_round) value = value.Round(1e-14);
                            }

                            int grade = gmv.Group(g1)[0].Grade();
                            int dualGrade = S.m_dimension - grade;
                            for (int g3 = 0; g3 < gmv.NbGroups; g3++)
                            {
                                if (gmv.Group(g3)[0].Grade() == dualGrade)
                                {
                                    string funcName = (d == 0) ? GetUndualPartFunctionName(S, FT, M, g1, g3) : GetDualPartFunctionName(S, FT, M, g1, g3);

                                    // get assignment code
                                    string code = "";

                                    if (S.m_gmvCodeGeneration == GMV_CODE.EXPAND)
                                    { // full code expansion
                                        int dstBaseIdx = 0;
                                        code = G25.CG.Shared.CodeUtil.GenerateGMVassignmentCode(S, FT, mustCast, gmv, name3, g3, dstBaseIdx, value, nbCodeTabs, writeZeros);
                                    }
                                    else if (S.m_gmvCodeGeneration == GMV_CODE.RUNTIME)
                                    { // runtime code
                                        code = GetRuntimeDualCode(S, FT, M, d, g1, g3, name1, name2, name3);
                                    }

                                    cgd.m_gmvDualPartFuncNames[new Tuple<string, string, string>(FT.type, M.m_name, funcName)] = (code.Length > 0);

                                    if (code.Length == 0) continue; // only if code is non-empty

                                    // is the following ever required: (i.e. the dual of a basis blade wrt to the full space is not a single basis blade?)
                                    //if (!M.m_metric.IsDiagonal())
                                    //    code = code.Replace("=", "+=");

                                    // check if code was already generated, and, if so, reuse it
                                    if (generatedCode.ContainsKey(code))
                                    {
                                        // ready generated: call that function
                                        code = new string('\t', nbCodeTabs) + generatedCode[code] + "(" + name1 + ", " + name3 + ");\n";
                                    }
                                    else
                                    {
                                        // not generated yet: remember code -> function
                                        generatedCode[code] = funcName;
                                    }

                                    // write comment
                                    string comment = "Computes the partial " + ((d == 0) ? "un" : "") + "dual (w.r.t. full space) of a multivector.";

                                    string ACCESS = "";
                                    if (S.OutputJava()) ACCESS = "protected final static ";
                                    else if (S.OutputCSharp()) ACCESS  = "protected internal static ";
                                    string ARR = (S.OutputCSharpOrJava()) ? "[] " : " *";
                                    string CONST = (S.OutputCSharpOrJava()) ? "" : "const ";

                                    string funcDecl = ACCESS + "void " + funcName + "(" + CONST + FT.type + ARR + name1 + ", " + FT.type + ARR + name3 + ")";

                                    if (S.OutputCppOrC())
                                    {
                                        new Comment(comment).Write(cgd.m_declSB, S, nbBaseTabs);
                                        cgd.m_declSB.Append(funcDecl); cgd.m_declSB.AppendLine(";");
                                    }
                                    else
                                    {
                                        new Comment(comment).Write(cgd.m_defSB, S, nbBaseTabs);
                                    }

                                    // emit def
                                    cgd.m_defSB.Append('\t', nbBaseTabs);
                                    cgd.m_defSB.Append(funcDecl);
                                    cgd.m_defSB.AppendLine(" {");
                                    cgd.m_defSB.Append(code);
                                    cgd.m_defSB.Append('\t', nbBaseTabs);
                                    cgd.m_defSB.AppendLine("}");
                                }
                            } // end of loop over all output groups
                        } // end of loop over undual (0) and dual(1)
                    } // end of loop over all input groups
                } // end of loop over all metric
            } // end of loop over all float types
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:dual_parts.cs

示例13: WriteSpecializedFunction

        /// <summary>
        /// Writes a simple function which assigns some value based on specialized multivectors or scalars to some variable.
        /// 
        /// Used by a lot of simple C functions, like gp, op, lc.
        /// 
        /// Somewhat obsolete (preferably, use the more generic, instruction based WriteFunction()).
        /// 
        /// </summary>
        /// <param name="S">Specification of algebra.</param>
        /// <param name="cgd">Results go into cgd.m_defSB, and so on</param>
        /// <param name="F">The function generation specification.</param>
        /// <param name="FT">Default float pointer type.</param>
        /// <param name="FAI">Info on the arguments of the function.</param>
        /// <param name="value">The value to assign.</param>
        /// <param name="comment">Optional comment for function (can be null).</param>
        public static void WriteSpecializedFunction(Specification S, G25.CG.Shared.CGdata cgd, G25.fgs F,
            FloatType FT, G25.CG.Shared.FuncArgInfo[] FAI, RefGA.Multivector value, Comment comment)
        {
            // get return type (may be a G25.SMV or a G25.FloatType)
            G25.VariableType returnType = G25.CG.Shared.SpecializedReturnType.GetReturnType(S, cgd, F, FT, value);

            if (returnType == null)
                throw new G25.UserException("Missing return type: " + G25.CG.Shared.BasisBlade.MultivectorToTypeDescription(S, value),
                    XML.FunctionToXmlString(S, F));

            bool ptr = true;

            string dstName = G25.fgs.RETURN_ARG_NAME;
            //string dstTypeName = (returnType is G25.SMV) ? FT.GetMangledName((returnType as G25.SMV).Name) : (returnType as G25.FloatType).type;

            string funcName = F.OutputName;

            // write comment to declaration
            if (comment != null)
            {
                if (S.OutputCppOrC())
                    comment.Write(cgd.m_declSB, S, 0);
                else comment.Write(cgd.m_defSB, S, 0);
            }

            if ((returnType is G25.SMV) && (S.OutputC()))
            {
                bool mustCast = false;
                G25.SMV dstSmv = returnType as G25.SMV;

                G25.CG.Shared.FuncArgInfo returnArgument = null;
                returnArgument = new G25.CG.Shared.FuncArgInfo(S, F, -1, FT, dstSmv.Name, false); // false = compute value

                bool staticFunc = S.OutputCSharpOrJava();
                G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                    S.m_inlineFunctions, staticFunc, "void", null, funcName, returnArgument, FAI, FT, mustCast, dstSmv, dstName, ptr,
                    value);
            }
            else
            {
                G25.FloatType returnFT = ((returnType as G25.FloatType) == null) ? FT : (returnType as G25.FloatType);

                bool mustCast = false;
                for (int i = 0; i < FAI.Length; i++)
                    mustCast |= returnFT.MustCastIfAssigned(S, FAI[i].FloatType);

                bool staticFunc = S.OutputCSharpOrJava();
                G25.CG.Shared.Functions.WriteReturnFunction(S, cgd,
                    S.m_inlineSet, staticFunc, funcName, FAI, FT, mustCast, returnType, value);

            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:67,代码来源:functions.cs

示例14: WriteReturnFunction

        /// <summary>
        /// 
        /// </summary>
        /// <param name="S">Used for all kinds of stuff.</param>
        /// <param name="cgd">Results go into cgd.m_defSB, and so on</param>
        /// <param name="inline">Should the function we inline?</param>
        /// <param name="staticFunc">Static function?</param>
        /// <param name="functionName">The name of the function which is to be generated.</param>
        /// <param name="arguments">Array of FuncArg which describes the arguments of the function.</param>
        /// <param name="returnFT">Floating point type of return variable.</param>
        /// <param name="mustCastDst">set to true if coordinates of 'value' must be cast to 'dstFT'.</param>
        /// <param name="returnType">The type to be returned.</param>
        /// <param name="value">Value to be written to the returned.</param>
        public static void WriteReturnFunction(
            Specification S, G25.CG.Shared.CGdata cgd,
            bool inline, bool staticFunc, string functionName,
            FuncArgInfo[] arguments,
            FloatType returnFT, bool mustCastDst, G25.VariableType returnType, RefGA.Multivector value)
        {
            string returnTypeName;
            bool returnSMV = returnType is G25.SMV;

            if (returnSMV) returnTypeName = returnFT.GetMangledName(S, (returnType as G25.SMV).Name);
            else returnTypeName = (returnType as G25.FloatType).type;

            // where the definition goes:
            StringBuilder defSB = (inline) ? cgd.m_inlineDefSB : cgd.m_defSB;

            // declaration:
            if (S.OutputCppOrC())
            {
                WriteDeclaration(cgd.m_declSB, S, cgd, false, staticFunc, returnTypeName, functionName, null, arguments);
                cgd.m_declSB.AppendLine(";");
            }

            WriteDeclaration(defSB, S, cgd, inline, staticFunc, returnTypeName, functionName, null, arguments);

            defSB.AppendLine("");
            defSB.AppendLine("{");

            int nbTabs = 1;
            ReturnInstruction RI = new ReturnInstruction(nbTabs, returnType, returnFT, mustCastDst, value);
            RI.Write(defSB, S, cgd);

            defSB.Append("\n");

            defSB.AppendLine("}");
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:48,代码来源:functions.cs

示例15: WriteSetVectorImages

        /// <summary>
        /// Writes a function to set a GOM struct according to vector images, for all floating point types.
        /// </summary>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Results go here. Also intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float type.</param>
        /// <param name="matrixMode">When true, generates code for setting from matrix instead of vector images.</param>
        /// <param name="transpose">When this parameter is true and <c>matrixMode</c> is true, generates code for setting from transpose matrix.</param>
        public static void WriteSetVectorImages(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, bool matrixMode, bool transpose)
        {
            G25.GOM gom = S.m_GOM;

            // get the 'plan' on how to initialize all domain basis blades efficiently:
            uint[][][] plan = G25.CG.Shared.OMinit.ComputeOmInitFromVectorsPlan(S, gom);
            double[][] signs = G25.CG.Shared.OMinit.ComputeOmInitFromVectorsSigns(S, gom, plan);

            // get range vector type
            G25.SMV rangeVectorType = G25.CG.Shared.OMinit.GetRangeVectorType(S, FT, cgd, gom);

            // setup array of arguments, function specification, etc
            int NB_ARGS = (matrixMode) ? 1 : gom.DomainVectors.Length;
            string[] argTypes = new string[NB_ARGS], argNames = new string[NB_ARGS];
            RefGA.Multivector[] symbolicBBvalues = new RefGA.Multivector[1 << S.m_dimension]; // symbolic basis blade values go here
            if (matrixMode)
            {
                argTypes[0] = FT.type;
                argNames[0] = "M";

                // convert matrix columns to symbolic Multivector values
                for (int d = 0; d < gom.DomainVectors.Length; d++)
                {
                    RefGA.BasisBlade[] IV = new RefGA.BasisBlade[gom.RangeVectors.Length];
                    for (int r = 0; r < gom.RangeVectors.Length; r++)
                    {
                        int matrixIdx = (transpose) ? (d * gom.RangeVectors.Length + r) : (r * gom.DomainVectors.Length + d);
                        string entryName = argNames[0] + "[" + matrixIdx + "]";
                        IV[r] = new RefGA.BasisBlade(gom.RangeVectors[r].bitmap, 1.0, entryName);
                    }
                    symbolicBBvalues[gom.DomainVectors[d].bitmap] = new RefGA.Multivector(IV);
                }
            }
            else
            {
                for (int d = 0; d < NB_ARGS; d++)
                {
                    argTypes[d] = rangeVectorType.Name;
                    argNames[d] = "i" + gom.DomainVectors[d].ToLangString(S.m_basisVectorNames);
                    bool ptr = S.OutputC();

                    symbolicBBvalues[gom.DomainVectors[d].bitmap] = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, rangeVectorType, argNames[d], ptr);
                }
            }

            // generate function names for all grades (basis blade names not included)
            string typeName = FT.GetMangledName(S, gom.Name);
            string[] funcNames = GetSetFromLowerGradeFunctionNames(S, FT, matrixMode);

            // setup instructions (for main function, and subfunctions for grades)
            List<G25.CG.Shared.Instruction> mainI = new List<G25.CG.Shared.Instruction>();
            List<G25.CG.Shared.Instruction>[] bladeI = new List<G25.CG.Shared.Instruction>[1 << S.m_dimension];
            {
                bool mustCast = false;
                int nbTabs = 1;
                string dstName = (S.OutputC()) ? G25.fgs.RETURN_ARG_NAME : SmvUtil.THIS;
                bool dstPtr = S.OutputCppOrC();
                bool declareDst = false;
                for (int g = 1; g < gom.Domain.Length; g++)
                {

                    for (int d = 0; d < gom.DomainForGrade(g).Length; d++)
                    {
                        G25.SMVOM smvOM = gom.DomainSmvForGrade(g)[d];
                        RefGA.BasisBlade domainBlade = gom.DomainForGrade(g)[d];

                        if (g > 1)
                        {
                            bladeI[domainBlade.bitmap] = new List<G25.CG.Shared.Instruction>();

                            string funcCallCode = funcNames[g] + "_" + d + "(";
                            if (S.OutputC()) funcCallCode += G25.fgs.RETURN_ARG_NAME;
                            funcCallCode += ");";
                            mainI.Add(new G25.CG.Shared.VerbatimCodeInstruction(nbTabs, funcCallCode));
                        }

                        // follow the plan
                        RefGA.Multivector value = new RefGA.Multivector(signs[g][d]);
                        uint[] P = plan[g][d];
                        for (int p = 0; p < P.Length; p++)
                            value = RefGA.Multivector.op(value, symbolicBBvalues[P[p]]);

                        // add instructions
                        List<G25.CG.Shared.Instruction> I = (g == 1) ? mainI : bladeI[domainBlade.bitmap];
                        I.Add(new G25.CG.Shared.CommentInstruction(nbTabs, "Set image of " + domainBlade.ToString(S.m_basisVectorNames)));
                        I.Add(new G25.CG.Shared.AssignInstruction(nbTabs, smvOM, FT, mustCast, value, dstName, dstPtr, declareDst));

                        // store symbolic value
                        symbolicBBvalues[domainBlade.bitmap] = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, smvOM, dstName, dstPtr);
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:om_init.cs


注:本文中的Specification.OutputCppOrC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。