1 /* 2 * $Id: Matrix.java,v 1.4 2010/01/05 21:27:57 pah Exp $ 3 * 4 * Created on 21 Nov 2008 by Paul Harrison (paul.harrison@manchester.ac.uk) 5 * Copyright 2008 Astrogrid. All rights reserved. 6 * 7 * This software is published under the terms of the Astrogrid 8 * Software License, a copy of which has been included 9 * with this distribution in the LICENSE.txt file. 10 * 11 */ 12 13 package org.astrogrid.matrix; 14 15 import no.uib.cipr.matrix.AGDenseMatrix; 16 import no.uib.cipr.matrix.Vector; 17 18 public interface Matrix extends no.uib.cipr.matrix.Matrix { 19 /** 20 * slice an array - indices are 0 based. Creates a new array storage - original data is untouched. 21 * @param rowstart 22 * @param rowend 23 * @param colstart 24 * @param colend 25 * @return 26 * @deprecated too complex - use {@link #slicev(int, boolean)} or {@link #sliceCol(int, int)} instead. 27 */ 28 Matrix slice(int rowstart, int rowend, int colstart, int colend); 29 30 31 /** 32 * Return the sum of a matrix along a dimension. 33 * @param dim the dimension along which to sum 1=sum the columns 2 = sum the rows 34 * @return 35 */ 36 Vector sum(int dim); 37 38 /** 39 * Return a matrix with elements raised to the power. 40 * @param i 41 * @return 42 */ 43 Matrix pow(double i); 44 45 /** 46 * Return a single column or row of the matrix 47 * @param idx the 0 based index of the row or column to return; 48 * @param dorow if true return a row - if false return a column. 49 * 50 * @return 51 * @deprecated use sliceRow or SliceCol instead. 52 */ 53 public Vector slicev(int idx, boolean dorow); 54 55 56 /** 57 * Returns a Vector of the row. 58 * matlab syntax mat(idx, :) 59 * @param idx 60 * @return 61 */ 62 public Vector sliceRow(int idx); 63 /** 64 * Returns a matrix consisting of only the row. 65 * matlab syntax mat(idx, :). 66 * @param k 67 * @return 68 */ 69 public Matrix sliceRowM(int k); 70 71 /** 72 * Returns a new Matrix consisting of only the specified columns. This is equivalent to the 73 * Matlab syntax mat(:, colstart:colstart+ncols). 74 * @param colstart 75 * @param ncols 76 * @return 77 */ 78 public Matrix sliceCol(int colstart, int ncols); 79 /** 80 * Returns a new Matrix consisting of only the specified column. This is equivalent to the 81 * Matlab syntax mat(:, col). 82 * @param colstart 83 * @param ncols 84 * @return 85 */ 86 public Vector sliceCol(int col); 87 88 /** 89 * @return 90 */ 91 public Matrix ones(); 92 93 94 /** 95 * Reshapes the matrix to have the new size. Elements are copied columnwise. 96 * @param irow 97 * @return 98 */ 99 public Matrix reshape(int irow, int icol); 100 101 102 /** 103 * return a copy of the data as a vector. The storage is assumed to be column major. This is similar to the A(:) 'linear' addressing in matlab. 104 * @return 105 */ 106 public Vector asVector(); 107 108 /** 109 * return a copy of the data as a vector. The storage is assumed to be column major. This is similar to the A(:) 'linear' addressing in matlab. 110 * @return 111 */ 112 public Vector asVector(int istart, int idend); 113 114 /** 115 * return a copy of the data as a vector. The storage is assumed to be column major. a matrix treating as one large columnwise array. - Indices are 0 based. 116 * @param istart 117 * @return 118 */ 119 public Vector asVector(int istart); 120 121 /** 122 * Return the determinant of the matrix. 123 * @return 124 */ 125 double det(); 126 127 /** 128 * Produce the trace of the matrix. 129 * @return 130 */ 131 public double trace(); 132 133 /** 134 * Computes the inverse of the matrix. 135 * B = A^-1 136 * @return 137 */ 138 Matrix inv(); 139 140 /** 141 * C= A/B where the division is elementwise. 142 * @param b 143 * @param c 144 * @return 145 */ 146 public Matrix divide(Matrix b, Matrix c); 147 148 public Matrix add(double a); 149 150 151 /** 152 * Set a complete column in the matrix to the value given. 153 * @param idx 154 * @param v 155 * @return 156 */ 157 public Matrix setColumn(int idx, Vector v); 158 /** 159 * Set a complete column in the matrix to the value given. Note that the matrix must have only one column. 160 * @param idx 161 * @param v 162 * @return 163 */ 164 public Matrix setColumn(int idx, Matrix v); 165 166 167 168 /** 169 * Append the matrix as new rows onto the existing matrix. 170 * @param m 171 * @return 172 */ 173 public AGDenseMatrix append(Matrix m); 174 175 176 /** 177 * Append the matrix as new rows onto the existing matrix. 178 * @param m 179 * @return 180 */ 181 public AGDenseMatrix append(Vector m); 182 183 184 public double asScalar(); 185 186 /** 187 * append double value. 188 * @param d 189 */ 190 public AGDenseMatrix append(double d); 191 192 193 Matrix setRow(int k, Matrix m); 194 195 196 Matrix setRow(int k, Vector v); 197 198 /** 199 * Delete column k from the matrix. 200 * @param k 201 * @return 202 */ 203 Matrix delCol(int k); 204 205 Matrix delRow(int k); 206 } 207 208 209 /* 210 * $Log: Matrix.java,v $ 211 * Revision 1.4 2010/01/05 21:27:57 pah 212 * add delete colum/row functions 213 * 214 * Revision 1.3 2009/09/22 07:04:16 pah 215 * daily checkin 216 * 217 * Revision 1.2 2009/09/08 19:24:03 pah 218 * further slicing possibilites 219 * 220 * Revision 1.1 2009/09/07 16:06:12 pah 221 * initial transcription of the core 222 * 223 */