#include <linalg.hpp>
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 |
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.
| linalg::slice::slice | ( | size_t | a, | |
| size_t | b, | |||
| size_t | k = 1 | |||
| ) |
| slice linalg::slice::operator() | ( | size_t | a, | |
| size_t | b, | |||
| size_t | k = 1 | |||
| ) |
| 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] |
| size_t linalg::slice::end | ( | ) | const [inline] |
| size_t linalg::slice::stride | ( | ) | const [inline] |
size_t linalg::slice::beg [private] |
size_t linalg::slice::fin [private] |
size_t linalg::slice::str [private] |
1.5.6