#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 | |||
) |
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] |
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] |