[ 
https://issues.apache.org/jira/browse/MAHOUT-300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12836245#action_12836245
 ] 

Robin Anil commented on MAHOUT-300:
-----------------------------------

bq. It may be that someday we will need maxNonZero, but we can do that when it 
comes up.

Then no need of all these checks. Just need to iterateAll(). It will be slow. 
But thats the penalty you pay to use this function(should be documented) on 
large sparse vector. If you just need the maxNonZero, which should use 
iterateNonZero. All implementations return -INF if nothing is found..


{code}
  public double maxValue() {
    double result = Double.NEGATIVE_INFINITY;
    Iterator<Element> iter = this.iterateAll();
    while (iter.hasNext()) {
      Element element = iter.next();
      result = Math.max(result, element.get());
    }  
    return result;
  }

  public int maxValueIndex() {
    int result = -1;
    double max = Double.NEGATIVE_INFINITY;
    Iterator<Element> iter = this.iterateAll();
    while (iter.hasNext()) {
      Element element = iter.next();
      double tmp = element.get();
      if (tmp > max) {
        max = tmp;
        result = element.index();
      }
    }
    return result;
  }
{code}

> 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.

Reply via email to