![]() |
fml
0.1-0
Fused Matrix Library
|
Matrix class for data held on a single CPU. More...
#include <cpumat.hh>
Public Member Functions | |
cpumat () | |
Construct matrix object with no internal allocated storage. More... | |
cpumat (len_t nrows, len_t ncols) | |
Construct matrix object. More... | |
cpumat (REAL *data, len_t nrows, len_t ncols, bool free_on_destruct=false) | |
Construct matrix object with inherited data. Essentially the same as using the minimal constructor and immediately calling the inherit() method. More... | |
cpumat (cpumat &&x) | |
cpumat (const cpumat &x) | |
void | resize (len_t nrows, len_t ncols) |
Resize the internal object storage. More... | |
void | inherit (REAL *data, len_t nrows, len_t ncols, bool free_on_destruct=false) |
Set the internal object storage to the specified array. More... | |
void | inherit (cpumat< REAL > &data) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
cpumat< REAL > | dupe () const |
Duplicate the object in a deep copy. | |
void | print (uint8_t ndigits=4, bool add_final_blank=true) const |
Print all values in the object. More... | |
void | info () const |
Print some brief information about the object. | |
void | fill_zero () |
Set all values to zero. | |
void | fill_val (const REAL v) |
Set all values to input value. More... | |
void | fill_linspace () |
Set values to linearly spaced numbers. More... | |
void | fill_linspace (const REAL start, const REAL stop) |
void | fill_eye () |
Set diagonal entries to 1 and non-diagonal entries to 0. | |
void | fill_diag (const cpuvec< REAL > &v) |
Set diagonal entries of the matrix to those in the vector. More... | |
void | fill_runif (const uint32_t seed, const REAL min=0, const REAL max=1) |
Set diagonal entries to 1 and non-diagonal entries to 0. More... | |
void | fill_runif (const REAL min=0, const REAL max=1) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | fill_rnorm (const uint32_t seed, const REAL mean=0, const REAL sd=1) |
Set diagonal entries to 1 and non-diagonal entries to 0. More... | |
void | fill_rnorm (const REAL mean=0, const REAL sd=1) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | diag (cpuvec< REAL > &v) |
Get the diagonal entries. More... | |
void | antidiag (cpuvec< REAL > &v) |
Get the anti-diagonal entries, i.e. those on the bottom-left to top-right. More... | |
void | scale (const REAL s) |
Multiply all values by the input value. More... | |
void | rev_rows () |
Reverse the rows of the matrix. | |
void | rev_cols () |
Reverse the columns of the matrix. | |
bool | any_inf () const |
Are any values infinite? | |
bool | any_nan () const |
Are any values NaN? | |
REAL | get (const len_t i) const |
Get the specified value. More... | |
REAL | get (const len_t i, const len_t j) const |
Get the specified value. More... | |
void | set (const len_t i, const REAL v) |
Set the storage at the specified index with the provided value. More... | |
void | set (const len_t i, const len_t j, const REAL v) |
Set the storage at the specified index with the provided value. More... | |
void | get_row (const len_t i, cpuvec< REAL > &v) const |
Get the specified row. More... | |
void | set_row (const len_t i, const cpuvec< REAL > &v) |
Set the specified row. More... | |
void | get_col (const len_t j, cpuvec< REAL > &v) const |
Get the specified column. More... | |
void | set_col (const len_t i, const cpuvec< REAL > &v) |
Set the specified column. More... | |
bool | operator== (const cpumat< REAL > &x) const |
See if the two objects are the same. More... | |
bool | operator!= (const cpumat< REAL > &x) const |
See if the two objects are not the same. Uses same internal logic as the == method. More... | |
cpumat< REAL > & | operator= (cpumat< REAL > &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... | |
cpumat< REAL > & | operator= (const cpumat< REAL > &x) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | fill_linspace (const int start, const int stop) |
![]() | |
bool | is_square () const |
Is the matrix square? | |
len_t | nrows () const |
Number of rows. | |
len_t | ncols () const |
Number of columns. | |
REAL * | data_ptr () |
Pointer to the internal array. | |
REAL * | 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 | check_index (const len_t i, const len_t j) const |
void | printval (const REAL val, uint8_t ndigits) const |
void | printval (const int val, uint8_t ndigits) const |
Additional Inherited Members | |
![]() | |
len_t | m |
len_t | n |
REAL * | data |
bool | free_data |
Matrix class for data held on a single CPU.
REAL | should be 'float' or 'double'. |
fml::cpumat< REAL >::cpumat |
Construct matrix object with no internal allocated storage.
fml::cpumat< REAL >::cpumat | ( | len_t | nrows, |
len_t | ncols | ||
) |
Construct matrix object.
[in] | nrows,ncols | Number rows/columns of the matrix. |
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::cpumat< REAL >::cpumat | ( | REAL * | data_, |
len_t | nrows, | ||
len_t | ncols, | ||
bool | free_on_destruct = false |
||
) |
Construct matrix object with inherited data. Essentially the same as using the minimal constructor and immediately calling the inherit()
method.
[in] | data_ | Storage array. |
[in] | nrows,ncols | Number rows/columns of the array, i.e. the length of the array is nrows*ncols. |
[in] | free_on_destruct | Should the inherited array data_ be freed when the matrix object is destroyed? |
Exceptions
If the input values are invalid, a runtime_error
exception will be thrown.
void fml::cpumat< REAL >::antidiag | ( | cpuvec< REAL > & | v | ) |
Get the anti-diagonal entries, i.e. those on the bottom-left to top-right.
[out] | v | The anti-diagonal. Length should match the length of the diagonal of the input (minimum of the matrix dimensions). If not, the vector will automatically be resized. |
Memory Allocations
If the output dimension is inappropriately sized, it will automatically be re-allocated.
Exceptions
If a reallocation is triggered and fails, a bad_alloc
exception will be thrown.
void fml::cpumat< REAL >::diag | ( | cpuvec< REAL > & | v | ) |
Get the diagonal entries.
[out] | v | The diagonal. Length should match the length of the diagonal of the input (minimum of the matrix dimensions). If not, the vector will automatically be resized. |
Memory Allocations
If the output dimension is inappropriately sized, it will automatically be re-allocated.
Exceptions
If a reallocation is triggered and fails, a bad_alloc
exception will be thrown.
void fml::cpumat< REAL >::fill_diag | ( | const cpuvec< REAL > & | v | ) |
Set diagonal entries of the matrix to those in the vector.
If the vector is smaller than the matrix diagonal, the vector will recycle until the matrix diagonal is filled. If the vector is longer, then not all of it will be used.
[in] | v | Vector of values to set the matrix diagonal to. |
void fml::cpumat< T >::fill_linspace |
Set values to linearly spaced numbers.
[in] | start,stop | Beginning/ending numbers. If not supplied, the matrix will be filled with whole numbers from 1 to the total number of elements. |
void fml::cpumat< REAL >::fill_rnorm | ( | const uint32_t | seed, |
const REAL | mean = 0 , |
||
const REAL | sd = 1 |
||
) |
Set diagonal entries to 1 and non-diagonal entries to 0.
[in] | seed | Seed for the rng. |
[in] | mean,sd | Parameters for the generator. |
void fml::cpumat< REAL >::fill_runif | ( | const uint32_t | seed, |
const REAL | min = 0 , |
||
const REAL | max = 1 |
||
) |
Set diagonal entries to 1 and non-diagonal entries to 0.
[in] | seed | Seed for the rng. |
[in] | min,max | Parameters for the generator. |
void fml::cpumat< REAL >::fill_val | ( | const REAL | v | ) |
Set all values to input value.
[in] | v | Value to set all data values to. |
REAL fml::cpumat< REAL >::get | ( | const len_t | i | ) | const |
Get the specified value.
[in] | i | The index of the desired value, 0-indexed. The numbering considers the internal storage as a 1-dimensional array. |
Exceptions
If indices are out of bounds, the method will throw a runtime_error
exception.
REAL fml::cpumat< REAL >::get | ( | const len_t | i, |
const len_t | j | ||
) | const |
Get the specified value.
[in] | i,j | The indices of the desired value, 0-indexed. |
Exceptions
If indices are out of bounds, the method will throw a runtime_error
exception.
void fml::cpumat< REAL >::get_col | ( | const len_t | j, |
cpuvec< REAL > & | v | ||
) | const |
Get the specified column.
[in] | j | The desired column, 0-indexed. |
[out] | v | The column values. |
Memory Allocations
If the output dimension is inappropriately sized, it will automatically be re-allocated.
Exceptions
If j
is an inappropriate value (i.e. does not refer to a matrix column), then the method will throw a logic_error
exception. If a reallocation is triggered and fails, a bad_alloc
exception will be thrown.
void fml::cpumat< REAL >::get_row | ( | const len_t | i, |
cpuvec< REAL > & | v | ||
) | const |
Get the specified row.
[in] | i | The desired row, 0-indexed. |
[out] | v | The row values. |
Memory Allocations
If the output dimension is inappropriately sized, it will automatically be re-allocated.
Exceptions
If i
is an inappropriate value (i.e. does not refer to a matrix row), then the method will throw a logic_error
exception. If a reallocation is triggered and fails, a bad_alloc
exception will be thrown.
void fml::cpumat< REAL >::inherit | ( | REAL * | data, |
len_t | nrows, | ||
len_t | ncols, | ||
bool | free_on_destruct = false |
||
) |
Set the internal object storage to the specified array.
[in] | data | Value storage. |
[in] | nrows,ncols | Number rows/columns of the matrix. The product of these should be 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::cpumat< REAL >::operator!= | ( | const cpumat< REAL > & | x | ) | const |
See if the two objects are not the same. Uses same internal logic as the ==
method.
[in] | Comparison | object. |
fml::cpumat< REAL > & fml::cpumat< REAL >::operator= | ( | fml::cpumat< REAL > & | 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::cpumat< REAL >::operator== | ( | const cpumat< REAL > & | 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::cpumat< REAL >::print | ( | uint8_t | ndigits = 4 , |
bool | add_final_blank = true |
||
) | const |
Print all values in the object.
[in] | ndigits | Number of decimal digits to print. |
[in] | add_final_blank | Should a final blank line be printed? |
void fml::cpumat< REAL >::resize | ( | len_t | nrows, |
len_t | ncols | ||
) |
Resize the internal object storage.
[in] | nrows,ncols | Number rows/columns 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::cpumat< REAL >::scale | ( | const REAL | s | ) |
Multiply all values by the input value.
[in] | s | Scaling value. |
void fml::cpumat< REAL >::set | ( | const len_t | i, |
const len_t | j, | ||
const REAL | v | ||
) |
Set the storage at the specified index with the provided value.
[in] | i,j | The indices 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.
void fml::cpumat< REAL >::set | ( | const len_t | i, |
const REAL | v | ||
) |
Set the storage at the specified index with the provided value.
[in] | i | The index of the desired value, 0-indexed. The numbering considers the internal storage as a 1-dimensional array. |
[in] | v | Setter value. |
Exceptions
If indices are out of bounds, the method will throw a runtime_error
exception.
void fml::cpumat< REAL >::set_col | ( | const len_t | j, |
const cpuvec< REAL > & | v | ||
) |
Set the specified column.
[in] | j | The desired column, 0-indexed. |
[in] | v | The column values. |
Exceptions
If i
is an inappropriate value (i.e. does not refer to a matrix row), then the method will throw a logic_error
exception. If the vector is inappropriately sized, a runtime_error
exception will be thrown.
void fml::cpumat< REAL >::set_row | ( | const len_t | i, |
const cpuvec< REAL > & | v | ||
) |
Set the specified row.
[in] | i | The desired row, 0-indexed. |
[in] | v | The row values. |
Exceptions
If i
is an inappropriate value (i.e. does not refer to a matrix row), then the method will throw a logic_error
exception. If the vector is inappropriately sized, a runtime_error
exception will be thrown.