diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
index 8afc4d82..4dbe5825 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
@@ -1271,28 +1271,65 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
///
- /// Check equality. If this is regular vector, then check by base implementation. If Sparse - use own method.
+ /// Returns a hash code for this instance.
///
- /// Object to compare
///
- /// true if the specified is equal to this instance; otherwise, false.
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
- public override bool Equals(object obj)
+ public override int GetHashCode()
{
- var sparseVector = obj as SparseVector;
+ var hashNum = Math.Min(NonZerosCount, 20);
+ long hash = 0;
+ for (var i = 0; i < hashNum; i++)
+ {
+#if SILVERLIGHT
+ hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
+#else
+ hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
+#endif
+ }
- if (sparseVector == null)
+ return BitConverter.ToInt32(BitConverter.GetBytes(hash), 4);
+ }
+
+ #endregion
+
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ ///
+ /// An object to compare with this object.
+ ///
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public override bool Equals(Vector other)
+ {
+ // Reject equality when the argument is null or has a different length.
+ if (other == null)
{
- return base.Equals(obj);
+ return false;
+ }
+
+ if (Count != other.Count)
+ {
+ return false;
}
// Accept if the argument is the same object as this.
- if (ReferenceEquals(this, sparseVector))
+ if (ReferenceEquals(this, other))
{
return true;
}
- if ((Count != sparseVector.Count) || (NonZerosCount != sparseVector.NonZerosCount))
+ var sparseVector = other as SparseVector;
+
+ if (sparseVector == null)
+ {
+ return base.Equals(other);
+ }
+
+ if (NonZerosCount != sparseVector.NonZerosCount)
{
return false;
}
@@ -1309,30 +1346,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return true;
}
- ///
- /// Returns a hash code for this instance.
- ///
- ///
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- ///
- public override int GetHashCode()
- {
- var hashNum = Math.Min(NonZerosCount, 20);
- long hash = 0;
- for (var i = 0; i < hashNum; i++)
- {
-#if SILVERLIGHT
- hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
-#else
- hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
-#endif
- }
-
- return BitConverter.ToInt32(BitConverter.GetBytes(hash), 4);
- }
-
- #endregion
-
///
/// Returns an that contains the position and value of the element.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
index e1326c25..f18393e0 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
@@ -1301,28 +1301,65 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
///
- /// Check equality. If this is regular vector, then check by base implementation. If Sparse - use own method.
+ /// Returns a hash code for this instance.
///
- /// Object to compare
///
- /// true if the specified is equal to this instance; otherwise, false.
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
- public override bool Equals(object obj)
+ public override int GetHashCode()
{
- var sparseVector = obj as SparseVector;
+ var hashNum = Math.Min(NonZerosCount, 20);
+ long hash = 0;
+ for (var i = 0; i < hashNum; i++)
+ {
+#if SILVERLIGHT
+ hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
+#else
+ hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
+#endif
+ }
- if (sparseVector == null)
+ return BitConverter.ToInt32(BitConverter.GetBytes(hash), 4);
+ }
+
+ #endregion
+
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ ///
+ /// An object to compare with this object.
+ ///
+ ///
+ /// true if the current object is equal to the parameter; otherwise, false.
+ ///
+ public override bool Equals(Vector other)
+ {
+ // Reject equality when the argument is null or has a different length.
+ if (other == null)
{
- return base.Equals(obj);
+ return false;
+ }
+
+ if (Count != other.Count)
+ {
+ return false;
}
// Accept if the argument is the same object as this.
- if (ReferenceEquals(this, sparseVector))
+ if (ReferenceEquals(this, other))
{
return true;
}
- if ((Count != sparseVector.Count) || (NonZerosCount != sparseVector.NonZerosCount))
+ var sparseVector = other as SparseVector;
+
+ if (sparseVector == null)
+ {
+ return base.Equals(other);
+ }
+
+ if (NonZerosCount != sparseVector.NonZerosCount)
{
return false;
}
@@ -1339,30 +1376,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return true;
}
- ///
- /// Returns a hash code for this instance.
- ///
- ///
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- ///
- public override int GetHashCode()
- {
- var hashNum = Math.Min(NonZerosCount, 20);
- long hash = 0;
- for (var i = 0; i < hashNum; i++)
- {
-#if SILVERLIGHT
- hash ^= Precision.DoubleToInt64Bits(this._nonZeroValues[i].GetHashCode());
-#else
- hash ^= BitConverter.DoubleToInt64Bits(_nonZeroValues[i].GetHashCode());
-#endif
- }
-
- return BitConverter.ToInt32(BitConverter.GetBytes(hash), 4);
- }
-
- #endregion
-
///
/// Returns an that contains the position and value of the element.
///