Uploaded image for project: 'Mahout'
  1. Mahout
  2. MAHOUT-67

plus method and divide method in AbstractVector can be optimized for SparseVectors

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.2
    • Component/s: Math
    • Labels:
      None
    1. MAHOUT-67.patch
      2 kB
      Pallavi Palleti
    2. MAHOUT-67.patch
      4 kB
      Pallavi Palleti
    3. MAHOUT-67.patch
      2 kB
      Pallavi Palleti
    4. MAHOUT-67.patch
      2 kB
      Pallavi Palleti

      Activity

      Hide
      srowen Sean Owen added a comment -

      I checked, and at this point AbstractVector already does what this patch did, through use of iterateNonZero(). Marking this basically obsoleted.

      Show
      srowen Sean Owen added a comment - I checked, and at this point AbstractVector already does what this patch did, through use of iterateNonZero(). Marking this basically obsoleted.
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      I have restored the cardinality check in dot method and also added cardinality check for plus method and so updated unit tests accordingly. As this code is optimization of existing code, the previous unit tests holds.

      Show
      pallavipalleti Pallavi Palleti added a comment - I have restored the cardinality check in dot method and also added cardinality check for plus method and so updated unit tests accordingly. As this code is optimization of existing code, the previous unit tests holds.
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      I misunderstood the sparse vector representation. I agree that the cardinality exception should be thrown if two sparse vectors' cardinality is not same. But, my implementation still holds and optimizes the computation of divide and plus operation over sparse vectors.

      Show
      pallavipalleti Pallavi Palleti added a comment - I misunderstood the sparse vector representation. I agree that the cardinality exception should be thrown if two sparse vectors' cardinality is not same. But, my implementation still holds and optimizes the computation of divide and plus operation over sparse vectors.
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      I have added unit tests to show that the current implementation breaks for sparse vector plus, dot and divide operation. and my version works.

      Show
      pallavipalleti Pallavi Palleti added a comment - I have added unit tests to show that the current implementation breaks for sparse vector plus, dot and divide operation. and my version works.
      Hide
      isabel Isabel Drost-Fromm added a comment -

      Could you please also add a unit test that shows, that the current implementation is broken but your version works?

      Show
      isabel Isabel Drost-Fromm added a comment - Could you please also add a unit test that shows, that the current implementation is broken but your version works?
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      changed to Java5 notation style.
      Also added divide method for sparse vector.

      Show
      pallavipalleti Pallavi Palleti added a comment - changed to Java5 notation style. Also added divide method for sparse vector.
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      also added divide method

      Show
      pallavipalleti Pallavi Palleti added a comment - also added divide method
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      Isabel: Sure, I will make those changes.

      Karl: I couldn't get. Can you please elaborate it?

      Show
      pallavipalleti Pallavi Palleti added a comment - Isabel: Sure, I will make those changes. Karl: I couldn't get. Can you please elaborate it?
      Hide
      karl.wettin Karl Wettin added a comment - - edited

      You say you need to modify the cardinality. I'm not sure about what has been said about the constraints of Vector modifiers, but the code seems rather static about Vectors being compatible from the start.

      [deleted some stuff here that made no sense]

      Show
      karl.wettin Karl Wettin added a comment - - edited You say you need to modify the cardinality. I'm not sure about what has been said about the constraints of Vector modifiers, but the code seems rather static about Vectors being compatible from the start. [deleted some stuff here that made no sense]
      Hide
      isabel Isabel Drost-Fromm added a comment -

      Instead of using the following explicitly, you might consider using Java5 style notation, as vector implements Iterable:

      > java.util.Iterator<Vector.Element> iterator = x.iterator();
      > while (iterator.hasNext()) {
      > Vector.Element element = iterator.next();

      I haven't tried it, but it should be possible to use the following expression:

      for (Vector.Element element : x) {
      ...
      }

      I always find this style easier to read than the explicit use of iterator()

      Isabel

      Show
      isabel Isabel Drost-Fromm added a comment - Instead of using the following explicitly, you might consider using Java5 style notation, as vector implements Iterable: > java.util.Iterator<Vector.Element> iterator = x.iterator(); > while (iterator.hasNext()) { > Vector.Element element = iterator.next(); I haven't tried it, but it should be possible to use the following expression: for (Vector.Element element : x) { ... } I always find this style easier to read than the explicit use of iterator() Isabel
      Hide
      pallavipalleti Pallavi Palleti added a comment -

      I have overridden plus() method in SparseVector. Inorder to do this, I need to add a method called addCardinality().
      Also, I found that in dot() method, it shouldn't throw cardinalityException. So, I removed that condition. Please review the code.

      Thanks
      Pallavi

      Show
      pallavipalleti Pallavi Palleti added a comment - I have overridden plus() method in SparseVector. Inorder to do this, I need to add a method called addCardinality(). Also, I found that in dot() method, it shouldn't throw cardinalityException. So, I removed that condition. Please review the code. Thanks Pallavi

        People

        • Assignee:
          srowen Sean Owen
          Reporter:
          pallavipalleti Pallavi Palleti
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Development