[ https://issues.apache.org/jira/browse/MAHOUT-300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836238#action_12836238 ]
Ted Dunning commented on MAHOUT-300: ------------------------------------ {quote} I dont know what to do in the edge case of vector being negative valued and sparse. We could return -1 or first index of 0; {quote} The rule of thumb is that this should return the same as if you copied the vector into any other implementation (such as DenseVector) and did the same operation. Thus 0 is the correct answer. It may be that someday we will need maxNonZero, but we can do that when it comes up. {quote} An issue i found here was for empty dense vectors IterateNonZero() optimises for iterating over non zero elements hence result is still -INF getNumNonDefaultElements() == size hence it returns -INF instead of zero. I guess i will have to go with a bool hasNoElements/checkedNoElements based solution [ Show ยป ] Robin Anil added a comment - 20/Feb/10 02:14 PM An issue i found here was for empty dense vectors IterateNonZero() optimises for iterating over non zero elements hence result is still -INF getNumNonDefaultElements() == size hence it returns -INF instead of zero. I guess i will have to go with a bool hasNoElements/checkedNoElements based solution {quote} Actually, if size() == 0, I am happy with the result being ill-defined. Probably the best course would be to simply throw an IllegalArgumentException or something similar to signal that asking for the max of a zero sized vector doesn't make a lot of sense. > Solve performance issues with Vector Implementations > ---------------------------------------------------- > > Key: MAHOUT-300 > URL: https://issues.apache.org/jira/browse/MAHOUT-300 > Project: Mahout > Issue Type: Improvement > Affects Versions: 0.3 > Reporter: Robin Anil > Fix For: 0.3 > > Attachments: MAHOUT-300.patch, MAHOUT-300.patch > > > AbstractVector operations like times > public Vector times(double x) { > Vector result = clone(); > Iterator<Element> iter = iterateNonZero(); > while (iter.hasNext()) { > Element element = iter.next(); > int index = element.index(); > result.setQuick(index, element.get() * x); > } > return result; > } > should be implemented as follows > public Vector times(double x) { > Vector result = clone(); > Iterator<Element> iter = result.iterateNonZero(); > while (iter.hasNext()) { > Element element = iter.next(); > element.set(element.get() * x); > } > return result; > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.