Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

DenseVector< T > Class Template Reference
[Linear Algebra library]

A linear algebraic vector, without any assumptions of sparseness or symmetry. More...

#include <linalg.h>

Inherits vectorview< T >< T >, and Vector< T >< T >.

Inheritance diagram for DenseVector< T >:

Inheritance graph
[legend]
Collaboration diagram for DenseVector< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void initialize (const datablock< T > *db, itype s, itype r, itype o)
virtual bool Valid () const
virtual datablock< T > * GetDataBlock () const
 Each dataview is attached to a datablock; this should give access to it. Only usable from derived classes (i.e., views).
virtual itype Dimensionality () const
 Should return the number of indices required to define an element in this view.
virtual itype Range (itype i) const
 Should return the virtual range of index i.
virtual bool Is1DCompatible () const
 Should return TRUE if and only if this view provides 1-D strided access.
virtual bool Is2DCompatible () const
 Should return TRUE if and only if this view provides 2-D semi-contiguous strided access.
virtual T * Get1DRep (itype &n_elements, itype &r_stride) const
virtual T * Get2DRep (itype &n_series, itype &series_size, itype &series_extent) const
virtual T & item (itype index) const
virtual T & element (itype *iarr) const
virtual T & element (itype i1,...) const
virtual void PrettyPrint (std::ostream &os=std::cout) const
virtual void DataPrint (std::ostream &os=std::cout) const
virtual void OwnData (bool copyflag)
virtual void FillFromStream (std::istream &is, bool clear=true)
virtual void InitFromStream (std::istream &is)
virtual void Fill (T val)
void SetSize (itype s, bool copyflag)
Constructors and destructors
 DenseVector ()
 Default constructor; creates a null vector of length 0.
 DenseVector (itype s)
 Standard constructor; creates a blank vector of length s.
 DenseVector (itype s, T array[])
 Initializing constructor; creates a vector of length s and initializes from array. Use with caution -- not memory safe!
 DenseVector (const vectorview< T > &other)
 Semi-copy constructor; creates a vector as a copy of an existing vectorview<T> (the parent class).
 DenseVector (const DenseVector< T > &other)
 Copy constructor; creates a vector as a copy of an existing DenseVector<T>.
virtual ~DenseVector ()
 Destructor; does nothing.
Overridden base class methods
virtual DenseVector< T > Subvector (interval i)
 Takes an interval, and returns a subvector defined by that interval.
virtual const DenseVector< T > Subvector (interval i) const
 Takes an interval, and returns a subvector defined by that interval.
DenseVector< T > copy () const
 Returns a copy of this vector, which uses a separate data block.
virtual itype Size () const
 Returns the number of elements in the vector.
virtual T & operator() (itype i)
 Returns a reference to a specific data element from the vector.
virtual T operator() (itype i) const
 Returns the value of a specific data element from the vector.
virtual void print (std::ostream &os=std::cout) const
 Prints the entire vector to an output stream.
New methods
DenseVector< typename linalg_traits<
T >::conjugate_type > & 
Conjugate ()
 Performs an in-place conjugation: V[i] -> V*[i].
linalg_traits< T >::norm_type Norm ()
 Returns the squared 2-norm of the vector.
linalg_traits< T >::abs_type Abs ()
 Returns the 2-norm length of the vector.
DenseVector< T > & Normalize ()
 Divides every element by the vector's absolute value, so that Norm() and Abs() will subsequently yield 1.
In-place operators
DenseVector< T > & operator= (const Vector< T > &other)
 Assignment operator: sets this vector equal to other.
DenseVector< T > & operator+= (const Vector< T > &other)
 Addition-in-place operator: adds other to this vector, in place.
DenseVector< T > & operator-= (const Vector< T > &other)
 Subtraction-in-place operator: adds other to this vector, in place.
DenseVector< T > & operator= (const DenseVector< T > &other)
 Assignment operator: sets this vector equal to other.
DenseVector< T > & operator+= (const DenseVector< T > &other)
 Addition-in-place operator: adds other to this vector, in place.
DenseVector< T > & operator-= (const DenseVector< T > &other)
 Subtraction-in-place operator: adds other to this vector, in place.
DenseVector< T > & operator *= (T scalar)
 Scalar-multiplication-in-place operator: multiplies this vector by scalar, in place.
DenseVector< T > & operator/= (T scalar)
 Scalar-division-in-place operator: divides this vector by scalar, in place.

Protected Member Functions

DenseVector GetSubVectorView (interval i) const
 GetSubVector takes an interval as argument, and returns a DenseVector<T> referencing the desired subvector.
void CreateSubVectorView (interval sub_I, vectorview< T > &sv) const

Detailed Description

template<typename T>
class DenseVector< T >

A linear algebraic vector, without any assumptions of sparseness or symmetry.

Together with DenseMatrix<T>, one of the two central classes of LinAlg. A DenseVector<T> supports all the basic linear algebraic operations. DenseVectors of type double and complex use BLAS routines for extra speed.


Constructor & Destructor Documentation

template<typename T>
DenseVector< T >::DenseVector const vectorview< T > &  other  )  [inline]
 

Semi-copy constructor; creates a vector as a copy of an existing vectorview<T> (the parent class).

The standard copy-constructor for vectorview<T> is a shallow copy -- it adds a reference to other's datablock. For DenseVector<T>, we force a deep copy by using "other.copy()". This reflects deep confusion about how to best implement copying!

template<typename T>
DenseVector< T >::DenseVector const DenseVector< T > &  other  )  [inline]
 

Copy constructor; creates a vector as a copy of an existing DenseVector<T>.

Copy constructor MUST be supplied to prevent g++ from providing a shallow copy, otherwise we could just rely on the semi-copy constructor that takes a vectorview<T>. NOTE: we should add a constructor from Vector<T>!


Member Function Documentation

template<typename T>
DenseVector DenseVector< T >::GetSubVectorView interval  i  )  const [inline, protected]
 

GetSubVector takes an interval as argument, and returns a DenseVector<T> referencing the desired subvector.

This is implemented as a straightforward thunk to vectorview<>'s CreateSubVectorView method, with a changed return type. NOTE: does this function actually serve any purpose?

Reimplemented from vectorview< T >.

template<typename T>
virtual DenseVector<T> DenseVector< T >::Subvector interval  i  )  [inline, virtual]
 

Takes an interval, and returns a subvector defined by that interval.

Subvector (const and non-const) are overrides of Vector<> methods NOTE 1: that's not actually true because covariant returns are unimplemented, so I removed them from Vector<>. NOTE: Fix this since g++ 3.4 implements covariant returns?

template<typename T>
virtual const DenseVector<T> DenseVector< T >::Subvector interval  i  )  const [inline, virtual]
 

Takes an interval, and returns a subvector defined by that interval.

Subvector (const and non-const) are overrides of Vector<> methods NOTE 1: that's not actually true because covariant returns are unimplemented, so I removed them from Vector<>. NOTE: Fix this since g++ 3.4 implements covariant returns?

template<typename T>
DenseVector<T> DenseVector< T >::copy  )  const [inline]
 

Returns a copy of this vector, which uses a separate data block.

copy() overrides the implementation provided by vectorview<>, but does nothing except change the return type.

Reimplemented from vectorview< T >.

template<typename T>
virtual itype DenseVector< T >::Size  )  const [inline, virtual]
 

Returns the number of elements in the vector.

Size() must be provided for the Vector<> interface. It overrides vectorview<>'s method as well, but thunks directly through to it.

Reimplemented from vectorview< T >.

template<typename T>
virtual T& DenseVector< T >::operator() itype  i  )  [inline, virtual]
 

Returns a reference to a specific data element from the vector.

operator() must be provided for the Vector<> interface. It overrides vectorview<>'s method as well, but thunks directly through to it.

Implements Vector< T >.

template<typename T>
virtual T DenseVector< T >::operator() itype  i  )  const [inline, virtual]
 

Returns the value of a specific data element from the vector.

operator() [const] must be provided for the Vector<> interface. It overrides vectorview<>'s method as well, but thunks directly through to it.

Reimplemented from vectorview< T >.

template<typename T>
virtual void DenseVector< T >::print std::ostream &  os = std::cout  )  const [inline, virtual]
 

Prints the entire vector to an output stream.

print() overrides Vector<T>::print to use vectorview<T>'s output method, DataPrint().

Reimplemented from Vector< T >.

template<typename T>
DenseVector<typename linalg_traits<T>::conjugate_type>& DenseVector< T >::Conjugate  )  [inline]
 

Performs an in-place conjugation: V[i] -> V*[i].

Conjugate() will cause a compile-time error if T != conjugate_type<T>.

template<typename T>
DenseVector<T>& DenseVector< T >::Normalize  )  [inline]
 

Divides every element by the vector's absolute value, so that Norm() and Abs() will subsequently yield 1.

Normalize(I) will cause a compile-time error if abs_type<T> is not implicitly convertible to T.

template<typename T>
DenseVector< T > & DenseVector< T >::operator= const DenseVector< T > &  other  ) 
 

Assignment operator: sets this vector equal to other.

I believe (6/03/06) that this is not done lazily. We need to figure out a way to do lazy assignment when appropriate!

template<typename T>
void vectorview< T >::initialize const datablock< T > *  db,
itype  s,
itype  r,
itype  o
[inherited]
 

The initialize() method is a quasi-constructor. Used to set the parameters of an existing vectorview, it also does the heavy lifting of constructing a new dataview AFTER "dblock" is initialized to NULL.

template<class T>
virtual bool vectorview< T >::Valid  )  const [inline, virtual, inherited]
 

We also provide the mandated "dataview_interface" interface

Implements dataview_interface< T >.

template<class T>
virtual bool vectorview< T >::Is1DCompatible  )  const [inline, virtual, inherited]
 

Should return TRUE if and only if this view provides 1-D strided access.

In other words, the data elements must be evenly spaced -- spacing of 1 means contiguous. There must exist a T* ptr and an int K such that every element X of the view is accessible as X = ptr[ N * K ] for some N in {0...Size()-1}.

Implements dataview_interface< T >.

template<class T>
virtual bool vectorview< T >::Is2DCompatible  )  const [inline, virtual, inherited]
 

Should return TRUE if and only if this view provides 2-D semi-contiguous strided access.

In other words, the data must be arranged in evenly spaced blocks, e.g. as blocks of length L followed by gaps of length K-L. There must exist a T* ptr and int K such that every element X of the view is accessible as X = ptr[ M + N * K ] for some N,M.

Implements dataview_interface< T >.

template<typename T>
T * vectorview< T >::Get1DRep itype n_elements,
itype r_stride
const [virtual, inherited]
 

If the view is 1D compatible, should provide its 1D representation in n_elements and stride, and the returned pointer.

See Is1DCompatible(). Using the notation defined there, this function should:

  • place Size() in n_elements,
  • place K in stride,
  • return ptr

Implements dataview_interface< T >.

template<typename T>
T * vectorview< T >::Get2DRep itype n_series,
itype series_size,
itype series_extent
const [virtual, inherited]
 

If the view is 2D compatible, should provide its 2D representation in n_series, series_range, series_extent, and the returned pointer.

See Is2DCompatible(). Using the notation defined there, this function should:

  • place Range(0) in n_series,
  • place Range(1) in series_range,
  • return K in series_extent

Implements dataview_interface< T >.

template<class T>
virtual T& vectorview< T >::item itype  index  )  const [inline, virtual, inherited]
 

Should return a unique element corresponding to index, as long as index is in [0...Size()-1].

If the view has a 1DRep or 2DRep, then the ordering of the elements must agree with the ordering in that representation. Otherwise, there are no ordering requirements. Every element in the view must be accessible through this function, for some index in [0...Size()-1].

Implements dataview_interface< T >.

template<class T>
virtual T& vectorview< T >::element itype iarr  )  const [inline, virtual, inherited]
 

Should return a unique element corresponding to the set of indices iarr.

iarr must contain Dimensionality() indices, and iarr[i] must be in [0...Range(i)-1]. if Dimensionality() = 1, this function must agree with item( iarr[0] ). If the view has a 2DRep, the ordering must agree with it.

Implements dataview_interface< T >.

template<class T>
virtual T& vectorview< T >::element itype  i1,
  ...
const [inline, virtual, inherited]
 

Should return a unique element corresponding to the first Dimensionality() parameters passed.

This function must behave identically to element( itype* iarr ) when Dimensionality() parameters are given. Extra parameters must be ignored. Behavior is undefined when insufficient parameters given.

Implements dataview_interface< T >.

template<typename T>
void vectorview< T >::PrettyPrint std::ostream &  os = std::cout  )  const [virtual, inherited]
 

Should print the elements of the view to os, formatted for human reading.

The exact format of printing is flexible -- it should be maximally readable for users.

Implements dataview_interface< T >.

template<typename T>
void vectorview< T >::DataPrint std::ostream &  os = std::cout  )  const [virtual, inherited]
 

Should print the elements of the view, arranged in columnar form, to os.

Unlike PrettyPrint(), DataPrint should follow a fairly strict format.

  • 1 dimensional views should be printed as "lines": sequences of numbers (of type T), separated by spaces. The numbers themselves should not contain spaces, or if they must, they should be enclosed in quotes.
  • 2 dimensional views should be printed as "blocks": sequences of "lines" (see above), separated by newline characters.
  • 3 dimensional views should be printed as a sequence of "blocks", separated by double newlines.
  • For 4 and higher dimensions, proceed recursively, separating N-dimensional "hyperblocks" by N newlines. Thus, e.g., a 4D view should be printed as a sequence of 3D views, separated by triple newlines.

Implements dataview_interface< T >.

template<class T>
virtual void vectorview< T >::OwnData bool  copyflag  )  [inline, virtual, inherited]
 

Ensures that the view has sole access to its datablock, by creating a virgin copy if necessary.

The purpose of OwnData() is to permit the view to ensure that it has sole control of the data that it references, possibly resizing it. Note that there is no way to tell who "owns" a block of data -- it is possible, although not explicitly supported through data_view, to identify how many views on a given datablock exist, but none of them have special "owner" rights. Thus, OwnData simply initializes new data and discards the old data. Note that the old data is copied only if copying is explicitly requested, since that can be slow. Also, it is permitted for a view to ignore this call IF-AND-ONLY-IF the reference count for its datablock is 1, meaning it already owns it.

Implements dataview_interface< T >.

template<typename T>
void vectorview< T >::FillFromStream std::istream &  is,
bool  clear = true
[virtual, inherited]
 

Should read in elements from a tabular data stream, and fill this view with them.

The FillFromStream() function is the input version of DataPrint(). It should read from a tabular data stream, where the format is simply T's separated by whitespace, with a newline for each end- of-series. Thus, a 2D dataset will have single newlines after each series, while a 3D dataset will have 2D blocks separated by double newlines. FillFromStream() maintains the current dimensions of the view, but replaces as much data as possible with that obtained from the stream. If clear = TRUE, then it will set all elements not specified by the stream to 0. See also InitFromStream().

Implements dataview_interface< T >.

template<typename T>
void vectorview< T >::InitFromStream std::istream &  is  )  [virtual, inherited]
 

Should reconstruct this view (changing size if necessary) to hold elements read in from a tabular data stream.

InitFromStream should read from a tabular data stream, where the format is simply T's separated by whitespace, with a newline for each end- of-series. Thus, a 2D dataset will have single newlines after each series, while a 3D dataset will have 2D blocks separated by double newlines. It then resizes the view to be just large enough to hold all that data, and fills it with the data read in. Elements not specified in the input stream will be set to zero. See also FillFromStream().

Implements dataview_interface< T >.


The documentation for this class was generated from the following file:
Generated on Wed Jun 14 22:25:28 2006 for linalg by  doxygen 1.4.4