Coverage Report - net.sourceforge.combean.mathprog.linalg.statics.SparseVectorUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
SparseVectorUtil
45%
5/11
50%
2/4
0
 
 1  
 /*
 2  
  * Created on 12.08.2006
 3  
  *
 4  
  */
 5  
 package net.sourceforge.combean.mathprog.linalg.statics;
 6  
 
 7  
 import java.util.Set;
 8  
 import java.util.TreeSet;
 9  
 
 10  
 import net.sourceforge.combean.interfaces.mathprog.linalg.SparseVec;
 11  
 import net.sourceforge.combean.interfaces.mathprog.linalg.VectorIterator;
 12  
 
 13  
 /**
 14  
  * A collection of utility function to calculate with sparse vectors
 15  
  * 
 16  
  * @author schickin
 17  
  *
 18  
  */
 19  0
 public class SparseVectorUtil {
 20  
     
 21  
     /**
 22  
      * Calculate the sum of the components of the vector
 23  
      * 
 24  
      * @param vec a sparse vector
 25  
      * @return the sum of the components of vec
 26  
      */
 27  
     public static final <Label> double sum(SparseVec<Label> vec) {
 28  36
         double result = 0.0;
 29  
         
 30  36
         VectorIterator<Label> itVec = vec.iterator();
 31  144
         while (itVec.hasNext()) {
 32  108
             result += itVec.next().doubleValue();
 33  
         }
 34  
         
 35  36
         return result;
 36  
     }
 37  
     
 38  
     public static final <Label> Set<Label> collectLabels(SparseVec<Label> vec) {
 39  0
         Set<Label> labels = new TreeSet<Label>();
 40  0
         VectorIterator<Label> itVec = vec.iterator();
 41  0
         while (itVec.hasNext()) {
 42  0
             labels.add(itVec.next().label());
 43  
         }
 44  0
         return labels;
 45  
     }
 46  
 
 47  
 }