View Javadoc
1   /*
2    * The baseCode project
3    * 
4    * Copyright (c) 2006 University of British Columbia
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   */
19  package ubic.basecode.dataStructure.matrix;
20  
21  /**
22   * Use this class when fast iteration over the matrix is of primary interest. The primary change is that getQuick is
23   * faster, and toArray returns the actual elements, not a copy.
24   * 
25   * @author pavlidis
26   * 
27   */
28  public class DenseDoubleMatrix1D extends cern.colt.matrix.impl.DenseDoubleMatrix1D {
29  
30      /**
31       * 
32       */
33      private static final long serialVersionUID = -5196826500179433512L;
34  
35      /**
36       * @param values
37       */
38      public DenseDoubleMatrix1D( double[] values ) {
39          super( values );
40      }
41  
42      /**
43       * @param size
44       */
45      public DenseDoubleMatrix1D( int size ) {
46          super( size );
47      }
48  
49      /**
50       * @param size
51       * @param elements
52       * @param zero
53       * @param stride
54       */
55      protected DenseDoubleMatrix1D( int size, double[] elements, int zero, int stride ) {
56          super( size, elements, zero, stride );
57      }
58  
59      /**
60       * This is an optimized version of getQuick. Implementation note: the superclass uses an add and a multiply. This is
61       * faster, but there might be unforseen consequences...
62       * 
63       * @see cern.colt.matrix.DoubleMatrix1D#getQuick(int)
64       */
65      @Override
66      public double getQuick( int i ) {
67          return elements[i];
68      }
69  
70      /**
71       * WARNING unlike the superclass, this returns the actual underlying array, not a copy.
72       * 
73       * @return the elements
74       * @see cern.colt.matrix.DoubleMatrix1D#toArray()
75       */
76      @Override
77      public double[] toArray() {
78          return elements;
79      }
80  
81  }