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

SubVec.h

Go to the documentation of this file.
00001 /*
00002     File:           SubVec.h
00003 
00004     Function:       Defines a scatter-gather vector, i.e., a subvector of another vector, 
00005                     or the row, column or diagonal of a matrix.
00006                     
00007     Author(s):      Andrew Willmott
00008 
00009     Copyright:      (c) 1995-2000, Andrew Willmott
00010  */
00011 
00012 #ifndef __SubVec__
00013 #define __SubVec__
00014 
00015 #include "vl/VL.h"
00016 
00017 class TVec;
00018  
00019 class TSubVec
00020 {
00021 public:
00022 
00023                     TSubVec(Int n, Int span, TVReal data[]);
00024                     TSubVec(const TSubVec &v);
00025                     TSubVec(const TVec &v);
00026 
00027     inline Int      Elts() const { return(elts); };
00028 
00029     inline TVReal   &operator [] (Int i);
00030     inline TVReal   operator [] (Int i) const;
00031 
00032     TSubVec         &operator = (const TSubVec &v);
00033     TSubVec         &operator = (const TVec &v);
00034     
00035     Int             elts;
00036     Int             span;
00037     TVReal          *data; 
00038 };
00039 
00040 inline TSubVec  sub(const TSubVec &v, Int start, Int length);   
00041 inline TSubVec  first(const TSubVec &v, Int length);    
00042 inline TSubVec  last(const TSubVec &v, Int length);     
00043 
00044 
00045 // --- SubVec In-Place operators ----------------------------------------------
00046 
00047 TSubVec     &operator += (TSubVec &a, const TSubVec &b);
00048 TSubVec     &operator -= (TSubVec &a, const TSubVec &b);
00049 TSubVec     &operator *= (TSubVec &a, const TSubVec &b);
00050 TSubVec     &operator *= (TSubVec &v, TVReal s);
00051 TSubVec     &operator /= (TSubVec &a, const TSubVec &b);
00052 TSubVec     &operator /= (TSubVec &v, TVReal s);
00053 
00054 
00055 // --- Inlines ----------------------------------------------------------------
00056 
00057 inline TVReal &TSubVec::operator [] (Int i)
00058 {
00059     CheckRange(i, 0, elts, "Vec::[i]");
00060     
00061     return(data[i * span]);
00062 }
00063 
00064 inline TVReal TSubVec::operator [] (Int i) const
00065 {
00066     CheckRange(i, 0, elts, "Vec::[i]");
00067 
00068     return(data[i * span]);
00069 }
00070 
00071 inline TSubVec sub(const TSubVec &v, Int start, Int length)
00072 {
00073     Assert(start >= 0 && length > 0 && start + length <= v.Elts(),
00074         "(sub(Vec)) illegal subset of vector");
00075 
00076     return(TSubVec(length, v.span, v.data + start * v.span));
00077 }
00078 
00079 inline TSubVec first(const TSubVec &v, Int length)
00080 {
00081     Assert(length > 0 && length <= v.Elts(),
00082         "(first(Vec)) illegal subset of vector");
00083 
00084     return(TSubVec(length, v.span, v.data));
00085 }
00086 
00087 inline TSubVec last(const TSubVec &v, Int length)
00088 {
00089     Assert(length > 0 && length <= v.Elts(),
00090         "(last(Vec)) illegal subset of vector");
00091 
00092     return(TSubVec(length, v.span, v.data + (v.elts - length) * v.span));
00093 }
00094 
00095 #endif

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