Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 240 |  | Methods: | 23
| NCLOC: | 116 |  | 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
SparseDoubleMatrix2DNamed.java | 55% | 47.1% | 26.1% | 43.6% |

1 |  |
     package baseCode.dataStructure.matrix;
2 |  |
3 |  |
     import java.text.NumberFormat;
4 |  |
5 |  |
     import cern.colt.list.DoubleArrayList;
6 |  |
     import cern.colt.matrix.DoubleMatrix1D;
7 |  |
     import cern.colt.matrix.impl.SparseDoubleMatrix2D;
8 |  |
9 |  |
     /**
10 |  |
      * <p>
11 |  |
      * Title: SparseDoubleMatrix2DNamed
12 |  |
      * </p>
13 |  |
      * <p>
14 |  |
      * Description: A sparse matrix that knows about row and column names.
15 |  |
      * </p>
16 |  |
      * <p>
17 |  |
      * Copyright (c) 2004
18 |  |
      * </p>
19 |  |
      * <p>
20 |  |
      * Institution:: Columbia University
21 |  |
      * </p>
22 |  |
      *
23 |  |
      * @author Paul Pavlidis
24 |  |
      * @version $Id: SparseDoubleMatrix2DNamed.java,v 1.5 2004/08/16 02:06:01 pavlidis Exp $
25 |  |
      */
26 |  |
     public class SparseDoubleMatrix2DNamed extends AbstractNamedDoubleMatrix implements
27 |  |
           NamedMatrix {
28 |  |
29 |  |
        private SparseDoubleMatrix2D matrix;
30 |  |
31 |  |
        /**
32 |  |
         * @param T double[][]
33 |  |
         */
34 | 0 |
        public SparseDoubleMatrix2DNamed( double T[][] ) {
35 | 0 |
           super();
36 | 0 |
           matrix = new SparseDoubleMatrix2D( T );
37 |  |
        }
38 |  |
39 |  |
        /**
40 |  |
         * @param rows int
41 |  |
         * @param cols int
42 |  |
         */
43 | 2 |
        public SparseDoubleMatrix2DNamed( int rows, int cols ) {
44 | 2 |
           super();
45 | 2 |
           matrix = new SparseDoubleMatrix2D( rows, cols );
46 |  |
        }
47 |  |
48 | 0 |
        public void set( int row, int col, Object value ) {
49 | 0 |
           set( row, col, ( ( Double ) value ).doubleValue() );
50 |  |
        }
51 |  |
52 |  |
        /**
53 |  |
         * Return a reference to a specific row.
54 |  |
         *
55 |  |
         * @param row int
56 |  |
         * @return double[]
57 |  |
         */
58 | 0 |
        public double[] getRow( int row ) {
59 | 0 |
           return viewRow( row ).toArray();
60 |  |
        }
61 |  |
62 |  |
        /**
63 |  |
         * Return a copy of a given column.
64 |  |
         *
65 |  |
         * @param col int
66 |  |
         * @return double[]
67 |  |
         */
68 | 0 |
        public double[] getCol( int col ) {
69 | 0 |
           double[] result = new double[rows()];
70 | 0 |
           for ( int i = 0; i < rows(); i++ ) {
71 | 0 |
              result[i] = get( i, col );
72 |  |
           }
73 | 0 |
           return result;
74 |  |
        }
75 |  |
76 | 0 |
        public Object[] getRowObj( int row ) {
77 | 0 |
           Double[] result = new Double[columns()];
78 | 0 |
           for ( int i = 0; i < columns(); i++ ) {
79 | 0 |
              result[i] = new Double( get( row, i ) );
80 |  |
           }
81 | 0 |
           return result;
82 |  |
        }
83 |  |
84 | 0 |
        public Object[] getColObj( int col ) {
85 | 0 |
           Double[] result = new Double[rows()];
86 | 0 |
           for ( int i = 0; i < rows(); i++ ) {
87 | 0 |
              result[i] = new Double( get( i, col ) );
88 |  |
           }
89 | 0 |
           return result;
90 |  |
        }
91 |  |
92 |  |
        /**
93 |  |
         * @return java.lang.String
94 |  |
         */
95 | 2 |
        public String toString() {
96 | 2 |
           NumberFormat nf = NumberFormat.getInstance();
97 | 2 |
           String result = "";
98 | 2 |
           if ( this.hasColNames() || this.hasRowNames() ) {
99 | 2 |
              result = "label";
100 |  |
           }
101 |  |
102 | 2 |
           if ( this.hasColNames() ) {
103 | 2 |
              for ( int i = 0; i < columns(); i++ ) {
104 | 6 |
                 result = result + "\t" + getColName( i );
105 |  |
              }
106 | 2 |
              result += "\n";
107 |  |
           }
108 |  |
109 | 2 |
           for ( int i = 0; i < rows(); i++ ) {
110 | 6 |
              if ( this.hasRowNames() ) {
111 | 6 |
                 result += getRowName( i );
112 |  |
              }
113 | 6 |
              for ( int j = 0; j < columns(); j++ ) {
114 |  |
115 | 18 |
                 double value = get( i, j );
116 |  |
117 | 18 |
                 if ( value == 0.0 ) {
118 | 5 |
                    result = result + "\t";
119 |  |
                 } else {
120 |  |
121 | 13 |
                    result = result + "\t" + nf.format( value );
122 |  |
                 }
123 |  |
              }
124 | 6 |
              result += "\n";
125 |  |
           }
126 | 2 |
           return result;
127 |  |
        }
128 |  |
129 |  |
        /**
130 |  |
         * @param s String
131 |  |
         * @return double[]
132 |  |
         */
133 | 0 |
        public double[] getRowByName( String s ) {
134 | 0 |
           return getRow( getRowIndexByName( s ) );
135 |  |
        }
136 |  |
137 | 0 |
        public boolean isMissing( int i, int j ) {
138 | 0 |
           return Double.isNaN( get( i, j ) );
139 |  |
        }
140 |  |
141 |  |
        /**
142 |  |
         * @return
143 |  |
         */
144 | 36 |
        public int columns() {
145 | 36 |
           return matrix.columns();
146 |  |
        }
147 |  |
148 |  |
        /**
149 |  |
         * @param row
150 |  |
         * @param column
151 |  |
         * @return
152 |  |
         */
153 | 18 |
        public double get( int row, int column ) {
154 | 18 |
           return matrix.get( row, column );
155 |  |
        }
156 |  |
157 |  |
        /**
158 |  |
         * @param row
159 |  |
         * @param column
160 |  |
         * @return
161 |  |
         */
162 | 0 |
        public double getQuick( int row, int column ) {
163 | 0 |
           return matrix.getQuick( row, column );
164 |  |
        }
165 |  |
166 |  |
        /**
167 |  |
         * @return
168 |  |
         */
169 | 14 |
        public int rows() {
170 | 14 |
           return matrix.rows();
171 |  |
        }
172 |  |
173 |  |
        /**
174 |  |
         * @param row
175 |  |
         * @param column
176 |  |
         * @param value
177 |  |
         */
178 | 0 |
        public void set( int row, int column, double value ) {
179 | 0 |
           matrix.set( row, column, value );
180 |  |
        }
181 |  |
182 |  |
        /**
183 |  |
         * @param row
184 |  |
         * @param column
185 |  |
         * @param value
186 |  |
         */
187 | 30 |
        public void setQuick( int row, int column, double value ) {
188 | 30 |
           matrix.setQuick( row, column, value );
189 |  |
        }
190 |  |
191 |  |
        /**
192 |  |
         * @param column
193 |  |
         * @return
194 |  |
         */
195 | 0 |
        public DoubleMatrix1D viewColumn( int column ) {
196 | 0 |
           return matrix.viewColumn( column );
197 |  |
        }
198 |  |
199 |  |
        /**
200 |  |
         * @param row
201 |  |
         * @return
202 |  |
         */
203 | 0 |
        public DoubleMatrix1D viewRow( int row ) {
204 | 0 |
           return matrix.viewRow( row );
205 |  |
        }
206 |  |
207 |  |
        /**
208 |  |
         * @return
209 |  |
         */
210 | 0 |
        public int cardinality() {
211 | 0 |
           return matrix.cardinality();
212 |  |
        }
213 |  |
        /**
214 |  |
         * @param minNonZeros
215 |  |
         */
216 | 0 |
        public void ensureCapacity( int minNonZeros ) {
217 | 0 |
           matrix.ensureCapacity( minNonZeros );
218 |  |
        }
219 |  |
        /**
220 |  |
         * @return
221 |  |
         */
222 | 0 |
        public int size() {
223 | 0 |
           return matrix.size();
224 |  |
        }
225 |  |
        /**
226 |  |
         *
227 |  |
         */
228 | 0 |
        public void trimToSize() {
229 | 0 |
           matrix.trimToSize();
230 |  |
        }
231 |  |
232 |  |
        /* (non-Javadoc)
233 |  |
         * @see baseCode.dataStructure.matrix.AbstractNamedDoubleMatrix#getRowArrayList(int)
234 |  |
         */
235 | 0 |
        public DoubleArrayList getRowArrayList( int i ) {
236 | 0 |
          return new DoubleArrayList(getRow(i));
237 |  |
        }
238 |  |
239 |  |
240 |  |
     }