ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
clockwerk::CartesianVector< T, L > Class Template Reference

Standard vector class derived from Matrix. More...

#include <CartesianVector.hpp>

Inheritance diagram for clockwerk::CartesianVector< T, L >:
Collaboration diagram for clockwerk::CartesianVector< T, L >:

Public Member Functions

 CartesianVector ()
 Redeclare constructors - note here that we're defining these to call their matrix counterparts, with the exception of the initializer list which we redefine for a vector Default constructor to initialize a vector to all zeroes.
 
 CartesianVector (T elements)
 Constructor to initialize a matrix with all the same element.
 
 CartesianVector (const T(&initial)[L])
 Constructor for Matrix class with initialization. Initializes matrix to values passed in via array.
 
 CartesianVector (const CartesianVector< T, L > &initial)
 Copy constructor for Matrix class. Copies data from matrix object to the current instance.
 
 CartesianVector (const std::array< T, L > &initial)
 Constructor for vector initialization via array.
 
 ~CartesianVector ()
 Destructor – doesn't do anything because we don't dynamically allocate.
 
T & operator[] (unsigned int idx)
 Function to return a vector value.
 
int set (const unsigned int &idx, const T &value)
 Setter specific to the vector class.
 
int get (const unsigned int &idx, T &result) const
 Getter specific to the vector class.
 
get (const unsigned int &idx) const
 Getter specific to the vector class.
 
int norm (T &result) const
 Function to take the norm of a vector.
 
norm () const
 Function to take the norm of a vector.
 
int normSquared (T &result) const
 Function to take the squared norm of a vector.
 
normSquared () const
 Function to take the squared norm of a vector.
 
int unit (CartesianVector< T, L > &result) const
 Function to return the unitized version of the vector.
 
int unitize ()
 Function to unitize the current vector.
 
int normalize ()
 Function to unitize the current vector.
 
std::string str () const
 Function to write out vector as a string.
 
void dump () const
 Function to dump information on matrix.
 
int set (const unsigned int &row, const unsigned int &col, const T &value)
 Function to set a single value in the matrix.
 
int get (const unsigned int &row, const unsigned int &col, T &result) const
 Function to get a single value in the matrix.
 
get (const unsigned int &row, const unsigned int &col) const
 Function to get a single value in the matrix.
 
void setFromArray (const T *start_ptr)
 Function to set the values of the matrix row-wise.
 
void getAsArray (T *start_ptr) const
 Function to get the values of the matrix row-wise.
 
void getCopy (Matrix< T, R, C > &result) const
 Function to get a copy of the matrix.
 
std::pair< unsigned int, unsigned int > size ()
 Function to get the size of the matrix.
 
void max (T &result, std::pair< unsigned int, unsigned int > &index) const
 Function to return the maximum value in the matrix.
 
void min (T &result, std::pair< unsigned int, unsigned int > &index) const
 Function to return the minimum value in the matrix.
 
int det (T &result) const
 Function to return the determinant of the matrix.
 
int inverse (Matrix< T, R, C > &result) const
 Function to return the inverse of the matrix.
 
Matrix< T, R, C > inverse () const
 
void transpose (Matrix< T, C, R > &result) const
 Function to return the transpose of the matrix.
 
Matrix< T, C, R > transpose () const
 
int trace (T &result) const
 Function to return the trace of the matrix.
 
void setToZeros ()
 Function to set all elements of the matrix to zero.
 
int identity ()
 Function to set matrix to identity, if it is a square matrix.
 
int eye ()
 

Public Attributes

std::array< std::array< T, C >, R > values
 The actual values held by the matrix – a two dimensional array of values indexed as (row, column). NOTE: Public for ease of access and speed (no need to use setter/getter), and functions in Matrix and Safemath libraries are tested safe. Behavior using matrices outside of clockwerk libraries should use setter/getter, rather than direct access, for safety.
 

Protected Member Functions

int _checkLookupBoundaries (const unsigned int &start_r, const unsigned int &end_r, const unsigned int &start_c, const unsigned int &end_c) const
 Function to check, given a set of submatrix boundaries, that those boundaries are valid for the current matrix.
 
int _LUPDecompose (T *A[R], unsigned int P[R+1]) const
 Function to take a 2-d matrix represented by A and decompose it into LU form.
 

Detailed Description

template<typename T, unsigned int L>
class clockwerk::CartesianVector< T, L >

Standard vector class derived from Matrix.

This file defines a simple vector class for cartesian systems in any number of dimensions. As an inherited class from the Matrix class defined in this directory, it can perform all matrix operations and has several operations of its own specific to vectors.

Member Function Documentation

◆ _LUPDecompose()

int clockwerk::Matrix< T, R, C >::_LUPDecompose ( T *  A[R],
unsigned int  P[R+1] 
) const
protectedinherited

Function to take a 2-d matrix represented by A and decompose it into LU form.

Parameters
AA 2-d matrix represented as a double pointer After ops A contains a copy of both matrices L-E and U as A=(L-E)+U such that P*A=L*U.
PThe permutation matrix to hold info on matrix changes
Returns
Error code corresponding to codes in clockwerkerrors.h
Note
Code borrowed/updated from sample C code on wikipedia here: https://en.wikipedia.org/wiki/LU_decomposition

◆ det()

int clockwerk::Matrix< T, R, C >::det ( T &  result) const
inherited

Function to return the determinant of the matrix.


Operations to return important matrix information

Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ get() [1/4]

template<typename T , unsigned int L>
T clockwerk::CartesianVector< T, L >::get ( const unsigned int &  idx) const
inline

Getter specific to the vector class.

Parameters
idxThe index to return
Returns
Value at index
Note
Does not bounds check index and should be treated safely

◆ get() [2/4]

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::get ( const unsigned int &  idx,
T &  result 
) const
inline

Getter specific to the vector class.

Parameters
idxThe index to return
valuePBR return of the value in the vector
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ get() [3/4]

T clockwerk::Matrix< T, R, C >::get ( const unsigned int &  row,
const unsigned int &  col 
) const
inherited

Function to get a single value in the matrix.

Parameters
rowThe row index
colThe column index
Returns
Matrix value at index
Note
Does not bounds check and is unsafe for embedded operations

◆ get() [4/4]

int clockwerk::Matrix< T, R, C >::get ( const unsigned int &  row,
const unsigned int &  col,
T &  result 
) const
inherited

Function to get a single value in the matrix.

Parameters
rowThe row index
colThe column index
valuePBR return of the value in the matrix
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ getAsArray()

void clockwerk::Matrix< T, R, C >::getAsArray ( T *  start_ptr) const
inherited

Function to get the values of the matrix row-wise.

Parameters
start_ptrThe data address at which write should begin.
Note
start_ptr must represent an array or similar type of at least R*C values
Not protected. May segfault if not used properly
The matrix [1 2; 3 4] would output as an array [1 2 3 4]

◆ getCopy()

void clockwerk::Matrix< T, R, C >::getCopy ( Matrix< T, R, C > &  result) const
inherited

Function to get a copy of the matrix.

Parameters
resultPBR return of a copy of this matrix

◆ identity()

int clockwerk::Matrix< T, R, C >::identity ( )
inherited

Function to set matrix to identity, if it is a square matrix.

Returns
Error code corresponding to success/failure

◆ inverse()

int clockwerk::Matrix< T, R, C >::inverse ( Matrix< T, R, C > &  result) const
inherited

Function to return the inverse of the matrix.

Parameters
resultPBR return of matrix inverse
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ max()

void clockwerk::Matrix< T, R, C >::max ( T &  result,
std::pair< unsigned int, unsigned int > &  index 
) const
inherited

Function to return the maximum value in the matrix.

Parameters
resultPBR return of maximum value

◆ min()

void clockwerk::Matrix< T, R, C >::min ( T &  result,
std::pair< unsigned int, unsigned int > &  index 
) const
inherited

Function to return the minimum value in the matrix.

Parameters
resultPBR return of minimum value

◆ norm() [1/2]

template<typename T , unsigned int L>
T clockwerk::CartesianVector< T, L >::norm ( ) const
inline

Function to take the norm of a vector.

Returns
return of the norm operation

◆ norm() [2/2]

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::norm ( T &  result) const

Function to take the norm of a vector.

Parameters
resultPBR return of the norm operation

◆ normalize()

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::normalize ( )

Function to unitize the current vector.

Returns
Error code corresponding to those in clockwerkerrors.h

◆ normSquared() [1/2]

template<typename T , unsigned int L>
T clockwerk::CartesianVector< T, L >::normSquared ( ) const
inline

Function to take the squared norm of a vector.

Returns
return of the norm squared operation

◆ normSquared() [2/2]

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::normSquared ( T &  result) const

Function to take the squared norm of a vector.

Parameters
resultPBR return of the norm^2 operation

◆ operator[]()

template<typename T , unsigned int L>
T & clockwerk::CartesianVector< T, L >::operator[] ( unsigned int  idx)

Function to return a vector value.

Parameters
idxThe index to return
Returns
Reference to the vector element
Note
This vector, much like std::array, does not check index range and should be used accordingly

◆ set() [1/2]

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::set ( const unsigned int &  idx,
const T &  value 
)
inline

Setter specific to the vector class.

Parameters
idxVector element to set
valueThe value to set the element to
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ set() [2/2]

int clockwerk::Matrix< T, R, C >::set ( const unsigned int &  row,
const unsigned int &  col,
const T &  value 
)
inherited

Function to set a single value in the matrix.


Getters and setters

Parameters
rowThe row index
colThe column index
valueThe value to set the matrix to
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ setFromArray()

void clockwerk::Matrix< T, R, C >::setFromArray ( const T *  start_ptr)
inherited

Function to set the values of the matrix row-wise.

Parameters
start_ptrThe data address at which read should begin.
Note
start_ptr must represent an array or similar type of at least R*C values
Not protected. May segfault if not used properly
The array [1 2 3 4] would read into a matrix as [1 2; 3 4]

◆ size()

std::pair< unsigned int, unsigned int > clockwerk::Matrix< T, R, C >::size ( )
inlineinherited

Function to get the size of the matrix.


Operations to get matrix info

◆ str()

template<typename T , unsigned int L>
std::string clockwerk::CartesianVector< T, L >::str ( ) const

Function to write out vector as a string.

Returns
Vector written as a square brace enclosed string

◆ trace()

int clockwerk::Matrix< T, R, C >::trace ( T &  result) const
inherited

Function to return the trace of the matrix.

Parameters
resultPBR return of matrix trace
Returns
Integer value corresponding to error codes in clockwerkerrrors.h

◆ transpose()

void clockwerk::Matrix< T, R, C >::transpose ( Matrix< T, C, R > &  result) const
inherited

Function to return the transpose of the matrix.

Parameters
resultPBR return of matrix transpose
Note
Overloaded for return as well

◆ unit()

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::unit ( CartesianVector< T, L > &  result) const

Function to return the unitized version of the vector.

Parameters
resultPBR return of the unit vector
Returns
Error code corresponding to those in clockwerkerrors.h

◆ unitize()

template<typename T , unsigned int L>
int clockwerk::CartesianVector< T, L >::unitize ( )

Function to unitize the current vector.

Returns
Error code corresponding to those in clockwerkerrors.h

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