26 #ifndef COMPLEXMATRIX_H_ 27 #define COMPLEXMATRIX_H_ 32 #include <boost/serialization/utility.hpp> 33 #include <boost/serialization/split_member.hpp> 80 template<
class Archive>
81 void save(Archive & ar,
const unsigned int version)
const 92 for (
NeuronID i = 0 ; i < m_rows+1 ; ++i ) {
97 for (
AurynLong i = 0 ; i < n_nonzero ; ++i) {
101 for (
StateID z = 0; z < n_z_values ; ++z ) {
105 template<
class Archive>
106 void load(Archive & ar,
const unsigned int version)
120 if ( n_z_values != cur_num_syn_states ) {
128 for (
NeuronID i = 0 ; i < m_rows+1 ; ++i ) {
134 for (
AurynLong i = 0 ; i < load_n_nonzero ; ++i) {
138 for (
StateID z = 0; z < n_z_values ; ++z ) {
142 n_nonzero = load_n_nonzero;
144 BOOST_SERIALIZATION_SPLIT_MEMBER()
225 void copy(ComplexMatrix * mat);
401 template <
typename T>
407 template <
typename T>
413 template <
typename T>
420 template <
typename T>
426 template <
typename T>
432 template <
typename T>
435 if (data_index<statesize)
440 template <
typename T>
446 template <
typename T>
449 if (data_index<statesize)
453 template <
typename T>
459 template <
typename T>
469 template <
typename T>
476 template <
typename T>
480 logger->
error(
"Trying to access a complex state larger than number of states in the tensor");
486 template <
typename T>
503 template <
typename T>
512 data_index_error_value = std::numeric_limits<AurynTime>::max();
521 template <
typename T>
527 if ( old_statesize == new_statesize )
return;
533 const AurynLong copysize = std::min(old_statesize,new_statesize);
537 ptrdiff_t offset = new_colinds-
colinds;
538 for (
NeuronID i = 0 ; i < m_rows+1 ; ++i ) {
544 colinds = new_colinds;
551 statesize = new_statesize;
554 template <
typename T>
558 init(m_rows, n_cols, size, n_z_values );
561 template <
typename T>
568 template <
typename T>
574 template <
typename T>
581 template <
typename T>
584 init(rows, cols, statesize, n_values);
587 template <
typename T>
599 template <
typename T>
620 template <
typename T>
626 template <
typename T>
630 while ( i > current_row )
638 if (i >= current_row && j >= current_col) {
643 rowptrs[m_rows] = rowptrs[i+1];
650 template <
typename T>
656 template <
typename T>
663 template <
typename T>
666 return statesize*n_z_values;
669 template <
typename T>
675 template <
typename T>
678 for (
NeuronID i = current_row ; i < m_rows-1 ; ++i )
685 template <
typename T>
691 template <
typename T>
700 template <
typename T>
708 template <
typename T>
714 template <
typename T>
720 template <
typename T>
726 template <
typename T>
732 template <
typename T>
738 template <
typename T>
745 template <
typename T>
752 template <
typename T>
756 std::cout <<
"cm: starting bisect " << i <<
":" << j << std::endl;
760 if ( !(i < m_rows && j < n_cols) )
return data_index_error_value;
767 return data_index_error_value;
771 if ( *c < j ) lo = c+1;
774 std::cout <<
"cm: " << i <<
":" << j <<
" " << *lo <<
":" << *hi << std::endl;
780 std::cout <<
"cm: " <<
"found element at data array position " 787 std::cout <<
"cm: " <<
"element not found" << std::endl;
790 return data_index_error_value;
795 template <
typename T>
801 template <
typename T>
807 template <
typename T>
813 template <
typename T>
817 if ( data_index != data_index_error_value )
823 template <
typename T>
827 if ( data_index != data_index_error_value )
833 template <
typename T>
840 template <
typename T>
846 template <
typename T>
852 template <
typename T>
858 template <
typename T>
870 template <
typename T>
876 for (
NeuronID * c = rowbegin ; c <= rowend ; ++c)
882 template <
typename T>
888 template <
typename T>
894 for (
NeuronID * c = rowbegin ; c <= rowend ; ++c)
900 template <
typename T>
906 template <
typename T>
909 for (
AurynLong i = 0 ; i < n_nonzero ; ++i ) {
914 template <
typename T>
918 for (
AurynLong i = 0 ; i < n_nonzero ; ++i ) {
925 template <
typename T>
928 for (
AurynLong i = 0 ; i < n_nonzero ; ++i ) {
933 template <
typename T>
939 template <
typename T>
945 template <
typename T>
951 template <
typename T>
957 template <
typename T>
964 template <
typename T>
970 template <
typename T>
976 template <
typename T>
983 template <
typename T>
989 template <
typename T>
995 template <
typename T>
1002 template <
typename T>
1005 std::cout <<
get_nonzero() <<
" elements in sparse matrix:" << std::endl;
1006 for (
NeuronID i = 0 ; i < m_rows ; ++i) {
1014 template <
typename T>
1024 template <
typename T>
1034 template <
typename T>
1042 template <
typename T>
1050 template <
typename T>
1058 template <
typename T>
1066 template <
typename T>
1072 template <
typename T>
1080 template <
typename T>
1088 template <
typename T>
1092 if ( x[i] < a ) x[i] = a;
1093 else if ( x[i] > b ) x[i] = b;
1097 template <
typename T>
1103 template <
typename T>
1109 template <
typename T>
1115 template <
typename T>
1121 template <
typename T>
AurynVector< T, AurynLong > * get_state_vector(StateID z=0)
Sames as get_synaptic_state_vector(StateID z)
Definition: ComplexMatrix.h:733
Default Auryn vector template.
Definition: auryn_definitions.h:327
void print()
stdout dump of all elements – for testing only.
Definition: ComplexMatrix.h:1003
NeuronID get_n_cols()
Definition: ComplexMatrix.h:996
AurynLong ind_ptr_to_didx(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:796
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
T get_element(const AurynLong data_index, const StateID z)
Returns a particular element given its position in the data array.
Definition: ComplexMatrix.h:427
T get(const NeuronID i, const NeuronID j, const NeuronID z=0)
Value of synaptic state variable i,j,z returns zero if the element is zero or does not exist...
Definition: ComplexMatrix.h:824
AurynLong get_row_begin_index(NeuronID i)
Definition: ComplexMatrix.h:946
void copy(ComplexMatrix *mat)
Copies complex matrix mat.
Definition: ComplexMatrix.h:600
AurynLong get_memsize()
Returns statesize multiplied by number of states.
Definition: ComplexMatrix.h:664
void set_num_synapse_states(const StateID zsize)
Sets number of synaptic states (z-value)
Definition: ComplexMatrix.h:709
StateID get_num_synapse_states()
Synonymous to get_num_synaptic_states.
Definition: ComplexMatrix.h:727
AurynDouble get_fill_level()
Returns the fill level of the matrix element buffer.
Definition: ComplexMatrix.h:984
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
void prune()
Prunes the reserved memory such that datasize=get_nonzero() Note that this is an expensive operation ...
Definition: ComplexMatrix.h:562
void set_all(const T v)
Set all elements to value v.
Definition: AurynVector.h:232
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
void state_sub(T *x, T *y)
Computes x-y and stores result in y.
Definition: ComplexMatrix.h:1067
void set_all(const T value, const StateID z=0)
Sets all non-zero elements to value.
Definition: ComplexMatrix.h:901
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
T get_value(const AurynLong data_index)
Returns the data value to an item that is i-th in the colindex array.
Definition: ComplexMatrix.h:841
AurynVector< T, AurynLong > * get_synaptic_state_vector(StateID z=0)
Returns pointer to statevector which is an AurynVector of specified synaptic state.
Definition: ComplexMatrix.h:477
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
void state_set_all(T *x, const T value)
Sets all values in state x to value.
Definition: ComplexMatrix.h:1025
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
void state_clip(T *x, const T a, const T b)
Clips state values to interval [a,b].
Definition: ComplexMatrix.h:1089
bool set(const NeuronID i, const NeuronID j, T value)
Definition: ComplexMatrix.h:859
int n
Definition: mkpat.py:5
void scale_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:454
double mean()
Return mean value of elements for the first complex state (z=0).
Definition: ComplexMatrix.h:1015
NeuronID get_m_rows()
Definition: ComplexMatrix.h:990
Definition: auryn_definitions.h:232
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
AurynLong get_row_end_index(NeuronID i)
Definition: ComplexMatrix.h:958
Template for a sparse matrix with row major ordering and fast access of rows and capability to store ...
Definition: ComplexMatrix.h:75
void prepare_state_vectors()
Matches size of statevectors to number of synaptic states.
Definition: ComplexMatrix.h:487
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
void state_scale(const T a, T *x)
Scale state x by a.
Definition: ComplexMatrix.h:1073
T get_data(AurynLong i, StateID z=0)
Definition: ComplexMatrix.h:408
void fill_na()
Pads non-existing elements for the remaining elements to a matrix.
Definition: ComplexMatrix.h:676
virtual ~ComplexMatrix()
Default destructor.
Definition: ComplexMatrix.h:621
Definition: ABSConnection.h:38
StateID get_num_z_values()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:721
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void state_mul(T *x, T *y)
Multiplies x and y and stores result in y.
Definition: ComplexMatrix.h:1043
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
void scale_row(const NeuronID i, const T value)
Scales all non-zero elements in row i to value.
Definition: ComplexMatrix.h:871
void resize_buffers(AurynLong size)
Resize buffer.
Definition: ComplexMatrix.h:522
void clear()
Clears matrix.
Definition: ComplexMatrix.h:460
T * get_state_end(const StateID z=0)
Gets pointer for the element behind the last of a given synaptic state vector.
Definition: ComplexMatrix.h:746
void fill_zeros()
Same as fill_na but deprecated because of bad name.
Definition: ComplexMatrix.h:686
T * get_state_begin(const StateID z=0)
Gets pointer for the first element of a given synaptic state vector.
Definition: ComplexMatrix.h:739
void scale_all(const T value)
Scales all non-zero elements.
Definition: ComplexMatrix.h:883
void set_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:441
bool exists(const NeuronID i, const NeuronID j, const StateID z=0)
Returns true if the matrix element exists.
Definition: ComplexMatrix.h:692
void set_col(const NeuronID j, const T value)
Sets all non-zero elements in col j to value. Due to ordering this is slow and the use of this functi...
Definition: ComplexMatrix.h:926
void set_element(AurynLong data_index, T value, StateID z=0)
Definition: ComplexMatrix.h:433
void resize_buffer_and_clear(AurynLong size)
Resizes buffer and clears the matrix. This saves to copy all the data.
Definition: ComplexMatrix.h:555
void free()
Definition: ComplexMatrix.h:588
Definition: auryn_definitions.h:240
void push_back(const NeuronID i, const NeuronID j, const T value)
Definition: ComplexMatrix.h:627
NeuronID get_data_offset(NeuronID *r)
Definition: ComplexMatrix.h:1122
NeuronID ** get_rowptrs()
Definition: ComplexMatrix.h:965
AurynLong get_data_index(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:802
friend class boost::serialization::access
Definition: ComplexMatrix.h:79
AurynVector< T, AurynLong > * alloc_synaptic_state_vector()
Returns a synaptic state vector.
Definition: ComplexMatrix.h:470
T * get_value_ptr(const NeuronID i)
Returns pointer to the the data value to an item that is i-th in the colindex array.
Definition: ComplexMatrix.h:1110
void set_row(const NeuronID i, const T value)
Sets all non-zero elements in row i to value.
Definition: ComplexMatrix.h:889
void error(std::string text)
Definition: Logger.cpp:141
void scale_col(const NeuronID j, const T value)
Scales all non-zero elements in col j to value. Due to ordering this is slow and the use of this func...
Definition: ComplexMatrix.h:907
void state_add_const(const T a, T *x)
Adds constant a to all values in x.
Definition: ComplexMatrix.h:1081
void add_value(const AurynLong data_index, T value)
Definition: ComplexMatrix.h:847
void init(NeuronID m, NeuronID n, AurynLong size, NeuronID z)
Default initializiation called by the constructor.
Definition: ComplexMatrix.h:504
void state_add(T *x, T *y)
Adds x and y and stores result in y.
Definition: ComplexMatrix.h:1051
Definition: auryn_definitions.h:224
double sum_col(const NeuronID j)
Definition: ComplexMatrix.h:915
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
Definition: auryn_definitions.h:248
T * state_get_data_ptr(T *x, NeuronID i)
Get data pointer for that state.
Definition: ComplexMatrix.h:1098
unsigned int StateID
StateID is an unsigned integeger type used to index synaptic states in Auryn.
Definition: auryn_definitions.h:153
T * get_data_end(const StateID z=0)
Returns pointer to data value corresponding to the element behind the last nonzero element...
Definition: ComplexMatrix.h:977
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
T * get_data_ptr(const AurynLong data_index, const StateID z=0)
Gets the matching data ptr for a given index i and state z.
Definition: ComplexMatrix.h:402
void state_saxpy(const T a, T *x, T *y)
Computes a*x + y and stores result in y.
Definition: ComplexMatrix.h:1035
NeuronID get_colind(const AurynLong data_index)
Definition: ComplexMatrix.h:853
void scale_element(AurynLong data_index, T value, StateID z=0)
Definition: ComplexMatrix.h:447
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
AurynLong data_ptr_to_didx(const T *ptr)
Returns data index to a particular element specifed by a data pointer.
Definition: ComplexMatrix.h:808
ComplexMatrix()
Empty constructor.
Definition: ComplexMatrix.h:569
void set_num_synaptic_states(const StateID zsize)
Sets number of synaptic states (z-value)
Definition: ComplexMatrix.h:701
void scale(const T a)
Scales all vector elements by a.
Definition: AurynVector.h:246
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162