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


C# Specification.OutputC方法代码示例

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


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

示例1: WriteAddSubHpFunction

        /// <summary>
        /// Writes any addition or subtraction function for general multivectors,
        /// based on CASN parts code.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd"></param>
        /// <param name="FT"></param>
        /// <param name="FAI"></param>
        /// <param name="F"></param>
        /// <param name="comment"></param>
        /// <param name="funcType">ADD, SUB or HP</param>
        /// <returns>Full name of generated function.</returns>
        public static string WriteAddSubHpFunction(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI, G25.fgs F,
            Comment comment, G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE funcType)
        {
            // setup instructions
            System.Collections.Generic.List<G25.CG.Shared.Instruction> I = new System.Collections.Generic.List<G25.CG.Shared.Instruction>();
            int nbTabs = 1;

            // write this function:
            string code = G25.CG.Shared.CANSparts.GetAddSubtractHpCode(S, cgd, FT, funcType, FAI, fgs.RETURN_ARG_NAME);

            // add one instruction (verbatim code)
            I.Add(new G25.CG.Shared.VerbatimCodeInstruction(nbTabs, code));

            // because of lack of overloading, function names include names of argument types
            G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(S, FT, F, FAI);

            // setup return type and argument:
            string returnTypeName = FT.GetMangledName(S, S.m_GMV.Name);
            G25.CG.Shared.FuncArgInfo returnArgument = null;
            if (S.OutputC())
                returnArgument = new G25.CG.Shared.FuncArgInfo(S, CF, -1, FT, S.m_GMV.Name, false); // false = compute value

            string funcName = CF.OutputName;
            //if (S.OutputC())
              //  funcName = FT.GetMangledName(S, funcName);

            // write function
            bool inline = false; // never inline GMV functions
            bool staticFunc = Functions.OutputStaticFunctions(S);
            G25.CG.Shared.Functions.WriteFunction(S, cgd, F, inline, staticFunc, returnTypeName, funcName, returnArgument, FAI, I, comment);

            return funcName;
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:46,代码来源:gmv_casn_parts.cs

示例2: GetDualCodeCppOrC

        private static string GetDualCodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, 
            G25.Metric M, G25.CG.Shared.FuncArgInfo[] FAI, string resultName, bool dual)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";

            // allocate memory to store result:
            SB.AppendLine("int idx = 0;");
            bool resultIsScalar = false;
            bool initResultToZero = true; // must init to zero because of compression
            SB.Append(GPparts.GetExpandCode(S, cgd, FT, null, resultIsScalar, initResultToZero));

            // get number of groups:
            int nbGroups = gmv.NbGroups;

            // for each combination of groups, check if the dual goes from one to the other
            for (int gi = 0; gi < nbGroups; gi++)
            {
                SB.AppendLine("if (" + agu + " & " + (1 << gi) + ") {");
                for (int go = 0; go < nbGroups; go++)
                {
                    string funcName = (dual) ? GetDualPartFunctionName(S, FT, M, gi, go) : GetUndualPartFunctionName(S, FT, M, gi, go);
                    Tuple<string, string, string> key = new Tuple<string, string, string>(FT.type, M.m_name, funcName);
                    if (cgd.m_gmvDualPartFuncNames.ContainsKey(key) &&
                        cgd.m_gmvDualPartFuncNames[key]) {
                        SB.AppendLine("\t" + funcName + "(" + ac + " + idx, c + " + gmv.GroupStartIdx(go) +");");
                    }
                }
                if (gi < (nbGroups - 1)) SB.AppendLine("\tidx += " + gmv.Group(gi).Length + ";");
                SB.AppendLine("}");
                SB.AppendLine("");
            }

            // compress result
            SB.Append(GPparts.GetCompressCode(S, FT, FAI, resultName, resultIsScalar));

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:42,代码来源:dual_parts.cs

示例3: GetCompressCode

        public static string GetCompressCode(Specification S, G25.FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI, string resultName, bool resultIsScalar, string GUstr)
        {
            if ((GUstr == null) || (GUstr.Length == 0))
            {
                GUstr = ((1 << S.m_GMV.NbGroups) - 1).ToString();
            }

            StringBuilder SB = new StringBuilder();
            if (resultIsScalar)
            {
                SB.AppendLine("return c[0];");
            }
            else
            {
                string funcName = (S.OutputC())
                    ? FT.GetMangledName(S, "compress")
                    : FT.GetMangledName(S, S.m_GMV.Name) + "_compress";

                if (S.m_outputLanguage != OUTPUT_LANGUAGE.C)
                    SB.Append("return ");

                SB.Append(funcName + "(c, ");
                if (S.OutputC())
                    SB.Append(resultName + "->c, &(" + resultName + "->gu), ");
                SB.AppendLine(FT.DoubleToString(S, 0.0) + ", " + GUstr + ");");
            }
            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:29,代码来源:gp_parts.cs

示例4: GetDiagonalMetricNormCode

        private static string GetDiagonalMetricNormCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, 
            G25.Metric M, bool squared,
            G25.CG.Shared.FuncArgInfo[] FAI, G25.SMV returnType, string returnName)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            if (S.OutputCSharpOrJava())
            {
                SB.AppendLine(FT.type + "[] c = new " + FT.type + "[1];");
                SB.AppendLine(FT.type + "[][] ac = " + FAI[0].Name + ".to_" + FAI[0].MangledTypeName + "().c();");
            }
            else SB.AppendLine(FT.type + " c[1];");

            SB.AppendLine(FT.type + " n2 = " + FT.DoubleToString(S, 0.0) + ";");
            if (S.OutputCppOrC())
                SB.AppendLine("int idx = 0;");

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";

            for (int g = 0; g < gmv.NbGroups; g++)
            {
                // get function name
                string funcName = GetGPpartFunctionName(S, FT, M, g, g, 0); // grade 0 part of gp(g, g)

                // get multiplier
                double m = gmv.Group(g)[0].Reverse().scale / gmv.Group(g)[0].scale;

                SB.AppendLine("");
                if (S.OutputCSharpOrJava())
                    SB.Append("if (ac[" + g + "] != null) {");
                else SB.Append("if (" + agu + " & " + (1 << g) + ") {");
                SB.AppendLine(" /* group " + g + " (grade " + gmv.Group(g)[0].Grade() + ") */");

                // check if funcName (gp part) exists)
                Tuple<string, string, string> key = new Tuple<string, string, string>(FT.type, M.m_name, funcName);
                if (cgd.m_gmvGPpartFuncNames.ContainsKey(key) && cgd.m_gmvGPpartFuncNames[key])
                {
                    SB.AppendLine("\tc[0] = " + FT.DoubleToString(S, 0.0) + ";");

                    if (S.OutputCSharpOrJava())
                        SB.AppendLine("\t" + funcName + "(ac[" + g + "], ac[ " + g + "], c);");
                    else SB.AppendLine("\t" + funcName + "(" + ac + " + idx, " + ac + " + idx, c);");

                    if (m == 1.0) SB.AppendLine("\tn2 += c[0];");
                    else if (m == -1.0) SB.AppendLine("\tn2 -= c[0];");
                    else SB.AppendLine("\tn2 += " + FT.DoubleToString(S, m) + " * c[0];");
                }
                if ((g < (gmv.NbGroups - 1)) && S.OutputCppOrC())
                    SB.AppendLine("\tidx += " + gmv.Group(g).Length + ";");
                SB.AppendLine("}");
            }

            string returnVal;
            { // get return value
                if (squared) returnVal = "n2";
                else
                {
                    string sqrtFuncName = G25.CG.Shared.CodeUtil.OpNameToLangString(S, FT, RefGA.Symbolic.UnaryScalarOp.SQRT);
                    if (M.m_metric.IsPositiveDefinite()) // if PD, then negative values are impossible
                        returnVal = sqrtFuncName + "(n2)";
                    else returnVal = "((n2 < " + FT.DoubleToString(S, 0.0) + ") ? " + sqrtFuncName + "(-n2) : " + sqrtFuncName + "(n2))";
                }
            }

            if ((returnType == null) || (returnName == null))
            {
                SB.AppendLine("return " + returnVal + ";");
            }
            else
            {
                if (S.OutputC())
                {
                    // get assign code, assign it
                    bool mustCast = false;
                    bool dstPtr = true;
                    int nbTabs = 0;
                    bool writeZeros = true;
                    SB.Append(CodeUtil.GenerateSMVassignmentCode(S, FT, mustCast,
                        returnType, returnName, dstPtr, new RefGA.Multivector(returnVal), nbTabs, writeZeros));
                }
                else
                {
                    bool mustCast = false;
                    int nbTabs = 0;
                    new ReturnInstruction(nbTabs, returnType, FT, mustCast, new RefGA.Multivector(returnVal)).Write(SB, S, cgd);
                }
            }

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:93,代码来源:gp_parts.cs

示例5: GetVersorApplicationCode

        /// <summary>
        /// Returns the code for applying a versor <c>V</c>to some multivector <c>M</c> (V M / V).
        /// The code is composed of calls to functions generated by <c>WriteGmvGpParts()</c>.
        /// 
        /// This function does not explicitly use the geometric product parts code, but makes calls
        /// to the geometric product and the reverse/versor inverse. As such it generates dependencies
        /// on <c>gp</c>, <c>reverse</c>, <c>versorInverse</c> and <c>grade</c>.
        /// 
        /// Three types of code can be generated, depending on the value of 
        /// argument <c>T</c>:
        ///   - <c>REVERSE</c>: the versor is unit, so the reverse can be used.
        ///   - <c>INVERSE</c>: the versor inverse is used to compute the inverse.
        ///   - <c>EXPLICIT_INVERSE</c>: the inverse is explicitly provided.
        /// 
        /// 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 for resolving dependencies.</param>
        /// <param name="FT">Floating point type.</param>
        /// <param name="M">Metric type used in the geometric products.</param>
        /// <param name="T">The product (e.g., geometric, outer, etc).</param>
        /// <param name="FAI">Info about function arguments. All arguments must be general multivectors.</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 GetVersorApplicationCode(Specification S, G25.CG.Shared.CGdata cgd, 
            G25.FloatType FT, G25.Metric M, ApplyVersorTypes T,
            G25.CG.Shared.FuncArgInfo[] FAI, String resultName)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            // get geometric product function
            string gpFuncName = G25.CG.Shared.Dependencies.GetDependency(S, cgd, "gp", new String[] { gmv.Name, gmv.Name }, FT, M.m_name);

            // get reverse or inverse function
            string invFuncName = null;
            if ((T == ApplyVersorTypes.INVERSE) || (T == ApplyVersorTypes.REVERSE))
            {
                string inputFuncName = (T == ApplyVersorTypes.INVERSE) ? "versorInverse" : "reverse";

                invFuncName = G25.CG.Shared.Dependencies.GetDependency(S, cgd,
                     inputFuncName, new string[] { gmv.Name }, FT, (T == ApplyVersorTypes.INVERSE) ? M.m_name : null);
            }

            // get grade function
            string gradeFuncName = G25.CG.Shared.Dependencies.GetDependency(S, cgd, G25.CG.Shared.CANSparts.EXTRACT_GRADE, new String[] { gmv.Name, G25.GroupBitmapType.GROUP_BITMAP }, FT, null);

            // get string to be used for grade extraction
            string gradeUsageString;
            string bgu;
            if (S.OutputC()) {
                bgu = FAI[1].Name + "->gu";
            }
            else if (S.OutputCSharpOrJava()) {
                bgu = FAI[1].Name + ".to_" + FAI[1].MangledTypeName + "().gu()";
            }
            else {
                bgu = FAI[1].Name + ".gu()";
            }

            string groupBitmapType = (S.OutputCSharp() ? "GroupBitmap" : "int");
            if (!gmv.IsGroupedByGrade(S.m_dimension))
            {
                SB.AppendLine(groupBitmapType + " gradeUsageBitmap;");
                gradeUsageString = "gradeUsageBitmap";
            }
            else
            {
                gradeUsageString = bgu;
                /*if (S.OutputC())
                    gradeUsageString = FAI[1].Name + "->gu";
                else gradeUsageString = FAI[1].Name + ".gu()";*/
            }

            // select grade parts!
            StringBuilder gradeUsageCode = new StringBuilder();
            if (!gmv.IsGroupedByGrade(S.m_dimension))
            {
                string groupBitmapStr = (S.OutputCSharpOrJava() ? ("GroupBitmap.") : "");
                gradeUsageCode.Append(gradeUsageString + " = ");
                for (int g = 0; g <= S.m_dimension; g++)
                {
                    if (g > 0) gradeUsageCode.Append(" | ");
                    gradeUsageCode.Append("(((" + bgu + " & " + groupBitmapStr + "GRADE_" + g + ") != 0) ? " + groupBitmapStr + "GRADE_" + g + " : 0)");
                }
                gradeUsageCode.AppendLine(";");
            }

            if (S.OutputC())
            {
                // get name of inverse, decl tmp variable for inverse if required
                string inverseInputName;
                if (T == ApplyVersorTypes.EXPLICIT_INVERSE) inverseInputName = FAI[2].Name;
                else if (T == ApplyVersorTypes.INVERSE)
                {
                    inverseInputName = "&inv";
                    SB.AppendLine(FT.GetMangledName(S, gmv.Name) + " inv; /* temp space for reverse */");
                }
                else // (T == ApplyVersorTypes.REVERSE)
//.........这里部分代码省略.........
开发者ID:Sciumo,项目名称:gaigen,代码行数:101,代码来源:gp_parts.cs

示例6: 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

示例7: WriteEqualsOrZeroOrGradeBitmapFunction

        /// <summary>
        /// Writes a zero or equality test function for general multivectors,
        /// based on CASN parts code.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd"></param>
        /// <param name="FT"></param>
        /// <param name="FAI"></param>
        /// <param name="F"></param>
        /// <param name="comment"></param>
        /// <param name="writeZero">When true, a function to test for zero is written.</param>
        /// <returns>full (mangled) name of generated function</returns>
        public static string WriteEqualsOrZeroOrGradeBitmapFunction(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI, G25.fgs F,
            Comment comment, G25.CG.Shared.CANSparts.EQUALS_ZERO_GRADEBITMAP_TYPE funcType)
        {
            // setup instructions
            System.Collections.Generic.List<G25.CG.Shared.Instruction> I = new System.Collections.Generic.List<G25.CG.Shared.Instruction>();
            int nbTabs = 1;

            // write this function:
            string code = "";
            if (funcType == G25.CG.Shared.CANSparts.EQUALS_ZERO_GRADEBITMAP_TYPE.EQUALS)
                code = G25.CG.Shared.CANSparts.GetEqualsCode(S, cgd, FT, FAI);
            else if (funcType == G25.CG.Shared.CANSparts.EQUALS_ZERO_GRADEBITMAP_TYPE.ZERO)
                code = G25.CG.Shared.CANSparts.GetZeroCode(S, cgd, FT, FAI);
            else if (funcType == G25.CG.Shared.CANSparts.EQUALS_ZERO_GRADEBITMAP_TYPE.GRADE_BITMAP)
                code = G25.CG.Shared.CANSparts.GetGradeBitmapCode(S, cgd, FT, FAI);

            // add one instruction (verbatim code)
            I.Add(new G25.CG.Shared.VerbatimCodeInstruction(nbTabs, code));

            // because of lack of overloading, function names include names of argument types
            G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(S, FT, F, FAI);

            // setup return type and argument:
            string returnTypeName = null;
            if (S.OutputC())
            {
                returnTypeName = G25.IntegerType.INTEGER;
            }
            else {
                if (funcType == G25.CG.Shared.CANSparts.EQUALS_ZERO_GRADEBITMAP_TYPE.GRADE_BITMAP)
                    returnTypeName = G25.IntegerType.INTEGER;
                else returnTypeName = CodeUtil.GetBoolType(S);
            }

            G25.CG.Shared.FuncArgInfo returnArgument = null;

            // write function
            bool inline = false; // never inline GMV functions
            bool staticFunc = Functions.OutputStaticFunctions(S);
            G25.CG.Shared.Functions.WriteFunction(S, cgd, F, inline, staticFunc, returnTypeName, CF.OutputName, returnArgument, FAI, I, comment);

            return CF.OutputName;
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:56,代码来源:gmv_casn_parts.cs

示例8: GetZeroCodeCppOrC

        private static string GetZeroCodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            SB.AppendLine("int idx = 0;");

            // get number of groups:
            int nbGroups = gmv.NbGroups;

            // for each group
            // test if present, then code / negate, etc

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";

            string falseStr = CodeUtil.GetFalseValue(S);
            string trueStr = CodeUtil.GetTrueValue(S);

            for (int g = 0; g < nbGroups; g++)
            {
                SB.AppendLine("");

                string funcName = GetZeroPartFunctionName(S, FT, g);

                SB.AppendLine("if (" + agu + " & " + (1 << g) + ") {");
                SB.AppendLine("\tif (!" + funcName + "(" + ac + " + idx, " + FAI[1].Name + ")) return " + falseStr + ";");

                if (g < (nbGroups - 1)) SB.AppendLine("\tidx += " + gmv.Group(g).Length + ";");

                SB.AppendLine("}");

            }
            SB.AppendLine("return " + trueStr + ";");

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:39,代码来源:copy_add_sub_neg_parts.cs

示例9: GetIncrementCode

        /// <summary>
        /// Returns the code for <c>gmv + scalar</c>
        /// 
        /// The code is NOT composed of calls to functions generated by <c>WriteCANSparts()</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="FAI">Info about function arguments</param>
        /// <param name="resultName">Name of variable where the result goes (in the generated code).</param>
        /// <param name="increment">Whether write increment or decrement function.</param>
        /// <returns>code for the requested function.</returns>
        public static string GetIncrementCode(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI, string resultName, bool increment)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            if (S.OutputC())
            {
                SB.AppendLine(FT.type + " val" + " = " +
                    FAI[0].MangledTypeName + "_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "(" + FAI[0].Name + ")" +
                    ((increment) ? " + " : " - ") + FT.DoubleToString(S, 1.0) + ";");

                SB.AppendLine(FAI[0].MangledTypeName + "_copy(" + resultName + ", " + FAI[0].Name + ");");
                SB.AppendLine(FAI[0].MangledTypeName + "_set_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "(" + resultName + ", val);");
            }
            else
            {
                string convertMvIfCode = (S.OutputCSharpOrJava()) ? (".to_" + FAI[0].MangledTypeName + "()") : "";

                if (S.OutputCpp())
                    SB.AppendLine(FAI[0].MangledTypeName + " " + resultName + "(" + FAI[0].Name + ");");
                else SB.AppendLine(FAI[0].MangledTypeName + " " + resultName + " = new " + FAI[0].MangledTypeName + "(" + FAI[0].Name + convertMvIfCode + ");");
                SB.AppendLine(FT.type + " val" + " = " + resultName + ".get_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "()" +
                    ((increment) ? " + " : " - ") + FT.DoubleToString(S, 1.0) + ";");
                SB.AppendLine(resultName + ".set_" + gmv.Group(0)[0].ToLangString(S.m_basisVectorNames) + "(val);");
                SB.AppendLine("return " + resultName + ";");
            }

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:45,代码来源:copy_add_sub_neg_parts.cs

示例10: GetSAScodeCppOrC

        private static string GetSAScodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI, string resultName)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            SB.AppendLine("int idxa = 0, idxc = 0;");

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";
            string resultCoordPtr = (S.OutputC()) ? resultName + "->c" : "C";

            // copy group usage / allocate memory for result
            if (S.OutputC())
            {
                SB.AppendLine(resultName + "->gu = " + agu + " | ((" + FAI[2].Name + " != 0.0) ? GRADE_0 : 0); /* '| GRADE_0' to make sure the scalar part is included */");
            }
            else
            {
                SB.AppendLine("int gu = " + agu + " | ((" + FAI[2].Name + " != 0.0) ? GRADE_0 : 0); // '| GRADE_0' to make sure the scalar part is included");
                SB.AppendLine(FT.type + " C[" + (1 << S.m_dimension) + "];");
            }

            int nbGroups = gmv.NbGroups;
            for (int g = 0; g < nbGroups; g++)
            {
                SB.AppendLine("");

                // get func name
                string funcName = GetCopyMulPartFunctionName(S, FT, g);

                SB.AppendLine("if (" + agu + " & " + (1 << g) + ") {");
                SB.AppendLine("\t" + funcName + "(" + ac + " + idxa, " + resultCoordPtr + " + idxc, " + FAI[1].Name + ");");
                if (g == 0)
                { // also add scalar
                    SB.AppendLine("\tif (" + FAI[2].Name + " != 0.0) " + resultCoordPtr + "[idxc] += " + FAI[2].Name + ";");
                }
                if (g < (nbGroups - 1))
                {
                    SB.AppendLine("\tidxa += " + gmv.Group(g).Length + ";");
                    SB.AppendLine("\tidxc += " + gmv.Group(g).Length + ";");
                }
                SB.AppendLine("}");

                if (g == 0)
                { // always add the scalar:
                    SB.AppendLine("else if (" + FAI[2].Name + " != 0.0) {");
                    SB.AppendLine("\t" + resultCoordPtr + "[idxc] = " + FAI[2].Name + ";");
                    SB.AppendLine("\tidxc += " + gmv.Group(g).Length + ";");
                    SB.AppendLine("}");
                }
            }

            // return result
            if (S.m_outputLanguage != OUTPUT_LANGUAGE.C)
            {
                SB.AppendLine("return " + FT.GetMangledName(S, gmv.Name) + "(gu, C);");
            }

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:62,代码来源:copy_add_sub_neg_parts.cs

示例11: GetUnaryToggleSignCodeCppOrC

        private static string GetUnaryToggleSignCodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, 
            UnaryToggleSignType T,
            G25.CG.Shared.FuncArgInfo[] FAI, string resultName)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB=  new StringBuilder();

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";
            string resultCoordPtr = (S.OutputC()) ? resultName + "->c" : "c";

            SB.AppendLine("int idx = 0;");

            if (S.OutputC())
            {
                SB.AppendLine(resultName + "->gu = " + agu + ";");
            }
            else
            {
                SB.AppendLine("int gu = " + agu + ";");
                SB.AppendLine(FT.type + " c[" + (1 << S.m_dimension) + "];");
            }

            // get number of groups:
            int nbGroups = gmv.NbGroups;

            // for each group
            // test if present, then code / negate, etc

            for (int g = 0; g < nbGroups; g++)
            {
                SB.AppendLine("");

                // do we need to negate this group?
                bool neg = NeedToNegate(gmv, g, T);

                string funcName = (neg) ? GetNegPartFunctionName(S, FT, g) : GetCopyPartFunctionName(S, FT, g);

                SB.AppendLine("if (" + agu + " & " + (1 << g) + ") {");
                SB.AppendLine("\t" + funcName + "(" + ac + " + idx, " + resultCoordPtr + " + idx);");

                if (g < (nbGroups - 1)) SB.AppendLine("\tidx += " + gmv.Group(g).Length + ";");

                SB.AppendLine("}");
            }

            // return result
            if (S.m_outputLanguage != OUTPUT_LANGUAGE.C)
            {
                SB.AppendLine("return " + FT.GetMangledName(S, gmv.Name) + "(gu, c);");
            }

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:55,代码来源:copy_add_sub_neg_parts.cs

示例12: GetGradeCodeCppOrC

        private static string GetGradeCodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
            int gradeIdx,
            G25.CG.Shared.FuncArgInfo[] FAI, string resultName, string groupBitmapName)
        {
            G25.GMV gmv = S.m_GMV;
            if (gradeIdx >= 0)
            {  // if a specific grade is requested, convert it into a group bitmap, and call the grade(A, groupBitmap) function
                // get name of grade function
                //bool returnTrueName = false;
                string gradeFuncName = G25.CG.Shared.Dependencies.GetDependency(S, cgd, EXTRACT_GRADE, new string[] { gmv.Name, G25.GroupBitmapType.GROUP_BITMAP }, FT, null);

                // turn grade into group
                int groupBitmap = gmv.GradeToGroupBitmap(gradeIdx);

                if (S.OutputC())
                {
                    return gradeFuncName + "(" + resultName + ", " + FAI[0].Name + ", " + groupBitmap + ");";
                }
                else
                {
                    return "return " + gradeFuncName + "(" + FAI[0].Name + ", " + groupBitmap + ");";
                }
            }
            else
            {
                StringBuilder SB = new StringBuilder();

                // get indices into coordinates for input and output
                SB.AppendLine("int aidx = 0, cidx = 0;");

                string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
                string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";

                if (S.OutputC())
                {
                    SB.AppendLine(resultName + "->gu = " + agu +" & " + groupBitmapName + ";");
                }
                else
                {
                    SB.AppendLine("int gu =  " + agu + " & " + groupBitmapName + ";");
                    SB.AppendLine(FT.type + " c[" + (1 << S.m_dimension) + "];");
                }

                string resultCoordPtr = (S.OutputC()) ? resultName + "->c" : "c";

                // for each group, test if present
                int nbGroups = gmv.NbGroups;
                for (int g = 0; g < nbGroups; g++)
                {
                    SB.AppendLine("");

                    string funcName = GetCopyPartFunctionName(S, FT, g);

                    SB.AppendLine("if (" + agu + " & " + (1 << g) + ") {");
                    SB.AppendLine("\tif (" + groupBitmapName + " & " + (1 << g) + ") {");
                    SB.AppendLine("\t\t" + funcName + "(" + ac + " + aidx, " + resultCoordPtr + " + cidx);");
                    if (g < (nbGroups - 1)) SB.AppendLine("\t\tcidx += " + gmv.Group(g).Length + ";");
                    SB.AppendLine("\t}");
                    if (g < (nbGroups - 1)) SB.AppendLine("\taidx += " + gmv.Group(g).Length + ";");
                    SB.AppendLine("}");
                }

                // return result
                if (S.m_outputLanguage != OUTPUT_LANGUAGE.C)
                {
                    SB.AppendLine("return " + FT.GetMangledName(S, gmv.Name) + "(gu, c);");
                }

                return SB.ToString();
            }
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:71,代码来源:copy_add_sub_neg_parts.cs

示例13: GetEqualsCodeCppOrC

        private static string GetEqualsCodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            SB.AppendLine("int aidx = 0, bidx = 0;");

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";
            string bgu = (S.OutputC()) ? FAI[1].Name + "->gu" : FAI[1].Name + ".gu()";
            string bc = (S.OutputC()) ? FAI[1].Name + "->c" : FAI[1].Name + ".getC()";

            // get number of groups, and possible assurances that a group is always present:
            int nbGroups = gmv.NbGroups;

            string falseStr = CodeUtil.GetFalseValue(S);
            string trueStr = CodeUtil.GetTrueValue(S);

            // for each group
            // test if present in both-> then add both, etc
            for (int g = 0; g < nbGroups; g++)
            {
                SB.AppendLine("");

                string equalsFuncName = GetEqualsPartFunctionName(S, FT, g);
                string zeroFuncName = GetZeroPartFunctionName(S, FT, g);

                SB.AppendLine("if (" + agu + " & " + (1 << g) + ") {");
                SB.AppendLine("\tif (" + bgu + " & " + (1 << g) + ") {");

                SB.AppendLine("\t\tif (!" + equalsFuncName + "(" + ac + " + aidx, " + bc + " + bidx, " + FAI[2].Name + ")) return " + falseStr + ";");
                if (g < (nbGroups - 1)) SB.AppendLine("\t\tbidx += " + gmv.Group(g).Length + ";");
                SB.AppendLine("\t}");
                SB.AppendLine("\telse if (!" + zeroFuncName + "(" + ac + " + bidx, " + FAI[2].Name + ")) return " + falseStr + ";");

                if (g < (nbGroups - 1)) SB.AppendLine("\taidx += " + gmv.Group(g).Length + ";");

                SB.AppendLine("}");
                SB.AppendLine("else if (" + bgu + " & " + (1 << g) + ") {");

                SB.AppendLine("\tif (!" + zeroFuncName + "(" + bc + " + bidx, " + FAI[2].Name + ")) return " + falseStr + ";");
                if (g < (nbGroups - 1)) SB.AppendLine("\tbidx += " + gmv.Group(g).Length + ";");

                SB.AppendLine("}");

            }
            SB.AppendLine("return " + trueStr + ";");

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:52,代码来源:copy_add_sub_neg_parts.cs

示例14: GetDivCodeCppOrC

        private static string GetDivCodeCppOrC(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT,
            G25.Metric M, G25.CG.Shared.FuncArgInfo[] FAI, string resultName, DIVCODETYPE funcType)
        {
            G25.GMV gmv = S.m_GMV;

            StringBuilder SB = new StringBuilder();

            string normFuncName = G25.CG.Shared.Dependencies.GetDependency(S, cgd, (funcType == DIVCODETYPE.UNIT) ? "norm" : "norm2", new String[] { gmv.Name }, FT, M.m_name);
            string normVarName = (funcType == DIVCODETYPE.UNIT) ? "n" : "n2";

            string agu = (S.OutputC()) ? FAI[0].Name + "->gu" : FAI[0].Name + ".gu()";
            string ac = (S.OutputC()) ? FAI[0].Name + "->c" : FAI[0].Name + ".getC()";
            string resultCoordPtr = (S.OutputC()) ? resultName + "->c" : "c";

            SB.AppendLine("int idx = 0;");
            if ((funcType == DIVCODETYPE.UNIT) || (funcType == DIVCODETYPE.VERSOR_INVERSE))
            {
                // compute norm
                SB.AppendLine(FT.type + " " + normVarName + " = " + normFuncName + G25.CG.Shared.CANSparts.RETURNS_SCALAR + "(" + FAI[0].Name + ");");
            }

            // copy group usage
            if (S.OutputC())
            {
                SB.AppendLine(resultName + "->gu = " + agu + ";");
            }
            else
            {
                SB.AppendLine("int gu = " + agu + ";");
                SB.AppendLine(FT.type + " c[" + (1 << S.m_dimension) + "];");
            }

            // for each group present, copy and scale (for versor inverse, modulate with reverse)
            // for each group, test if present
            int nbGroups = gmv.NbGroups;
            for (int g = 0; g < nbGroups; g++)
            {
                SB.AppendLine("");

                // get func name
                string funcName = GetCopyDivPartFunctionName(S, FT, g);

                // get multiplier, normVarName string (depends on whether this is unit or versor inverse)
                string normString;
                if ((funcType == DIVCODETYPE.UNIT) || (funcType == DIVCODETYPE.VERSOR_INVERSE))
                {
                    double m = (funcType == DIVCODETYPE.UNIT) ? 1 : gmv.Group(g)[0].Reverse().scale / gmv.Group(g)[0].scale;
                    normString = ((m < 0) ? "-" : "") + normVarName;
                }
                else normString = FAI[1].Name;

                SB.AppendLine("if (" + agu + " & " + (1 << g) + ") {");
                SB.AppendLine("\t" + funcName + "(" + ac + " + idx, " + resultCoordPtr + " + idx, " + normString + ");");
                if (g < (nbGroups - 1)) SB.AppendLine("\tidx += " + gmv.Group(g).Length + ";");
                SB.AppendLine("}");
            }

            // return result
            if (S.m_outputLanguage != OUTPUT_LANGUAGE.C)
            {
                SB.AppendLine("return " + FT.GetMangledName(S, gmv.Name) + "(gu, c);");
            }

            return SB.ToString();
        }
开发者ID:Sciumo,项目名称:gaigen,代码行数:65,代码来源:copy_add_sub_neg_parts.cs

示例15: 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


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