![]() |
fml
0.1-0
Fused Matrix Library
|
Vector class for data held on a single CPU. More...
#include <cpuvec.hh>
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 (cpuvec &&x) | |
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 () |
Set values to linearly spaced numbers. More... | |
void | fill_linspace (const T start, const T stop) |
void | subset (const len_t start, const len_t stop, const bool interior=true) |
void | scale (const T s) |
Multiply all values by the input value. More... | |
void | pow (const T p) |
Raise every value of the vector to the given power. More... | |
void | rev () |
Reverse the vector. | |
T | sum () const |
Sum the vector. | |
T | max () const |
Maximum value of the vector. | |
T | min () const |
Minimum value of the vector. | |
T | 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= (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... | |
cpuvec< T > & | operator= (const cpuvec< T > &x) |
void | fill_linspace (const int start, const int stop) |
![]() | |
len_t | size () const |
Number of elements in the vector. | |
T * | data_ptr () |
Pointer to the internal array. | |
T * | data_ptr () const |
Protected Member Functions | |
bool | free_on_destruct () const |
void | dont_free_on_destruct () |
![]() | |
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 |
Additional Inherited Members | |
![]() | |
len_t | _size |
T * | data |
bool | free_data |
Vector class for data held on a single CPU.
T | should be 'int', 'float' or 'double'. |
fml::cpuvec< T >::cpuvec |
Construct vector object with no internal allocated storage.
fml::cpuvec< T >::cpuvec | ( | len_t | size | ) |
Construct vector object with no internal allocated storage.
[in] | size | Number elements of the vector. |
Exceptions
If the allocation fails, a bad_alloc
exception will be thrown. If the input values are invalid, a runtime_error
exception will be thrown.
fml::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.
[in] | data_ | Storage array. |
[in] | size | Number elements of the array. |
[in] | free_on_destruct | Should the inherited array data_ be freed when the vector object is destroyed? |
Exceptions
If the input values are invalid, a runtime_error
exception will be thrown.
void fml::cpuvec< T >::fill_linspace |
Set values to linearly spaced numbers.
[in] | start,stop | Beginning/ending numbers. If not supplied, the vector will be filled with whole numbers from 1 to the total number of elements. |
void fml::cpuvec< T >::fill_val | ( | const T | v | ) |
Set all values to input value.
[in] | v | Value to set all data values to. |
T fml::cpuvec< T >::get | ( | const len_t | i | ) | const |
Get the specified value.
[in] | i | The index of the desired value, 0-indexed. |
Exceptions
If indices are out of bounds, the method will throw a runtime_error
exception.
void fml::cpuvec< T >::inherit | ( | T * | data, |
len_t | size, | ||
bool | free_on_destruct = false |
||
) |
Set the internal object storage to the specified array.
[in] | data | Value storage. |
[in] | size | Length of the vector. Should match the length of the input data . |
[in] | free_on_destruct | Should the object destructor free the internal array data ? |
Exceptions
If the input values are invalid, a runtime_error
exception will be thrown.
bool fml::cpuvec< T >::operator!= | ( | const cpuvec< T > & | x | ) | const |
See if the two objects are not the same. Uses same internal logic as the ==
method.
[in] | Comparison | object. |
fml::cpuvec< T > & fml::cpuvec< T >::operator= | ( | fml::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.
[in] | x | Setter value. |
bool fml::cpuvec< T >::operator== | ( | const cpuvec< T > & | x | ) | const |
See if the two objects are the same.
[in] | Comparison | object. |
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. void fml::cpuvec< T >::pow | ( | const T | p | ) |
Raise every value of the vector to the given power.
[in] | p | Power. |
void fml::cpuvec< T >::print | ( | uint8_t | ndigits = 4 , |
bool | add_final_blank = true |
||
) | const |
Copy data from a CPU object to another.
[in] | ndigits | Number of decimal digits to print. |
[in] | add_final_blank | Should a final blank line be printed? |
void fml::cpuvec< T >::resize | ( | len_t | size | ) |
Resize the internal object storage.
[in] | size | Length of the vector needed. |
Memory Allocations
Resizing triggers a re-allocation.
Exceptions
If the reallocation fails, a bad_alloc
exception will be thrown. If the input values are invalid, a runtime_error
exception will be thrown.
void fml::cpuvec< T >::scale | ( | const T | s | ) |
Multiply all values by the input value.
[in] | s | Scaling value. |
void fml::cpuvec< T >::set | ( | const len_t | i, |
const T | v | ||
) |
Set the storage at the specified index with the provided value.
[in] | i | The index of the desired value, 0-indexed. |
[in] | v | Setter value. |
Exceptions
If indices are out of bounds, the method will throw a runtime_error
exception.