View Javadoc
1   /*
2    * The baseCode project
3    * 
4    * Copyright (c) 2008-2019 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  import cern.colt.matrix.DoubleMatrix2D;
22  
23  /**
24   * TODO Document Me
25   * 
26   * @author Xwan
27   * 
28   * @param <R> Row label type
29   * @param <C> Column label type
30   * @param <S> Slice label type
31   */
32  public abstract class DoubleMatrix3D<R, C, S> extends AbstractMatrix3D<R, C, S, Double> {
33      protected static final int MAX_ROWS_TO_PRINT = 20;
34      protected static final int MAX_SLICES_TO_PRINT = 10;
35  
36      public abstract double get( int slice, int row, int column );
37  
38      public abstract Double[][] getColObj( int col );
39  
40      public abstract double[][] getColumn( int column );
41  
42      /**
43       * @param s String
44       * @return double[]
45       */
46      public double[][] getColumnByName( C col ) {
47          return getColumn( getColIndexByName( col ) );
48      }
49  
50      public abstract double[][] getRow( int row );
51  
52      /**
53       * @param s String
54       * @return double[]
55       */
56      public double[][] getRowByName( R row ) {
57          return getRow( getRowIndexByName( row ) );
58      }
59  
60      public abstract Double[][] getRowObj( int row );
61  
62      public abstract double[][] getSlice( int slice );
63  
64      public double[][] getSliceByName( S slice ) {
65          return getSlice( getSliceIndexByName( slice ) );
66      }
67  
68      public abstract Double[][] getSliceObj( int slice );
69  
70      @Override
71      public abstract boolean isMissing( int slice, int row, int col );
72  
73      /*
74       * (non-Javadoc)
75       * 
76       * @see basecode.dataStructure.matrix.NamedMatrix#rows()
77       */
78      @Override
79      public abstract int rows();
80  
81      public abstract void set( int x, int y, int z, double value );
82  
83      /**
84       * @param j
85       * @param i
86       * @param c
87       */
88      public abstract void setQuick( int slice, int row, int column, double c );
89  
90      @Override
91      public abstract int slices();
92  
93      @Override
94      public String toString() {
95          int slices = this.slices();
96          int rows = this.rows();
97          int columns = this.columns();
98          StringBuffer buf = new StringBuffer();
99          buf.append( "Slice\tRow" );
100         for ( int j = 0; j < columns; j++ ) {
101             buf.append( "\t" + this.getColName( j ) );
102         }
103         buf.append( "\n" );
104         for ( int i = 0; i < slices; i++ ) {
105             for ( int k = 0; k < rows; k++ ) {
106 
107                 buf.append( getSliceName( i ) + "\t" + this.getRowName( k ) );
108                 for ( int j = 0; j < columns; j++ ) {
109                     buf.append( "\t" + this.get( i, k, j ) );
110                 }
111                 buf.append( "\n" );
112                 if ( k > MAX_ROWS_TO_PRINT ) {
113                     buf.append( "...\n" );
114                     break;
115                 }
116             }
117             if ( i > MAX_SLICES_TO_PRINT ) {
118                 buf.append( "...\n" );
119                 break;
120             }
121         }
122         return buf.toString();
123     }
124 
125     public abstract DoubleMatrix2D viewColumn( int column );
126 
127     /**
128      * @param j
129      * @return
130      */
131     public abstract DoubleMatrix2D viewRow( int slice );
132 
133     public abstract DoubleMatrix2D viewSlice( int slice );
134 }