00001 /*
00002 File: SubMat.h
00003
00004 Function: Defines a scatter-gather matrix, i.e., a submatrix of another matrix.
00005
00006 Author(s): Andrew Willmott
00007
00008 Copyright: (c) 1995-2000, Andrew Willmott
00009 */
00010
00011 #ifndef __SubMat__
00012 #define __SubMat__
00013
00014 #include "vl/VL.h"
00015 #include "vl/SubVec.h"
00016
00017 // --- SubMat Class -----------------------------------------------------------
00018
00019 class TMat;
00020 class TVec;
00021
00022 class TSubMat
00023 {
00024 public:
00025
00026 // Constructors
00027
00028 TSubMat(Int m, Int n, Int span, TMReal data[]);
00029 TSubMat(const TSubMat &m);
00030
00031 // Accessor functions
00032
00033 Int Rows() const { return rows; };
00034 Int Cols() const { return cols; };
00035
00036 inline TMVec operator [] (Int i) const;
00037
00038 inline TMReal &Elt(Int i, Int j);
00039 inline TMReal Elt(Int i, Int j) const;
00040
00041 // Assignment operators
00042
00043 TSubMat &operator = (const TSubMat &m); // Assignment of a matrix
00044 TSubMat &operator = (const TMat &m);
00045
00046 Int rows;
00047 Int cols;
00048 Int span;
00049 TMReal *data;
00050 };
00051
00052
00053 // --- Submatrix functions ----------------------------------------------------
00054
00055 TSubMat sub(const TMat &m, Int top, Int left, Int height, Int width);
00056 TSubMat sub(const TMat &m, Int rows, Int cols);
00057 TMSubVec row(const TMat &m, Int i);
00058 TMSubVec col(const TMat &m, Int i);
00059 TMSubVec diag(const TMat &m, Int diagNum = 0);
00060 // -i = diag. starting on row i, +i = diag. starting on col i
00061
00062 TSubMat sub(const TSubMat &m, Int top, Int left, Int height, Int width);
00063 TSubMat sub(const TSubMat &m, Int rows, Int cols);
00064 TMSubVec row(const TSubMat &m, Int i);
00065 TMSubVec col(const TSubMat &m, Int i);
00066 TMSubVec diag(const TSubMat &m, Int diagNum = 0);
00067
00068 // --- SubMat Inlines ---------------------------------------------------------
00069
00070
00071 #include "vl/Vec.h"
00072
00073 inline TMVec TSubMat::operator [] (Int i) const
00074 {
00075 CheckRange(i, 0, Rows(), "(SubMat::(i)) index out of range");
00076 return(TMVec(cols, data + i * span));
00077 }
00078
00079 inline TMReal &TSubMat::Elt(Int i, Int j)
00080 {
00081 CheckRange(i, 0, Rows(), "(SubMat::(i,j)) i index out of range");
00082 CheckRange(j, 0, Cols(), "(SubMat::(i,j)) j index out of range");
00083 return(data[i * span + j]);
00084 }
00085
00086 inline TMReal TSubMat::Elt(Int i, Int j) const
00087 {
00088 CheckRange(i, 0, Rows(), "(SubMat::(i,j)) i index out of range");
00089 CheckRange(j, 0, Cols(), "(SubMat::(i,j)) j index out of range");
00090 return(data[i * span + j]);
00091 }
00092
00093 #endif
00094