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).
00682                                            {
00683     set(a,b,k);
00684   } 

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

Empty and private default constructor.

00369 {};


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).
00686                                                       {
00687     return set(a,b,k);
00688   }

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

00690                                                {
00691     if(b < a){
00692       badArgument exc;
00693       exc.reason = 
00694         "Invalid arguments to slice::set. "
00695         "Right endpoint must be greater than left endpoint.";
00696       throw exc;
00697     }
00698     else if(k==0){
00699       badArgument exc;
00700       exc.reason = 
00701         "Invalid arguments to slice::set. "
00702         "Cannot take zero stride.";
00703       throw exc;
00704     }
00705     else if( k > b-a){
00706       badArgument exc;
00707       exc.reason = "Invalid arguments to slice::set. " 
00708         "Step size cannot be greater than range.";
00709       throw exc;
00710     }
00711     beg = a-1;
00712     fin = b-1;
00713     str = k;
00714     return *this;
00715   }

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

00363 {return beg;};

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

00364 {return fin;};

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

00365 {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 Fri Jun 6 17:28:30 2008 by  doxygen 1.5.6