/// <summary> /// Adds the specified vector. /// </summary> /// <param name="other">The vector to add.</param> /// <param name="result">The result.</param> /// <returns>IVector.</returns> /// <exception cref="System.ArgumentNullException">The other vector must not be null</exception> /// <exception cref="System.ArgumentException">The other vector must be of the same length as this instance</exception> protected void Add <TResult>(IReadableVector other, ref TResult result) where TResult : IWritableVector { if (other == null) { throw new ArgumentNullException("other", "The other vector must not be null"); } if (result == null) { throw new ArgumentNullException("result", "The result vector must not be null"); } if (other.Length != Length) { throw new ArgumentException("The other vector must be of the same length as this instance", "other"); } if (result.Length != Length) { throw new ArgumentException("The result vector must be of the same length as this instance", "other"); } for (int i = 0; i < Length; ++i) { var left = GetValue(i); var right = other.GetValue(i); result.SetValue(i, new VariableValue(left + right)); } }
/// <summary> /// Adds the specified vector. /// </summary> /// <param name="other">The vector to add.</param> /// <returns>IVector.</returns> /// <exception cref="System.ArgumentNullException">The other vector must not be null</exception> /// <exception cref="System.ArgumentException">The other vector must be of the same length as this instance</exception> protected void AddInPlace(IReadableVector other) { if (other == null) { throw new ArgumentNullException("other", "The other vector must not be null"); } if (other.Length != Length) { throw new ArgumentException("The other vector must be of the same length as this instance", "other"); } for (int i = 0; i < Length; ++i) { var left = GetValue(i); var right = other.GetValue(i); SetValue(i, new VariableValue(left + right)); } }
/// <summary> /// Transforms the specified vector. /// </summary> /// <param name="vector">The vector.</param> /// <param name="resultingVector">The resulting vector.</param> /// <exception cref="System.ArgumentException">The input vector must have the same length as this matrix has columns;vector</exception> public void Transform(IReadableVector vector, ref IWritableVector resultingVector) { if (vector.Length != _columns) { throw new ArgumentException("The input vector must have the same length as this matrix has columns", "vector"); } if (resultingVector.Length != _rows) { throw new ArgumentException("The resulting vector must have the same length as this matrix has rows", "vector"); } // _transformationExpression(this, vector, resultingVector); for (int r = 0; r < Rows; ++r) { double sum = 0; for (int c = 0; c < Columns; ++c) { var m = GetValue(r, c); var v = vector.GetValue(c); sum += m * v; } resultingVector.SetValue(r, sum); } }
/// <summary> /// Transforms the specified vector. /// </summary> /// <param name="vector">The vector.</param> /// <param name="resultingVector">The resulting vector.</param> /// <exception cref="System.ArgumentException">The input vector must have the same length as this matrix has columns;vector</exception> public void Transform(IReadableVector vector, ref IWritableVector resultingVector) { if (vector.Length != _columns) throw new ArgumentException("The input vector must have the same length as this matrix has columns", "vector"); if (resultingVector.Length != _rows) throw new ArgumentException("The resulting vector must have the same length as this matrix has rows", "vector"); // _transformationExpression(this, vector, resultingVector); for (int r = 0; r < Rows; ++r) { double sum = 0; for (int c = 0; c < Columns; ++c) { var m = GetValue(r, c); var v = vector.GetValue(c); sum += m*v; } resultingVector.SetValue(r, sum); } }