Exemplo n.º 1
0
        public ValueStructureSparse ToValue(StringSequenceTemplate varNameTemplate)
        {
            var structValue = ValueStructureSparse.Create(BaseStructure.AssociatedStructure);

            foreach (var pair in _patternDictionary)
            {
                var scalarPattern = pair.Value as GMacScalarBinding;

                if (scalarPattern != null)
                {
                    structValue[pair.Key] = scalarPattern.ToValue(varNameTemplate).AssociatedValue;

                    continue;
                }

                var mvPattern = pair.Value as GMacMultivectorBinding;

                if (mvPattern != null)
                {
                    structValue[pair.Key] = mvPattern.ToValue(varNameTemplate).AssociatedValue;

                    continue;
                }

                var structPattern = pair.Value as GMacStructureBinding;

                if (structPattern != null)
                {
                    structValue[pair.Key] = structPattern.ToValue(varNameTemplate);
                }
            }

            return(structValue);
        }
Exemplo n.º 2
0
        public override ILanguageValue CreateDefaultValue(ILanguageType langType)
        {
            if (ReferenceEquals(langType, null))
            {
                throw new ArgumentNullException();
            }

            if (langType.IsSameType(BooleanType))
            {
                return(ValuePrimitive <bool> .Create((TypePrimitive)langType, false));
            }

            if (langType.IsSameType(IntegerType))
            {
                return(ValuePrimitive <int> .Create((TypePrimitive)langType, 0));
            }

            if (langType.IsSameType(ScalarType))
            {
                return(ValuePrimitive <MathematicaScalar> .Create((TypePrimitive)langType, SymbolicUtils.Constants.Zero));
            }

            var typeStructure = langType as GMacStructure;

            if (typeStructure != null)
            {
                var structure = typeStructure;

                var valueSparse = ValueStructureSparse.Create(structure);

                //This code is not required for a sparse structure value
                //foreach (var data_member in structure.DataMembers)
                //    value_sparse[data_member.ObjectName] = this.CreateDefaultValue(data_member.SymbolType);

                return(valueSparse);
            }

            if (!(langType is GMacFrameMultivector))
            {
                throw new InvalidOperationException("GMac type not recognized!");
            }

            var mvType = (GMacFrameMultivector)langType;

            var value = GMacValueMultivector.CreateZero(mvType);

            //This code is not required for a sparse multivector value
            //for (int id = 0; id < mv_type.ParentFrame.GASpaceDimension; id++)
            //    value[id] = SymbolicUtils.Constants.Zero;

            return(value);
        }