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

Template for a sparse matrix with row major ordering and fast access of rows. More...

#include <SimpleMatrix.h>

Public Member Functions

 SimpleMatrix ()
 
 SimpleMatrix (SimpleMatrix *mat)
 
 SimpleMatrix (NeuronID rows, NeuronID cols)
 
 SimpleMatrix (NeuronID rows, NeuronID cols, AurynLong size)
 
virtual ~SimpleMatrix ()
 
void clear ()
 
void resize_buffer (AurynLong newsize)
 
void resize_buffer_and_clear (AurynLong size)
 
void prune ()
 
void push_back (const NeuronID i, const NeuronID j, const T value)
 
void copy (SimpleMatrix *mat)
 
void set_data (AurynLong i, T value)
 
void scale_data (AurynLong i, T value)
 
T * get_data_ptr (const AurynLong i)
 
get_data (const AurynLong i)
 
T * get_data_ptr (const NeuronID *ind_ptr)
 
get_data (const NeuronID *ind_ptr)
 
void fill_zeros ()
 Same as fill_na. More...
 
void fill_na ()
 Marks the remainder of buffers non-existing connections. More...
 
AurynDouble get_fill_level ()
 
get (NeuronID i, NeuronID j)
 
bool exists (NeuronID i, NeuronID j)
 
T * get_ptr (NeuronID i, NeuronID j)
 
T * get_ptr (AurynLong data_index)
 
get_value (AurynLong data_index)
 
void add_value (AurynLong data_index, T value)
 
NeuronID get_colind (AurynLong data_index)
 
bool set (NeuronID i, NeuronID j, T value)
 
void set_all (T value)
 
void set_row (NeuronID i, T value)
 
void scale_row (NeuronID i, T value)
 
void scale_all (T value)
 
void set_col (NeuronID j, T value)
 
void scale_col (NeuronID j, T value)
 
double sum_col (NeuronID j)
 
AurynLong get_datasize ()
 
AurynLong get_nonzero ()
 
void print ()
 
double mean ()
 
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 ()
 
T * get_data_end ()
 Returns value behind last element in data array corresponding to a nonzero value. More...
 
get_value (NeuronID i)
 
get_value (NeuronID *r)
 
T * get_value_ptr (NeuronID i)
 
T * get_value_ptr (NeuronID *r)
 
NeuronID get_data_offset (NeuronID *r)
 

Protected Member Functions

void init (NeuronID m, NeuronID n, AurynLong size=256)
 
void free ()
 

Protected Attributes

NeuronID ** rowptrs
 
NeuronIDcolinds
 
T * coldata
 

Friends

class boost::serialization::access
 

Detailed Description

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

Template for a sparse matrix with row major ordering and fast access of rows.

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.

Constructor & Destructor Documentation

◆ SimpleMatrix() [1/4]

template<typename T >
auryn::SimpleMatrix< T >::SimpleMatrix ( )
325 {
326  init(1,1);
327 }
void init(NeuronID m, NeuronID n, AurynLong size=256)
Definition: SimpleMatrix.h:258
Here is the call graph for this function:

◆ SimpleMatrix() [2/4]

template<typename T >
auryn::SimpleMatrix< T >::SimpleMatrix ( SimpleMatrix< T > *  mat)
331 {
332  init(mat->get_m_rows(),mat->get_n_cols(),mat->get_nonzero());
333  copy(mat);
334 }
void copy(SimpleMatrix *mat)
Definition: SimpleMatrix.h:359
void init(NeuronID m, NeuronID n, AurynLong size=256)
Definition: SimpleMatrix.h:258
Here is the call graph for this function:

◆ SimpleMatrix() [3/4]

template<typename T >
auryn::SimpleMatrix< T >::SimpleMatrix ( NeuronID  rows,
NeuronID  cols 
)
340 {
341  init(rows,cols);
342 }
void init(NeuronID m, NeuronID n, AurynLong size=256)
Definition: SimpleMatrix.h:258
Here is the call graph for this function:

◆ SimpleMatrix() [4/4]

template<typename T >
auryn::SimpleMatrix< T >::SimpleMatrix ( NeuronID  rows,
NeuronID  cols,
AurynLong  size 
)
346 {
347  init(rows,cols,datasize);
348 }
void init(NeuronID m, NeuronID n, AurynLong size=256)
Definition: SimpleMatrix.h:258
Here is the call graph for this function:

◆ ~SimpleMatrix()

template<typename T >
auryn::SimpleMatrix< T >::~SimpleMatrix ( )
virtual
375 {
376  free();
377 }
void free()
Definition: SimpleMatrix.h:351
Here is the call graph for this function:

Member Function Documentation

◆ add_value()

template<typename T >
void auryn::SimpleMatrix< T >::add_value ( AurynLong  data_index,
value 
)
492 {
493  coldata[data_index] += value;
494 }
T * coldata
Definition: SimpleMatrix.h:100

◆ clear()

template<typename T >
void auryn::SimpleMatrix< T >::clear ( )
249 {
250  current_row = 0;
251  current_col = 0;
252  n_nonzero = 0;
253  rowptrs[0] = colinds;
254  rowptrs[1] = colinds;
255 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98

◆ copy()

template<typename T >
void auryn::SimpleMatrix< T >::copy ( SimpleMatrix< T > *  mat)
360 {
361  if ( get_m_rows() != mat->get_m_rows() || get_n_cols() != mat->get_n_cols() )
362  throw AurynMatrixDimensionalityException();
363 
364  clear();
365 
366  for ( NeuronID i = 0 ; i < mat->get_m_rows() ; ++i ) {
367  for ( NeuronID * r = mat->get_row_begin(i) ; r != mat->get_row_end(i) ; ++r ) {
368  push_back(i,*r,mat->get_value(r));
369  }
370  }
371 }
r
Definition: mkpat.py:9
void clear()
Definition: SimpleMatrix.h:248
void push_back(const NeuronID i, const NeuronID j, const T value)
Definition: SimpleMatrix.h:380
NeuronID get_m_rows()
Definition: SimpleMatrix.h:636
NeuronID get_n_cols()
Definition: SimpleMatrix.h:642
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:

◆ exists()

template<typename T >
bool auryn::SimpleMatrix< T >::exists ( NeuronID  i,
NeuronID  j 
)
439 {
440  if ( get_ptr(i,j) == NULL )
441  return false;
442  else
443  return true;
444 }
T * get_ptr(NeuronID i, NeuronID j)
Definition: SimpleMatrix.h:447
Here is the call graph for this function:

◆ fill_na()

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

Marks the remainder of buffers non-existing connections.

Should be called by finalize before using the matrix.

417 {
418  for ( NeuronID i = current_row ; i < m_rows-1 ; ++i )
419  {
420  rowptrs[i+2] = rowptrs[i+1]; // save value of last element
421  }
422  current_row = get_m_rows();
423 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID get_m_rows()
Definition: SimpleMatrix.h:636
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:

◆ fill_zeros()

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

Same as fill_na.

Deprecated:
Because it does not really fill zeros, but NA.
427 {
428  fill_na();
429 }
void fill_na()
Marks the remainder of buffers non-existing connections.
Definition: SimpleMatrix.h:416
Here is the call graph for this function:

◆ free()

template<typename T >
void auryn::SimpleMatrix< T >::free ( )
protected
352 {
353  delete [] rowptrs;
354  delete [] colinds;
355  delete [] coldata;
356 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98

◆ get()

template<typename T >
T auryn::SimpleMatrix< T >::get ( NeuronID  i,
NeuronID  j 
)
433 {
434  return *get_ptr(i,j);
435 }
T * get_ptr(NeuronID i, NeuronID j)
Definition: SimpleMatrix.h:447
Here is the call graph for this function:

◆ get_colind()

template<typename T >
NeuronID auryn::SimpleMatrix< T >::get_colind ( AurynLong  data_index)
498 {
499  return colinds[data_index];
500 }
NeuronID * colinds
Definition: SimpleMatrix.h:98

◆ get_data() [1/2]

template<typename T >
T auryn::SimpleMatrix< T >::get_data ( const AurynLong  i)

Gets the matching data entry for a given index i

215 {
216  return coldata[i];
217 }
T * coldata
Definition: SimpleMatrix.h:100

◆ get_data() [2/2]

template<typename T >
T auryn::SimpleMatrix< T >::get_data ( const NeuronID ind_ptr)

Gets the matching data value for a given index pointer

228 {
229  return *(get_data_ptr(ind_ptr));
230 }
T * get_data_ptr(const AurynLong i)
Definition: SimpleMatrix.h:208
Here is the call graph for this function:

◆ get_data_begin()

template<typename T >
T * auryn::SimpleMatrix< T >::get_data_begin ( )
618 {
619  return coldata;
620 }
T * coldata
Definition: SimpleMatrix.h:100

◆ get_data_end()

template<typename T >
T * auryn::SimpleMatrix< T >::get_data_end ( )

Returns value behind last element in data array corresponding to a nonzero value.

624 {
625  return coldata+get_nonzero();
626 }
T * coldata
Definition: SimpleMatrix.h:100
AurynLong get_nonzero()
Definition: SimpleMatrix.h:410
Here is the call graph for this function:

◆ get_data_offset()

template<typename T >
NeuronID auryn::SimpleMatrix< T >::get_data_offset ( NeuronID r)
693 {
694  return r-get_ind_begin();
695 }
r
Definition: mkpat.py:9
NeuronID * get_ind_begin()
Definition: SimpleMatrix.h:580
Here is the call graph for this function:

◆ get_data_ptr() [1/2]

template<typename T >
T * auryn::SimpleMatrix< T >::get_data_ptr ( const AurynLong  i)

Gets the matching data ptr for a given index i

209 {
210  return coldata+i;
211 }
T * coldata
Definition: SimpleMatrix.h:100

◆ get_data_ptr() [2/2]

template<typename T >
T * auryn::SimpleMatrix< T >::get_data_ptr ( const NeuronID ind_ptr)

Gets the matching data ptr for a given index pointer

221 {
222  size_t ptr_offset = ind_ptr-get_ind_begin();
223  return coldata+ptr_offset;
224 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID * get_ind_begin()
Definition: SimpleMatrix.h:580
Here is the call graph for this function:

◆ get_datasize()

template<typename T >
AurynLong auryn::SimpleMatrix< T >::get_datasize ( )
404 {
405  return datasize;
406 }

◆ get_fill_level()

template<typename T >
AurynDouble auryn::SimpleMatrix< T >::get_fill_level ( )
631 {
632  return 1.*n_nonzero/datasize;
633 }

◆ get_ind_begin()

template<typename T >
NeuronID * auryn::SimpleMatrix< T >::get_ind_begin ( )
581 {
582  return rowptrs[0];
583 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96

◆ get_m_rows()

template<typename T >
NeuronID auryn::SimpleMatrix< T >::get_m_rows ( )
637 {
638  return m_rows;
639 }

◆ get_n_cols()

template<typename T >
NeuronID auryn::SimpleMatrix< T >::get_n_cols ( )
643 {
644  return n_cols;
645 }

◆ get_nonzero()

template<typename T >
AurynLong auryn::SimpleMatrix< T >::get_nonzero ( )
411 {
412  return n_nonzero;
413 }

◆ get_ptr() [1/2]

template<typename T >
T * auryn::SimpleMatrix< T >::get_ptr ( NeuronID  i,
NeuronID  j 
)

Returns the pointer to a particular element

448 {
449  // check bounds
450  if ( !(i < m_rows && j < n_cols) ) return NULL;
451 
452 #ifdef DEBUG
453  std::cout << "enter search" << std::endl;
454 #endif // DEBUG
455  // perform binary search
456  NeuronID * lo = rowptrs[i];
457  NeuronID * hi = rowptrs[i+1];
458 
459  if ( lo >= hi ) // no elements/targets in this row
460  return NULL;
461 
462  while ( lo < hi ) {
463  NeuronID * c = lo + (hi-lo)/2;
464  if ( *c < j ) lo = c+1;
465  else hi = c;
466 #ifdef DEBUG
467  std::cout << i << ":" << j << " " << *lo << ":" << *hi << std::endl;
468 #endif // DEBUG
469  }
470 
471  if ( *lo == j ) {
472  return coldata+(lo-colinds);
473  }
474 
475  return NULL;
476 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151

◆ get_ptr() [2/2]

template<typename T >
T * auryn::SimpleMatrix< T >::get_ptr ( AurynLong  data_index)

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

480 {
481  return &coldata[data_index];
482 }
T * coldata
Definition: SimpleMatrix.h:100

◆ get_row_begin()

template<typename T >
NeuronID * auryn::SimpleMatrix< T >::get_row_begin ( NeuronID  i)
587 {
588  return rowptrs[i];
589 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96

◆ get_row_begin_index()

template<typename T >
AurynLong auryn::SimpleMatrix< T >::get_row_begin_index ( NeuronID  i)
593 {
594  return rowptrs[i]-rowptrs[0];
595 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96

◆ get_row_end()

template<typename T >
NeuronID * auryn::SimpleMatrix< T >::get_row_end ( NeuronID  i)
599 {
600  return rowptrs[i+1];
601 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96

◆ get_row_end_index()

template<typename T >
AurynLong auryn::SimpleMatrix< T >::get_row_end_index ( NeuronID  i)
605 {
606  return rowptrs[i+1]-rowptrs[0];
607 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96

◆ get_rowptrs()

template<typename T >
NeuronID ** auryn::SimpleMatrix< T >::get_rowptrs ( )
612 {
613  return rowptrs;
614 }
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96

◆ get_value() [1/3]

template<typename T >
T auryn::SimpleMatrix< T >::get_value ( AurynLong  data_index)
486 {
487  return coldata[data_index];
488 }
T * coldata
Definition: SimpleMatrix.h:100

◆ get_value() [2/3]

template<typename T >
T auryn::SimpleMatrix< T >::get_value ( NeuronID  i)

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

669 {
670  return get_data_begin()[i];
671 }
T * get_data_begin()
Definition: SimpleMatrix.h:617
Here is the call graph for this function:

◆ get_value() [3/3]

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

675 {
676  return get_data_begin()[r-get_ind_begin()];
677 }
r
Definition: mkpat.py:9
T * get_data_begin()
Definition: SimpleMatrix.h:617
NeuronID * get_ind_begin()
Definition: SimpleMatrix.h:580
Here is the call graph for this function:

◆ get_value_ptr() [1/2]

template<typename T >
T * auryn::SimpleMatrix< T >::get_value_ptr ( NeuronID  i)

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

681 {
682  return &get_data_begin()[i];
683 }
T * get_data_begin()
Definition: SimpleMatrix.h:617
Here is the call graph for this function:

◆ get_value_ptr() [2/2]

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

687 {
688  return &get_data_begin()[r-get_ind_begin()];
689 }
r
Definition: mkpat.py:9
T * get_data_begin()
Definition: SimpleMatrix.h:617
NeuronID * get_ind_begin()
Definition: SimpleMatrix.h:580
Here is the call graph for this function:

◆ init()

template<typename T >
void auryn::SimpleMatrix< T >::init ( NeuronID  m,
NeuronID  n,
AurynLong  size = 256 
)
protected

Default initializiation called by the constructor.

259 {
260  m_rows = m;
261  n_cols = n;
262  datasize = size;
263  rowptrs = new NeuronID * [m_rows+1];
264  colinds = new NeuronID [datasize];
265  coldata = new T [datasize];
266  clear();
267 }
T * coldata
Definition: SimpleMatrix.h:100
void clear()
Definition: SimpleMatrix.h:248
int n
Definition: mkpat.py:5
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98
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:

◆ mean()

template<typename T >
double auryn::SimpleMatrix< T >::mean ( )
659 {
660  double sum = 0;
661  for (NeuronID i = 0 ; i < get_nonzero() ; ++i) {
662  sum += coldata[i];
663  }
664  return sum/get_nonzero();
665 }
T * coldata
Definition: SimpleMatrix.h:100
AurynLong get_nonzero()
Definition: SimpleMatrix.h:410
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:

◆ print()

template<typename T >
void auryn::SimpleMatrix< T >::print ( )
649 {
650  for (NeuronID i = 0 ; i < m_rows ; ++i) {
651  for (NeuronID * r = get_row_begin(i) ; r != get_row_end(i) ; ++r ) {
652  std::cout << i << " " << *r << " " << coldata[r-colinds] << "\n";
653  }
654  }
655 }
r
Definition: mkpat.py:9
T * coldata
Definition: SimpleMatrix.h:100
NeuronID * get_row_end(NeuronID i)
Definition: SimpleMatrix.h:598
NeuronID * colinds
Definition: SimpleMatrix.h:98
NeuronID * get_row_begin(NeuronID i)
Definition: SimpleMatrix.h:586
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::SimpleMatrix< T >::prune ( )

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

318 {
319  if ( get_datasize() > get_nonzero() )
321 }
AurynLong get_nonzero()
Definition: SimpleMatrix.h:410
AurynLong get_datasize()
Definition: SimpleMatrix.h:403
void resize_buffer(AurynLong newsize)
Definition: SimpleMatrix.h:270
Here is the call graph for this function:

◆ push_back()

template<typename T >
void auryn::SimpleMatrix< 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
381 {
382  if ( i >= m_rows || j >= n_cols ) throw AurynMatrixDimensionalityException();
383  while ( i > current_row )
384  {
385  rowptrs[current_row+2] = rowptrs[current_row+1]; // save value of last element
386  current_col = 0;
387  current_row++;
388  }
389  current_col = j;
390  if (i >= current_row && j >= current_col) {
391  if ( n_nonzero >= datasize ) throw AurynMatrixBufferException();
392  *(rowptrs[i+1]) = j; // write last j to end of index array
393  coldata[rowptrs[i+1]-colinds] = value; // write value to end of data array
394  ++rowptrs[i+1]; //increment end by one
395  rowptrs[m_rows] = rowptrs[i+1]; // last (m_row+1) marks end of last row
396  n_nonzero++;
397  } else {
398  throw AurynMatrixPushBackException();
399  }
400 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98

◆ resize_buffer()

template<typename T >
void auryn::SimpleMatrix< T >::resize_buffer ( AurynLong  newsize)

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

271 {
272  const AurynLong oldsize = datasize;
273  if ( oldsize == newsize ) return;
274  const AurynLong copysize = std::min(oldsize,newsize);
275 
276  // std::cout << " copy colinds " << std::endl;
277 
278  NeuronID * new_colinds = new NeuronID [newsize];
279  std::copy(colinds, colinds+copysize, new_colinds);
280 
281  // std::cout << " update rowptrs " << std::endl;
282 
283  // update rowpointers
284  ptrdiff_t offset = new_colinds-colinds;
285  for ( NeuronID i = 0 ; i < m_rows+1 ; ++i ) {
286  rowptrs[i] += offset;
287  }
288 
289  // std::cout << " delete old colinds " << std::endl;
290  // FIXME I get regular crashes in this line:
291  // invalid pointer: 0x0000000001d954c0 ***
292  delete [] colinds;
293 
294  // std::cout << " replace colinds " << std::endl;
295  colinds = new_colinds;
296 
297  // std::cout << " create new data array " << std::endl;
298  T * new_coldata = new T [newsize];
299  std::copy(coldata, coldata+copysize, new_coldata);
300  delete [] coldata;
301  coldata = new_coldata;
302 
303  datasize = newsize;
304  // std::cout << " done " << std::endl;
305 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
NeuronID * colinds
Definition: SimpleMatrix.h:98
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151

◆ resize_buffer_and_clear()

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

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

309 {
310  // free();
311  // init(m_rows, n_cols, size);
312  resize_buffer(size);
313  clear();
314 }
void clear()
Definition: SimpleMatrix.h:248
void resize_buffer(AurynLong newsize)
Definition: SimpleMatrix.h:270
Here is the call graph for this function:

◆ scale_all()

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

Scales all non-zero elements

528 {
529  for ( AurynLong i = 0 ; i < n_nonzero ; ++i )
530  scale_data( i , value );
531 }
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
void scale_data(AurynLong i, T value)
Definition: SimpleMatrix.h:240
Here is the call graph for this function:

◆ scale_col()

template<typename T >
void auryn::SimpleMatrix< T >::scale_col ( NeuronID  j,
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.

554 {
555  for ( AurynLong i = 0 ; i < n_nonzero ; ++i ) {
556  if ( colinds[i] == j ) scale_data(i,value);
557  }
558 }
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
NeuronID * colinds
Definition: SimpleMatrix.h:98
void scale_data(AurynLong i, T value)
Definition: SimpleMatrix.h:240
Here is the call graph for this function:

◆ scale_data()

template<typename T >
void auryn::SimpleMatrix< T >::scale_data ( AurynLong  i,
value 
)
241 {
242  if (i<datasize)
243  coldata[i] *= value;
244 }
T * coldata
Definition: SimpleMatrix.h:100

◆ scale_row()

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

Scales all non-zero elements in row i to value

516 {
517  NeuronID * rowbegin = rowptrs[i];
518  NeuronID * rowend = rowptrs[i+1]--;
519 
520  for (NeuronID * c = rowbegin ; c <= rowend ; ++c)
521  {
522  coldata[c-colinds] *= value;
523  }
524 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151

◆ set()

template<typename T >
bool auryn::SimpleMatrix< T >::set ( NeuronID  i,
NeuronID  j,
value 
)
504 {
505  T * ptr = get_ptr(i,j);
506  if ( ptr != NULL) {
507  *ptr = value;
508  return true;
509  }
510  else
511  return false;
512 }
T * get_ptr(NeuronID i, NeuronID j)
Definition: SimpleMatrix.h:447
Here is the call graph for this function:

◆ set_all()

template<typename T >
void auryn::SimpleMatrix< T >::set_all ( value)

Sets all non-zero elements to value

547 {
548  for ( AurynLong i = 0 ; i < n_nonzero ; ++i )
549  set_data( i , value );
550 }
void set_data(AurynLong i, T value)
Definition: SimpleMatrix.h:233
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:

◆ set_col()

template<typename T >
void auryn::SimpleMatrix< T >::set_col ( NeuronID  j,
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.

573 {
574  for ( AurynLong i = 0 ; i < n_nonzero ; ++i ) {
575  if ( colinds[i] == j ) set_data(i,value);
576  }
577 }
void set_data(AurynLong i, T value)
Definition: SimpleMatrix.h:233
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
NeuronID * colinds
Definition: SimpleMatrix.h:98
Here is the call graph for this function:

◆ set_data()

template<typename T >
void auryn::SimpleMatrix< T >::set_data ( AurynLong  i,
value 
)
234 {
235  if (i<datasize)
236  coldata[i] = value;
237 }
T * coldata
Definition: SimpleMatrix.h:100

◆ set_row()

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

Sets all non-zero elements in row i to value

535 {
536  NeuronID * rowbegin = rowptrs[i];
537  NeuronID * rowend = rowptrs[i+1]--;
538 
539  for (NeuronID * c = rowbegin ; c <= rowend ; ++c)
540  {
541  coldata[c-colinds] = value;
542  }
543 }
T * coldata
Definition: SimpleMatrix.h:100
NeuronID ** rowptrs
Definition: SimpleMatrix.h:96
NeuronID * colinds
Definition: SimpleMatrix.h:98
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151

◆ sum_col()

template<typename T >
double auryn::SimpleMatrix< T >::sum_col ( NeuronID  j)
562 {
563  double sum = 0;
564  for ( AurynLong i = 0 ; i < n_nonzero ; ++i ) {
565  if ( colinds[i] == j )
566  sum += *(get_data_begin()+i);
567  }
568  return sum;
569 }
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
NeuronID * colinds
Definition: SimpleMatrix.h:98
T * get_data_begin()
Definition: SimpleMatrix.h:617
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

◆ coldata

template<typename T >
T* auryn::SimpleMatrix< T >::coldata
protected

Array that holds the data values of the non-zero elements

◆ colinds

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

Array that holds the column indices of non-zero elements

◆ rowptrs

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

Array that holds the begin addresses of column indices


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