-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sparse matrix equality efficient #480
Changes from 6 commits
dac531d
60356f6
ae28f5b
f8b9c79
5999fc4
ad09cb7
bfb3d75
d5bbee0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,11 +131,35 @@ trait Matrix[@spec(Double, Int, Float, Long) V] extends MatrixLike[V, Matrix[V]] | |
|
||
def flatten(view: View=View.Prefer): Vector[V] | ||
|
||
override def equals(p1: Any) = p1 match { | ||
case x: Matrix[_] => | ||
this.rows == x.rows && this.cols == x.cols && | ||
keysIterator.forall(k => this(k) == x(k)) | ||
case _ => false | ||
override def equals(p1: Any) : Boolean = (this, p1) match { | ||
case (x: CSCMatrix[V], y: CSCMatrix[V]) => | ||
if(x.rows != y.rows || x.cols != y.cols){ | ||
return false | ||
} else { | ||
val xIter = x.activeIterator | ||
val yIter = y.activeIterator | ||
|
||
while(xIter.hasNext && yIter.hasNext){ | ||
var xkeyval = xIter.next() | ||
var ykeyval = yIter.next() | ||
while(xkeyval._2 == 0 && xIter.hasNext) xkeyval = xIter.next() | ||
while(ykeyval._2 == 0 && yIter.hasNext) ykeyval = yIter.next() | ||
if(xkeyval != ykeyval) return false | ||
} | ||
if(xIter.hasNext == true && yIter.hasNext == false){ | ||
while(xIter.hasNext) if(xIter.next()._2 != 0) return false | ||
} | ||
|
||
if(xIter.hasNext == false && yIter.hasNext == true){ | ||
while(yIter.hasNext) if(yIter.next()._2 != 0) return false | ||
} | ||
} | ||
return true | ||
case (x: Matrix[V], y: Matrix[_]) => | ||
x.rows == y.rows && x.cols == y.cols && | ||
keysIterator.forall(k => x(k) == y(k)) | ||
case _ => | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh this should be super.==(p1) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh - this is in Matrix.scala not CSCMatrix.scala so I am not sure you want to use the equals method of the super class. Do you want to override the equals method in CSCMatrix? It doesn't have an explicit implementation in CSCMatrix.scala There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, blah, sorry. maybe move the CSC/CSC check to CSC itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd rather (xIter.hasNext && !yIter.hasNext) (and on the next one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed with latest commit