Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SubSMat.cc

Go to the documentation of this file.
00001 /*
00002     File:           SubSMat.cc
00003 
00004     Function:       Implements SubSMat.h
00005 
00006     Author(s):      Andrew Willmott
00007 
00008     Copyright:      (c) 1995-2000, Andrew Willmott
00009 
00010     Notes:          
00011 
00012 */
00013 
00014 
00015 #include "vl/SubSMat.h"
00016 #include "vl/SparseMat.h"
00017 #include "vl/SubSVec.h"
00018 
00019 
00020 // --- SubSMat Constructors & Destructors -------------------------------------
00021 
00022 
00023 TSubSMat::TSubSMat(Int m, Int n, Int start, TMSparseVec *target) : 
00024     rows(m), cols(n), start(start), target(target)
00025 {
00026 }
00027 
00028 TSubSMat::TSubSMat(const TSubSMat &m) :
00029     rows(m.rows), cols(m.cols), start(m.start), target(m.target)
00030 {
00031 }
00032 
00033 
00034 // --- SubSMat Assignment Operators -------------------------------------------
00035 
00036 TSubSMat &TSubSMat::operator = (const TSubSMat &m)
00037 {   
00038     Int i;
00039     
00040     for (i = 0; i < m.Rows(); i++) 
00041         SELF[i] = m[i];
00042         
00043     return(SELF);
00044 }
00045       
00046 TSubSMat &TSubSMat::operator = (const TSparseMat &m)
00047 {   
00048     Int i;
00049     
00050     for (i = 0; i < m.Rows(); i++) 
00051         SELF[i] = m[i];
00052         
00053     return(SELF);
00054 }
00055 
00056 TSubSMat &TSubSMat::operator = (const TMat &m)
00057 {   
00058     Int i;
00059     
00060     for (i = 0; i < m.Rows(); i++) 
00061         SELF[i] = m[i];
00062         
00063     return(SELF);
00064 }
00065 
00066 TSubSMat sub(const TSparseMat &m, Int top, Int left, Int nrows, Int ncols)
00067 {
00068     Assert(left >= 0 && ncols > 0 && left + ncols <= m.Cols(), 
00069            "(sub(SparseMat)) illegal subset of matrix");
00070     Assert(top >= 0 && nrows > 0 && top + nrows <= m.Rows(), 
00071            "(sub(SparseMat)) illegal subset of matrix");
00072 
00073     return(TSubSMat(nrows, ncols, left, m.Ref() + top));
00074 }
00075 
00076 TSubSMat sub(const TSparseMat &m, Int nrows, Int ncols)
00077 {
00078     Assert(ncols > 0 && ncols <= m.Cols(), 
00079            "(sub(SparseMat)) illegal subset of matrix");
00080     Assert(nrows > 0 && nrows <= m.Rows(), 
00081            "(sub(SparseMat)) illegal subset of matrix");
00082 
00083     return(TSubSMat(nrows, ncols, 0, m.Ref()));
00084 }
00085 
00086 TMSubSVec col(const TSparseMat &m, Int i)
00087 {
00088     CheckRange(i, 0, m.Cols(), "(col(SparseMat)) illegal column index");
00089 
00090     return(TSubSVec(i, m.Rows(), m.Ref(), m.Cols()));
00091 }
00092 
00093 TMSubSVec diag(const TSparseMat &m, Int diagNum)
00094 {
00095     if (diagNum == 0)
00096         return(TSubSVec(0, Min(m.Rows(), m.Cols()), m.Ref(), m.Cols() + 1));
00097     else if (diagNum < 0)
00098         return(TSubSVec(0, Min(m.Rows() + diagNum, m.Cols()), 
00099                         m.Ref() - diagNum, m.Cols() + 1));
00100     else
00101         return(TSubSVec(diagNum, Min(m.Cols() - diagNum, m.Rows()), m.Ref(), 
00102                         m.Cols() + 1));
00103 }
00104 

Generated at Sat Aug 5 00:16:48 2000 for Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000