Clover coverage report - baseCode - 0.2.5
Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT
file stats: LOC: 195   Methods: 13
NCLOC: 94   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
RCDoubleMatrix1D.java 75% 80% 61.5% 75.9%
coverage coverage
 1   
 package baseCode.dataStructure.matrix;
 2   
 
 3   
 import cern.colt.function.DoubleFunction;
 4   
 import cern.colt.list.DoubleArrayList;
 5   
 import cern.colt.list.IntArrayList;
 6   
 import cern.colt.matrix.DoubleMatrix1D;
 7   
 import cern.colt.matrix.DoubleMatrix2D;
 8   
 import cern.colt.matrix.impl.DenseDoubleMatrix2D;
 9   
 
 10   
 /**
 11   
  * A row-compressed 1D matrix. The only deviation from the contract of DoubleMatrix1D is in apply(), which only operates
 12   
  * on the non-empty elements. This implementation has a highly optimized dot product computer. If you need to compute
 13   
  * the dot product of a RCDoubleMatrix1D with another DoubleMatrix1D, call zDotProduct on this, not on the other. This
 14   
  * is because getQuick() and setQuick() are not very fast for this.
 15   
  * <hr>
 16   
  * <p>
 17   
  * Copyright (c) 2004 Columbia University
 18   
  * 
 19   
  * @author pavlidis
 20   
  * @version $Id: RCDoubleMatrix1D.java,v 1.14 2005/01/05 02:01:02 pavlidis Exp $
 21   
  */
 22   
 public class RCDoubleMatrix1D extends DoubleMatrix1D {
 23   
 
 24   
    protected IntArrayList indexes;
 25   
    protected DoubleArrayList values;
 26   
 
 27   
    /**
 28   
     * @param values
 29   
     */
 30  3
    public RCDoubleMatrix1D( double[] values ) {
 31  3
       this( values.length );
 32  3
       assign( values );
 33   
    }
 34   
 
 35   
    /**
 36   
     * @param length
 37   
     */
 38  3
    public RCDoubleMatrix1D( int length ) {
 39  3
       setUp( length );
 40  3
       this.indexes = new IntArrayList( length );
 41  3
       this.values = new DoubleArrayList( length );
 42   
    }
 43   
 
 44   
    /**
 45   
     * @param indexes These MUST be in sorted order.
 46   
     * @param values These MuST be in the same order as the indexes, meaning that indexes[0] is the column for values[0].
 47   
     */
 48  1791
    public RCDoubleMatrix1D( IntArrayList indexes, DoubleArrayList values ) {
 49  1791
       int k = indexes.size();
 50  1791
       int s = 0;
 51  1791
       if ( k > 0 ) {
 52  1791
          s = indexes.get( k - 1 ) + 1;
 53   
       }
 54   
 
 55  1791
       setUp( s );
 56  1791
       this.indexes = indexes;
 57  1791
       this.values = values;
 58   
    }
 59   
 
 60   
    /*
 61   
     * (non-Javadoc)
 62   
     * 
 63   
     * @see cern.colt.matrix.DoubleMatrix1D#getQuick(int)
 64   
     */
 65  3090627
    public double getQuick( int index ) {
 66   
 
 67  3090627
       int location = indexes.binarySearch( index );
 68   
 
 69  3090627
       if ( location >= 0 ) {
 70  25277
          return values.get( location );
 71   
       }
 72  3065350
       return 0.0;
 73   
    }
 74   
 
 75   
    /*
 76   
     * (non-Javadoc)
 77   
     * 
 78   
     * @see cern.colt.matrix.DoubleMatrix1D#like(int)
 79   
     */
 80  0
    public DoubleMatrix1D like( int s ) {
 81  0
       return new RCDoubleMatrix1D( s );
 82   
    }
 83   
 
 84   
    /*
 85   
     * (non-Javadoc)
 86   
     * 
 87   
     * @see cern.colt.matrix.DoubleMatrix1D#like2D(int, int)
 88   
     */
 89  0
    public DoubleMatrix2D like2D( int rows, int columns ) {
 90  0
       return new DenseDoubleMatrix2D( rows, columns );
 91   
    }
 92   
 
 93   
     
 94   
 
 95   
    /*
 96   
     * (non-Javadoc)
 97   
     * 
 98   
     * @see cern.colt.matrix.DoubleMatrix1D#setQuick(int, double)
 99   
     */
 100  13
    public void setQuick( int column, double value ) {
 101  13
       int location = indexes.binarySearch( column );
 102   
 
 103  13
       if ( location >= 0 ) {
 104  0
          values.set( location, value ); // just change the value
 105   
       } else {
 106  13
          location = -location - 1; // e.g., -1 means to insert just before 0.
 107  13
          indexes.beforeInsert( location, column ); // add this column, so the order is still right.
 108  13
          values.beforeInsert( location, value ); // keep this in the same order.
 109   
       }
 110   
    }
 111   
 
 112   
    /*
 113   
     * (non-Javadoc)
 114   
     * 
 115   
     * @see cern.colt.matrix.DoubleMatrix1D#viewSelectionLike(int[])
 116   
     */
 117  0
    protected DoubleMatrix1D viewSelectionLike( int[] offsets ) {
 118  0
       throw new UnsupportedOperationException(); // should never be called
 119   
    }
 120   
 
 121   
    /**
 122   
     * Apply the given function to each element non-zero element in the matrix.
 123   
     * 
 124   
     * @param function
 125   
     * @return
 126   
     */
 127  1
    public DoubleMatrix1D forEachNonZero(
 128   
          final cern.colt.function.DoubleFunction function ) {
 129   
 
 130  1
       double[] elements = values.elements();
 131  1
       for ( int i = elements.length; --i >= 0; ) {
 132  3
          elements[i] = function.apply( elements[i] );
 133   
       }
 134  1
       return this;
 135   
 
 136   
    }
 137   
 
 138   
    /*
 139   
     * (non-Javadoc)
 140   
     * 
 141   
     * @see cern.colt.matrix.DoubleMatrix1D#zDotProduct(cern.colt.matrix.DoubleMatrix1D)
 142   
     */
 143  3
    public double zDotProduct( DoubleMatrix1D y ) {
 144   
 
 145  3
       int[] idx = indexes.elements();
 146  3
       double[] el = values.elements();
 147  3
       double[] other = y.toArray();
 148  3
       double returnVal = 0.0;
 149  3
       int otherSize = y.size();
 150  3
       for ( int i = idx.length; --i >= 0; ) {
 151  10
          int index = idx[i];
 152  2
          if ( index >= otherSize ) continue; // in case our arrays are ragged.
 153  8
          returnVal += el[i] * other[index];
 154   
       }
 155  3
       return returnVal;
 156   
    }
 157   
 
 158   
    /**
 159   
     * WARNING this only even assigns to the non-empty values, for performance reasons. If you need to assign to any
 160   
     * index, you have to use another way.
 161   
     * 
 162   
     * @see cern.colt.matrix.DoubleMatrix1D#assign(cern.colt.function.DoubleFunction)
 163   
     */
 164  1
    public DoubleMatrix1D assign( DoubleFunction function ) {
 165   
 
 166  1
       double[] elements = values.elements();
 167  1
       for ( int i = elements.length; --i >= 0; ) {
 168  3
          elements[i] = function.apply( elements[i] );
 169   
       }
 170  1
       return this;
 171   
    }
 172   
 
 173   
    /*
 174   
     * (non-Javadoc)
 175   
     * 
 176   
     * @see cern.colt.matrix.DoubleMatrix1D#zSum()
 177   
     */
 178  0
    public double zSum() {
 179  0
       double sum = 0.0;
 180  0
       double[] elements = values.elements();
 181  0
       for ( int i = elements.length; --i >= 0; ) {
 182  0
          sum += elements[i];
 183   
       }
 184  0
       return sum;
 185   
    }
 186   
 
 187   
    /*
 188   
     * (non-Javadoc)
 189   
     * 
 190   
     * @see java.lang.Object#toString()
 191   
     */
 192  0
    public String toString() {
 193  0
       return new cern.colt.matrix.doublealgo.Formatter().toString( this );
 194   
    }
 195   
 }