/// <summary> /// Adds another vector to this vector and stores the result into the result vector. /// </summary> /// <param name="other">The vector to add to this one.</param> /// <param name="result">The vector to store the result of the addition.</param> /// <exception cref="ArgumentNullException">If the other vector is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="other"/> are not the same size.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception> public override void Add(Vector other, Vector result) { if (result == null) { throw new ArgumentNullException("result"); } if (Count != other.Count) { throw new ArgumentException("other", Resources.ArgumentVectorsSameLength); } if (Count != result.Count) { throw new ArgumentException("result", Resources.ArgumentVectorsSameLength); } if (ReferenceEquals(this, result) || ReferenceEquals(other, result)) { var tmp = result.CreateVector(result.Count); Add(other, tmp); tmp.CopyTo(result); } else { CopyTo(result); result.Add(other); } }
/// <summary> /// Adds a scalar to each element of the vector and stores the result in the result vector. /// </summary> /// <param name="scalar">The scalar to add.</param> /// <param name="result">The vector to store the result of the addition.</param> /// <exception cref="ArgumentNullException">If the result vector is <see langword="null" />.</exception> /// <exception cref="ArgumentException">If this vector and <paramref name="result"/> are not the same size.</exception> public override void Add(double scalar, Vector result) { if (result == null) { throw new ArgumentNullException("result"); } if (Count != result.Count) { throw new ArgumentException("result", Resources.ArgumentVectorsSameLength); } CopyTo(result); result.Add(scalar); }