/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other"> /// An object to compare with this object. /// </param> /// <returns> /// <c>true</c> if the current object is equal to the <paramref name="other"/> parameter; otherwise, <c>false</c>. /// </returns> public virtual bool Equals(ISparseMatrixStorage <T> other) { // Reject equality when the argument is null or has a different shape. if (other == null) { return(false); } // Accept if the argument is the same object as this. if (ReferenceEquals(this, other)) { return(true); } return(Equals(other, Constants.EqualsThreshold)); }
public override bool Equals(ISparseMatrixStorage <double> other, double tolerance) { var o = other as CompressedColumnStorage; if (o == null) { return(false); } int nz = this.NonZerosCount; if (this.ncols != o.ColumnCount || this.nrows != o.RowCount || nz != o.NonZerosCount) { return(false); } for (int i = 0; i < this.ncols; i++) { if (this.ColumnPointers[i] != o.ColumnPointers[i]) { return(false); } } for (int i = 0; i < nz; i++) { if (this.RowIndices[i] != o.RowIndices[i]) { return(false); } // TODO: should compare relative values! if (Math.Abs(this.Values[i] - o.Values[i]) > tolerance) { return(false); } } return(true); }
/// <summary> /// Check two matrices for equality. /// </summary> public abstract bool Equals(ISparseMatrixStorage <T> other, double tolerance);