Example #1
0
        public static void GenerateBasicInfo(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd)
        {
            string accessModifier = Keywords.ConstAccessModifier(S);
            string accessModifierArr = Keywords.ConstArrayAccessModifier(S);
            string stringType = Keywords.StringType(S);
            string boolType = G25.CG.Shared.CodeUtil.GetBoolType(S);

            // dimension of space
            new G25.CG.Shared.Comment("The dimension of the space").Write(SB, S, 1);
            SB.AppendLine("\tpublic " + accessModifier + " int SpaceDim = " + S.m_dimension + ";");

            // number of groups in general multivector
            new G25.CG.Shared.Comment("Number of groups/grades of coordinates in a multivector").Write(SB, S, 1);
            SB.AppendLine("\tpublic " + accessModifier + " int NbGroups = " + S.m_GMV.NbGroups + ";");

            // Euclidean metric?
            new G25.CG.Shared.Comment("Is the metric of the space Euclidean? (false or true)").Write(SB, S, 1);
            SB.AppendLine("\tpublic " + accessModifier + " " + boolType + " MetricEuclidean = " +
                (S.GetMetric("default").m_metric.IsEuclidean() ? "true" : "false") + ";");

            // basis vector names
            new G25.CG.Shared.Comment("Names of the basis vectors.").Write(SB, S, 1);
            SB.AppendLine("\tpublic " + accessModifierArr + " " + stringType + "[] BasisVectorNames = new " + stringType + "[] {");
            SB.Append("\t\t");
            for (int i = 0; i < S.m_dimension; i++)
            {
                if (i > 0) SB.Append(", ");
                SB.Append("\"" + S.m_basisVectorNames[i] + "\"");
            }
            SB.AppendLine("");
            SB.AppendLine("\t};");
        }
Example #2
0
        /// <summary>
        /// Writes a shortcut for 'type', 'fgs'.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Used for basis vector names and output language.</param>
        /// <param name="cgd">Not used yet.</param>
        /// <param name="FT">Float point type of 'type'.</param>
        /// <param name="type">The type for which shortcuts should be written.</param>
        /// <param name="fgs"></param>
        /// <param name="FAI"></param>
        public static void WriteFunctionShortcut(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.VariableType type,
            G25.fgs fgs, FuncArgInfo[] FAI)
        {
            int nbTabs = 1;

            FuncArgInfo[] tailFAI = getTail(FAI);

            string shortcutCall = getShortcutCall(S, fgs, tailFAI);

            SB.AppendLine("");

            // output comment
            new Comment("shortcut to " + shortcutCall).Write(SB, S, nbTabs);

            bool inline = false;
            bool staticFunc = false;
            string returnType = FT.GetMangledName(S, fgs.ReturnTypeName);
            FuncArgInfo returnArgument = null;

            SB.Append('\t', nbTabs);
            Functions.WriteDeclaration(SB, S, cgd,
                inline, staticFunc, returnType, fgs.OutputName,
                returnArgument, tailFAI);
            SB.AppendLine(" {");

            SB.Append('\t', nbTabs+1);
            SB.Append("return ");
            SB.Append(shortcutCall);
            SB.AppendLine(";");

            SB.Append('\t', nbTabs);
            SB.AppendLine("}");
        }
Example #3
0
File: hp.cs Project: Sciumo/gaigen
 /// <summary>
 /// Checks if this FunctionGenerator can implement a certain function.
 /// </summary>
 /// <param name="S">The specification of the algebra.</param>
 /// <param name="F">The function to be implemented.</param>
 /// <returns>true if 'F' can be implemented</returns>
 public override bool CanImplement(Specification S, G25.fgs F)
 {
     return (((F.Name == "hp") || (F.Name == "ihp")) && (F.MatchNbArguments(NB_ARGS)) &&
         G25.CG.Shared.Functions.NotMixScalarGmv(S, F, NB_ARGS, S.m_GMV.Name) &&
         G25.CG.Shared.Functions.NotMixSmvGmv(S, F, NB_ARGS, S.m_GMV.Name) &&
         G25.CG.Shared.Functions.NotUseOm(S, F, NB_ARGS, S.m_GMV.Name));
 }
Example #4
0
        /// <summary>
        /// Resolves a converter (underscore constructor) dependency.
        /// Searches for a converter from 'fromType' to 'toType'.
        /// 
        /// If the function is not found, this is also enlisted in cgd.m_missingDependencies.
        /// Call cgd.PrintMissingDependencies() should be called to report the missing dependencies
        /// to the end-user.
        /// </summary>
        /// <param name="S">The spec.</param>
        /// <param name="cgd">Missing dependencies go into cgd.m_missingDependencies.</param>
        /// <param name="fromType"></param>
        /// <param name="toType"></param>
        /// <param name="FT"></param>
        /// <returns></returns>
        public static string GetConverterDependency(Specification S, CGdata cgd, string fromType, string toType, G25.FloatType FT)
        {
            // look for 'funcName' in all G25.fgs in the spec
            //                    string funcName = "_" + FT.GetMangledName(S, toType);
            string funcName = "_" + toType;
            foreach (G25.fgs F in S.m_functions)
            {
                if (F.IsConverter(S)) // is 'F' a converter (underscore constructor)?
                {
                    if ((F.Name == funcName) &&
                        (F.ArgumentTypeNames[0] == fromType))
                    {
                        return G25.CG.Shared.Converter.GetConverterName(S, F, FT.GetMangledName(S, fromType), FT.GetMangledName(S, toType));
                    }
                }
            }

            // converter not found: add it to missing deps:
            {
                // add dependency to list of missing deps:
                string outputName = null;
                string[] argumentTypes = new string[] { fromType };
                string[] argVarNames = null;
                string returnTypeName = null;
                string metricName = null;
                string comment = null;
                Dictionary<string, string> options = null;
                G25.fgs F = new G25.fgs(funcName, outputName, returnTypeName, argumentTypes, argVarNames, new string[] { FT.type }, metricName, comment, options);
                cgd.AddMissingDependency(S, F);
            }

            // return fictional name:
            G25.fgs tmpF = null;
            return "missingFunction_" + G25.CG.Shared.Converter.GetConverterName(S, tmpF, FT.GetMangledName(S, fromType), FT.GetMangledName(S, toType));
        }
Example #5
0
        protected G25.SMV m_smv2 = null; ///< if function over SMV, type goes here

        #endregion Fields

        #region Methods

        /// <summary>
        /// Checks if this FunctionGenerator can implement a certain function.
        /// </summary>
        /// <param name="S">The specification of the algebra.</param>
        /// <param name="F">The function to be implemented.</param>
        /// <returns>true if 'F' can be implemented</returns>
        public override bool CanImplement(Specification S, G25.fgs F)
        {
            //String type F.GetArgumentTypeName(0, S.m_GMV.Name);
            return ((F.Name == "equals") && (F.MatchNbArguments(NB_ARGS)) &&
                G25.CG.Shared.Functions.NotMixSmvGmv(S, F, NB_ARGS, S.m_GMV.Name) &&
                G25.CG.Shared.Functions.NotUseOm(S, F, NB_ARGS, S.m_GMV.Name));
        }
Example #6
0
File: gom.cs Project: Sciumo/gaigen
        /// <summary>
        /// Generates a source file with the GOM class definition.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="cgd"></param>
        /// <param name="FT"></param>
        /// <returns></returns>
        public static string GenerateCode(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT)
        {
            G25.GOM gom = S.m_GOM;
            string className = FT.GetMangledName(S, gom.Name);

            // get range vector type
            G25.SMV rangeVectorType = G25.CG.Shared.OMinit.GetRangeVectorType(S, FT, cgd, gom);
            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.GOM.WriteComment(SB, S, cgd, FT, gom);

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

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

            // write constructors
            G25.CG.CSJ.GOM.WriteConstructors(SB, S, cgd, FT, gom, className, rangeVectorSMVname);

            // write set functions
            G25.CG.CSJ.GOM.WriteSetIdentity(SB, S, cgd, FT);
            G25.CG.CSJ.GOM.WriteSetCopy(SB, S, cgd, FT);
            G25.CG.CSJ.GOM.WriteSetVectorImages(S, cgd, FT, false, false); // false, false = matrixMode, transpose
            G25.CG.CSJ.GOM.WriteSetVectorImages(S, cgd, FT, true, false); // true, false = matrixMode, transpose
            G25.CG.CSJ.GOM.WriteSOMtoGOMcopy(S, cgd, FT);

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

            // 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;
        }
Example #7
0
        private static string GetComment(Specification S, bool declOnly, G25.fgs FGS, G25.Operator op, G25.FloatType FT, bool assign)
        {
            StringBuilder SB = new StringBuilder();

            if ((S.OutputCpp()) && op.IsUnaryInPlace())
            {
                if (op.IsPrefix)
                {
                    SB.Append("returns (" + FGS.ArgumentVariableNames[0] + " = " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0] + "))");
                }
                else
                {
                    SB.Append("returns input value of " + FGS.ArgumentVariableNames[0] + ", but sets " + FGS.ArgumentVariableNames[0] + " to " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0] + ")");
                }
            }
            else if (assign)
            {
                SB.Append("returns (" + FGS.ArgumentVariableNames[0] + " = " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0]);
                SB.Append(", " + FGS.ArgumentVariableNames[1]);
                SB.Append("))");
            }
            else {
                SB.Append("returns " + FGS.OutputName + "(" + FGS.ArgumentVariableNames[0]);
                if (op.IsBinary())
                    SB.Append(", " + FGS.ArgumentVariableNames[1]);
                SB.Append(")");
            }

            return SB.ToString();
        }
Example #8
0
 /// <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);
 }
Example #9
0
 public Converter(Specification S, G25.CG.Shared.CGdata cgd, G25.fgs F)
 {
     m_specification = S;
     m_cgd = cgd;
     m_fgs = F;
     m_fgs.InitArgumentPtrFromTypeNames(S);
 }
Example #10
0
        /// <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;
        }
Example #11
0
File: gom.cs Project: Sciumo/gaigen
        /// <summary>
        /// Writes a function to copy an GOM struct
        /// </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>
        public static void WriteCopy(Specification S, G25.CG.Shared.CGdata cgd)
        {
            StringBuilder declSB = cgd.m_declSB;
            StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB;
            declSB.AppendLine("");
            defSB.AppendLine("");

            string dstName = "dst";
            string srcName = "src";
            string matrixName = "m";

            foreach (G25.FloatType FT in S.m_floatTypes)
            {
                String typeName = FT.GetMangledName(S, S.m_GOM.Name);
                String funcName = typeName + "_copy";
                //string comment = "/** Copies " + typeName + " */";
                declSB.AppendLine("void " + funcName + "(" + typeName + "*" + dstName + ", const " + typeName + "*" + srcName + ");");
                defSB.AppendLine("void " + funcName + "(" + typeName + "*" + dstName + ", const " + typeName + "*" + srcName + ") {");
                for (int g = 1; g < S.m_GOM.Domain.Length; g++)
                {
                    int s = S.m_GOM.Domain[g].Length * S.m_GOM.Range[g].Length;
                    defSB.AppendLine("\t" + G25.CG.Shared.Util.GetCopyCode(S, FT, srcName + "->" + matrixName + g, dstName + "->" + matrixName + g, s));
                } // end of loop over all grades of the OM
                defSB.AppendLine("}");
            }
        }
Example #12
0
File: smv.cs Project: Sciumo/gaigen
        /// <summary>
        /// Writes a function to copy the value of one SMV struct to another, for all floating point types.
        /// </summary>
        /// <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>
        public static void WriteCopy(Specification S, G25.CG.Shared.CGdata cgd)
        {
            StringBuilder declSB = cgd.m_declSB;
            StringBuilder defSB = (S.m_inlineSet) ? cgd.m_inlineDefSB : cgd.m_defSB;
            declSB.AppendLine("");
            defSB.AppendLine("");

            foreach (G25.FloatType FT in S.m_floatTypes)
            {
                foreach (G25.SMV smv in S.m_SMV)
                {
                    if (smv.NbNonConstBasisBlade == 0) continue;

                    String typeName = FT.GetMangledName(S, smv.Name);
                    String funcName = typeName + "_copy";
                    bool mustCast = false;

                    G25.fgs F = new G25.fgs(funcName, funcName, "", new String[] { smv.Name }, null, new String[] { FT.type }, null, null, null); // null, null, null = metricName, comment, options
                    F.InitArgumentPtrFromTypeNames(S);
                    bool computeMultivectorValue = false;
                    G25.CG.Shared.FuncArgInfo returnArgument = new G25.CG.Shared.FuncArgInfo(S, F, -1, FT, smv.Name, computeMultivectorValue);
                    int nbArgs = 1;
                    G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(S, F, nbArgs, FT, null, computeMultivectorValue);

                    declSB.AppendLine("/** Copies " + typeName + ": " + FAI[0].Name + " = " + returnArgument.Name + " */");

                    RefGA.Multivector value = G25.CG.Shared.Symbolic.SMVtoSymbolicMultivector(S, smv, FAI[0].Name, FAI[0].Pointer);

                    bool staticFunc = false;
                    G25.CG.Shared.Functions.WriteAssignmentFunction(S, cgd,
                        S.m_inlineSet, staticFunc, "void", null, funcName, returnArgument, FAI, FT, mustCast, smv, returnArgument.Name, returnArgument.Pointer, value);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Converts a <c>RefGA.Symbolic.BinaryScalarOpToLangString</c> to code.
        /// 
        /// Handles special cases (such as inversion) and understands floating point
        /// types (e.g., <c>fabsf()</c> is used for floats and <c>fabs()</c> is used for doubles in C.
        /// </summary>
        /// <param name="S">Used for output language.</param>
        /// <param name="FT">Floating point type used.</param>
        /// <param name="Op">The operation to convert to code.</param>
        /// <returns>Code for implementing <c>Op</c>c>.</returns>
        public static string BinaryScalarOpToLangString(G25.Specification S, G25.FloatType FT, RefGA.Symbolic.BinaryScalarOp Op)
        {
            string value1Str = ScalarOpValueToLangString(S, FT, Op.value1);
            string value2Str = ScalarOpValueToLangString(S, FT, Op.value2);

            return OpNameToLangString(S, FT, Op.opName) + "(" + value1Str + ", " + value2Str + ")";
        }
Example #14
0
        private static void WriteDefinition(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.Constant C)
        {
            // assume only SMV constants for now
            G25.SMV smv = C.Type as G25.SMV;
            ConstantSMV Csmv = C as ConstantSMV;

            string className = FT.GetMangledName(S, smv.Name);

            // MANGLED_TYPENAME MANGLED_CONSTANT_NAME = {...}
            SB.Append(className);
            SB.Append(" ");
            SB.Append(FT.GetMangledName(S, C.Name));

            if (smv.NbNonConstBasisBlade > 0) {
                // MANGLED_TYPENAME MANGLED_CONSTANT_NAME(...)
                SB.Append("(" + className + "::" + G25.CG.Shared.SmvUtil.GetCoordinateOrderConstant(S, smv));

                for (int c = 0; c < smv.NbNonConstBasisBlade; c++)
                {
                    SB.Append(", ");
                    SB.Append(FT.DoubleToString(S, Csmv.Value[c]));
                }

                SB.Append(")");
            }

            SB.AppendLine(";");
        }
Example #15
0
        public static List<string> GenerateCode(Specification S, G25.CG.Shared.CGdata cgd)
        {
            // get filename, list of generated filenames
            List<string> generatedFiles = new List<string>();

            if (!S.m_reportUsage) return generatedFiles;

            string sourceFilename = S.GetOutputPath(GetRawSourceFilename(S));
            generatedFiles.Add(sourceFilename);

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

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

            // using ...
            Util.WriteGenericUsing(SB, S);
            SB.AppendLine("using System.Collections.Generic;");
            SB.AppendLine("using System.Text;");

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

            cgd.m_cog.EmitTemplate(SB, "reportUsage");

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

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

            return generatedFiles;
        }
Example #16
0
        private static void WriteDefinition(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.Constant C)
        {
            // assume only SMV constants for now
            G25.SMV smv = C.Type as G25.SMV;
            ConstantSMV Csmv = C as ConstantSMV;

            // MANGLED_TYPENAME MANGLED_CONSTANT_NAME = {...}
            SB.Append(FT.GetMangledName(S, C.Type.GetName()));
            SB.Append(" ");
            SB.Append(FT.GetMangledName(S, C.Name));
            SB.Append(" = {");

            if (smv.NbNonConstBasisBlade == 0)
            {
                // 'C' does not allow empty structs, so there is a filler that must be initialized
                SB.Append("0");
            }
            else
            {
                if (S.m_coordStorage == COORD_STORAGE.ARRAY)
                    SB.Append("{");

                for (int c = 0; c < smv.NbNonConstBasisBlade; c++)
                {
                    if (c > 0) SB.Append(", ");
                    SB.Append(FT.DoubleToString(S, Csmv.Value[c]));
                }

                if (S.m_coordStorage == COORD_STORAGE.ARRAY)
                    SB.Append("}");
            }

            SB.AppendLine("};");
        }
Example #17
0
 /// <summary>
 /// Instruction for generating code for an assignment to a variable, with an optional declration of that same variable.
 /// </summary>
 /// <param name="nbTabs">How many tabs to put in front of code.</param>
 /// <param name="T">Type of assigned variable.</param>
 /// <param name="FT">Floating point type of coordinates of assigned variable. If T is a floating point type, then is equal to T.</param>
 /// <param name="mustCast">When assigning to variable, should the coordinates be cast to FT?</param>
 /// <param name="value">The assigned value.</param>
 /// <param name="name">Name of assigned variable.</param>
 /// <param name="ptr">Is the assigned variable a pointer?</param>
 /// <param name="declareVariable">If true, code for declaring the variable is also generated.</param>
 public AssignInstruction(int nbTabs, G25.VariableType T, G25.FloatType FT, bool mustCast, RefGA.Multivector value, string name, bool ptr, bool declareVariable)
     : base(nbTabs, T, FT, mustCast, value)
 {
     m_name = name;
     m_ptr = ptr;
     m_declareVariable = declareVariable;
 }
Example #18
0
 public static RefGA.Util.SIGN_TOGGLE_FUNCTION GetRefGAFunctionId(G25.fgs F)
 {
     if (IsNegate(F)) return RefGA.Util.SIGN_TOGGLE_FUNCTION.NEGATION;
     else if (IsReverse(F)) return RefGA.Util.SIGN_TOGGLE_FUNCTION.REVERSION;
     else if (IsCliffordConjugate(F)) return RefGA.Util.SIGN_TOGGLE_FUNCTION.CLIFFORD_CONJUGATION;
     else if (IsGradeInvolution(F)) return RefGA.Util.SIGN_TOGGLE_FUNCTION.GRADE_INVOLUTION;
     else return RefGA.Util.SIGN_TOGGLE_FUNCTION.NONE;
 }
Example #19
0
 /// <summary>
 /// Checks if this FunctionGenerator can implement a certain function.
 /// </summary>
 /// <param name="S">The specification of the algebra.</param>
 /// <param name="F">The function to be implemented.</param>
 /// <returns>true if 'F' can be implemented.</returns>
 public override bool CanImplement(Specification S, G25.fgs F)
 {
     int NB_ARGS = 2;
     return ((IsAdd(F) || IsSubtract(F)) && (F.MatchNbArguments(NB_ARGS)) &&
         G25.CG.Shared.Functions.NotMixSmvGmv(S, F, NB_ARGS, S.m_GMV.Name) &&
         G25.CG.Shared.Functions.NotMixScalarGmv(S, F, NB_ARGS, S.m_GMV.Name) &&
         G25.CG.Shared.Functions.NotUseOm(S, F, NB_ARGS, S.m_GMV.Name));
 }
Example #20
0
        protected Dictionary<string, string> m_randomScalarFunc = new Dictionary<string, string>(); ///< = mangled name of random scalar func 

        #endregion Fields

        #region Methods

        /// <summary>
        /// Return true if  <c>smv</c> can be initialized with random values for each coordinate:
        ///   - scalar types
        ///   - vector types
        ///   - dual vector types
        ///   - pseudoscalar types
        ///   - G25.SMV.MULTIVECTOR_TYPE.MULTIVECTOR types
        /// </summary>
        /// <param name="S"></param>
        /// <param name="smv"></param>
        /// <returns>true if  <c>smv</c> can be initialized with random values for each coordinate.</returns>
        public static bool InitWithRandomCoordinates(Specification S, G25.SMV smv)
        {
            if (smv.MvType == G25.SMV.MULTIVECTOR_TYPE.MULTIVECTOR) return true;
            int lg = smv.LowestGrade();
            int hg = smv.HighestGrade();
            if (lg != hg) return false;
            return ((lg == 0) || (lg == 1) || (lg == (S.m_dimension - 1)) || (lg == S.m_dimension));
        }
Example #21
0
 public static G25.CG.Shared.CANSparts.UnaryToggleSignType GetToggleType(G25.fgs F)
 {
     if (IsNegate(F)) return G25.CG.Shared.CANSparts.UnaryToggleSignType.NEGATE;
     else if (IsReverse(F)) return G25.CG.Shared.CANSparts.UnaryToggleSignType.REVERSE;
     else if (IsCliffordConjugate(F)) return G25.CG.Shared.CANSparts.UnaryToggleSignType.CLIFFORD_CONJUGATE;
     else if (IsGradeInvolution(F)) return G25.CG.Shared.CANSparts.UnaryToggleSignType.GRADE_INVOLUTION;
     else throw new Exception("G25.CG.C.ToggleSign.GetToggleType(): unknown toggle type: " + F.Name);
 }
Example #22
0
 public static String GetDescriptiveName(G25.fgs F)
 {
     if (IsNegate(F)) return "negation";
     else if (IsReverse(F)) return "reverse";
     else if (IsCliffordConjugate(F)) return "Clifford conjugate";
     else if (IsGradeInvolution(F)) return "grade involution";
     else throw new Exception("G25.CG.C.ToggleSign.GetDescriptiveName(): unknown toggle type: " + F.Name);
 }
Example #23
0
File: sas.cs Project: Sciumo/gaigen
        protected RefGA.Multivector m_returnValue; ///< returned value (symbolic multivector)

        #endregion Fields

        #region Methods

        /// <summary>
        /// Checks if this FunctionGenerator can implement a certain function.
        /// </summary>
        /// <param name="S">The specification of the algebra.</param>
        /// <param name="F">The function to be implemented.</param>
        /// <returns>true if 'F' can be implemented</returns>
        public override bool CanImplement(Specification S, G25.fgs F)
        {
            String arg1Type = F.GetArgumentTypeName(0, S.m_GMV.Name);
            return ((F.Name == "sas") && (F.MatchNbArguments(3) &&
                (S.IsSpecializedMultivectorName(arg1Type) || (arg1Type == S.m_GMV.Name)) &&
                S.IsFloatType(F.GetArgumentTypeName(1, S.m_GMV.Name)) &&
                S.IsFloatType(F.GetArgumentTypeName(2, S.m_GMV.Name))));
        }
Example #24
0
        /// <summary>
        /// Utility function which takes a specialized multivector and returns an array of its variable
        /// RefGA.BasisBlades. I.e., extracts 'smv.NonConstBasisBlade()'
        /// </summary>
        /// <param name="smv">Specialized multivector.</param>
        /// <returns>Array of non-constant basis blades of 'smv'.</returns>
        public static RefGA.BasisBlade[] GetNonConstBladeList(G25.SMV smv)
        {
            RefGA.BasisBlade[] BL = new RefGA.BasisBlade[smv.NbNonConstBasisBlade];

            for (int i = 0; i < smv.NbNonConstBasisBlade; i++)
                BL[i] = smv.NonConstBasisBlade(i);

            return BL;
        }
Example #25
0
        public static List<string> GenerateCode(Specification S, G25.CG.Shared.CGdata cgd)
        {
            // get filename, list of generated filenames
            List<string> generatedFiles = new List<string>();
            string sourceFilename = S.GetOutputPath(GetRawSourceFilename(S));
            generatedFiles.Add(sourceFilename);

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

            // 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);

            SB.AppendLine("public interface GroupBitmap {");

            // group
            int[] gradeBitmap = new int[S.m_dimension + 1];
            for (int i = 0; i < S.m_GMV.NbGroups; i++)
            {
                gradeBitmap[S.m_GMV.Group(i)[0].Grade()] |= 1 << i;

                SB.Append("\tpublic static final int " + G25.CG.CSJ.GroupBitmap.GetGroupBitmapName(i) + "  = " + (1 << i) + "; // ");

                for (int j = 0; j < S.m_GMV.Group(i).Length; j++)
                {
                    if (j > 0) SB.Append(", ");
                    SB.Append(S.m_GMV.Group(i)[j].ToString(S.m_basisVectorNames));
                }
                SB.AppendLine();
            }
            SB.AppendLine();
            SB.AppendLine("\tpublic static final int ALL_GROUPS = " + ((1 << S.m_GMV.NbGroups) - 1) + "; // all groups");
            SB.AppendLine();

            // grade
            for (int i = 0; i <= S.m_dimension; i++)
            {
                SB.AppendLine("\tpublic static final int " + G25.CG.CSJ.GroupBitmap.GetGradeBitmapName(i) + " = " + gradeBitmap[i] + ";");
            }
            SB.AppendLine();
            SB.AppendLine("\tpublic static final int ALL_GRADES = " + ((1 << S.m_GMV.NbGroups) - 1) + "; // all grades");
            SB.AppendLine();

            SB.AppendLine("}");

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

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

            return generatedFiles;
        }
Example #26
0
File: smv.cs Project: Sciumo/gaigen
 /// <summary>
 /// Writes constructors.
 /// </summary>
 /// <param name="SB">Where the code goes.</param>
 /// <param name="S">Used for basis vector names and output language.</param>
 /// <param name="cgd">Not used yet.</param>
 /// <param name="FT">Float point type of 'SMV'.</param>
 /// <param name="smv">The specialized multivector for which the struct should be written.</param>
 public static void WriteConstructors(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.SMV smv)
 {
     cgd.m_cog.EmitTemplate(SB, "SMVconstructors",
         "S=", S,
         "smv=", smv,
         "className=", FT.GetMangledName(S, smv.Name),
         "gmvClassName=", FT.GetMangledName(S, S.m_GMV.Name),
         "FT=", FT);
 }
Example #27
0
        /// <summary>
        /// Checks if this FunctionGenerator can implement a certain function.
        /// </summary>
        /// <param name="S">The specification of the algebra.</param>
        /// <param name="F">The function to be implemented.</param>
        /// <returns>true if 'F' can be implemented</returns>
        public override bool CanImplement(Specification S, G25.fgs F)
        {
            if (!((F.Name == "log") && (F.MatchNbArguments(1)))) return false;

            string type = F.GetOption("type");
            if (type == null) return false;

            return type.ToLower().Equals("euclidean");
        }
Example #28
0
File: ip.cs Project: Sciumo/gaigen
        RefGA.BasisBlade.InnerProductType m_ipType; ///< type of inner product (left, right, Hestenes, etc)

        #endregion Fields

        #region Methods

        /// <summary>
        /// Converts the name of the function to a human readable name.
        /// </summary>
        /// <param name="S"></param>
        /// <param name="F">Function (used for <c>F.name</c>).</param>
        /// <returns>Human readable version of Function <c>F.name</c>.</returns>
        public static String GetIpName(Specification S, G25.fgs F)
        {
            if (IsHip(F)) return "Hestenes inner product";
            else if (IsMHip(F)) return "Modified Hestenes inner product";
            else if (IsLc(F)) return "left contraction";
            else if (IsRc(F)) return "right contraction";
            else if (IsSp(F)) return "scalar product";
            else throw new G25.UserException("G25.CG.C.IP.GetIpName(): unknown inner product type: " + F.Name, XML.FunctionToXmlString(S, F));
        }
Example #29
0
 /// <summary>
 /// Returns the name of the constant as first argument to functions which have coordinate arguments.
 /// </summary>
 /// <param name="S"></param>
 /// <param name="smv"></param>
 public static string GetCoordinateOrderConstant(Specification S, G25.SMV smv)
 {
     StringBuilder SB = new StringBuilder("coord");
     string wedgeSymbol = ""; // no symbol for wedge
     for (int i = 0; i < smv.NbNonConstBasisBlade; i++)
     {
         SB.Append("_");
         SB.Append(smv.NonConstBasisBlade(i).ToLangString(S.m_basisVectorNames, wedgeSymbol));
     }
     return SB.ToString();
 }
Example #30
0
 /// <summary>
 /// Returns string to access coordinates number 'coordIdx'.
 /// </summary>
 /// <param name="S"></param>
 /// <param name="smv"></param>
 /// <param name="coordIdx"></param>
 /// <returns></returns>
 public static string GetCoordAccessString(Specification S, G25.SMV smv, int coordIdx)
 {
     if (S.m_coordStorage == COORD_STORAGE.VARIABLES)
     {
         return "m_" + smv.GetCoordLangID(coordIdx, S);
     }
     else
     {
         return "m_c[" + coordIdx + "]";
     }
 }