Abstract base value for any value type.
상속: IRegisterElement
예제 #1
0
        /// <summary>
        /// Tries to perform the operation from finding the operator in the mapping.
        /// </summary>
        public static Boolean TryPerformOverFind(Value left, Value right, BinaryOperatorMappingList mapping, out Value value)
        {
            var least = default(Func<Value, Value, Value>);

            for (var i = 0; i != mapping.Count; i++)
            {
                var hit = mapping[i].IsMapping(left, right);

                if (hit == MapHit.Direct)
                {
                    value = mapping[i].Map(left, right);
                    return true;
                }
                else if (hit == MapHit.Indirect)
                {
                    least = mapping[i].Map;
                }
            }

            if (least != null)
            {
                value = least(left, right);
                return true;
            }

            value = null;
            return false;
        }
예제 #2
0
        public override Value Perform(Value argument)
        {
            if (argument is ScalarValue)
            {
                return argument;
            }

            if (argument is MatrixValue)
            {
                var m = argument as MatrixValue;

                if (m.DimensionX == 1)
                {
                    return GetVectorMin(m.GetColumnVector(1));
                }
                else if (m.DimensionY == 1)
                {
                    return GetVectorMin(m.GetRowVector(1));
                }
                else
                {
                    var M = new MatrixValue(1, m.DimensionX);

                    for (var i = 1; i <= m.DimensionX; i++)
                    {
                        M[1, i] = GetVectorMin(m.GetColumnVector(i));
                    }

                    return M;
                }
            }

            throw new YAMPOperationInvalidException("min", argument);
        }
예제 #3
0
        /// <summary>
        /// Performs the evaluation of the dot operator.
        /// </summary>
        /// <param name="left">The left value.</param>
        /// <param name="right">The right value.</param>
        /// <returns>The result of the operation.</returns>
        public override Value Perform(Value left, Value right)
        {
            if (left is NumericValue == false)
            {
                throw new YAMPOperationInvalidException(Op, left);
            }

            if (right is NumericValue == false)
            {
                throw new YAMPOperationInvalidException(Op, right);
            }

            if (left is MatrixValue && right is MatrixValue)
            {
                var l = (MatrixValue)left;
                var r = (MatrixValue)right;
                return Dot(l, r);
            }
            else if (left is MatrixValue && right is ScalarValue)
            {
                var l = (MatrixValue)left;
                var r = (ScalarValue)right;
                return Dot(l, r);
            }
            else if (left is ScalarValue && right is MatrixValue)
            {
                var l = (ScalarValue)left;
                var r = (MatrixValue)right;
                return Dot(l, r);
            }

            return _top.Perform(left, right);
        }
예제 #4
0
        /// <summary>
        /// Performs the function - maps each entry of a matrix to a matrix.
        /// </summary>
        /// <param name="argument">Either a Scalar or a Matrix.</param>
        /// <returns>The scalar or matrix.</returns>
        public override Value Perform(Value argument)
        {
            if (argument is ScalarValue)
            {
                return GetValue((ScalarValue)argument);
            }
            else if (argument is MatrixValue)
            {
                var A = (MatrixValue)argument;
                var M = new MatrixValue(A.DimensionY, A.DimensionX);

                for (var j = 1; j <= A.DimensionY; j++)
                {
                    for (var i = 1; i <= A.DimensionX; i++)
                    {
                        M[j, i] = GetValue(A[j, i]);
                    }
                }

                return M;
            }
            else if (argument is ArgumentsValue)
            {
                throw new YAMPArgumentNumberException(Name, ((ArgumentsValue)argument).Length, 1);
            }

            throw new YAMPOperationInvalidException(Name, argument);
        }
예제 #5
0
        public override Value Perform(Value left, Value right)
        {
            //NH:Check with Florian: Why was it using RightDivideOperator.Mapping ?!
            //Was it being used as an "alias" to it?
            //return PerformOverFind(left, right, RightDivideOperator.Mapping);

            return PerformOverFind(left, right, Mapping);
        }
예제 #6
0
        public override Value Perform(Value left, Value right)
        {
            var step = 1.0;
            var explicitStep = false;
            var start = 0.0;
            var end = 0.0;
            var all = false;

            if (left is ScalarValue)
            {
                start = (left as ScalarValue).Re;
            }
            else if (left is RangeValue)
            {
                var m = left as RangeValue;
                start = m.Start;
                step = m.End;
                explicitStep = true;
            }
            else
            {
                throw new YAMPOperationInvalidException(":", left);
            }

            if (right is ScalarValue)
            {
                end = (right as ScalarValue).Re;
            }
            else if (right is RangeValue)
            {
                var m = right as RangeValue;
                step = m.Start;
                end = m.End;
                all = m.All;
                explicitStep = true;
            }
            else if (right is StringValue)
            {
                all = (right as StringValue).Value.Equals(End);
            }
            else
            {
                throw new YAMPOperationInvalidException(":", left);
            }

            if (!all && !explicitStep && end < start)
            {
                step = -1.0;
            }

            if (all)
            {
                return new RangeValue(start, step);
            }

            return new RangeValue(start, end, step);
        }
예제 #7
0
        public override Value Perform(Value left, Value right)
        {
            if (left is StringValue || right is StringValue)
            {
                return new ScalarValue(left.ToString(Context) != right.ToString(Context));
            }

            return base.Perform(left, right);
        }
예제 #8
0
        public override Value Perform(Value left)
        {
            if (left is ScalarValue)
            {
                return (left as ScalarValue).Clone();
            }
            else if (left is MatrixValue)
            {
                return (left as MatrixValue).Transpose();
            }

            throw new YAMPOperationInvalidException(".'", left);
        }
예제 #9
0
        Value Assign(SymbolExpression left, Value value, IDictionary<String, Value> symbols)
        {
            if (symbols.ContainsKey(left.SymbolName))
            {
                symbols[left.SymbolName] = value.Copy();
            }
            else
            {
                Context.AssignVariable(left.SymbolName, value.Copy());
            }

            return value;
        }
예제 #10
0
        public SetValue Function(SetValue set1, Value id)
        {
            if (id is MatrixValue)
            {
                set1.RemoveElements((id as MatrixValue).ToArray());
            }
            else
            {
                set1.Set.Remove(new SetValue.ValueWrap(id));
            }

            return set1;
        }
예제 #11
0
        public override Value Perform(Value left)
        {
            if (left is ScalarValue)
            {
                return (left as ScalarValue).Conjugate();
            }
            else if (left is MatrixValue)
            {
                return (left as MatrixValue).Adjungate();
            }

            throw new YAMPOperationInvalidException("'", left);
        }
예제 #12
0
        public Value Handle(Expression left, Expression right, Value value, IDictionary<String, Value> symbols)
        {
            var obj = left.Interpret(symbols) as ObjectValue;
            var symbol = right as SymbolExpression;

            if (obj == null || symbol == null)
            {
                throw new YAMPOperationInvalidException(Op);
            }

            var key = new StringValue(symbol.SymbolName);
            return obj.Perform(Context, key, value);
        }
예제 #13
0
        public override Value Perform(Value left, Value right)
        {
            if (left is NumericValue == false)
            {
                throw new YAMPOperationInvalidException(";", left);
            }

            if (right is NumericValue == false)
            {
                throw new YAMPOperationInvalidException(";", right);
            }

            return MatrixValue.Create(left).AddRow(right);
        }
예제 #14
0
 public void Function(StringValue type, StringValue property, Value value)
 {
     switch(type.Value.ToLower())
     {
         case "plot":
             Function(property, value);
             break;
         case "series":
             Context.SetDefaultProperty("series", property.Value, value);
             break;
         default:
             throw new YAMPPropertyMissingException(type.Value, new[] { "Plot", "Series" });
     }
 }
예제 #15
0
            public override Value Perform(Value left, Value right)
            {
                Value ret;
                if (!TryPerformOverFind(left, right, Mapping, out ret))
                {
                    if (left is StringValue || right is StringValue)
                    {
                        return new ScalarValue(left.ToString(Context) != right.ToString(Context));
                    }

                    return base.Perform(left, right);
                }
                return ret;
            }
예제 #16
0
        public override Value Perform(Value value)
        {
            if (value is ScalarValue)
            {
                var scalar = (ScalarValue)value;
                return -scalar;
            }
            else if (value is MatrixValue)
            {
                var matrix = (MatrixValue)value;
                return -matrix;
            }

            throw new YAMPOperationInvalidException(Op, value);
        }
예제 #17
0
        /// <summary>
        /// Changes a given property to a certain value using the available value converter.
        /// </summary>
        /// <param name="series">The series (0..(n-1)) that should be changed.</param>
        /// <param name="parent">The object that should contain the property.</param>
        /// <param name="property">The name of the property (property needs to have a converter specified).</param>
        /// <param name="value">The new value of the property.</param>
        public static void AlterSeriesProperty(Object parent, Int32 series, String property, Value value)
        {
            var type = parent.GetType();
            var props = type.GetProperties();

            foreach (var prop in props)
            {
                var idx = prop.GetIndexParameters();

                if (idx.Length == 1)
                {
                    var method = prop.GetGetMethod();
                    var s = method.Invoke(parent, new Object[] { series });
                    AlterProperty(s, property, value);
                    break;
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Changes a given property to a certain value using the available value converter.
        /// </summary>
        /// <param name="parent">The object that should contain the property.</param>
        /// <param name="name">The name of the property (property needs to have a converter specified).</param>
        /// <param name="value">The new value of the property.</param>
        public static void AlterProperty(Object parent, String name, Value value)
        {
            var type = parent.GetType();
            var props = type.GetProperties();
            var available = new List<String>();

            foreach (var prop in props)
            {
                var attrs = prop.GetCustomAttributes(typeof(ValueConverterAttribute), false);

                if (attrs.Length != 0)
                {
                    available.Add(prop.Name);

                    if (prop.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        var content = default(Object);
                        var possible = new List<String>();

                        foreach (ValueConverterAttribute attr in attrs)
                        {
                            possible.Add(attr.Type);

                            if (attr.CanConvertFrom(value))
                            {
                                content = attr.Convert(value);
                                break;
                            }
                        }

                        if (content == null)
                        {
                            throw new YAMPArgumentWrongTypeException(value.Header, possible.ToArray(), "set");
                        }

                        prop.SetValue(parent, content, null);
                        return;
                    }
                }
            }

            throw new YAMPPropertyMissingException(name, available.ToArray());
        }
예제 #19
0
        public static Value Abs(Value argument)
        {
            if (argument is ScalarValue)
            {
                return new ScalarValue(((ScalarValue)argument).Abs());
            }
            else if (argument is MatrixValue)
            {
                var m = argument as MatrixValue;

                if (m.IsVector)
                {
                    return m.Abs();
                }

                return m.Det();
            }

            throw new YAMPOperationInvalidException("abs", argument);
        }
예제 #20
0
        public override Value Perform(Value value)
        {
            if (value is ScalarValue)
            {
                var scalar = (ScalarValue)value;
                return new ScalarValue(scalar.IsFalse);
            }
            else if (value is MatrixValue)
            {
                var A = (MatrixValue)value;
                var M = new MatrixValue(A.DimensionY, A.DimensionX);

                for (var j = 1; j <= A.DimensionY; j++)
                    for (var i = 1; i <= A.DimensionX; i++)
                        M[j, i] = new ScalarValue(A[j, i].IsFalse);

                return M;
            }

            return new ScalarValue(false);
        }
예제 #21
0
        protected Value Assign(Expression left, Value value, IDictionary<String, Value> symbols)
        {
            if (left is SymbolExpression)
            {
                return Assign((SymbolExpression)left, value, symbols);
            }
            else if (left is ContainerExpression)
            {
                var tree = (ContainerExpression)left;

                if (tree.Operator == null)
                {
                    return Assign(tree.Expressions[0], value, symbols);
                }
                else if (tree.Operator is ArgsOperator)
                {
                    var ix = (ArgsOperator)tree.Operator;
                    return ix.Handle(tree.Expressions[0], value, symbols);
                }
                else if (tree.Operator is MemberOperator)
                {
                    var mo = (MemberOperator)tree.Operator;
                    return mo.Handle(tree.Expressions[0], tree.Expressions[1], value, symbols);
                }
                else if (tree.IsSymbolList)
                {
                    var vars = tree.GetSymbols().ToArray();
                    return HandleMultipleOutputs(value, vars, symbols);
                }
                else
                {
                    throw new YAMPAssignmentException(Op);
                }
            }

            return value;
        }
예제 #22
0
        public override Value Perform(Value argument)
        {
            if (argument is ScalarValue)
            {
                return argument;
            }
            else if (argument is MatrixValue)
            {
                var m = argument as MatrixValue;

                if (m.DimensionX == 1)
                {
                    return GetVectorMax(m.GetColumnVector(1));
                }
                else if (m.DimensionY == 1)
                {
                    return GetVectorMax(m.GetRowVector(1));
                }

                return Function(m);
            }

            throw new YAMPOperationInvalidException("max", argument);
        }
예제 #23
0
 /// <summary>
 /// Scalar / Scalar
 /// </summary>
 /// <param name="left">Must be a scalar.</param>
 /// <param name="right">Must be a scalar.</param>
 /// <returns>The new scalar.</returns>
 public static ScalarValue Divide(Value left, Value right)
 {
     var l = (ScalarValue)left;
     var r = (ScalarValue)right;
     return l / r;
 }
예제 #24
0
 public override Value Perform(Value left, Value right)
 {
     return PerformOverFind(left, right, Mapping);
 }
예제 #25
0
 Value SetValue(StringValue key, Value value)
 {
     var name = key.Value;
     _values[name] = value;
     return value;
 }
예제 #26
0
 /// <summary>
 /// Scalar ^ Scalar
 /// </summary>
 /// <param name="basis">Must be a scalar.</param>
 /// <param name="exponent">Must be a scalar.</param>
 /// <returns>The new scalar.</returns>
 public static ScalarValue Pow(Value basis, Value exponent)
 {
     var l = (ScalarValue)basis;
     var r = (ScalarValue)exponent;
     return l.Pow(r);
 }
예제 #27
0
파일: SetValue.cs 프로젝트: marcusanth/YAMP
 internal void SerializeID(MemoryStream mem, BaseType id)
 {
     SerializeValue(mem, id);
 }
예제 #28
0
파일: SetValue.cs 프로젝트: marcusanth/YAMP
 public ValueWrap(BaseType id)
 {
     _id = id;
 }
예제 #29
0
 /// <summary>
 /// Scalar % Scalar
 /// </summary>
 /// <param name="left">Must be a scalar.</param>
 /// <param name="right">Must be a scalar.</param>
 /// <returns>The new scalar.</returns>
 public static ScalarValue Mod(Value left, Value right)
 {
     var l = (ScalarValue)left;
     var r = (ScalarValue)right;
     return l % r;
 }
예제 #30
0
 /// <summary>
 /// Scalar * Scalar
 /// </summary>
 /// <param name="left">Must be a scalar.</param>
 /// <param name="right">Must be a scalar.</param>
 /// <returns>The new scalar.</returns>
 public static ScalarValue Multiply(Value left, Value right)
 {
     var l = (ScalarValue)left;
     var r = (ScalarValue)right;
     return l * r;
 }
예제 #31
0
파일: SetValue.cs 프로젝트: marcusanth/YAMP
 internal void DeserializeID(MemoryStream mem)
 {
     _id = DeserializeValue(mem);
 }
예제 #32
0
 /// <summary>
 /// Scalar - Scalar
 /// </summary>
 /// <param name="left">Must be a scalar.</param>
 /// <param name="right">Must be a scalar.</param>
 /// <returns>The new scalar.</returns>
 public static ScalarValue Subtract(Value left, Value right)
 {
     var l = (ScalarValue)left;
     var r = (ScalarValue)right;
     return l - r;
 }
예제 #33
0
        /// <summary>
        /// Method used by YAMP to set a value to an object.
        /// </summary>
        /// <param name="context">The context where this is happening.</param>
        /// <param name="argument">The key of the value to retrieve.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>The value that has been set.</returns>
        public Value Perform(ParseContext context, Value argument, Value value)
        {
            var key = argument as StringValue;

            if (key == null)
            {
                throw new YAMPArgumentWrongTypeException(argument.Header, "String", String.Empty);
            }

            return SetValue(key, value);
        }