Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
auryn::ComplexMatrix< T > Class Template Reference

Template for a sparse matrix with row major ordering and fast access of rows and capability to store float values per matrix entry. More...

#include <ComplexMatrix.h>

Collaboration diagram for auryn::ComplexMatrix< T >:
Collaboration graph
[legend]

Public Member Functions

 ComplexMatrix ()
 Empty constructor. More...
 
 ComplexMatrix (ComplexMatrix *mat)
 Copy constructor. More...
 
 ComplexMatrix (NeuronID rows, NeuronID cols, AurynLong size=256, StateID n_values=1)
 Default constructor. More...
 
virtual ~ComplexMatrix ()
 Default destructor. More...
 
void clear ()
 Clears matrix. More...
 
AurynVector< T, AurynLong > * get_synaptic_state_vector (StateID z=0)
 Returns pointer to statevector which is an AurynVector of specified synaptic state. More...
 
AurynVector< T, AurynLong > * get_state_vector (StateID z=0)
 Sames as get_synaptic_state_vector(StateID z) More...
 
void resize_buffers (AurynLong size)
 Resize buffer. More...
 
void resize_buffer_and_clear (AurynLong size)
 Resizes buffer and clears the matrix. This saves to copy all the data. More...
 
void prune ()
 Prunes the reserved memory such that datasize=get_nonzero() Note that this is an expensive operation because it uses resize_buffers(size) and it should be used sparsely. More...
 
void push_back (const NeuronID i, const NeuronID j, const T value)
 
void copy (ComplexMatrix *mat)
 Copies complex matrix mat. More...
 
void set_element (AurynLong data_index, T value, StateID z=0)
 
void set_data (AurynLong i, T value, StateID z=0)
 
void scale_element (AurynLong data_index, T value, StateID z=0)
 
void scale_data (AurynLong i, T value, StateID z=0)
 
get_data (AurynLong i, StateID z=0)
 
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. More...
 
T * get_data_ptr (const NeuronID *ind_ptr, const StateID z=0)
 Gets the matching data ptr for a given index pointer and state z. More...
 
get_data (const NeuronID *ind_ptr, StateID z=0)
 Gets the matching data value for a given index pointer and state z. More...
 
void fill_na ()
 Pads non-existing elements for the remaining elements to a matrix. More...
 
void fill_zeros ()
 Same as fill_na but deprecated because of bad name. More...
 
AurynDouble get_fill_level ()
 Returns the fill level of the matrix element buffer. More...
 
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. More...
 
bool exists (const NeuronID i, const NeuronID j, const StateID z=0)
 Returns true if the matrix element exists. More...
 
T * get_ptr (const NeuronID i, const NeuronID j, const StateID z=0)
 Returns the pointer to a particular element. More...
 
T * get_ptr (const AurynLong data_index, const StateID z=0)
 Same as get_data_ptr. Returns the pointer to a particular element given its position in the data array. More...
 
get_element (const AurynLong data_index, const StateID z)
 Returns a particular element given its position in the data array. More...
 
AurynLong ind_ptr_to_didx (const NeuronID *ind_ptr)
 Returns data index to a particular element specifed by an index pointer. More...
 
AurynLong get_data_index (const NeuronID *ind_ptr)
 Returns data index to a particular element specifed by an index pointer. More...
 
AurynLong get_data_index (const NeuronID i, const NeuronID j)
 
AurynLong data_ptr_to_didx (const T *ptr)
 Returns data index to a particular element specifed by a data pointer. More...
 
AurynLong get_data_index (const T *ptr)
 Returns data index to a particular element specifed by a data pointer. More...
 
void set_num_synaptic_states (const StateID zsize)
 Sets number of synaptic states (z-value) More...
 
void set_num_synapse_states (const StateID zsize)
 Sets number of synaptic states (z-value) More...
 
StateID get_num_synaptic_states ()
 Returns number of synaptic states (z-value) More...
 
StateID get_num_z_values ()
 Returns number of synaptic states (z-value) More...
 
StateID get_num_synapse_states ()
 Synonymous to get_num_synaptic_states. More...
 
T * get_state_begin (const StateID z=0)
 Gets pointer for the first element of a given synaptic state vector. More...
 
T * get_state_end (const StateID z=0)
 Gets pointer for the element behind the last of a given synaptic state vector. More...
 
void state_set_all (T *x, const T value)
 Sets all values in state x to value. More...
 
void state_saxpy (const T a, T *x, T *y)
 Computes a*x + y and stores result in y. More...
 
void state_mul (T *x, T *y)
 Multiplies x and y and stores result in y. More...
 
void state_add (T *x, T *y)
 Adds x and y and stores result in y. More...
 
void state_sub (T *x, T *y)
 Computes x-y and stores result in y. More...
 
void state_sub (T *x, T *y, T *res)
 Computes x-y and stores result in res. More...
 
void state_scale (const T a, T *x)
 Scale state x by a. More...
 
void state_add_const (const T a, T *x)
 Adds constant a to all values in x. More...
 
void state_clip (T *x, const T a, const T b)
 Clips state values to interval [a,b]. More...
 
T * state_get_data_ptr (T *x, NeuronID i)
 Get data pointer for that state. More...
 
void add_value (const AurynLong data_index, T value)
 
NeuronID get_colind (const AurynLong data_index)
 
bool set (const NeuronID i, const NeuronID j, T value)
 
void set_all (const T value, const StateID z=0)
 Sets all non-zero elements to value. More...
 
void set_row (const NeuronID i, const T value)
 Sets all non-zero elements in row i to value. More...
 
void scale_row (const NeuronID i, const T value)
 Scales all non-zero elements in row i to value. More...
 
void scale_all (const T value)
 Scales all non-zero elements. More...
 
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 functions is discouraged. More...
 
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 functions is discouraged. More...
 
double sum_col (const NeuronID j)
 
AurynLong get_datasize ()
 Returns datasize: number of possible entries. More...
 
AurynLong get_statesize ()
 Same as datasize : number of possible entries. More...
 
AurynLong get_memsize ()
 Returns statesize multiplied by number of states. More...
 
AurynLong get_nonzero ()
 Returns number of non-zero elements. More...
 
void print ()
 stdout dump of all elements – for testing only. More...
 
double mean ()
 Return mean value of elements for the first complex state (z=0). More...
 
NeuronIDget_ind_begin ()
 
NeuronIDget_row_begin (NeuronID i)
 
AurynLong get_row_begin_index (NeuronID i)
 
NeuronIDget_row_end (NeuronID i)
 
AurynLong get_row_end_index (NeuronID i)
 
NeuronID get_m_rows ()
 
NeuronID get_n_cols ()
 
NeuronID ** get_rowptrs ()
 
T * get_data_begin (const StateID z=0)
 Returns pointer to data value corresponding to the first element. More...
 
T * get_data_end (const StateID z=0)
 Returns pointer to data value corresponding to the element behind the last nonzero element. More...
 
get_value (const AurynLong data_index)
 Returns the data value to an item that is i-th in the colindex array. More...
 
get_value (NeuronID *r)
 Returns the data value to an item that for pointer r pointing to the respective element in the index array. More...
 
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. More...
 
T * get_value_ptr (NeuronID *r)
 Returns the pointer to the data value to an item that for pointer r pointing to the respective element in the index array. More...
 
NeuronID get_data_offset (NeuronID *r)
 

Public Attributes

std::vector< AurynVector< T, AurynLong > *> statevectors
 Vector that holds pointers to the state vectors storing the synaptic states. More...
 

Protected Member Functions

AurynVector< T, AurynLong > * alloc_synaptic_state_vector ()
 Returns a synaptic state vector. More...
 
void prepare_state_vectors ()
 Matches size of statevectors to number of synaptic states. More...
 
void init (NeuronID m, NeuronID n, AurynLong size, NeuronID z)
 Default initializiation called by the constructor. More...
 
void free ()
 

Protected Attributes

NeuronID ** rowptrs
 Array that holds the begin addresses of column indices. More...
 
NeuronIDcolinds
 Array that holds the column indices of non-zero elements. More...
 

Friends

class boost::serialization::access
 

Detailed Description

template<typename T>
class auryn::ComplexMatrix< T >

Template for a sparse matrix with row major ordering and fast access of rows and capability to store float values per matrix entry.

This matrix class implements a sparse matrix that allows fast access of all elements of one row. It provides row interators to efficiently propagate spikes. Memory has to be reserved when the class is defined and elements can only be inserted row by row starting from "left to right". This scheme enables related data fields to reside in memory next to each other.

ComplexMatrix generalizes SimpleMatrix to a rank 3 tensor in which each synaptic connection can have more than one value (third tensor mode – corresponding to a synaptic state). This allows to efficiently implement state based complex synaptic models which have their own internal dynamics.

Instead of storing all synaptic data values in one long array the synaptic state values are stored in multiple state vectors which can be manipulated efficiently in a vector based manner.

For instance, suppose w holds your instance of ComplexMatris in which you have set_num_synapse_states(3) which makes it a connectivity matrix which reserves three state variables of type AurynWeight per synaptic connection. Now, decaying all elements of, say, state 3 by a factor "foo" is as simple as w->get_state_vector(2)->scale(foo). Adding two of the states for all synapses becomes w->get_state_vector(2)->add(w->get_state_vector(3)).

Because these expressions become quickly rather lenghty it is nice to declare shortcuts in your plastic Connection class such as: AurynSynStateVector * w_val = w->get_state_vector(0); AurynSynStateVector * tagging_val = w->get_state_vector(1); AurynSynStateVector * scaffold_val = w->get_state_vector(2);

You can now work with these as you are used with AurynVector or AurynStateVector instances w_val->saxpy(foo,tagging_val)

Constructor & Destructor Documentation

◆ ComplexMatrix() [1/3]

template<typename T >
auryn::ComplexMatrix< T >::ComplexMatrix ( )

Empty constructor.

570 {
571  init(1,1,2,1);
572 }
void init(NeuronID m, NeuronID n, AurynLong size, NeuronID z)
Default initializiation called by the constructor.
Definition: ComplexMatrix.h:504
Here is the call graph for this function:

◆ ComplexMatrix() [2/3]

template<typename T >
auryn::ComplexMatrix< T >::ComplexMatrix ( ComplexMatrix< T > *  mat)

Copy constructor.

576 {
577  init(mat->get_m_rows(), mat->get_n_cols(), mat->get_nonzero(), mat->get_num_z_values() );
578  copy(mat);
579 }
void copy(ComplexMatrix *mat)
Copies complex matrix mat.
Definition: ComplexMatrix.h:600
void init(NeuronID m, NeuronID n, AurynLong size, NeuronID z)
Default initializiation called by the constructor.
Definition: ComplexMatrix.h:504
Here is the call graph for this function:

◆ ComplexMatrix() [3/3]

template<typename T >
auryn::ComplexMatrix< T >::ComplexMatrix ( NeuronID  rows,
NeuronID  cols,
AurynLong  size = 256,
StateID  n_values = 1 
)

Default constructor.

583 {
584  init(rows, cols, statesize, n_values);
585 }
void init(NeuronID m, NeuronID n, AurynLong size, NeuronID z)
Default initializiation called by the constructor.
Definition: ComplexMatrix.h:504
Here is the call graph for this function:

◆ ~ComplexMatrix()

template<typename T >
auryn::ComplexMatrix< T >::~ComplexMatrix ( )
virtual

Default destructor.

622 {
623  free();
624 }
void free()
Definition: ComplexMatrix.h:588
Here is the call graph for this function:

Member Function Documentation

◆ add_value()

template<typename T >
void auryn::ComplexMatrix< T >::add_value ( const AurynLong  data_index,
value 
)
848 {
849  *get_ptr(data_index) += value;
850 }
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
Here is the call graph for this function:

◆ alloc_synaptic_state_vector()

template<typename T >
AurynVector< T, AurynLong > * auryn::ComplexMatrix< T >::alloc_synaptic_state_vector ( )
protected

Returns a synaptic state vector.

471 {
472  T * vec = new AurynVector<T,AurynLong>(get_statesize());
473  return vec;
474 }
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
Here is the call graph for this function:

◆ clear()

template<typename T >
void auryn::ComplexMatrix< T >::clear ( )

Clears matrix.

461 {
462  current_row = 0;
463  current_col = 0;
464  n_nonzero = 0;
465  rowptrs[0] = colinds;
466  rowptrs[1] = colinds;
467 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ copy()

template<typename T >
void auryn::ComplexMatrix< T >::copy ( ComplexMatrix< T > *  mat)

Copies complex matrix mat.

601 {
602  if ( get_m_rows() != mat->get_m_rows() || get_n_cols() != mat->get_n_cols() )
603  throw AurynMatrixDimensionalityException();
604 
605  clear();
606 
607  // copy sparse strcture and first state
608  for ( NeuronID i = 0 ; i < mat->get_m_rows() ; ++i ) {
609  for ( NeuronID * r = mat->get_row_begin(i) ; r != mat->get_row_end(i) ; ++r ) {
610  push_back(i,*r,mat->get_value(r));
611  }
612  }
613 
614  // copy the other states
615  for ( StateID z = 1 ; z < get_num_synaptic_states() ; ++z ) {
616  statevectors[z]->copy(mat->statevectors[z]);
617  }
618 }
r
Definition: mkpat.py:9
NeuronID get_n_cols()
Definition: ComplexMatrix.h:996
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
NeuronID get_m_rows()
Definition: ComplexMatrix.h:990
void clear()
Clears matrix.
Definition: ComplexMatrix.h:460
void push_back(const NeuronID i, const NeuronID j, const T value)
Definition: ComplexMatrix.h:627
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
unsigned int StateID
StateID is an unsigned integeger type used to index synaptic states in Auryn.
Definition: auryn_definitions.h:153
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ data_ptr_to_didx()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::data_ptr_to_didx ( const T *  ptr)

Returns data index to a particular element specifed by a data pointer.

809 {
810  return ptr - get_data_begin();
811 }
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
Here is the call graph for this function:

◆ exists()

template<typename T >
bool auryn::ComplexMatrix< T >::exists ( const NeuronID  i,
const NeuronID  j,
const StateID  z = 0 
)

Returns true if the matrix element exists.

693 {
694  if ( get_data_index(i,j) == data_index_error_value || z >= get_num_synaptic_states() )
695  return false;
696  else
697  return true;
698 }
AurynLong get_data_index(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:802
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
Here is the call graph for this function:

◆ fill_na()

template<typename T >
void auryn::ComplexMatrix< T >::fill_na ( )

Pads non-existing elements for the remaining elements to a matrix.

This function has to be called after filling the matrix with elements e.g. random sparse and before using it in a simulation. It is typically called by the finalize function in SparseConnection.

677 {
678  for ( NeuronID i = current_row ; i < m_rows-1 ; ++i )
679  {
680  rowptrs[i+2] = rowptrs[i+1]; // save value of last element
681  }
682  current_row = get_m_rows();
683 }
NeuronID get_m_rows()
Definition: ComplexMatrix.h:990
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162
Here is the call graph for this function:

◆ fill_zeros()

template<typename T >
void auryn::ComplexMatrix< T >::fill_zeros ( )

Same as fill_na but deprecated because of bad name.

Deprecated:
Due to bad name
687 {
688  fill_na();
689 }
void fill_na()
Pads non-existing elements for the remaining elements to a matrix.
Definition: ComplexMatrix.h:676
Here is the call graph for this function:

◆ free()

template<typename T >
void auryn::ComplexMatrix< T >::free ( )
protected
589 {
590  delete [] rowptrs;
591  delete [] colinds;
592  while ( statevectors.size() ) {
593  AurynVector<T,AurynLong> * vec = statevectors.back();
594  delete vec;
595  statevectors.pop_back();
596  }
597 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get()

template<typename T >
T auryn::ComplexMatrix< 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.

825 {
826  AurynLong data_index = get_data_index(i,j);
827  if ( data_index != data_index_error_value )
828  return *(statevectors[z]->data+get_data_index(i,j));
829  else
830  return 0;
831 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
AurynLong get_data_index(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:802
Here is the call graph for this function:

◆ get_colind()

template<typename T >
NeuronID auryn::ComplexMatrix< T >::get_colind ( const AurynLong  data_index)
854 {
855  return colinds[data_index];
856 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165

◆ get_data() [1/2]

template<typename T >
T auryn::ComplexMatrix< T >::get_data ( AurynLong  i,
StateID  z = 0 
)

Gets the matching data entry for a given index i and state z

409 {
410  return *get_data_ptr(i,z);
411 }
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
Here is the call graph for this function:

◆ get_data() [2/2]

template<typename T >
T auryn::ComplexMatrix< T >::get_data ( const NeuronID ind_ptr,
StateID  z = 0 
)

Gets the matching data value for a given index pointer and state z.

422 {
423  return *(get_data_ptr(ind_ptr,z));
424 }
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
Here is the call graph for this function:

◆ get_data_begin()

template<typename T >
T * auryn::ComplexMatrix< T >::get_data_begin ( const StateID  z = 0)

Returns pointer to data value corresponding to the first element.

972 {
973  return get_data_ptr((AurynLong)0,z);
974 }
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
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
Here is the call graph for this function:

◆ get_data_end()

template<typename T >
T * auryn::ComplexMatrix< T >::get_data_end ( const StateID  z = 0)

Returns pointer to data value corresponding to the element behind the last nonzero element.

978 {
979  return get_data_ptr(get_nonzero(),z);
980 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
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
Here is the call graph for this function:

◆ get_data_index() [1/3]

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_data_index ( const NeuronID ind_ptr)

Returns data index to a particular element specifed by an index pointer.

803 {
804  return ind_ptr_to_didx(ind_ptr);
805 }
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
Here is the call graph for this function:

◆ get_data_index() [2/3]

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_data_index ( const NeuronID  i,
const NeuronID  j 
)

Returns data index to a particular element specifed by i and j

754 {
755 #ifdef DEBUG
756  std::cout << "cm: starting bisect " << i << ":" << j << std::endl;
757 #endif // DEBUG
758 
759  // check bounds
760  if ( !(i < m_rows && j < n_cols) ) return data_index_error_value;
761 
762  // perform binary search
763  NeuronID * lo = rowptrs[i];
764  NeuronID * hi = rowptrs[i+1];
765 
766  if ( lo >= hi ) // no elements/targets in this row
767  return data_index_error_value;
768 
769  while ( lo < hi ) {
770  NeuronID * c = lo + (hi-lo)/2;
771  if ( *c < j ) lo = c+1;
772  else hi = c;
773 #ifdef DEBUG
774  std::cout << "cm: " << i << ":" << j << " " << *lo << ":" << *hi << std::endl;
775 #endif // DEBUG
776  }
777 
778  if ( *lo == j ) {
779 #ifdef DEBUG
780  std::cout << "cm: " << "found element at data array position "
781  << (lo-colinds) << std::endl;
782 #endif // DEBUG
783  return (lo-colinds);
784  }
785 
786 #ifdef DEBUG
787  std::cout << "cm: " << "element not found" << std::endl;
788 #endif // DEBUG
789 
790  return data_index_error_value;
791 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_data_index() [3/3]

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_data_index ( const T *  ptr)
inline

Returns data index to a particular element specifed by a data pointer.

302 { return data_ptr_to_didx(ptr); };
AurynLong data_ptr_to_didx(const T *ptr)
Returns data index to a particular element specifed by a data pointer.
Definition: ComplexMatrix.h:808
Here is the call graph for this function:

◆ get_data_offset()

template<typename T >
NeuronID auryn::ComplexMatrix< T >::get_data_offset ( NeuronID r)
1123 {
1124  return r-get_ind_begin();
1125 }
r
Definition: mkpat.py:9
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
Here is the call graph for this function:

◆ get_data_ptr() [1/2]

template<typename T >
T * auryn::ComplexMatrix< 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.

403 {
404  return statevectors[z]->data+data_index;
405 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179

◆ get_data_ptr() [2/2]

template<typename T >
T * auryn::ComplexMatrix< T >::get_data_ptr ( const NeuronID ind_ptr,
const StateID  z = 0 
)

Gets the matching data ptr for a given index pointer and state z.

415 {
416  size_t ptr_offset = ind_ptr-get_ind_begin();
417  return statevectors[z]->data+ptr_offset;
418 }
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
Here is the call graph for this function:

◆ get_datasize()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_datasize ( )

Returns datasize: number of possible entries.

652 {
653  return get_statesize();
654 }
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
Here is the call graph for this function:

◆ get_element()

template<typename T >
T auryn::ComplexMatrix< T >::get_element ( const AurynLong  data_index,
const StateID  z 
)

Returns a particular element given its position in the data array.

428 {
429  return *get_data_ptr(data_index);
430 }
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
Here is the call graph for this function:

◆ get_fill_level()

template<typename T >
AurynDouble auryn::ComplexMatrix< T >::get_fill_level ( )

Returns the fill level of the matrix element buffer.

A fill level of 1.0 corresponds to the sparse matrix element buffer being full.

985 {
986  return 1.*n_nonzero/get_datasize();
987 }
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
Here is the call graph for this function:

◆ get_ind_begin()

template<typename T >
NeuronID * auryn::ComplexMatrix< T >::get_ind_begin ( )
935 {
936  return rowptrs[0];
937 }
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_m_rows()

template<typename T >
NeuronID auryn::ComplexMatrix< T >::get_m_rows ( )
991 {
992  return m_rows;
993 }

◆ get_memsize()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_memsize ( )

Returns statesize multiplied by number of states.

665 {
666  return statesize*n_z_values;
667 }

◆ get_n_cols()

template<typename T >
NeuronID auryn::ComplexMatrix< T >::get_n_cols ( )
997 {
998  return n_cols;
999 }

◆ get_nonzero()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_nonzero ( )

Returns number of non-zero elements.

671 {
672  return n_nonzero;
673 }

◆ get_num_synapse_states()

template<typename T >
NeuronID auryn::ComplexMatrix< T >::get_num_synapse_states ( )

Synonymous to get_num_synaptic_states.

728 {
729  return get_num_synaptic_states();
730 }
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
Here is the call graph for this function:

◆ get_num_synaptic_states()

template<typename T >
StateID auryn::ComplexMatrix< T >::get_num_synaptic_states ( )

Returns number of synaptic states (z-value)

716 {
717  return n_z_values;
718 }

◆ get_num_z_values()

template<typename T >
NeuronID auryn::ComplexMatrix< T >::get_num_z_values ( )

Returns number of synaptic states (z-value)

722 {
723  return get_num_synaptic_states();
724 }
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
Here is the call graph for this function:

◆ get_ptr() [1/2]

template<typename T >
T * auryn::ComplexMatrix< T >::get_ptr ( const NeuronID  i,
const NeuronID  j,
const StateID  z = 0 
)

Returns the pointer to a particular element.

815 {
816  AurynLong data_index = get_data_index(i,j);
817  if ( data_index != data_index_error_value )
818  return statevectors[z]->data+data_index;
819  else
820  return NULL;
821 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
AurynLong get_data_index(const NeuronID *ind_ptr)
Returns data index to a particular element specifed by an index pointer.
Definition: ComplexMatrix.h:802
Here is the call graph for this function:

◆ get_ptr() [2/2]

template<typename T >
T * auryn::ComplexMatrix< T >::get_ptr ( const AurynLong  data_index,
const StateID  z = 0 
)

Same as get_data_ptr. Returns the pointer to a particular element given its position in the data array.

Todo:
TODO For two args this function is ambiguous with the above get_ptr def – need to find a better way for that
835 {
836  return get_data_ptr(data_index, z);
837 }
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
Here is the call graph for this function:

◆ get_row_begin()

template<typename T >
NeuronID * auryn::ComplexMatrix< T >::get_row_begin ( NeuronID  i)
941 {
942  return rowptrs[i];
943 }
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_row_begin_index()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_row_begin_index ( NeuronID  i)
947 {
948  return rowptrs[i]-rowptrs[0];
949 }
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_row_end()

template<typename T >
NeuronID * auryn::ComplexMatrix< T >::get_row_end ( NeuronID  i)
953 {
954  return rowptrs[i+1];
955 }
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_row_end_index()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_row_end_index ( NeuronID  i)
959 {
960  return rowptrs[i+1]-rowptrs[0];
961 }
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_rowptrs()

template<typename T >
NeuronID ** auryn::ComplexMatrix< T >::get_rowptrs ( )
966 {
967  return rowptrs;
968 }
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162

◆ get_state_begin()

template<typename T >
T * auryn::ComplexMatrix< T >::get_state_begin ( const StateID  z = 0)

Gets pointer for the first element of a given synaptic state vector.

740 {
741  return statevectors[z]->data;
742 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179

◆ get_state_end()

template<typename T >
T * auryn::ComplexMatrix< T >::get_state_end ( const StateID  z = 0)

Gets pointer for the element behind the last of a given synaptic state vector.

747 {
748  return get_state_begin(z)+get_datasize();
749 }
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
T * get_state_begin(const StateID z=0)
Gets pointer for the first element of a given synaptic state vector.
Definition: ComplexMatrix.h:739
Here is the call graph for this function:

◆ get_state_vector()

template<typename T >
AurynVector< T, AurynLong > * auryn::ComplexMatrix< T >::get_state_vector ( StateID  z = 0)

Sames as get_synaptic_state_vector(StateID z)

734 {
735  return get_synaptic_state_vector(z);
736 }
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
Here is the call graph for this function:

◆ get_statesize()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::get_statesize ( )

Same as datasize : number of possible entries.

658 {
659  return statesize;
660 }

◆ get_synaptic_state_vector()

template<typename T >
AurynVector< T, AurynLong > * auryn::ComplexMatrix< T >::get_synaptic_state_vector ( StateID  z = 0)

Returns pointer to statevector which is an AurynVector of specified synaptic state.

478 {
479  if ( z >= get_num_synaptic_states() ) {
480  logger->error("Trying to access a complex state larger than number of states in the tensor");
481  throw AurynMatrixDimensionalityException();
482  }
483  return statevectors[z];
484 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
void error(std::string text)
Definition: Logger.cpp:141
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
Here is the call graph for this function:

◆ get_value() [1/2]

template<typename T >
T auryn::ComplexMatrix< T >::get_value ( const AurynLong  data_index)

Returns the data value to an item that is i-th in the colindex array.

842 {
843  return *get_ptr(data_index);
844 }
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
Here is the call graph for this function:

◆ get_value() [2/2]

template<typename T >
T auryn::ComplexMatrix< T >::get_value ( NeuronID r)

Returns the data value to an item that for pointer r pointing to the respective element in the index array.

1105 {
1106  return get_data_begin()[r-get_ind_begin()];
1107 }
r
Definition: mkpat.py:9
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
Here is the call graph for this function:

◆ get_value_ptr() [1/2]

template<typename T >
T * auryn::ComplexMatrix< 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.

1111 {
1112  return &get_data_begin()[i];
1113 }
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
Here is the call graph for this function:

◆ get_value_ptr() [2/2]

template<typename T >
T * auryn::ComplexMatrix< T >::get_value_ptr ( NeuronID r)

Returns the pointer to the data value to an item that for pointer r pointing to the respective element in the index array.

1117 {
1118  return &get_data_begin()[r-get_ind_begin()];
1119 }
r
Definition: mkpat.py:9
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
Here is the call graph for this function:

◆ ind_ptr_to_didx()

template<typename T >
AurynLong auryn::ComplexMatrix< T >::ind_ptr_to_didx ( const NeuronID ind_ptr)

Returns data index to a particular element specifed by an index pointer.

797 {
798  return ind_ptr - get_ind_begin();
799 }
NeuronID * get_ind_begin()
Definition: ComplexMatrix.h:934
Here is the call graph for this function:

◆ init()

template<typename T >
void auryn::ComplexMatrix< T >::init ( NeuronID  m,
NeuronID  n,
AurynLong  size,
NeuronID  z 
)
protected

Default initializiation called by the constructor.

505 {
506  m_rows = m;
507  n_cols = n;
508 
509  statesize = size; // assumed maximum number of connections
510  n_z_values = z;
511 
512  data_index_error_value = std::numeric_limits<AurynTime>::max();
513 
514 
515  rowptrs = new NeuronID * [m_rows+1];
516  colinds = new NeuronID [get_datasize()];
518  clear();
519 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
int n
Definition: mkpat.py:5
void prepare_state_vectors()
Matches size of statevectors to number of synaptic states.
Definition: ComplexMatrix.h:487
void clear()
Clears matrix.
Definition: ComplexMatrix.h:460
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162
Here is the call graph for this function:

◆ mean()

template<typename T >
double auryn::ComplexMatrix< T >::mean ( )

Return mean value of elements for the first complex state (z=0).

Warning: Note that ComplexMatrix can only compute the mean of all the subset of elements stored on thank it runs on.

1016 {
1017  double sum = 0;
1018  for (NeuronID i = 0 ; i < get_nonzero() ; ++i) {
1019  sum += *get_ptr(i);
1020  }
1021  return sum/get_nonzero();
1022 }
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ prepare_state_vectors()

template<typename T >
void auryn::ComplexMatrix< T >::prepare_state_vectors ( )
protected

Matches size of statevectors to number of synaptic states.

488 {
489  // add synaptic state vectors until we have enough
490  while ( statevectors.size() < get_num_synaptic_states() ) {
491  AurynVector<T,AurynLong> * vec = new AurynVector<T,AurynLong>(get_statesize());
492  statevectors.push_back(vec);
493  }
494 
495  // remove state vectors from the end until we have the right amount
496  // if the above code ran this will not run
497  while ( statevectors.size() > get_num_synaptic_states() ) {
498  delete [] *(statevectors.end());
499  statevectors.pop_back();
500  }
501 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
Here is the call graph for this function:

◆ print()

template<typename T >
void auryn::ComplexMatrix< T >::print ( )

stdout dump of all elements – for testing only.

1004 {
1005  std::cout << get_nonzero() << " elements in sparse matrix:" << std::endl;
1006  for (NeuronID i = 0 ; i < m_rows ; ++i) {
1007  for (NeuronID * r = get_row_begin(i) ; r != get_row_end(i) ; ++r ) {
1008  std::cout << i << " " << *r << " " << *get_ptr(r-colinds) << "\n";
1009  // TODO not dumping the other states yet
1010  }
1011  }
1012 }
r
Definition: mkpat.py:9
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
NeuronID * get_row_end(NeuronID i)
Definition: ComplexMatrix.h:952
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
NeuronID * get_row_begin(NeuronID i)
Definition: ComplexMatrix.h:940
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function:

◆ prune()

template<typename T >
void auryn::ComplexMatrix< T >::prune ( )

Prunes the reserved memory such that datasize=get_nonzero() Note that this is an expensive operation because it uses resize_buffers(size) and it should be used sparsely.

563 {
564  if ( get_datasize() > get_nonzero() )
566 }
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
void resize_buffers(AurynLong size)
Resize buffer.
Definition: ComplexMatrix.h:522
Here is the call graph for this function:

◆ push_back()

template<typename T >
void auryn::ComplexMatrix< T >::push_back ( const NeuronID  i,
const NeuronID  j,
const T  value 
)

Add non-zero element in row/col order.

Parameters
irow index where to insert element
jcol index where to insert element
valueto insert
Exceptions
AurynMatrixBufferException
628 {
629  if ( i >= m_rows || j >= n_cols ) throw AurynMatrixDimensionalityException();
630  while ( i > current_row )
631  {
632  rowptrs[current_row+2] = rowptrs[current_row+1]; // save value of last element
633  current_col = 0;
634  current_row++;
635  }
636  current_col = j;
637  T * data_z0 = get_synaptic_state_vector(0)->data;
638  if (i >= current_row && j >= current_col) {
639  if ( n_nonzero >= get_datasize() ) throw AurynMatrixBufferException();
640  *(rowptrs[i+1]) = j; // write last j to end of index array
641  data_z0[rowptrs[i+1]-colinds] = value; // write value to end of data array
642  ++rowptrs[i+1]; //increment end by one
643  rowptrs[m_rows] = rowptrs[i+1]; // last (m_row+1) marks end of last row
644  n_nonzero++;
645  } else {
646  throw AurynMatrixPushBackException();
647  }
648 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
T * data
Pointer to the array housing the data.
Definition: AurynVector.h:154
AurynLong get_datasize()
Returns datasize: number of possible entries.
Definition: ComplexMatrix.h:651
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
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162
Here is the call graph for this function:

◆ resize_buffer_and_clear()

template<typename T >
void auryn::ComplexMatrix< T >::resize_buffer_and_clear ( AurynLong  size)

Resizes buffer and clears the matrix. This saves to copy all the data.

556 {
557  free();
558  init(m_rows, n_cols, size, n_z_values );
559 }
void free()
Definition: ComplexMatrix.h:588
void init(NeuronID m, NeuronID n, AurynLong size, NeuronID z)
Default initializiation called by the constructor.
Definition: ComplexMatrix.h:504
Here is the call graph for this function:

◆ resize_buffers()

template<typename T >
void auryn::ComplexMatrix< T >::resize_buffers ( AurynLong  size)

Resize buffer.

Allocates a new buffer of size and copies the old buffers before freeing the memory

523 {
524  const AurynLong old_statesize = get_statesize();
525  const AurynLong new_statesize = std::min(new_size,(AurynLong)m_rows*n_cols);
526 
527  if ( old_statesize == new_statesize ) return; // nothing to be done
528 
529  // allocate new mem
530  NeuronID * new_colinds = new NeuronID [new_statesize];
531 
532  // copy column indices
533  const AurynLong copysize = std::min(old_statesize,new_statesize);
534  std::copy(colinds, colinds+copysize, new_colinds);
535 
536  // update rowpointers
537  ptrdiff_t offset = new_colinds-colinds;
538  for ( NeuronID i = 0 ; i < m_rows+1 ; ++i ) {
539  rowptrs[i] += offset;
540  }
541 
542  // free old memory
543  delete [] colinds;
544  colinds = new_colinds;
545 
546  // resize state vectors individually
547  for ( StateID i = 0 ; i < get_num_synaptic_states() ; ++i ) {
548  statevectors[i]->resize(new_statesize);
549  }
550 
551  statesize = new_statesize;
552 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
StateID get_num_synaptic_states()
Returns number of synaptic states (z-value)
Definition: ComplexMatrix.h:715
unsigned int StateID
StateID is an unsigned integeger type used to index synaptic states in Auryn.
Definition: auryn_definitions.h:153
AurynLong get_statesize()
Same as datasize : number of possible entries.
Definition: ComplexMatrix.h:657
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162
Here is the call graph for this function:

◆ scale_all()

template<typename T >
void auryn::ComplexMatrix< T >::scale_all ( const T  value)

Scales all non-zero elements.

884 {
886 }
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
void scale(const T a)
Scales all vector elements by a.
Definition: AurynVector.h:246
Here is the call graph for this function:

◆ scale_col()

template<typename T >
void auryn::ComplexMatrix< T >::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 functions is discouraged.

908 {
909  for ( AurynLong i = 0 ; i < n_nonzero ; ++i ) {
910  if ( colinds[i] == j ) scale_data(i,value);
911  }
912 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
void scale_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:454
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ scale_data()

template<typename T >
void auryn::ComplexMatrix< T >::scale_data ( AurynLong  i,
value,
StateID  z = 0 
)
455 {
456  scale_element(i, value, z);
457 }
void scale_element(AurynLong data_index, T value, StateID z=0)
Definition: ComplexMatrix.h:447
Here is the call graph for this function:

◆ scale_element()

template<typename T >
void auryn::ComplexMatrix< T >::scale_element ( AurynLong  data_index,
value,
StateID  z = 0 
)
448 {
449  if (data_index<statesize)
450  statevectors[z]->data[data_index] *= value;
451 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179

◆ scale_row()

template<typename T >
void auryn::ComplexMatrix< T >::scale_row ( const NeuronID  i,
const T  value 
)

Scales all non-zero elements in row i to value.

872 {
873  NeuronID * rowbegin = rowptrs[i];
874  NeuronID * rowend = rowptrs[i+1]--;
875 
876  for (NeuronID * c = rowbegin ; c <= rowend ; ++c)
877  {
878  *get_ptr(c-colinds) *= value;
879  }
880 }
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
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162
Here is the call graph for this function:

◆ set()

template<typename T >
bool auryn::ComplexMatrix< T >::set ( const NeuronID  i,
const NeuronID  j,
value 
)
860 {
861  T * ptr = get_ptr(i,j);
862  if ( ptr != NULL) {
863  *ptr = value;
864  return true;
865  }
866  else
867  return false;
868 }
T * get_ptr(const NeuronID i, const NeuronID j, const StateID z=0)
Returns the pointer to a particular element.
Definition: ComplexMatrix.h:814
Here is the call graph for this function:

◆ set_all()

template<typename T >
void auryn::ComplexMatrix< T >::set_all ( const T  value,
const StateID  z = 0 
)

Sets all non-zero elements to value.

902 {
903  get_state_vector(z)->set_all(value);
904 }
AurynVector< T, AurynLong > * get_state_vector(StateID z=0)
Sames as get_synaptic_state_vector(StateID z)
Definition: ComplexMatrix.h:733
void set_all(const T v)
Set all elements to value v.
Definition: AurynVector.h:232
Here is the call graph for this function:

◆ set_col()

template<typename T >
void auryn::ComplexMatrix< T >::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 functions is discouraged.

927 {
928  for ( AurynLong i = 0 ; i < n_nonzero ; ++i ) {
929  if ( colinds[i] == j ) set_data(i,value);
930  }
931 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void set_data(AurynLong i, T value, StateID z=0)
Definition: ComplexMatrix.h:441
Here is the call graph for this function:

◆ set_data()

template<typename T >
void auryn::ComplexMatrix< T >::set_data ( AurynLong  i,
value,
StateID  z = 0 
)
442 {
443  set_element(i,value,z);
444 }
void set_element(AurynLong data_index, T value, StateID z=0)
Definition: ComplexMatrix.h:433
Here is the call graph for this function:

◆ set_element()

template<typename T >
void auryn::ComplexMatrix< T >::set_element ( AurynLong  data_index,
value,
StateID  z = 0 
)
434 {
435  if (data_index<statesize)
436  statevectors[z]->data[data_index] = value;
437 }
std::vector< AurynVector< T, AurynLong > *> statevectors
Vector that holds pointers to the state vectors storing the synaptic states.
Definition: ComplexMatrix.h:179

◆ set_num_synapse_states()

template<typename T >
void auryn::ComplexMatrix< T >::set_num_synapse_states ( const StateID  zsize)

Sets number of synaptic states (z-value)

710 {
712 }
void set_num_synaptic_states(const StateID zsize)
Sets number of synaptic states (z-value)
Definition: ComplexMatrix.h:701
Here is the call graph for this function:

◆ set_num_synaptic_states()

template<typename T >
void auryn::ComplexMatrix< T >::set_num_synaptic_states ( const StateID  zsize)

Sets number of synaptic states (z-value)

702 {
703  n_z_values = zsize;
705  resize_buffers(statesize);
706 }
void prepare_state_vectors()
Matches size of statevectors to number of synaptic states.
Definition: ComplexMatrix.h:487
void resize_buffers(AurynLong size)
Resize buffer.
Definition: ComplexMatrix.h:522
Here is the call graph for this function:

◆ set_row()

template<typename T >
void auryn::ComplexMatrix< T >::set_row ( const NeuronID  i,
const T  value 
)

Sets all non-zero elements in row i to value.

890 {
891  NeuronID * rowbegin = rowptrs[i];
892  NeuronID * rowend = rowptrs[i+1]--;
893 
894  for (NeuronID * c = rowbegin ; c <= rowend ; ++c)
895  {
896  *get_ptr(c-colinds) = value;
897  }
898 }
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
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
NeuronID ** rowptrs
Array that holds the begin addresses of column indices.
Definition: ComplexMatrix.h:162
Here is the call graph for this function:

◆ state_add()

template<typename T >
void auryn::ComplexMatrix< T >::state_add ( T *  x,
T *  y 
)

Adds x and y and stores result in y.

1052 {
1053  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1054  y[i] = x[i]+y[i];
1055  }
1056 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ state_add_const()

template<typename T >
void auryn::ComplexMatrix< T >::state_add_const ( const T  a,
T *  x 
)

Adds constant a to all values in x.

1082 {
1083  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1084  y[i] = a+y[i];
1085  }
1086 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ state_clip()

template<typename T >
void auryn::ComplexMatrix< T >::state_clip ( T *  x,
const T  a,
const T  b 
)

Clips state values to interval [a,b].

1090 {
1091  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1092  if ( x[i] < a ) x[i] = a;
1093  else if ( x[i] > b ) x[i] = b;
1094  }
1095 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ state_get_data_ptr()

template<typename T >
T * auryn::ComplexMatrix< T >::state_get_data_ptr ( T *  x,
NeuronID  i 
)

Get data pointer for that state.

1099 {
1100  return x+i;
1101 }

◆ state_mul()

template<typename T >
void auryn::ComplexMatrix< T >::state_mul ( T *  x,
T *  y 
)

Multiplies x and y and stores result in y.

1044 {
1045  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1046  y[i] = x[i]*y[i];
1047  }
1048 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ state_saxpy()

template<typename T >
void auryn::ComplexMatrix< T >::state_saxpy ( const T  a,
T *  x,
T *  y 
)

Computes a*x + y and stores result in y.

1036 {
1037  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1038  y[i] = a*x[i]+y[i];
1039  }
1040 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ state_scale()

template<typename T >
void auryn::ComplexMatrix< T >::state_scale ( const T  a,
T *  x 
)

Scale state x by a.

1074 {
1075  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1076  y[i] = a*y[i];
1077  }
1078 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ state_set_all()

template<typename T >
void auryn::ComplexMatrix< T >::state_set_all ( T *  x,
const T  value 
)

Sets all values in state x to value.

1026 {
1027  for (T * iter=x;
1028  iter!=x+get_nonzero();
1029  ++iter ) {
1030  *iter = value;
1031  }
1032 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
Here is the call graph for this function:

◆ state_sub() [1/2]

template<typename T >
void auryn::ComplexMatrix< T >::state_sub ( T *  x,
T *  y 
)

Computes x-y and stores result in y.

1068 {
1069  state_sub(x,y,y);
1070 }
void state_sub(T *x, T *y)
Computes x-y and stores result in y.
Definition: ComplexMatrix.h:1067

◆ state_sub() [2/2]

template<typename T >
void auryn::ComplexMatrix< T >::state_sub ( T *  x,
T *  y,
T *  res 
)

Computes x-y and stores result in res.

1060 {
1061  for (AurynLong i = 0 ; i < get_nonzero() ; ++i ) {
1062  res[i] = x[i]-y[i];
1063  }
1064 }
AurynLong get_nonzero()
Returns number of non-zero elements.
Definition: ComplexMatrix.h:670
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
Here is the call graph for this function:

◆ sum_col()

template<typename T >
double auryn::ComplexMatrix< T >::sum_col ( const NeuronID  j)
916 {
917  double sum = 0;
918  for ( AurynLong i = 0 ; i < n_nonzero ; ++i ) {
919  if ( colinds[i] == j )
920  sum += *(get_data_begin()+i);
921  }
922  return sum;
923 }
NeuronID * colinds
Array that holds the column indices of non-zero elements.
Definition: ComplexMatrix.h:165
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
T * get_data_begin(const StateID z=0)
Returns pointer to data value corresponding to the first element.
Definition: ComplexMatrix.h:971
Here is the call graph for this function:

Friends And Related Function Documentation

◆ boost::serialization::access

template<typename T >
friend class boost::serialization::access
friend

Member Data Documentation

◆ colinds

template<typename T >
NeuronID* auryn::ComplexMatrix< T >::colinds
protected

Array that holds the column indices of non-zero elements.

◆ rowptrs

template<typename T >
NeuronID** auryn::ComplexMatrix< T >::rowptrs
protected

Array that holds the begin addresses of column indices.

◆ statevectors

template<typename T >
std::vector< AurynVector<T,AurynLong> * > auryn::ComplexMatrix< T >::statevectors

Vector that holds pointers to the state vectors storing the synaptic states.


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