Exemple #1
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);
                m_subtractGmvFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);

                // actual requirements:
                if (m_gmvFunc)
                {
                    m_randomBladeFuncName[FT.type]   = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_blade", new String[0], m_specification.m_GMV.Name, FT, null);
                    m_randomVersorFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_versor", new String[0], m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_unitVersorFuncName[FT.type]    = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "unit", new String[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_innerProductFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "mhip", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_versorInverseFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "versorInverse", new String[] { m_versorMv.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                }
                else
                {
                    string defaultReturnTypeName = null;

                    m_applyVersorGmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "applyVersor", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, defaultReturnTypeName, FT, m_G25M.m_name);
                    m_randomVersorFuncName[FT.type]   = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_versorMv.Name, new String[0], defaultReturnTypeName, FT, m_G25M.m_name);
                    m_randomSmvFuncName[FT.type]      = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_subjectMv.Name, new String[0], defaultReturnTypeName, FT, m_G25M.m_name);
                    //   Console.WriteLine("Asking for unit versor with metric " + m_G25M.m_name);
                    m_unitVersorFuncName[FT.type]    = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "unit", new String[] { m_versorMv.Name }, defaultReturnTypeName, FT, m_G25M.m_name);
                    m_versorInverseFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "versorInverse", new String[] { m_versorMv.Name }, defaultReturnTypeName, FT, m_G25M.m_name);
                    m_norm2VersorFuncName[FT.type]   = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "norm2", new String[] { m_versorMv.Name }, defaultReturnTypeName, FT, m_G25M.m_name);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new string[0], FT.type, FT, null);

                if (m_gmvFunc)
                {
                    m_randomBladeFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_blade", new string[0], m_specification.m_GMV.Name, FT, null);
                    m_expFuncName[FT.type]         = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "exp", new string[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_opFuncName[FT.type]          = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "op", new string[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                    m_subtractGmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new string[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                }
                else if (m_smv != null)
                {
                    //argTable["randomBivectorFuncName"] = m_randomBivectorFuncName[FT.type];
                    //argTable["expBivectorFunc"] = m_expBivectorFuncName[FT.type];
                    //argTable["subtractRotorFuncName"] = m_subtractRotorFuncName[FT.type];

                    string defaultReturnTypeName = null;
                    string bivectorName          = (m_returnType as G25.SMV).Name;
                    m_randomBivectorFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + (m_returnType as G25.SMV).Name, new string[0], defaultReturnTypeName, FT, null);
                    m_expBivectorFuncName[FT.type]    = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "exp", new string[] { bivectorName }, m_smv.Name, FT, m_G25M.m_name);
                    m_subtractRotorFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new string[] { m_smv.Name, m_smv.Name }, m_smv.Name, FT, null);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);

                // actual requirements:
                m_addGmvFuncName[FT.type]      = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "add", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                m_subtractGmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);

                if (m_gradeIdx >= 0)
                {
                    m_gradeGmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, G25.CG.Shared.CANSparts.EXTRACT_GRADE, new String[] { m_specification.m_GMV.Name, G25.GroupBitmapType.GROUP_BITMAP }, m_specification.m_GMV.Name, FT, null);
                }

                if (m_gmvFunc)
                {
                    m_randomVersorFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_versor", new String[0], m_specification.m_GMV.Name, FT, null);
                }
                else if (m_smv != null)
                {
                    string defaultReturnTypeName = null;

                    m_randomSmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv.Name, new String[0], defaultReturnTypeName, FT, null);
                }
            }
        }
Exemple #4
0
        } // end of CompleteFGS()

        /// <summary>
        /// Writes the declaration/definitions of 'F' to StringBuffer 'SB', taking into account parameters specified in specification 'S'.
        /// </summary>
        public override void WriteFunction()
        {
            foreach (String floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                bool computeMultivectorValue    = true;
                G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT,
                                                                                              m_specification.m_GMV.Name, computeMultivectorValue);

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

                m_funcName[FT.type] = CF.OutputName;

                Comment comment;
                if (IsDistance(m_fgs))
                {
                    comment = new Comment(m_fgs.AddUserComment("Returns distance of two conformal points."));
                }
                else
                {
                    comment = new Comment(m_fgs.AddUserComment("Returns distance squared of two conformal points."));
                }

                // write out the function:
                G25.CG.Shared.Functions.WriteSpecializedFunction(m_specification, m_cgd, CF, FT, FAI, m_returnValue, comment);
            }
        } // end of WriteFunction
Exemple #5
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);
                m_subtractGmvFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);

                // actual requirements:
                if (m_gmvFunc)
                {
                    m_randomBladeFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_blade", new String[0], m_specification.m_GMV.Name, FT, null);
                    m_gpGmvFuncName[FT.type]        = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "gp", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_extractGradeFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, G25.CG.Shared.CANSparts.EXTRACT_GRADE, new String[] { m_specification.m_GMV.Name, G25.GroupBitmapType.GROUP_BITMAP }, m_specification.m_GMV.Name, FT, null);
                }
                else if ((m_smv1 != null) && (m_smv2 != null))
                {
                    string defaultReturnTypeName = null;
                    m_randomSmv1FuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv1.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_randomSmv2FuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv2.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_gmvProductFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, m_fgs.Name, new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                }
            }
        } // end of CheckTestingDepencies()
Exemple #6
0
        /// <summary>
        /// Writes the declaration/definitions of 'F' to StringBuffer 'SB', taking into account parameters specified in specification 'S'.
        /// </summary>
        public override void WriteFunction()
        {
            foreach (String floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                bool computeMultivectorValue    = true;
                G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

                // comment
                Comment comment = new Comment(
                    m_fgs.AddUserComment("Returns outer product of " + FAI[0].TypeName + " and " + FAI[1].TypeName + "."));

                // if scalar or specialized: generate specialized function
                if (m_gmvFunc)
                {
                    m_funcName[FT.type] = G25.CG.Shared.GmvGpParts.WriteGMVgpFunction(m_specification, m_cgd, FT, m_specification.GetMetric(XML.XML_DEFAULT), FAI, m_fgs, comment, G25.CG.Shared.GPparts.ProductTypes.OUTER_PRODUCT);
                }
                else
                {// write simple specialized function:
                    // because of lack of overloading, function names include names of argument types
                    G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(m_specification, FT, m_fgs, FAI);
                    m_funcName[FT.type] = CF.OutputName;

                    // write out the function:
                    G25.CG.Shared.Functions.WriteSpecializedFunction(m_specification, m_cgd, CF, FT, FAI, m_returnValue, comment);
                }
            }
        } // end of WriteFunction
Exemple #7
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);
                m_subtractGmvFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);

                if (m_gmvFunc)
                {
                    m_addGmvFuncName[FT.type]      = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "add", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                    m_randomBladeFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_blade", new String[0], m_specification.m_GMV.Name, FT, null);
                    m_sinhFuncName[FT.type]        = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "sinh", new String[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_coshFuncName[FT.type]        = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "cosh", new String[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_expFuncName[FT.type]         = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "exp", new String[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                }
                else if (m_smv != null)
                {
                    string defaultReturnTypeName = null;
                    m_randomSmvFuncName[FT.type]   = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_gpSinCosExpFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, m_fgs.Name, new String[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);
                }
            }
        }
        public static G25.VariableType CreateSyntheticSMVtype(Specification S, CGdata cgd, FloatType FT, RefGA.Multivector value)
        {
            // make up list of basis blades
            rsbbp.BasisBlade[] L = new rsbbp.BasisBlade[value.BasisBlades.Length];
            for (int i = 0 ; i < value.BasisBlades.Length; i++)
            {
                RefGA.BasisBlade B = value.BasisBlades[i];
                if (B.symScale == null) L[i] = new rsbbp.BasisBlade(new RefGA.BasisBlade(B.bitmap), B.scale); // constant value
                else L[i] = new rsbbp.BasisBlade(new RefGA.BasisBlade(B.bitmap)); // non-const value
            }

            // get other required info
            String name = "nameOfType";
            SMV.MULTIVECTOR_TYPE mvType = SMV.MULTIVECTOR_TYPE.MULTIVECTOR;
            String comment = "MISSING; PLEASE ADD TO SPECIFICATION";
            //String constantName = null;

            // create the type
            G25.SMV synSMV = new G25.SMV(name, L, mvType, comment);

            // throw exception
            throw new G25.UserException("Missing specialized multivector type.\n" +
                "Please add the following XML to the specification to fix the dependency:\n" +
                XML.SMVtoXmlString(S, synSMV));
        }
Exemple #9
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("};");
        }
Exemple #10
0
        private void SumupRootWeighted(SumupInputData input, FeatureHistogram histogram)
        {
            // Sum up the non-zero values, then subtract from total to get the zero values
            Contracts.Assert(histogram.SumWeightsByBin != null);
            Contracts.Assert(input.Weights != null);
            double totalOutput = 0;
            double totalWeight = 0;
            int    currentPos  = 0;

            for (int i = 0; i < _values.Length; i++)
            {
                currentPos += _deltas[i];

                int       featureBin = _values[i];
                FloatType output     = (FloatType)input.Outputs[currentPos];
                FloatType weight     = (FloatType)input.Weights[currentPos];

                histogram.SumTargetsByBin[featureBin] = (FloatType)(histogram.SumTargetsByBin[featureBin] + output);
                histogram.SumWeightsByBin[featureBin] = (FloatType)(histogram.SumWeightsByBin[featureBin] + weight);
                ++histogram.CountByBin[featureBin];
                totalOutput += output;
                totalWeight += weight;
            }
            // Fixup the zeros. There were some zero items already placed in the zero-th entry, just add the remainder
            histogram.SumTargetsByBin[0] += (FloatType)(input.SumTargets - totalOutput);
            histogram.SumWeightsByBin[0] += (FloatType)(input.SumWeights - totalWeight);
            histogram.CountByBin[0]      += input.TotalCount - _values.Length;
        }
Exemple #11
0
        /// <summary>
        /// Calculates the weighted mean of a double array only on the elements that correspond to a specified leaf in the tree
        /// </summary>
        /// <param name="array">the double array</param>
        /// <param name="sampleWeights">Weights of array elements</param>
        /// <param name="leaf">the leaf index</param>
        /// <param name="filterZeros"></param>
        /// <returns>the mean</returns>
        public double Mean(double[] array, double[] sampleWeights, int leaf, bool filterZeros)
        {
            if (sampleWeights == null)
            {
                return(Mean(array, leaf, filterZeros));
            }
            double mean      = 0.0;
            int    end       = _leafBegin[leaf] + _leafCount[leaf];
            double sumWeight = 0;

            if (filterZeros)
            {
                double value;
                for (int i = _leafBegin[leaf]; i < end; ++i)
                {
                    value = array[_documents[i]];
                    if (value != 0)
                    {
                        FloatType weight = (FloatType)sampleWeights[_documents[i]];
                        mean      += value * weight;
                        sumWeight += weight;
                    }
                }
            }
            else
            {
                for (int i = _leafBegin[leaf]; i < end; ++i)
                {
                    FloatType weight = (FloatType)sampleWeights[_documents[i]];
                    mean      += array[_documents[i]] * weight;
                    sumWeight += weight;
                }
            }
            return(mean / sumWeight);
        }
Exemple #12
0
        /// <summary>
        /// Writes the testing function for 'F' to 'm_defSB'.
        /// The generated function returns success (1) or failure (0).
        /// </summary>
        /// <returns>The list of name name of the int() function which tests the function.</returns>
        public override List <string> WriteTestFunction()
        {
            StringBuilder defSB = (m_specification.m_inlineFunctions) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            List <string> testFuncNames = new List <string>();

            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                string testFuncName = Util.GetTestingFunctionName(m_specification, m_cgd, m_funcName[FT.type]);

                testFuncNames.Add(testFuncName);
                System.Collections.Hashtable argTable = new System.Collections.Hashtable();
                argTable["S"]                      = m_specification;
                argTable["FT"]                     = FT;
                argTable["gmv"]                    = m_specification.m_GMV;
                argTable["gmvName"]                = FT.GetMangledName(m_specification, m_specification.m_GMV.Name);
                argTable["testFuncName"]           = testFuncName;
                argTable["targetFuncName"]         = m_funcName[FT.type];
                argTable["targetFuncReturnsFloat"] = m_specification.IsFloatType(m_fgs.ReturnTypeName);
                argTable["randomScalarFuncName"]   = m_randomScalarFuncName[FT.type];
                argTable["reverseFuncName"]        = m_reverseFuncName[FT.type];
                argTable["gpFuncName"]             = m_gpFuncName[FT.type];
                m_cgd.m_cog.EmitTemplate(defSB, "testRandomGMV", argTable);
            }

            return(testFuncNames);
        } // end of WriteTestFunction()
Exemple #13
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(";");
        }
Exemple #14
0
        /// <summary>
        /// Writes the declaration/definitions of 'F' to StringBuffer 'SB', taking into account parameters specified in specification 'S'.
        /// </summary>
        public override void WriteFunction()
        {
            foreach (String floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                bool computeMultivectorValue    = true;
                G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

                // comment
                Comment comment = new Comment(
                    m_fgs.AddUserComment("Returns a bitmap where each one-bit means that at least one coordinate of the respective grade of  " + FAI[0].Name + " is larger than " + FAI[1].Name));

                // if scalar or specialized: generate specialized function
                if (m_gmvFunc)
                {
                    m_funcName[FT.type] = G25.CG.Shared.GmvCASNparts.WriteEqualsOrZeroOrGradeBitmapFunction(m_specification, m_cgd, FT, FAI, m_fgs, comment, G25.CG.Shared.CANSparts.EQUALS_ZERO_GRADEBITMAP_TYPE.GRADE_BITMAP);
                }
                else
                {// write simple specialized function:
                 // because of lack of overloading, function names include names of argument types
                 //G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(m_specification, m_fgs, FAI);

                    // write out the function:
                    WriteGradeBitmapFunction(FT, FAI, m_fgs, comment);
                }
            }
        } // end of WriteFunction
Exemple #15
0
        /// <summary>
        /// This function should check the dependencies of this function. If dependencies are
        /// missing, the function can complain (throw exception) or fix it (add the required functions).
        ///
        /// If changes are made to the specification then it must be locked first because
        /// multiple threads run in parallel which may all modify the specification!
        /// </summary>
        public override void CheckDepencies()
        {
            string GMVname = m_specification.m_GMV.Name;

            // check dependencies for all float types
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_GMVname[floatName] = FT.GetMangledName(m_specification, GMVname);

                //bool returnTrueName = false;
                m_randomScalarFunc[floatName] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, RandomScalar.RANDOM + floatName, new string[0], floatName, FT, null);
                //if (m_specification.m_outputLanguage != OUTPUT_LANGUAGE.C)
                //  m_randomScalarFunc[floatName] = FT.GetMangledName(m_specification, m_randomScalarFunc[floatName]);

                m_normFunc[floatName] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "norm", new string[] { GMVname }, FT, m_G25M.m_name) + G25.CG.Shared.CANSparts.RETURNS_SCALAR;

                m_scalarGpFunc[floatName] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "gp", new string[] { GMVname, floatName }, FT, null); // null = no metric for op required

                if (IsBlade(m_fgs))
                {
                    m_gpopFunc[floatName] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "op", new string[] { GMVname, GMVname }, FT, null);                 // null = no metric for op required
                }
                else if (IsVersor(m_fgs))
                {
                    m_gpopFunc[floatName] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "gp", new string[] { GMVname, GMVname }, FT, m_G25M.m_name);
                }
            }
        }
Exemple #16
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;
        }
Exemple #17
0
        } // end of WriteFunctions()

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

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

            bool ptr = true;

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

            string funcName = F.OutputName;

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

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

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

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

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

                bool staticFunc = S.OutputCSharpOrJava();
                G25.CG.Shared.Functions.WriteReturnFunction(S, cgd,
                                                            S.m_inlineSet, staticFunc, funcName, FAI, FT, mustCast, returnType, value);
            }
        } // end of WriteSpecializedFunction()
Exemple #18
0
        /// <summary>
        /// Writes the declaration/definitions of 'F' to StringBuffer 'SB', taking into account parameters specified in specification 'S'.
        /// </summary>
        public override void WriteFunction()
        {
            StringBuilder declSB = m_cgd.m_declSB;
            bool          inline = false; // never inline GMV functions
            StringBuilder defSB  = (inline) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                string funcName = FT.GetMangledName(m_specification, m_fgs.OutputName);
                m_funcName[FT.type] = funcName;

                // setup hashtable with template arguments:
                System.Collections.Hashtable argTable = new System.Collections.Hashtable();
                argTable["S"]                    = m_specification;
                argTable["functionName"]         = funcName;
                argTable["FT"]                   = FT;
                argTable["mvType"]               = FT.GetMangledName(m_specification, m_specification.m_GMV.Name);
                argTable["randomScalarFuncName"] = m_randomScalarFunc[floatName];
                argTable["gpopFuncName"]         = m_gpopFunc[floatName];
                argTable["normFuncName"]         = m_normFunc[floatName];
                argTable["gpScalarFuncName"]     = m_scalarGpFunc[floatName];
                argTable["generatorVersor"]      = (IsVersor(m_fgs) ? true : false);

                if (m_specification.OutputCppOrC())
                {
                    // header
                    m_cgd.m_cog.EmitTemplate(declSB, "randomBladeVersorHeader", argTable);
                }

                // source
                m_cgd.m_cog.EmitTemplate(defSB, "randomBladeVersor", argTable);
            }
        } // end of WriteFunction
Exemple #19
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);
                m_subtractGmvFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);

                // get name of undual function (this 'inverse' of the function that is being tested)
                string undualFuncName = IsDual(m_fgs) ? "undual" : "dual";
                m_undualFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, undualFuncName, new String[] { m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, m_G25M.m_name);

                if (m_gmvFunc)
                {
                    m_randomBladeFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_blade", new String[0], m_specification.m_GMV.Name, FT, null);
                }
                else if (m_smv != null)
                {
                    string defaultReturnTypeName = null;

                    m_randomSmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv.Name, new String[0], defaultReturnTypeName, FT, null);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);

                // actual requirements:
                if (m_gmvFunc)
                {
                    m_randomBladeFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_blade", new String[0], m_specification.m_GMV.Name, FT, null);
                    m_subtractGmvFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                    m_opGmvFuncName[FT.type]       = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "op", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                }
                else if (m_specification.m_GOM != null) // test for applyOM(SMV) can only be performed when GOM exists
                {
                    string defaultReturnTypeName = null;

                    G25.SMV gomRangeVectorType = getGomRangeVectorType(FT);

                    m_randomRangeVectorFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + gomRangeVectorType.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_randomDomainSmvFuncName[FT.type]   = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_mv.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_subtractGmvFuncName[FT.type]       = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, defaultReturnTypeName, FT, null);
                    m_gmvApplyOmFuncName[FT.type]        = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "applyOM", new String[] { m_specification.m_GOM.Name, m_specification.m_GMV.Name }, defaultReturnTypeName, FT, null);
                }
            }
        }
Exemple #21
0
 /// <summary>
 /// This function should check the dependencies of this function. If dependencies are
 /// missing, the function can complain (throw exception) or fix it (add the required functions).
 ///
 /// If changes are made to the specification then it must be locked first because
 /// multiple threads run in parallel which may all modify the specification!
 /// </summary>
 public override void CheckDepencies()
 {
     if (m_gmvFunc)
     {
         // check dependencies for all float types
         foreach (String floatName in m_fgs.FloatNames)
         {
             FloatType FT = m_specification.GetFloatType(floatName);
             //bool returnTrueName = false;
             G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "div", new String[] { m_gmv.Name, FT.type }, FT, null);
             if (m_arg2isGmv)
             {
                 G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "reverse", new String[] { m_gmv.Name }, FT, null);
                 G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "norm2", new String[] { m_gmv.Name }, FT, m_G25M.m_name);
                 if (m_arg1isGmv)
                 {
                     G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "gp", new String[] { m_gmv.Name, m_gmv.Name }, FT, m_G25M.m_name);
                 }
                 else
                 {
                     G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "gp", new String[] { m_gmv.Name, FT.type }, FT, m_G25M.m_name);
                 }
             }
         }
     }
 }
Exemple #22
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("}");
        }
Exemple #23
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new String[0], FT.type, FT, null);
                m_subtractGmvFuncName[FT.type]  = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "subtract", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);

                // actual requirements:
                if (m_trueGmvFunc)
                {
                    m_randomVersorFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_versor", new String[0], m_specification.m_GMV.Name, FT, m_G25M.m_name);
                    m_addGmvFuncName[FT.type]       = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "add", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, m_specification.m_GMV.Name, FT, null);
                }
                else if ((m_smv1 != null) && (m_smv2 != null))
                {
                    string defaultReturnTypeName = null;

                    m_randomSmv1FuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv1.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_randomSmv2FuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_smv2.Name, new String[0], defaultReturnTypeName, FT, null);
                    m_gpGmvFuncName[FT.type]      = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "gp", new String[] { m_specification.m_GMV.Name, m_specification.m_GMV.Name }, defaultReturnTypeName, FT, m_G25M.m_name);
                }
            }
        } // end of CheckTestingDepencies()
Exemple #24
0
        /// <summary>
        /// This function checks the dependencies for the _testing_ code of this function. If dependencies are
        /// missing, the function adds the required functions (this is done simply by asking for them . . .).
        /// </summary>
        public override void CheckTestingDepencies()
        {
            //bool returnTrueName = true;
            foreach (string floatName in m_fgs.FloatNames)
            {
                string    defaultReturnTypeName = null;
                FloatType FT = m_specification.GetFloatType(floatName);

                m_randomScalarFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + FT.type, new string[0], FT.type, FT, null);

                if (IsFlatPointBased(m_specification, m_fgs, FT))
                {
                    m_randomFlatPointFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_flatPointType.GetName(), new string[0], defaultReturnTypeName, FT, null);
                    m_opFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "op", new string[2] {
                        m_specification.m_GMV.Name, m_specification.m_GMV.Name
                    }, defaultReturnTypeName, FT, null);
                }
                else
                {
                    if (m_vectorType != null)
                    {
                        m_randomVectorFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_vectorType.GetName(), new string[0], defaultReturnTypeName, FT, null);
                        m_randomVectorFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "random_" + m_vectorType.GetName(), new string[0], defaultReturnTypeName, FT, null);
                    }
                    else
                    {
                        m_randomVectorFuncName[FT.type] = "not_set";
                    }

                    m_spFuncName[FT.type] = G25.CG.Shared.Dependencies.GetDependency(m_specification, m_cgd, "sp", new string[] { m_fgs.m_returnTypeName, m_fgs.m_returnTypeName }, defaultReturnTypeName, FT, m_G25M.m_name);
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Write the declaration/definition of 'F' to 'm_declSB', 'm_defSB' and 'm_inlineDefSB',
        /// taking into account parameters specified in specification 'S'.
        /// </summary>
        public override void WriteFunction()
        {
            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);
                bool      computeMultivectorValue = true;
                G25.CG.Shared.FuncArgInfo[] FAI   = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

                // comment
                Comment comment = new Comment(m_fgs.AddUserComment("Returns " + FAI[0].TypeName + (IsAdd(m_fgs) ? " + " : " - ") + FAI[1].TypeName + "."));

                // if scalar or specialized: generate specialized function
                if (m_gmvFunc)
                {
                    m_funcName[FT.type] = G25.CG.Shared.GmvCASNparts.WriteAddSubHpFunction(m_specification, m_cgd, FT, FAI, m_fgs, comment,
                                                                                           IsAdd(m_fgs) ? G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE.ADD : G25.CG.Shared.CANSparts.ADD_SUB_HP_TYPE.SUB);
                }
                else
                { // write simple specialized function:
                    // because of lack of overloading, function names include names of argument types
                    G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(m_specification, FT, m_fgs, FAI);
                    m_funcName[FT.type] = CF.OutputName;

                    // write out the function:
                    G25.CG.Shared.Functions.WriteSpecializedFunction(m_specification, m_cgd, CF, FT, FAI, m_returnValue, comment);
                }
            }
        } // end of WriteFunction
Exemple #26
0
        protected void WriteNormReturnsScalarPassThrough(Specification S, FloatType FT, G25.CG.Shared.FuncArgInfo[] FAI, string funcName)
        {
            StringBuilder declSB = m_cgd.m_declSB;
            StringBuilder defSB  = (m_specification.m_inlineFunctions) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            string inlineStr = G25.CG.Shared.Util.GetInlineString(m_specification, m_specification.m_inlineFunctions, " ");
            string refPtrStr = "";

            if (m_specification.OutputC())
            {
                refPtrStr = "*";
            }
            else if (m_specification.OutputCpp())
            {
                refPtrStr = "&";
            }

            string ACCESS = "";

            if (m_specification.OutputJava())
            {
                ACCESS = "public final static ";
            }
            else if (m_specification.OutputCSharp())
            {
                ACCESS = "public static ";
            }

            string VAR_MOD = "";

            if (m_specification.OutputCppOrC())
            {
                VAR_MOD = "const ";
            }
            if (m_specification.OutputJava())
            {
                VAR_MOD = "final ";
            }

            string funcDecl = ACCESS + FT.type + " " + funcName + G25.CG.Shared.CANSparts.RETURNS_SCALAR + "(" + VAR_MOD + FAI[0].MangledTypeName + " " + refPtrStr + FAI[0].Name + ")";
            string comment  = "internal conversion function";

            int nbTabs = 0;

            if (m_specification.OutputCppOrC())
            {
                new Comment(comment).Write(declSB, m_specification, nbTabs);
                declSB.Append(funcDecl);
                declSB.AppendLine(";");
            }
            else
            {
                new Comment(comment).Write(defSB, m_specification, nbTabs);
            }

            defSB.Append(inlineStr + funcDecl);
            defSB.AppendLine(" {");
            defSB.AppendLine("\treturn " + funcName + "(" + FAI[0].Name + ");");
            defSB.AppendLine("}");
        }
Exemple #27
0
        /// <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;
        }
Exemple #28
0
        private float UnpackFloatCellCoord(PropertyInfo info, Bitstream stream, FloatType type)
        {
            uint  value = stream.ReadBits(info.NumBits);
            float f     = value;

            if ((value >> 31) > 0)
            {
                f *= -1;
            }

            if (type == FloatType.None)
            {
                uint fraction = stream.ReadBits(5);

                return(f + 0.03125f * fraction);
            }
            else if (type == FloatType.LowPrecision)
            {
                uint fraction = stream.ReadBits(3);

                return(f + 0.125f * fraction);
            }
            else if (type == FloatType.Integral)
            {
                return(f);
            }
            else
            {
                throw new InvalidOperationException("Unknown float type");
            }
        }
Exemple #29
0
        /// <summary>
        /// Writes the declaration/definitions of 'F' to StringBuffer 'SB', taking into account parameters specified in specification 'S'.
        /// </summary>
        public override void WriteFunction()
        {
            const int nbArgs = 1;

            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                bool computeMultivectorValue    = true;
                G25.CG.Shared.FuncArgInfo[] FAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, nbArgs, FT, m_specification.m_GMV.Name, computeMultivectorValue);

                // comment
                Comment comment = new Comment(
                    m_fgs.AddUserComment("Returns " + m_fgs.Name + " of " + FAI[0].TypeName + " using " + m_G25M.m_name + " metric."));

                // if scalar or specialized: generate specialized function
                if (m_gmvFunc)
                {
                    bool dual = IsDual(m_fgs);
                    m_funcName[FT.type] = G25.CG.Shared.GmvDualParts.WriteDualFunction(m_specification, m_cgd, FT, m_G25M, FAI, m_fgs, comment, dual);
                }
                else
                {// write simple specialized function:
                    // because of lack of overloading, function names include names of argument types
                    G25.fgs CF = G25.CG.Shared.Util.AppendTypenameToFuncName(m_specification, FT, m_fgs, FAI);

                    m_funcName[FT.type] = CF.OutputName;

                    // write out the function:
                    G25.CG.Shared.Functions.WriteSpecializedFunction(m_specification, m_cgd, CF, FT, FAI, m_returnValue, comment);
                }
            }
        } // end of WriteFunction
Exemple #30
0
        } // end of CheckTestingDepencies()

        /// <summary>
        /// Writes the testing function for 'F' to 'm_defSB'.
        /// The generated function returns success (1) or failure (0).
        /// </summary>
        /// <returns>The list of name name of the int() function which tests the function.</returns>
        public override List <string> WriteTestFunction()
        {
            StringBuilder defSB = (m_specification.m_inlineFunctions) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            List <string> testFuncNames = new List <string>();


            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                string testFuncName = Util.GetTestingFunctionName(m_specification, m_cgd, m_funcName[FT.type]);

                if (m_trueGmvFunc) // GMV test
                {
                    testFuncNames.Add(testFuncName);
                    System.Collections.Hashtable argTable = new System.Collections.Hashtable();
                    argTable["S"]                     = m_specification;
                    argTable["FT"]                    = FT;
                    argTable["gmvName"]               = FT.GetMangledName(m_specification, m_specification.m_GMV.Name);
                    argTable["testFuncName"]          = testFuncName;
                    argTable["targetFuncName"]        = m_funcName[FT.type];
                    argTable["randomScalarFuncName"]  = m_randomScalarFuncName[FT.type];
                    argTable["randomVersorFuncName"]  = m_randomVersorFuncName[FT.type];
                    argTable["subtractFuncName"]      = m_subtractGmvFuncName[FT.type];
                    argTable["gpFuncName"]            = m_gpFuncName[FT.type];
                    argTable["versorInverseFuncName"] = m_versorInverseFuncName[FT.type];

                    m_cgd.m_cog.EmitTemplate(defSB, "testIGP_GMV", argTable);
                }
                else if ((m_smv1 != null) && (m_smv2 != null) &&
                         m_smv1.CanConvertToGmv(m_specification) && m_smv2.CanConvertToGmv(m_specification) &&
                         (m_specification.GetType(m_fgs.m_returnTypeName) as G25.MV).CanConvertToGmv(m_specification))
                { // SMV test
                    testFuncNames.Add(testFuncName);
                    System.Collections.Hashtable argTable = new System.Collections.Hashtable();
                    argTable["S"]                     = m_specification;
                    argTable["FT"]                    = FT;
                    argTable["testFuncName"]          = testFuncName;
                    argTable["targetFuncName"]        = m_funcName[FT.type];
                    argTable["smv1"]                  = m_smv1;
                    argTable["smv2"]                  = m_smv2;
                    argTable["smv1Name"]              = FT.GetMangledName(m_specification, m_smv1.Name);
                    argTable["smv2Name"]              = FT.GetMangledName(m_specification, m_smv2.Name);
                    argTable["smvRName"]              = FT.GetMangledName(m_specification, m_fgs.m_returnTypeName);
                    argTable["gmvName"]               = FT.GetMangledName(m_specification, m_specification.m_GMV.Name);
                    argTable["randomScalarFuncName"]  = m_randomScalarFuncName[FT.type];
                    argTable["randomSmv1FuncName"]    = m_randomSmv1FuncName[FT.type];
                    argTable["randomSmv2FuncName"]    = m_randomSmv2FuncName[FT.type];
                    argTable["gpFuncName"]            = m_gpFuncName[FT.type];
                    argTable["subtractFuncName"]      = m_subtractGmvFuncName[FT.type];
                    argTable["versorInverseFuncName"] = m_versorInverseFuncName[FT.type];

                    m_cgd.m_cog.EmitTemplate(defSB, "testIGP_SMV", argTable);
                }
            }

            return(testFuncNames);
        } // end of WriteTestFunction()
Exemple #31
0
 /// <summary>
 /// Writes the <c>defines</c> for indices of the smv struct to 'SB'. For example,  <c>define VECTOR_E1 0</c>.
 /// </summary>
 /// <param name="SB">Where the code goes.</param>
 /// <param name="S">Used for basis vector names.</param>
 /// <param name="FT"></param>
 /// <param name="smv">The specialized multivector for which the coordinate indices should be written.</param>
 public static void WriteCoordinateOrder(StringBuilder SB, Specification S, FloatType FT, G25.SMV smv)
 {
     //string className = FT.GetMangledName(smv.Name);
     SB.AppendLine("\ttypedef enum {");
     SB.AppendLine("\t\t/// the order of coordinates (this is the type of the first argument of coordinate-handling functions)");
     SB.AppendLine("\t\t" + G25.CG.Shared.SmvUtil.GetCoordinateOrderConstant(S, smv));
     SB.AppendLine("\t} " + G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM + ";");
 }
Exemple #32
0
        /// <summary>
        /// If this FunctionGenerator can implement 'F', then this function should complete the (possible)
        /// blanks in 'F'. This means:
        ///  - Fill in F.m_returnTypeName if it is empty
        ///  - Fill in F.m_argumentTypeNames (and m_argumentVariableNames) if it is empty.
        /// </summary>
        public override void CompleteFGS()
        {
            m_ipType = GetIpType(m_specification, m_fgs);

            // fill in ArgumentTypeNames
            if (m_fgs.ArgumentTypeNames.Length == 0)
            {
                m_fgs.m_argumentTypeNames = new String[] { m_gmv.Name, m_gmv.Name }
            }
            ;

            // init argument pointers from the completed typenames (language sensitive);
            m_fgs.InitArgumentPtrFromTypeNames(m_specification);

            // get all function info
            FloatType FT = m_specification.GetFloatType(m_fgs.FloatNames[0]);
            bool      computeMultivectorValue = true;

            G25.CG.Shared.FuncArgInfo[] tmpFAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

            m_gmvFunc = !(tmpFAI[0].IsScalarOrSMV() && tmpFAI[1].IsScalarOrSMV());
            m_smv1    = tmpFAI[0].Type as G25.SMV;
            m_smv2    = tmpFAI[1].Type as G25.SMV;

            // compute intermediate results, set return type
            if (m_gmvFunc)
            {
                if (m_ipType != RefGA.BasisBlade.InnerProductType.SCALAR_PRODUCT)
                {
                    m_fgs.m_returnTypeName = m_gmv.Name;// gmv * gmv = gmv
                }
                else
                {
                    m_fgs.ReturnTypeName = FT.type;
                }
            }
            else
            {
                // compute return value
                m_returnValue = RefGA.Multivector.ip(tmpFAI[0].MultivectorValue[0], tmpFAI[1].MultivectorValue[0], m_M, m_ipType);

                // round value if required by metric
                if (m_G25M.m_round)
                {
                    m_returnValue = m_returnValue.Round(1e-14);
                }

                // get name of return type
                if ((m_fgs.ReturnTypeName.Length == 0) && (m_ipType != RefGA.BasisBlade.InnerProductType.SCALAR_PRODUCT))
                {
                    m_fgs.ReturnTypeName = G25.CG.Shared.SpecializedReturnType.GetReturnType(m_specification, m_cgd, m_fgs, FT, m_returnValue).GetName();
                }
                else
                {
                    m_fgs.ReturnTypeName = FT.type;
                }
            }
        }
Exemple #33
0
 /// <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);
 }
Exemple #34
0
        /// <summary>
        /// If this FunctionGenerator can implement 'F', then this function should complete the (possible)
        /// blanks in 'F'. This means:
        ///  - Fill in F.m_returnTypeName if it is empty
        ///  - Fill in F.m_argumentTypeNames (and m_argumentVariableNames) if it is empty.
        /// </summary>
        public override void CompleteFGS()
        {
            // fill in ArgumentTypeNames
            if (m_fgs.ArgumentTypeNames.Length == 0)
            {
                m_fgs.m_argumentTypeNames = new String[] { m_gmv.Name, m_gmv.Name }
            }
            ;

            // init argument pointers from the completed typenames (language sensitive);
            m_fgs.InitArgumentPtrFromTypeNames(m_specification);

            // get all function info
            FloatType FT = m_specification.GetFloatType(m_fgs.FloatNames[0]);
            bool      computeMultivectorValue = true;

            G25.CG.Shared.FuncArgInfo[] tmpFAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

            m_gmvFunc     = !(tmpFAI[0].IsScalarOrSMV() && tmpFAI[1].IsScalarOrSMV());
            m_trueGmvFunc = (!tmpFAI[0].IsScalarOrSMV()) && (!tmpFAI[1].IsScalarOrSMV());
            m_arg1isGmv   = !tmpFAI[0].IsScalarOrSMV();
            m_arg2isGmv   = !tmpFAI[1].IsScalarOrSMV();
            m_smv1        = tmpFAI[0].Type as G25.SMV;
            m_smv2        = tmpFAI[1].Type as G25.SMV;

            // compute intermediate results, set return type
            if (m_gmvFunc)
            {
                m_fgs.m_returnTypeName = m_gmv.Name;           // gmv * gmv = gmv
            }
            else
            {
                // compute return value
                m_reverseValue = RefGA.Multivector.Reverse(tmpFAI[1].MultivectorValue[0]);
                m_n2Value      = RefGA.Multivector.gp(m_reverseValue, tmpFAI[1].MultivectorValue[0], m_M);
                if (m_G25M.m_round)
                {
                    m_n2Value = m_n2Value.Round(1e-14);
                }

                //m_returnValue = RefGA.Multivector.gp(RefGA.Multivector.gp(tmpFAI[0].MultivectorValue[0], m_reverseValue, m_M),
                //  RefGA.Symbolic.ScalarOp.Inverse(new RefGA.Multivector(new RefGA.BasisBlade(0, 1.0, m_normSquaredName))));
                m_returnValue = RefGA.Multivector.gp(tmpFAI[0].MultivectorValue[0], m_reverseValue, m_M);

                // round value if required by metric
                if (m_G25M.m_round)
                {
                    m_returnValue = m_returnValue.Round(1e-14);
                }

                // get name of return type
                if (m_fgs.m_returnTypeName.Length == 0)
                {
                    m_fgs.m_returnTypeName = G25.CG.Shared.SpecializedReturnType.GetReturnType(m_specification, m_cgd, m_fgs, FT, m_returnValue).GetName();
                }
            }
        }
Exemple #35
0
        /// <summary>
        /// If this FunctionGenerator can implement 'F', then this function should complete the (possible)
        /// blanks in 'F'. This means:
        ///  - Fill in F.m_returnTypeName if it is empty
        ///  - Fill in F.m_argumentTypeNames (and m_argumentVariableNames) if it is empty.
        /// </summary>
        public override void CompleteFGS()
        {
            // fill in ArgumentTypeNames
            if (m_fgs.ArgumentTypeNames.Length == 0)
            {
                m_fgs.m_argumentTypeNames = new String[] { m_gmv.Name }
            }
            ;

            // init argument pointers from the completed typenames (language sensitive);
            m_fgs.InitArgumentPtrFromTypeNames(m_specification);

            // get all function info
            FloatType FT = m_specification.GetFloatType(m_fgs.FloatNames[0]);
            bool      computeMultivectorValue = true;

            G25.CG.Shared.FuncArgInfo[] tmpFAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

            m_gmvFunc = !tmpFAI[0].IsScalarOrSMV();

            m_isNorm2 = IsNorm2(m_fgs);

            // compute intermediate results, set return type
            if (m_gmvFunc)
            {
                m_fgs.m_returnTypeName = G25.CG.Shared.SpecializedReturnType.GetReturnType(m_specification, m_cgd, m_fgs, FT, new RefGA.Multivector("x")).GetName();            // norm(gmv) = scalar
            }
            else
            {
                m_smv = tmpFAI[0].Type as G25.SMV;

                // compute return value
                if (m_isNorm2)
                {
                    m_returnValue = tmpFAI[0].MultivectorValue[0].Norm_r2(m_M);
                }
                else
                {
                    m_returnValue = RefGA.Symbolic.UnaryScalarOp.Abs(tmpFAI[0].MultivectorValue[0].Norm_r(m_M));
                }

                // round value if required by metric
                if (m_G25M.m_round)
                {
                    m_returnValue = m_returnValue.Round(1e-14);
                }

                // avoid null return value because that might return in getting the wrong return type
                RefGA.Multivector nonZeroReturnValue = (m_returnValue.IsZero()) ? RefGA.Multivector.ONE : m_returnValue;

                // get name of return type
                if (m_fgs.m_returnTypeName.Length == 0)
                {
                    m_fgs.m_returnTypeName = G25.CG.Shared.SpecializedReturnType.GetReturnType(m_specification, m_cgd, m_fgs, FT, nonZeroReturnValue).GetName();
                }
            }
        }
Exemple #36
0
        } // end of GenerateSMVassignmentCode

        /// <summary>
        /// Generates the code to assign a multivector value (which may have symbolic coordinates) to one specific coordinate group of a multivector.
        /// </summary>
        /// <param name="S">Specification of algebra. Used to known names of basis vector, output language, access strings, etc.</param>
        /// <param name="FT">Floating point type of destination.</param>
        /// <param name="mustCast">set to true if a cast to 'FT' must be performed before assigned to 'dstName'.</param>
        /// <param name="dstGmv">Type of general multivector assigned to.</param>
        /// <param name="dstName">Name of specialized multivector assigned to.</param>
        /// <param name="dstGroupIdx">Write to which group in destination type?</param>
        /// <param name="dstBaseIdx">Base index of coordinate 0 of group (needed for C# and Java)</param>
        /// <param name="value">Multivector value to assign to the GMV. Must not contain basis blades inside the symbolic scalars.</param>
        /// <param name="nbTabs">Number of tabs to put before the code.</param>
        /// <param name="writeZeros">Some callers want to skip "= 0.0" assignments because they would be redundant. So they set this argument to true.</param>
        /// <returns>String of code for dstName = value;</returns>
        public static string GenerateGMVassignmentCode(Specification S, FloatType FT, bool mustCast,
                                                       G25.GMV dstGmv, string dstName, int dstGroupIdx, int dstBaseIdx, RefGA.Multivector value, int nbTabs, bool writeZeros)
        {
            RefGA.BasisBlade[] BL          = dstGmv.Group(dstGroupIdx);
            string[]           accessStr   = GetAccessStr(S, dstGmv, dstName, dstGroupIdx, dstBaseIdx);
            string[]           assignedStr = GetAssignmentStrings(S, FT, mustCast, BL, value, writeZeros);

            return(GenerateAssignmentCode(S, accessStr, assignedStr, nbTabs, writeZeros));
        } // end of GenerateSMVassignmentCode
Exemple #37
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);
        }
Exemple #38
0
 private static void WriteDeclaration(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.Constant C)
 {
     // extern MANGLED_TYPENAME MANGLED_CONSTANT_NAME;
     if (C.Comment.Length > 0)
         SB.AppendLine("/** " + C.Comment + " */");
     SB.Append("extern ");
     SB.Append(FT.GetMangledName(S, C.Type.GetName()));
     SB.Append(" ");
     SB.Append(FT.GetMangledName(S, C.Name));
     SB.AppendLine(";");
 }
 public override void Parse(GameBitBuffer buffer)
 {
     Place = new WorldPlace();
     Place.Parse(buffer);
     Amount = buffer.ReadInt(32);
     if (buffer.ReadBool())
     {
         OptionalGoldAmount = buffer.ReadInt(32);
     }
     Type = (FloatType)buffer.ReadInt(6);
 }
Exemple #40
0
        public void WriteFloatType_WritesAtLeastOneDecimalPoint()
        {
            // Arrange
            var ft = new FloatType() { F = 123 };

            // Act
            var s = Toml.WriteString(ft);

            // Assert
            s.Trim().Should().Be("F = 123.0");
        }
Exemple #41
0
        /// <summary>
        /// Writes members variables of a GOM 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="gom">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.GOM gom)
        {
            int nbTabs = 1;
            for (int g = 1; g < gom.Domain.Length; g++) // start at '1' in order to skip scalar grade
            {
                string comment = "Matrix for grade " + g + "; the size is " + gom.DomainForGrade(g).Length + " x " + gom.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 + "[" + gom.DomainForGrade(g).Length * gom.RangeForGrade(g).Length + "];");
            }
        }
Exemple #42
0
        /// <summary>
        /// Writes the <c>defines</c> for indices of the smv struct to 'SB'. For example,  <c>define VECTOR_E1 0</c>.
        /// </summary>
        /// <param name="SB">Where the code goes.</param>
        /// <param name="S">Used for basis vector names.</param>
        /// <param name="FT"></param>
        /// <param name="smv">The specialized multivector for which the coordinate indices should be written.</param>
        public static void WriteCoordinateOrder(StringBuilder SB, Specification S, FloatType FT, G25.SMV smv)
        {
            string AccessModifier = Keywords.ConstAccessModifier(S);
            string typeName = G25.CG.Shared.SmvUtil.COORDINATE_ORDER_ENUM;
            string constantName = G25.CG.Shared.SmvUtil.GetCoordinateOrderConstant(S, smv);

            SB.AppendLine();

            int nbTabs = 1;
            new G25.CG.Shared.Comment("The order of coordinates (this is the type of the first argument of coordinate-handling functions.").Write(SB, S, nbTabs);

            string enumAccessModifier = (S.OutputCSharp()) ? "public" : "private";

            SB.AppendLine("\t" + enumAccessModifier + " enum " + typeName + " {");
            SB.AppendLine("\t\t" + constantName);
            SB.AppendLine("\t};");
            SB.AppendLine("\tpublic " + AccessModifier + " " + typeName + " " + constantName + " = " + typeName + "." + constantName + ";");
        }
Exemple #43
0
        /// <summary>
        /// Returns the comment for a GMV class.
        /// </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>
        /// <param name="FT">Float point type of 'GMV'.</param>
        /// <param name="gmv">The general multivector for which the class should be written.</param>
        public static Comment GetGmvComment(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.GMV gmv)
        {
            StringBuilder SB = new StringBuilder();

            SB.AppendLine("This class can hold a general multivector.");
            SB.AppendLine("");

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

            SB.AppendLine("There are " + gmv.NbGroups + " coordinate groups:");
            for (int g = 0; g < gmv.NbGroups; g++)
            {
                SB.Append("group " + g + ":");
                for (int i = 0; i < gmv.Group(g).Length; i++)
                {
                    if (i > 0) SB.Append(", ");
                    SB.Append(gmv.Group(g)[i].ToString(S.m_basisVectorNames));

                }
                if (gmv.Group(g).Length > 0)
                    SB.Append("  (grade " + gmv.Group(g)[0].Grade() + ")");

                SB.AppendLine(".");
            }
            SB.AppendLine("");

            switch (S.m_GMV.MemoryAllocationMethod)
            {
                case G25.GMV.MEM_ALLOC_METHOD.PARITY_PURE:
                    SB.AppendLine("" + (gmv.NbCoordinates / 2) + " " + FT.type + "s are allocated inside the struct ('parity pure').");
                    SB.AppendLine("Hence creating a multivector which needs more than that number of coordinates ");
                    SB.AppendLine("will result in unpredictable behaviour (buffer overflow).");
                    break;
                case G25.GMV.MEM_ALLOC_METHOD.FULL:
                    SB.AppendLine("" + gmv.NbCoordinates + " " + FT.type + "s are allocated inside the struct.");
                    break;
            }

            return new Comment(SB.ToString());
        }
Exemple #44
0
        static BuiltinType()
        {
            i8  = new IntegerType { Name = "i8",  FullyQualifiedName = "i8",  SymbolName = "int8_t",  Size = 1, Alignment = 1, Signed = true/*, Context = BindingContext.EmptyContext */};
            i16 = new IntegerType { Name = "i16", FullyQualifiedName = "i16", SymbolName = "int16_t", Size = 2, Alignment = 2, Signed = true/*, Context = BindingContext.EmptyContext */};
            i32 = new IntegerType { Name = "i32", FullyQualifiedName = "i32", SymbolName = "int32_t", Size = 4, Alignment = 4, Signed = true/*, Context = BindingContext.EmptyContext */};
            i64 = new IntegerType { Name = "i64", FullyQualifiedName = "i64", SymbolName = "int64_t", Size = 8, Alignment = 8, Signed = true/*, Context = BindingContext.EmptyContext */};

            u8  = new IntegerType { Name = "u8",  FullyQualifiedName = "u8",  SymbolName = "uint8_t",  Size = 1, Alignment = 1, Signed = false/*, Context = BindingContext.EmptyContext */};
            u16 = new IntegerType { Name = "u16", FullyQualifiedName = "u16", SymbolName = "uint16_t", Size = 2, Alignment = 2, Signed = false/*, Context = BindingContext.EmptyContext */};
            u32 = new IntegerType { Name = "u32", FullyQualifiedName = "u32", SymbolName = "uint32_t", Size = 4, Alignment = 4, Signed = false/*, Context = BindingContext.EmptyContext */};
            u64 = new IntegerType { Name = "u64", FullyQualifiedName = "u64", SymbolName = "uint64_t", Size = 8, Alignment = 8, Signed = false/*, Context = BindingContext.EmptyContext */};

            f32 = new FloatType { Name = "f32", FullyQualifiedName = "f32", SymbolName = "float",  Size = 4, Alignment = 4 /*, Context = BindingContext.EmptyContext */};
            f64 = new FloatType { Name = "f64", FullyQualifiedName = "f64", SymbolName = "double", Size = 8, Alignment = 8 /*, Context = BindingContext.EmptyContext */};

            Void = new VoidType { Name = "void", FullyQualifiedName = "void", SymbolName = "void" /*, Context = BindingContext.EmptyContext */};
            Auto = new AutoType();

            VoidPtr = new PointerType { PointsTo = Void };
            CharPtr = new PointerType { PointsTo = i8 };
        }
Exemple #45
0
 public CssStyle()
 {
     color=	new Color(0, 0, 0);
     background=	new Background();
     border=	new Border();
     clear=	FloatType.none;
     display=	Display.inline;
     _float=	FloatType.none;
     height=	new FlexibleFloat(0f, FlexFloatType.px);
     margin=	new Margin(0f, 0f, 0f, 0f);
     padding=	new Padding(0f, 0f, 0f, 0f);
     width=	new FlexibleFloat(100f, FlexFloatType.percentage);
     letterSpacing=	new FlexibleFloat(FlexibleFloat.letterSpacingNormal, FlexFloatType.px);
     lineHeight=	new FlexibleFloat(FlexibleFloat.lineHeightNormal, FlexFloatType.px);
     textAlign=	TextAlignment.left;
     textIndex=	new FlexibleFloat(0f, FlexFloatType.px);
     textTransform=	TextTransform.none;
     whiteSpace=	WhiteSpace.normal;
     wordSpacing=	new FlexibleFloat(FlexibleFloat.wordSpacingNormal, FlexFloatType.px);
     textDecoration=	TextDecoration.none;
     font=	new Sdx.Font("arial", 14);
     listStyle=	new ListStyle();
 }
Exemple #46
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);
 }
Exemple #47
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);
 }
Exemple #48
0
 public virtual Type VisitFloatType(FloatType node)
 {
   Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Type>() != null);
   return this.VisitType(node);
 }
Exemple #49
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);
 }
Exemple #50
0
        protected void WriteNormReturnsScalarPassThrough(Specification S, FloatType FT, G25.CG.Shared.FuncArgInfo[] FAI, string funcName)
        {
            StringBuilder declSB = m_cgd.m_declSB;
            StringBuilder defSB = (m_specification.m_inlineFunctions) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            string inlineStr = G25.CG.Shared.Util.GetInlineString(m_specification, m_specification.m_inlineFunctions, " ");
            string refPtrStr = "";
            if (m_specification.OutputC()) refPtrStr = "*";
            else if (m_specification.OutputCpp()) refPtrStr = "&";

            string ACCESS = "";
            if (m_specification.OutputJava()) ACCESS = "public final static ";
            else if (m_specification.OutputCSharp()) ACCESS = "public static ";

            string VAR_MOD = "";
            if (m_specification.OutputCppOrC()) VAR_MOD = "const ";
            if (m_specification.OutputJava()) VAR_MOD = "final ";

            string funcDecl = ACCESS + FT.type + " " + funcName + G25.CG.Shared.CANSparts.RETURNS_SCALAR + "(" + VAR_MOD + FAI[0].MangledTypeName + " " + refPtrStr + FAI[0].Name + ")";
            string comment = "internal conversion function";

            int nbTabs = 0;
            if (m_specification.OutputCppOrC())
            {
                new Comment(comment).Write(declSB, m_specification, nbTabs);
                declSB.Append(funcDecl);
                declSB.AppendLine(";");
            }
            else new Comment(comment).Write(defSB, m_specification, nbTabs);

            defSB.Append(inlineStr + funcDecl);
            defSB.AppendLine(" {");
            defSB.AppendLine("\treturn " + funcName + "(" + FAI[0].Name + ");");
            defSB.AppendLine("}");
        }
Exemple #51
0
        /// <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;
        }
Exemple #52
0
        private float UnpackFloatCellCoord(PropertyInfo info, Bitstream stream, FloatType type)
        {
            var value = stream.ReadBits(info.NumBits);
            float f = value;

            if ((value >> 31) > 0)
            {
                f *= -1;
            }

            if (type == FloatType.None)
            {
                var fraction = stream.ReadBits(5);

                return f + 0.03125f*fraction;
            }
            if (type == FloatType.LowPrecision)
            {
                var fraction = stream.ReadBits(3);

                return f + 0.125f*fraction;
            }
            if (type == FloatType.Integral)
            {
                return f;
            }
            throw new InvalidOperationException("Unknown float type");
        }
Exemple #53
0
        protected void WriteNormReturnsScalar(FloatType FT, G25.CG.Shared.FuncArgInfo[] FAI, String funcName, G25.SMV scalarSMV)
        {
            StringBuilder declSB = m_cgd.m_declSB;
            StringBuilder defSB = (m_specification.m_inlineFunctions) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            string inlineStr = G25.CG.Shared.Util.GetInlineString(m_specification, m_specification.m_inlineFunctions, " ");

            string refPtrStr = "";
            if (m_specification.OutputC()) refPtrStr = "*";
            else if (m_specification.OutputCpp()) refPtrStr = "&";

            string ACCESS = "";
            if (m_specification.OutputJava()) ACCESS = "public final static ";
            else if (m_specification.OutputCSharp()) ACCESS = "public static ";

            string VAR_MOD = "";
            if (m_specification.OutputCppOrC()) VAR_MOD = "const ";
            if (m_specification.OutputJava()) VAR_MOD = "final ";

            string funcDecl = FT.type + " " + funcName + G25.CG.Shared.CANSparts.RETURNS_SCALAR + "(" + VAR_MOD + FAI[0].MangledTypeName + " " + refPtrStr + FAI[0].Name + ")";
            string comment = "internal conversion function (this is just a pass through)";

            int nbTabs = 0;
            if (m_specification.OutputCppOrC())
            {
                new Comment(comment).Write(declSB, m_specification, nbTabs);
                declSB.Append(funcDecl);
                declSB.AppendLine(";");
            }
            else new Comment(comment).Write(defSB, m_specification, nbTabs);

            defSB.Append(inlineStr + ACCESS + funcDecl);
            defSB.AppendLine(" {");
            if (m_specification.OutputC())
            {
                defSB.AppendLine("\t" + FT.GetMangledName(m_specification, scalarSMV.Name) + " tmp;");
                defSB.AppendLine("\t" + funcName + "(&tmp, " + FAI[0].Name + ");");
            }
            else if (m_specification.OutputCpp())
            {
                defSB.AppendLine("\t" + FT.GetMangledName(m_specification, scalarSMV.Name) + " tmp(" + funcName + "(" + FAI[0].Name + "));");
            }
            else
            {
                defSB.AppendLine("\t" + FT.GetMangledName(m_specification, scalarSMV.Name) + " tmp = " + funcName + "(" + FAI[0].Name + ");");
            }

            string[] accessStr;
            {
                bool ptr = false;
                accessStr = G25.CG.Shared.CodeUtil.GetAccessStr(m_specification, scalarSMV, "tmp", ptr);
            }

            defSB.AppendLine("\treturn " + accessStr[0] + ";");

            defSB.AppendLine("}");
        }
Exemple #54
0
        /// <summary>
        /// Writes any code to extract a grade part.
        /// </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="gradeIdx">Grade to be selected (use -1 for user-specified).</param>
        public static string WriteGradeFunction(Specification S, G25.CG.Shared.CGdata cgd, FloatType FT,
            G25.CG.Shared.FuncArgInfo[] FAI, G25.fgs F,
            Comment comment, int gradeIdx)
        {
            // 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:
            const string GROUP_BITMAP_NAME = "groupBitmap";
            string code = G25.CG.Shared.CANSparts.GetGradeCode(S, cgd, FT, gradeIdx, FAI, fgs.RETURN_ARG_NAME, GROUP_BITMAP_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);

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

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

            //StringBuilder tmpSB = new StringBuilder(); // G25.CG.Shared.Functions.WriteFunction() writes to this SB first so we can add the grade index if required

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

            if (gradeIdx < 0) // hack: if grade is func arg, then add it:
            { // add extra argument (int) to select the grade
                //if (S.OutputCppOrC())
                //    tmpCgd.m_declSB = AddGradeArg(S, tmpCgd.m_declSB.ToString(), gradeIdx, GROUP_BITMAP_NAME);
                //tmpCgd.m_defSB = AddGradeArg(S, tmpCgd.m_defSB.ToString(), gradeIdx, GROUP_BITMAP_NAME);
                //tmpCgd.m_inlineDefSB = AddGradeArg(S, tmpCgd.m_inlineDefSB.ToString(), gradeIdx, GROUP_BITMAP_NAME);
            }

            cgd.m_declSB.Append(tmpCgd.m_declSB);
            cgd.m_defSB.Append(tmpCgd.m_defSB);
            cgd.m_inlineDefSB.Append(tmpCgd.m_inlineDefSB);

            return funcName;
        }
Exemple #55
0
        /// <summary>
        /// Writes the definition of an GMV 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="gmv">The general multivector for which the struct should be written.</param>
        public static void WriteGMVstruct(StringBuilder SB, Specification S, G25.CG.Shared.CGdata cgd, FloatType FT, G25.GMV gmv)
        {
            SB.AppendLine("");

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

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

                SB.AppendLine(" * There are " + gmv.NbGroups + " coordinate groups:");
                for (int g = 0; g < gmv.NbGroups; g++)
                {
                    SB.Append(" * group " + g + ":");
                    for (int i = 0; i < gmv.Group(g).Length; i++)
                    {
                        if (i > 0) SB.Append(", ");
                        SB.Append(gmv.Group(g)[i].ToString(S.m_basisVectorNames));

                    }
                    if (gmv.Group(g).Length > 0)
                        SB.Append("  (grade " + gmv.Group(g)[0].Grade() + ")");

                    SB.AppendLine(".");
                }
                SB.AppendLine(" * ");

                switch (S.m_GMV.MemoryAllocationMethod)
                {
                    case G25.GMV.MEM_ALLOC_METHOD.PARITY_PURE:
                        SB.AppendLine(" * " + (gmv.NbCoordinates / 2) + " " + FT.type + "s are allocated inside the struct ('parity pure').");
                        SB.AppendLine(" * Hence creating a multivector which needs more than that number of coordinates ");
                        SB.AppendLine(" * will result in unpredictable behaviour (buffer overflow).");
                        break;
                    case G25.GMV.MEM_ALLOC_METHOD.FULL:
                        SB.AppendLine(" * " + gmv.NbCoordinates + " " + FT.type + "s are allocated inside the struct.");
                        break;
                }

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

            // typedef
            SB.AppendLine("typedef struct ");
            SB.AppendLine("{");
            // group/grade usage
            SB.AppendLine("\t/** group/grade usage (a bitmap which specifies which groups/grades are stored in 'c', below). */");
            SB.AppendLine("\tint gu;");

            // coordinates
            switch (S.m_GMV.MemoryAllocationMethod)
            {
            //                        case G25.GMV.MEM_ALLOC_METHOD.DYNAMIC:
            //                          SB.AppendLine("\t" + FT.type + " *c; ///< the coordinates (array is allocated using realloc())");
            //                        break;
                case G25.GMV.MEM_ALLOC_METHOD.PARITY_PURE:
                    SB.AppendLine("\t/** The coordinates (note: parity pure). */");
                    SB.AppendLine("\t" + FT.type + " c[" + (gmv.NbCoordinates / 2) + "];");
                    break;
                case G25.GMV.MEM_ALLOC_METHOD.FULL:
                    SB.AppendLine("\t/** The coordinates (full). */");
                    SB.AppendLine("\t" + FT.type + " c[" + (gmv.NbCoordinates) + "];");
                    break;
            }

            // If we report non-optimized function usage, we need to know original type of GMVs:
            if (S.m_reportUsage)
            {
                SB.AppendLine("\t/** Specialized multivector type. Used to report about non-optimized function usage. */");
                SB.AppendLine("\tint t;");
            }

            SB.AppendLine("} " + FT.GetMangledName(S, gmv.Name) + ";");
        }
Exemple #56
0
 /// <returns>true when input to function has one argument which is a SMV of grade 1.</returns>
 public bool IsVectorBased(Specification S, G25.fgs F, FloatType FT)
 {
     if (!(F.ArgumentTypeNames.Length == 1) && (!IsCoordBased(S, F, FT))) return false;
     G25.SMV smv = S.GetSMV(F.ArgumentTypeNames[0]);
     if (smv == null) return false;
     return (smv.LowestGrade() == 1) && (smv.HighestGrade() == 1);
 }
Exemple #57
0
 /// <returns>true when input to function is coordinates.</returns>
 public bool IsCoordBased(Specification S, G25.fgs F, FloatType FT)
 {
     return F.MatchNbArguments(S.m_dimension - 2) &&
         S.IsFloatType(F.GetArgumentTypeName(0, FT.type)) &&
         (!IsRandom(S, F));
 }
 public override void Parse(GameBitBuffer buffer)
 {
     ActorID = buffer.ReadUInt(32);
     Number = buffer.ReadFloat32();
     Type = (FloatType)buffer.ReadInt(6);
 }
Exemple #59
0
 private float UnpackFloatCoordMp(Bitstream stream, FloatType type)
 {
     throw new NotImplementedException();
 }
Exemple #60
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) + ";");
        }