1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package ubic.basecode.dataStructure.matrix;
20  
21  import cern.colt.matrix.DoubleMatrix2D;
22  
23  
24  
25  
26  
27  
28  
29  
30  
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  
44  
45  
46      public double[][] getColumnByName( C col ) {
47          return getColumn( getColIndexByName( col ) );
48      }
49  
50      public abstract double[][] getRow( int row );
51  
52      
53  
54  
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  
75  
76  
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  
85  
86  
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 
129 
130 
131     public abstract DoubleMatrix2D viewRow( int slice );
132 
133     public abstract DoubleMatrix2D viewSlice( int slice );
134 }