fml  0.1-0
Fused Matrix Library
cpuvec< T > Class Template Reference

Vector class for data held on a single CPU. More...

#include <cpuvec.hh>

Inheritance diagram for cpuvec< T >:
univec< T >

Public Member Functions

 cpuvec ()
 Construct vector object with no internal allocated storage. More...
 
 cpuvec (len_t size)
 Construct vector object with no internal allocated storage. More...
 
 cpuvec (T *data, len_t size, bool free_on_destruct=false)
 Construct vector object with inherited data. Essentially the same as using the minimal constructor and immediately calling the inherit() method. More...
 
 cpuvec (const cpuvec &x)
 
void resize (len_t size)
 Resize the internal object storage. More...
 
void inherit (T *data, len_t size, bool free_on_destruct=false)
 Set the internal object storage to the specified array. More...
 
cpuvec< T > dupe () const
 Duplicate the object in a deep copy.
 
void print (uint8_t ndigits=4, bool add_final_blank=true) const
 Copy data from a CPU object to another. More...
 
void info () const
 Print some brief information about the object.
 
void fill_zero ()
 Set all values to zero.
 
void fill_val (const T v)
 Set all values to input value. More...
 
void fill_linspace (const T start, const T stop)
 Set values to linearly spaced numbers. More...
 
void scale (const T s)
 Multiply all values by the input value. More...
 
void rev ()
 Reverse the vector.
 
sum ()
 Sum the vector.
 
get (const len_t i) const
 Get the specified value. More...
 
void set (const len_t i, const T v)
 Set the storage at the specified index with the provided value. More...
 
bool operator== (const cpuvec< T > &x) const
 See if the two objects are the same. More...
 
bool operator!= (const cpuvec< T > &x) const
 See if the two objects are not the same. Uses same internal logic as the == method. More...
 
cpuvec< T > & operator= (const cpuvec< T > &x)
 Operator that sets the LHS to a shallow copy of the input. Desctruction of the LHS object will not result in the internal array storage being freed. More...
 
void fill_linspace (const int start, const int stop)
 
- Public Member Functions inherited from univec< T >
len_t size () const
 Number of elements in the vector.
 
T * data_ptr ()
 Pointer to the internal array.
 
T * data_ptr () const
 

Additional Inherited Members

- Protected Member Functions inherited from univec< T >
bool should_free () const
 
void check_index (const len_t i) const
 
void printval (const T val, uint8_t ndigits) const
 
void printval (const int val, uint8_t ndigits) const
 
- Protected Attributes inherited from univec< T >
len_t _size
 
T * data
 
bool free_data
 

Detailed Description

template<typename T>
class cpuvec< T >

Vector class for data held on a single CPU.

Template Parameters
Tshould be 'int', 'float' or 'double'.

Constructor & Destructor Documentation

◆ cpuvec() [1/3]

template<typename T >
cpuvec< T >::cpuvec

Construct vector object with no internal allocated storage.

◆ cpuvec() [2/3]

template<typename T >
cpuvec< T >::cpuvec ( len_t  size)

Construct vector object with no internal allocated storage.

Parameters
[in]sizeNumber elements of the vector.
Exceptions\n If the allocation fails, a bad_alloc exception will be thrown.
If the input values are invalid, a runtime_error exception will be thrown.

◆ cpuvec() [3/3]

template<typename T >
cpuvec< T >::cpuvec ( T *  data_,
len_t  size,
bool  free_on_destruct = false 
)

Construct vector object with inherited data. Essentially the same as using the minimal constructor and immediately calling the inherit() method.

Parameters
[in]data_Storage array.
[in]sizeNumber elements of the array.
[in]free_on_destructShould the inherited array data_ be freed when the vector object is destroyed?
Exceptions\n If the input values are invalid, a runtime_error exception will be
thrown.

Member Function Documentation

◆ fill_linspace()

template<typename T >
void cpuvec< REAL >::fill_linspace ( const T  start,
const T  stop 
)

Set values to linearly spaced numbers.

Parameters
[in]start,stopBeginning/ending numbers.

◆ fill_val()

template<typename T >
void cpuvec< T >::fill_val ( const T  v)

Set all values to input value.

Parameters
[in]vValue to set all data values to.

◆ get()

template<typename T >
T cpuvec< T >::get ( const len_t  i) const

Get the specified value.

Parameters
[in]iThe index of the desired value, 0-indexed.
Exceptions\n If indices are out of bounds, the method will throw a runtime_error
exception.

◆ inherit()

template<typename T >
void cpuvec< T >::inherit ( T *  data,
len_t  size,
bool  free_on_destruct = false 
)

Set the internal object storage to the specified array.

Parameters
[in]dataValue storage.
[in]sizeLength of the vector. Should match the length of the input data.
[in]free_on_destructShould the object destructor free the internal array data?
Exceptions\n If the input values are invalid, a runtime_error exception will be
thrown.

◆ operator!=()

template<typename T >
bool cpuvec< T >::operator!= ( const cpuvec< T > &  x) const

See if the two objects are not the same. Uses same internal logic as the == method.

Parameters
[in]Comparisonobject.

◆ operator=()

template<typename T >
cpuvec< T > & cpuvec< T >::operator= ( const cpuvec< T > &  x)

Operator that sets the LHS to a shallow copy of the input. Desctruction of the LHS object will not result in the internal array storage being freed.

Parameters
[in]xSetter value.

◆ operator==()

template<typename T >
bool cpuvec< T >::operator== ( const cpuvec< T > &  x) const

See if the two objects are the same.

Parameters
[in]Comparisonobject.
Returns
If the sizes mismatch, then false is necessarily returned. Next, if the pointer to the internal storage arrays match, then true is necessarily returned. Otherwise the objects are compared value by value.

◆ print()

template<typename T >
void cpuvec< T >::print ( uint8_t  ndigits = 4,
bool  add_final_blank = true 
) const

Copy data from a CPU object to another.

Parameters
[in]ndigitsNumber of decimal digits to print.
[in]add_final_blankShould a final blank line be printed?

◆ resize()

template<typename T >
void cpuvec< T >::resize ( len_t  size)

Resize the internal object storage.

Parameters
[in]sizeLength of the vector needed.
Memory Allocations\n Resizing triggers a re-allocation.
Exceptions\n If the reallocation fails, a bad_alloc exception will be thrown.
If the input values are invalid, a runtime_error exception will be thrown.

◆ scale()

template<typename T >
void cpuvec< T >::scale ( const T  s)

Multiply all values by the input value.

Parameters
[in]sScaling value.

◆ set()

template<typename T >
void cpuvec< T >::set ( const len_t  i,
const T  v 
)

Set the storage at the specified index with the provided value.

Parameters
[in]iThe index of the desired value, 0-indexed.
[in]vSetter value.
Exceptions\n If indices are out of bounds, the method will throw a runtime_error
exception.

The documentation for this class was generated from the following file:
cpuvec
Vector class for data held on a single CPU.
Definition: cpuvec.hh:29