/// <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; }
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); }
/// <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); }
/// <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); }
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); }
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); }
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); }
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); }
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; }
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; }
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); }
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); }
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); }
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" }); } }
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; }
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); }
/// <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; } } }
/// <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()); }
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); }
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); }
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; }
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); }
/// <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; }
public override Value Perform(Value left, Value right) { return PerformOverFind(left, right, Mapping); }
Value SetValue(StringValue key, Value value) { var name = key.Value; _values[name] = value; return value; }
/// <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); }
internal void SerializeID(MemoryStream mem, BaseType id) { SerializeValue(mem, id); }
public ValueWrap(BaseType id) { _id = id; }
/// <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; }
/// <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; }
internal void DeserializeID(MemoryStream mem) { _id = DeserializeValue(mem); }
/// <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; }
/// <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); }