Esempio n. 1
0
        /// <summary>
        /// Writes functions to copy SOM to GOMs.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd">Results go here. Also intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT"></param>
        public static void WriteSOMtoGOMcopy(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT)
        {
            G25.GOM gom = S.m_GOM;
            for (int s = 0; s < S.m_SOM.Count; s++)
            {
                G25.SOM som = S.m_SOM[s];

                WriteOMtoOMcopy(S, cgd, FT, som, gom);
            } // end of loop over all SMVs
        }
Esempio n. 2
0
        public static void WriteSetVectorImages(Specification S, G25.CG.Shared.CGdata cgd, G25.FloatType FT, G25.SOM som)
        {
            G25.SMV rangeVectorType = G25.CG.Shared.OMinit.GetRangeVectorType(S, FT, cgd, som);

            // loop over som.DomainVectors
            // setup array of arguments, function specification, etc
            int NB_ARGS = som.DomainVectors.Length;

            string[]            argTypes = new string[NB_ARGS];
            string[]            argNames = new string[NB_ARGS];
            RefGA.Multivector[] argValue = new RefGA.Multivector[NB_ARGS];
            for (int d = 0; d < NB_ARGS; d++)
            {
                argTypes[d] = rangeVectorType.Name;
                argNames[d] = "i" + som.DomainVectors[d].ToLangString(S.m_basisVectorNames);
                bool ptr = (S.OutputC());
                argValue[d] = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, rangeVectorType, argNames[d], ptr);
            }


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


            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);
            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, argValue[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 images of the domain vectors.");
            bool    writeDecl  = false;
            bool    staticFunc = false;

            G25.CG.Shared.Functions.WriteFunction(S, cgd, F, S.m_inlineSet, staticFunc, "void", funcName, returnArgument, FAI, I, comment, writeDecl);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
 /// <summary>
 /// Writes constructors of a SOM class to 'SB'.
 /// </summary>
 /// <param name="SB">Where the code goes.</param>
 /// <param name="S">Used for basis vector names and output language.</param>
 /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
 /// <param name="FT">Float point type of 'SOM'.</param>
 /// <param name="som">The specialized outermorphism for which the class should be written.</param>
 /// <param name="className">Mangled name of SOM class.</param>
 /// <param name="rangeVectorSMVname">The name of the SMV which can represent a column of the OM.</param>
 /// <param name="gomClassName">Mangled name of GOM class.</param>
 public static void WriteConstructors(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som, string className, string rangeVectorSMVname, string gomClassName)
 {
     cgd.m_cog.EmitTemplate(SB, "SOMconstructors", "S=", S, "FT=", FT, "som=", som, "className=", className, "gomClassName=", gomClassName, "rangeVectorSMVname=", rangeVectorSMVname);
 }
Esempio n. 6
0
 /// <summary>
 /// Returns the SMV type that can hold an image of a basis vector.
 /// </summary>
 public static G25.SMV GetRangeVectorType(Specification S, G25.FloatType FT, CGdata cgd, G25.SOM som)
 {
     RefGA.Multivector rangeVectorValue = new RefGA.Multivector(som.RangeVectors);
     G25.SMV           rangeVectorType  = (G25.SMV)G25.CG.Shared.SpecializedReturnType.FindTightestMatch(S, rangeVectorValue, FT);
     if (rangeVectorType == null) // type is missing, add it and tell user to add it to XML
     {
         rangeVectorType = (G25.SMV)G25.CG.Shared.SpecializedReturnType.CreateSyntheticSMVtype(S, cgd, FT, rangeVectorValue);
     }
     return(rangeVectorType);
 }
Esempio n. 7
0
        /// <summary>
        /// Writes members variables of a SOM class to 'SB'.
        /// </summary>
        /// <param name="SB">Where the comment goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float point type of 'GOM'.</param>
        /// <param name="som">The general outermorphism for which the class should be written.</param>
        public static void WriteMemberVariables(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            SB.AppendLine("public:");

            for (int g = 1; g < som.Domain.Length; g++) // start at '1' in order to skip scalar grade
            {
                if (!som.EmptyGrade(g))
                {
                    SB.AppendLine("\t/// Matrix for grade " + g + "; the size is " + som.DomainForGrade(g).Length + " x " + som.RangeForGrade(g).Length);
                    SB.AppendLine("\t" + FT.type + " m_m" + g + "[" +
                                  som.DomainForGrade(g).Length *som.RangeForGrade(g).Length + "];");
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Generates a source file with the SOM class definition.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd"></param>
        /// <param name="som"></param>
        /// <param name="FT"></param>
        /// <returns></returns>
        public static string GenerateCode(Specification S, G25.CG.Shared.CGdata cgd, G25.SOM som, FloatType FT)
        {
            string className = FT.GetMangledName(S, som.Name);

            // get range vector type
            G25.SMV rangeVectorType    = G25.CG.Shared.OMinit.GetRangeVectorType(S, FT, cgd, som);
            string  rangeVectorSMVname = FT.GetMangledName(S, rangeVectorType.Name);

            // get filename, list of generated filenames
            List <string> generatedFiles = new List <string>();
            string        sourceFilename = MainGenerator.GetClassOutputPath(S, className);

            generatedFiles.Add(sourceFilename);

            // get StringBuilder where all generated code goes
            StringBuilder SB = new StringBuilder();

            // get a new 'cgd' where all ouput goes to the one StringBuilder SB
            cgd = new G25.CG.Shared.CGdata(cgd, SB, SB, SB);

            // output license, copyright
            G25.CG.Shared.Util.WriteCopyright(SB, S);
            G25.CG.Shared.Util.WriteLicense(SB, S);

            // open namespace
            G25.CG.Shared.Util.WriteOpenNamespace(SB, S);

            // write class comment
            G25.CG.CSJ.SOM.WriteComment(SB, S, cgd, FT, som);

            // open class
            G25.CG.Shared.Util.WriteOpenClass(SB, S, G25.CG.Shared.AccessModifier.AM_public, className, null, null);

            // write member variables
            G25.CG.CSJ.SOM.WriteMemberVariables(SB, S, cgd, FT, som);

            // write constructors
            G25.CG.CSJ.SOM.WriteConstructors(SB, S, cgd, FT, som, rangeVectorSMVname);

            // write set functions
            G25.CG.Shared.OMinit.WriteSetIdentity(S, cgd, FT, som);
            G25.CG.Shared.OMinit.WriteSetCopy(S, cgd, FT, som);
            G25.CG.Shared.OMinit.WriteSetVectorImages(S, cgd, FT, som);
            G25.CG.Shared.OMinit.WriteSetMatrix(S, cgd, FT, som, false); // false = !transpose
            G25.CG.Shared.OMinit.WriteSetMatrix(S, cgd, FT, som, true);  // true = transpose
            G25.CG.CSJ.SOM.WriteGOMtoSOMcopy(S, cgd, FT, som);

            // write shortcuts for functions
            G25.CG.Shared.Shortcut.WriteFunctionShortcuts(SB, S, cgd, FT, som);

            // close class
            G25.CG.Shared.Util.WriteCloseClass(SB, S, className);

            // close namespace
            G25.CG.Shared.Util.WriteCloseNamespace(SB, S);

            // write all to file
            G25.CG.Shared.Util.WriteFile(sourceFilename, SB.ToString());

            return(sourceFilename);
        }
Esempio n. 9
0
        /// <summary>
        /// Writes the definition of an SOM struct to 'SB' (including comments).
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float point type of 'SOM'.</param>
        /// <param name="som">The general outermorphism for which the struct should be written.</param>
        public static void WriteSOMclass(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            SB.AppendLine("");

            string className    = FT.GetMangledName(S, som.Name);
            string gomClassName = (S.m_GOM == null) ? "" : FT.GetMangledName(S, S.m_GOM.Name);

            // get range vector type
            G25.SMV rangeVectorType    = G25.CG.Shared.OMinit.GetRangeVectorType(S, FT, cgd, som);
            string  rangeVectorSMVname = FT.GetMangledName(S, rangeVectorType.Name);

            WriteComment(SB, S, cgd, FT, som);

            // typedef
            SB.AppendLine("class " + className);
            SB.AppendLine("{");

            // member vars
            WriteMemberVariables(SB, S, cgd, FT, som);

            SB.AppendLine("public:");

            // Float type
            WriteFloatType(SB, S, cgd, FT, som, className);

            // constructors
            WriteConstructors(SB, S, cgd, FT, som, className, rangeVectorSMVname, gomClassName);

            // operator=
            WriteAssignmentOps(SB, S, cgd, FT, som, className, rangeVectorSMVname, gomClassName);

            // set(...)
            WriteSetDeclarations(SB, S, cgd, FT, som, className, rangeVectorSMVname, gomClassName);


            SB.AppendLine("}; // end of " + className);
        }
Esempio n. 10
0
 /// <summary>
 /// Writes comments of a SOM class to 'SB'.
 /// </summary>
 /// <param name="SB">Where the comment goes.</param>
 /// <param name="S">Used for basis vector names and output language.</param>
 /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
 /// <param name="FT">Float point type of 'GOM'.</param>
 /// <param name="som">The general outermorphism for which the class should be written.</param>
 public static void WriteComment(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
 {
     G25.CG.Shared.ClassComments.GetSomComment(S, cgd, FT, som).Write(SB, S, 0);
 }
Esempio n. 11
0
 /// <summary>
 /// Writes functions to copy SOMs to GOM.
 /// </summary>
 /// <param name="S"></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>
 public static void WriteGOMtoSOMcopy(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
 {
     if (S.m_GOM != null)
     {
         G25.CG.Shared.OMinit.WriteOMtoOMcopy(S, cgd, FT, S.m_GOM, som);
     }
 } // end of WriteGOMtoSOMcopy()
Esempio n. 12
0
        /// <summary>
        /// Writes constructors of a SOM class to 'SB'.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float point type of 'SOM'.</param>
        /// <param name="som">The specialized outermorphism for which the class should be written.</param>
        /// <param name="rangeVectorSMVname">The name of the SMV which can represent a column of the OM.</param>
        public static void WriteConstructors(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som, string rangeVectorSMVname)
        {
            string className    = FT.GetMangledName(S, som.Name);
            string gomClassName = (S.m_GOM == null) ? "" : FT.GetMangledName(S, S.m_GOM.Name);

            cgd.m_cog.EmitTemplate(SB, "SOMconstructors", "S=", S, "FT=", FT, "som=", som, "className=", className, "gomClassName=", gomClassName, "rangeVectorSMVname=", rangeVectorSMVname);
        }
Esempio n. 13
0
        /// <summary>
        /// Writes members variables of a SOM class to 'SB'.
        /// </summary>
        /// <param name="SB">Where the comment goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float point type of 'GOM'.</param>
        /// <param name="som">The general outermorphism for which the class should be written.</param>
        public static void WriteMemberVariables(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            int nbTabs = 1;

            for (int g = 1; g < som.Domain.Length; g++) // start at '1' in order to skip scalar grade
            {
                if (!som.EmptyGrade(g))
                {
                    string comment = "Matrix for grade " + g + "; the size is " + som.DomainForGrade(g).Length + " x " + som.RangeForGrade(g).Length;
                    new G25.CG.Shared.Comment(comment).Write(SB, S, nbTabs);
                    SB.AppendLine(new string('\t', nbTabs) + Keywords.PackageProtectedAccessModifier(S) + " " + FT.type + "[] m_m" + g + " = new " +
                                  FT.type + "[" + som.DomainForGrade(g).Length *som.RangeForGrade(g).Length + "];");
                }
            }
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
 /// <summary>
 /// Writes members variables of a SOM class to 'SB'.
 /// </summary>
 /// <param name="SB">Where the comment goes.</param>
 /// <param name="S">Used for basis vector names and output language.</param>
 /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
 /// <param name="FT">Float point type of 'GOM'.</param>
 /// <param name="som">The specialized outermorphism for which the class should be written.</param>
 /// <param name="className"></param>
 public static void WriteFloatType(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som, string className)
 {
     cgd.m_cog.EmitTemplate(SB, "classFloatType", "S=", S, "FT=", FT, "className=", className);
 }
Esempio n. 16
0
        /// <summary>
        /// Writes the definition of an SOM struct to 'SB' (including comments).
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float point type of 'SMV'.</param>
        /// <param name="som">The general outermorphism for which the struct should be written.</param>
        public static void WriteSOMstruct(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            SB.AppendLine("");

            { // comments for type:
                SB.AppendLine("/**");
                SB.AppendLine(" * This struct can hold a specialized outermorphism.");
                SB.AppendLine(" * ");

                SB.AppendLine(" * The coordinates are stored in type " + FT.type + ".");
                SB.AppendLine(" * ");

                SB.AppendLine(" * There are " + som.Domain.Length + " matrices, one for each grade.");
                SB.AppendLine(" * The columns of these matrices are the range of the outermorphism.");
                SB.AppendLine(" * Matrices are stored in row-major order. So the coordinates of rows are stored contiguously.");
                for (int g = 1; g < som.Domain.Length; g++) // start at '1' in order to skip scalar grade
                {
                    SB.Append(" * Domain grade " + g + ": ");
                    for (int i = 0; i < som.DomainForGrade(g).Length; i++)
                    {
                        if (i > 0)
                        {
                            SB.Append(", ");
                        }
                        SB.Append(som.DomainForGrade(g)[i].ToString(S.m_basisVectorNames));
                    }

                    SB.AppendLine(".");
                }
                SB.AppendLine(" * ");
                if (!som.DomainAndRangeAreEqual())
                {
                    for (int g = 1; g < som.Range.Length; g++) // start at '1' in order to skip scalar grade
                    {
                        SB.Append(" * Range grade " + g + ": ");
                        for (int i = 0; i < som.RangeForGrade(g).Length; i++)
                        {
                            if (i > 0)
                            {
                                SB.Append(", ");
                            }
                            SB.Append(som.RangeForGrade(g)[i].ToString(S.m_basisVectorNames));
                        }

                        SB.AppendLine(".");
                    }
                }
                else
                {
                    SB.AppendLine(" * The range and domain are equal.");
                }
                SB.AppendLine(" * ");

                SB.AppendLine(" */");
            } // end of comment

            // typedef
            SB.AppendLine("typedef struct ");
            SB.AppendLine("{");
            for (int g = 1; g < som.Domain.Length; g++) // start at '1' in order to skip scalar grade
            {
                if (!som.EmptyGrade(g))
                {
                    SB.AppendLine("\t/** Matrix for grade " + g + "; the size is " + som.DomainForGrade(g).Length + " x " + som.RangeForGrade(g).Length + " */");
                    SB.AppendLine("\t" + FT.type + " m" + g + "[" +
                                  som.DomainForGrade(g).Length *som.RangeForGrade(g).Length + "];");
                }
            }

            SB.AppendLine("} " + FT.GetMangledName(S, som.Name) + ";");
        }
Esempio n. 17
0
        /// <summary>
        /// Writes comments of a SOM class to 'SB'.
        /// </summary>
        /// <param name="SB">Where the comment goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Intermediate data for code generation. Also contains plugins and cog.</param>
        /// <param name="FT">Float point type of 'GOM'.</param>
        /// <param name="som">The general outermorphism for which the class should be written.</param>
        public static void WriteComment(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SOM som)
        {
            SB.AppendLine("/**");
            SB.AppendLine(" * This class can hold a specialized outermorphism.");
            SB.AppendLine(" * ");

            SB.AppendLine(" * The coordinates are stored in type " + FT.type + ".");
            SB.AppendLine(" * ");

            SB.AppendLine(" * There are " + som.Domain.Length + " matrices, one for each grade.");
            SB.AppendLine(" * The columns of these matrices are the range of the outermorphism.");
            SB.AppendLine(" * Matrices are stored in row-major order. So the coordinates of rows are stored contiguously.");
            for (int g = 1; g < som.Domain.Length; g++) // start at '1' in order to skip scalar grade
            {
                SB.Append(" * Domain grade " + g + ": ");
                for (int i = 0; i < som.DomainForGrade(g).Length; i++)
                {
                    if (i > 0)
                    {
                        SB.Append(", ");
                    }
                    SB.Append(som.DomainForGrade(g)[i].ToString(S.m_basisVectorNames));
                }

                SB.AppendLine(".");
            }
            SB.AppendLine(" * ");
            if (!som.DomainAndRangeAreEqual())
            {
                for (int g = 1; g < som.Range.Length; g++) // start at '1' in order to skip scalar grade
                {
                    SB.Append(" * Range grade " + g + ": ");
                    for (int i = 0; i < som.RangeForGrade(g).Length; i++)
                    {
                        if (i > 0)
                        {
                            SB.Append(", ");
                        }
                        SB.Append(som.RangeForGrade(g)[i].ToString(S.m_basisVectorNames));
                    }

                    SB.AppendLine(".");
                }
            }
            else
            {
                SB.AppendLine(" * The range and domain are equal.");
            }
            SB.AppendLine(" * ");

            SB.AppendLine(" */");
        }