linalg::slice Class Reference

Vector slices corresponding to GNU Octave ranges. More...

#include <linalg.hpp>

List of all members.

Public Member Functions

 slice (size_t a, size_t b, size_t k=1)
 Create a vector slice.
slice operator() (size_t a, size_t b, size_t k=1)
slice set (size_t a, size_t b, size_t k=1)
size_t begin () const
size_t end () const
size_t stride () const

Private Member Functions

 slice ()
 Empty and private default constructor.

Private Attributes

size_t beg
size_t fin
size_t str


Detailed Description

Vector slices corresponding to GNU Octave ranges.

Vector slices are useful for certain vectorisation routines and for referring to rows, columns, or equally spaced chunks of a vector or a matrix. Set a begininning and an end for the stride, and a step size, and this will be the elements that can be indexed by this slice in a vector or matrix. E.g. if the beginning is 2, the end 8, and the stride is 2, then this refers to the slice [2, 4, 6, 8]. The default stride is 1.

Unlike GNU Octave slices, there is no shorthand for referring to the entirety of a column or row of a matrix. Must instead create a slice for that purpose as s(1,n) where n is the number of rows or columns respectively.


Constructor & Destructor Documentation

linalg::slice::slice ( size_t  a,
size_t  b,
size_t  k = 1 
)

Create a vector slice.

Parameters:
a - Beginning of the slice.
b - End of the slice.
k - Stride (default is 1).
00724                                            {
00725     set(a,b,k);
00726   } 

linalg::slice::slice (  )  [inline, private]

Empty and private default constructor.

00388 {};


Member Function Documentation

slice linalg::slice::operator() ( size_t  a,
size_t  b,
size_t  k = 1 
)

For setting the slice parameters anew.

Indices start from 1.

Parameters:
a - Beginning of the slice.
b - End of the slice.
k - Stride (default is 1).
00728                                                       {
00729     return set(a,b,k);
00730   }

slice linalg::slice::set ( size_t  a,
size_t  b,
size_t  k = 1 
)

00732                                                {
00733     if(b < a){
00734       badArgument exc;
00735       exc.reason = 
00736         "Invalid arguments to slice::set. "
00737         "Right endpoint must be greater than left endpoint.";
00738       exc.line = __LINE__; exc.file = __FILE__;
00739       throw exc;
00740     }
00741     else if(k==0){
00742       badArgument exc;
00743       exc.reason = 
00744         "Invalid arguments to slice::set. "
00745         "Cannot take zero stride.";
00746       exc.line = __LINE__; exc.file = __FILE__;
00747       throw exc;
00748     }
00749     else if( k > b-a){
00750       badArgument exc;
00751       exc.reason = "Invalid arguments to slice::set. " 
00752         "Step size cannot be greater than range.";
00753       exc.line = __LINE__; exc.file = __FILE__;
00754       throw exc;
00755     }
00756     beg = a-1;
00757     fin = b-1;
00758     str = k;
00759     return *this;
00760   }

size_t linalg::slice::begin (  )  const [inline]

00382 {return beg;};

size_t linalg::slice::end (  )  const [inline]

00383 {return fin;};

size_t linalg::slice::stride (  )  const [inline]

00384 {return str;};


Member Data Documentation

size_t linalg::slice::beg [private]

size_t linalg::slice::fin [private]

size_t linalg::slice::str [private]


The documentation for this class was generated from the following files:

Generated on Mon Sep 29 23:54:13 2008 for RBF-DDM by  doxygen 1.5.6