10 #include "../basecode/header.h"
11 #include "../basecode/global.h"
12 #include "../shell/Shell.h"
13 #include "../basecode/SparseMatrix.h"
31 "Number of rows in matrix.",
36 "Number of columns in matrix.",
41 "Number of Entries in matrix.",
47 "Pairwise specification of connection matrix where each x,y value "
48 "represents a connection from src[x] to dest[y]. "
49 "The (x,y) entries are ordered in a single vector as \n"
50 "(x0, x1,... x_n-1, y0, y1,... y_n-1)\n",
59 "The non-zero matrix entries in the sparse matrix. Their"
60 "column indices are in a separate vector and the row"
61 "informatino in a third",
68 "Column Index of each matrix entry",
75 "Row start for each block of entries and column indices",
81 "connection probability for random connectivity.",
88 "Random number seed for generating probabilistic connectivity.",
98 "Assigns connectivity with specified probability and seed",
103 "Assigns single row,column value",
108 "Clears single row,column entry",
113 "Clears out the entire matrix",
118 "Transposes the sparse matrix",
123 "Fills entire matrix using pairs of (x,y) indices to indicate "
124 "presence of a connection. If the target is a FieldElement it"
125 "automagically assigns FieldIndices.",
127 vector< unsigned int >, vector< unsigned int> >(
131 "Fills entire matrix using triplets of (x,y,fieldIndex) to fully "
132 "specify every connection in the sparse matrix.",
134 vector< unsigned int >, vector< unsigned int>,
135 vector< unsigned int > >(
139 "Single contiguous array to fill entire connection matrix using "
140 "triplets of (x,y, fieldindex) ordered as \n"
141 "(x0, x1,... xn-1, y0, y1,... yn-1, fi0, fi1,... fi_n-1)\n",
149 static Finfo* sparseMsgFinfos[] =
175 sizeof( sparseMsgFinfos ) /
sizeof(
Finfo* ),
246 vector< unsigned int > src( v.begin(), v.begin() + v.size()/2 );
247 vector< unsigned int > dest( v.begin() + v.size()/2, v.end() );
254 vector< unsigned int > y;
255 for (
unsigned int row = 0; row <
matrix_.
nRows(); ++row )
259 for (
unsigned int j = begin; j < end; ++j )
262 assert( cols.size() == y.size() );
263 y.insert( y.end(), cols.begin(), cols.end() );
279 unsigned int row,
unsigned int column,
unsigned int value )
307 for (
unsigned int i = 0; i < temp.
nRows(); ++ i )
309 const unsigned int* colIndex;
310 const unsigned int* entry;
311 unsigned int num = temp.
getRow( i, &entry, &colIndex );
312 if ( i >= startData && i < endData )
324 vector< unsigned int> dest )
327 vector< unsigned int >::const_iterator i;
328 for ( i = src.begin(); i != src.end(); ++i )
332 cout <<
"Warning: SparseMsg::pairFill: Src index " << *i <<
333 " exceeds Src array size " <<
e1()->
numData() <<
338 for ( i = dest.begin(); i != dest.end(); ++i )
342 cout <<
"Warning: SparseMsg::pairFill: Dest index " << *i <<
343 " exceeds Dest array size " <<
e2()->
numData() <<
349 vector< unsigned int > numAtDest( dest.size(), 0 );
350 vector< unsigned int > fieldIndex( dest.size(), 0 );
351 for (
unsigned int i = 0; i < dest.size(); ++i )
353 fieldIndex[i] = numAtDest[ dest[i] ];
355 ++numAtDest[ dest[i] ];
367 vector< unsigned int> destDataIndex,
368 vector< unsigned int> destFieldIndex )
377 unsigned int s3 = v.size() / 3;
378 vector< unsigned int > src( v.begin(), v.begin() + s3 );
379 vector< unsigned int > dest( v.begin() + s3, v.begin() + 2 * s3 );
380 vector< unsigned int > fieldIndex( v.begin() + 2 * s3, v.end() );
390 :
Msg(
ObjId( managerId_, (msgIndex != 0) ? msgIndex: msg_.size() ),
394 p_( 0.0 ), seed_( 0 )
396 unsigned int nrows = 0;
397 unsigned int ncolumns = 0;
403 msg_.push_back(
this );
407 if (
msg_.size() <= msgIndex )
408 msg_.resize( msgIndex + 1 );
409 msg_[ msgIndex ] =
this;
440 const unsigned int* fieldIndex;
441 const unsigned int* colIndex;
443 &fieldIndex, &colIndex );
446 return Eref(
e2_, colIndex[0], fieldIndex[0] );
470 unsigned int totalSynapses = 0;
471 vector< unsigned int > sizes( nCols, 0 );
472 unsigned int totSynNum = 0;
477 assert( nCols == syn->
numData() );
480 for (
unsigned int i = 0; i < nCols; ++i )
482 vector< unsigned int > synIndex;
485 unsigned int synNum = 0;
486 for (
unsigned int j = 0; j < nRows; ++j )
489 if ( r < probability )
491 synIndex.push_back( synNum );
497 synIndex.push_back( ~0 );
501 if ( i >= startData && i < endData )
505 totalSynapses += synNum;
526 return totalSynapses;
548 const unsigned int* entry;
549 const unsigned int* colIndex;
553 return ObjId(
e2()->
id(), colIndex[0] );
559 vector< unsigned int > entry;
571 FuncId fid,
unsigned int b,
unsigned int n )
const
582 else if ( orig ==
e2() )
598 cout <<
"Error: SparseMsg::copy: SparseSliceMsg not yet implemented\n";
611 for (
unsigned int i = 0; i < e1->
numData(); ++i )
613 const unsigned int* entry;
614 const unsigned int* colIndex;
615 unsigned int num = matrix.
getRow( i, &entry, &colIndex );
617 for (
unsigned int j = 0; j < num; ++j )
619 v[i][j] =
Eref( e2, colIndex[j], entry[j] );
645 assert( index <
msg_.size() );
646 return reinterpret_cast< char*
>(
msg_[index] );
unsigned int nEntries() const
unsigned int randomConnect(double probability)
void tripletFill(const vector< unsigned int > &row, const vector< unsigned int > &col, const vector< T > &z, bool retainSize=false)
const vector< T > & matrixEntry() const
Here we expose the sparse matrix for MOOSE use.
unsigned int nColumns() const
vector< unsigned int > getEntryPairs() const
static const Cinfo * sparseMsgCinfo
Element * element() const
Synonym for Id::operator()()
void set(unsigned int row, unsigned int column, T value)
unsigned int getRow(unsigned int row, const T **entry, const unsigned int **colIndex) const
moose::MOOSE_RNG_DEFAULT_ENGINE rng_
unsigned int dataIndex() const
void setEntryPairs(vector< unsigned int > entries)
void fillErefsFromMatrix(const SparseMatrix< unsigned int > &matrix, vector< vector< Eref > > &v, Element *e1, Element *e2)
unsigned int nRows() const
void addMsgAndFunc(ObjId mid, FuncId fid, BindIndex bindIndex)
Element * element() const
void tripletFill(vector< unsigned int > src, vector< unsigned int > dest, vector< unsigned int > field)
unsigned int getNumColumns() const
SparseMatrix< unsigned int > matrix_
vector< unsigned int > getColIndex() const
void setRandomConnectivity(double probability, long seed)
unsigned int getNumRows() const
void setProbability(double value)
vector< unsigned int > getMatrixEntry() const
void tripletFill1(vector< unsigned int > entries)
unsigned int rowIndex(const Element *e, const DataId &d)
void addRow(unsigned int rowNum, const vector< T > &row)
static char * lookupMsg(unsigned int index)
Static function for Msg access.
const vector< unsigned int > & colIndex() const
moose::MOOSE_UNIFORM_DISTRIBUTION< double > dist_
static unsigned int numMsg()
Msg lookup functions.
void pairFill(vector< unsigned int > src, vector< unsigned int > dest)
void unsetEntry(unsigned int row, unsigned int column)
void setSize(unsigned int nrows, unsigned int ncolumns)
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
Element * e1_
Index of this Msg on the msg_ vector.
void setSeed(unsigned long value)
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
double getProbability() const
ObjId findOtherEnd(ObjId end) const
void setEntry(unsigned int row, unsigned int column, unsigned int value)
Element * element() const
static const Cinfo * initCinfo()
unsigned int getNumEntries() const
void unset(unsigned int row, unsigned int column)
void sources(vector< vector< Eref > > &v) const
const vector< unsigned int > & rowStart() const
SparseMatrix< unsigned int > & getMatrix()
moose::MOOSE_RANDOM_DEVICE rd_
static vector< SparseMsg * > msg_
Element * e2_
Element 1 attached to Msg.
vector< unsigned int > getRowStart() const
void setMatrix(const SparseMatrix< unsigned int > &m)
void targets(vector< vector< Eref > > &v) const
virtual void resizeField(unsigned int rawIndex, unsigned int newNumField)=0
const unsigned int BADINDEX
Used by ObjId and Eref.
unsigned int getColumn(unsigned int col, vector< T > &entry, vector< unsigned int > &rowIndex) const
SparseMsg(Element *e1, Element *e2, unsigned int msgIndex)
static const Cinfo * initCinfo()
unsigned long getSeed() const
Msg * copy(Id origSrc, Id newSrc, Id newTgt, FuncId fid, unsigned int b, unsigned int n) const
Eref firstTgt(const Eref &src) const