31 const int nnz = table.
I[size];
34 memcpy(I, table.
I,
sizeof(
int)*(size+1));
35 memcpy(J, table.
J,
sizeof(
int)*nnz);
45 int i, j, sum = dim * connections_per_row;
52 for (i = 1; i <= size; i++)
54 I[i] = I[i-1] + connections_per_row;
55 for (j = I[i-1]; j < I[i]; j++) { J[j] = -1; }
66 for (
int i = 0; i < size; i++)
69 J[i] = partitioning[i];
78 for (
int i = 0; i <= nrows; i++)
88 for (k = i = 0; i < size; i++)
90 j = I[i], I[i] = k, k += j;
93 J =
new int[I[size]=k];
100 for (
int i = 0; i < nc; i++)
109 for (
int i = size; i > 0; i--)
118 SetDims (dim, dim * connections_per_row);
123 for (
int i = 0, j = 0; i < size; i++)
125 int end = I[i] + connections_per_row;
127 for ( ; j < end; j++) { J[j] = -1; }
136 j = (I) ? (I[size]) : (0);
140 if (I) {
delete [] I; }
141 I = (rows >= 0) ? (
new int[rows+1]) : (NULL);
146 if (J) {
delete [] J; }
147 J = (nnz > 0) ? (
new int[nnz]) : (NULL);
159 if ( i>=size || i<0 )
165 for (k = I[i]; k < end; k++)
181 MFEM_ASSERT(i >= 0 && i < size,
"Row index " << i <<
" is out of range [0,"
190 for (
int r = 0; r < size; r++)
192 std::sort(J + I[r], J + I[r+1]);
210 MFEM_ASSERT( i >=0 && i<size,
"Index out of bounds. i = "<<i);
212 for (
int k = I[i], end = I[i+1]; k < end; k++)
223 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
231 int i, j, end, sum = 0, n = 0, newI = 0;
233 for (i=0; i<I[size]; i++)
241 int *NewJ =
new int[sum];
243 for (i=0; i<size; i++)
246 for (j=I[i]; j<end; j++)
248 if (J[j] == -1) {
break; }
260 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
269 int nnz = list.
Size();
274 for (
int i = 0, k = 0; i <= size; i++)
277 while (k < nnz && list[k].from == i)
287 int width = -1, nnz = (size >= 0) ? I[size] : 0;
288 for (
int k = 0; k < nnz; k++)
290 if (J[k] > width) { width = J[k]; }
299 for (i = 0; i < size; i++)
301 out <<
"[row " << i <<
"]\n";
302 for (j = I[i]; j < I[i+1]; j++)
304 out << setw(5) << J[j];
305 if ( !((j+1-I[i]) % width) )
310 if ((j-I[i]) % width)
321 for (i = 0; i < size; i++)
322 for (j = I[i]; j < I[i+1]; j++)
324 out << i <<
" " << J[j] <<
" 1. \n";
336 for (i = 0; i <= size; i++)
340 for (i = 0; i < I[size]; i++)
358 int * i_copy =
new int[size+1];
359 int * j_copy =
new int[I[size]];
361 memcpy(i_copy, I,
sizeof(
int)*(size+1));
362 memcpy(j_copy, J,
sizeof(
int)*I[size]);
364 copy.
SetIJ(i_copy, j_copy, size);
381 if (size < 0 || I == NULL) {
return 0; }
382 return (size+1 + I[size]) *
sizeof(int);
387 if (I) {
delete [] I; }
388 if (J) {
delete [] J; }
393 const int *i_A = A.
GetI();
394 const int *j_A = A.
GetJ();
395 const int nrows_A = A.
Size();
396 const int ncols_A = (_ncols_A < 0) ? A.
Width() : _ncols_A;
397 const int nnz_A = i_A[nrows_A];
401 int *i_At = At.
GetI();
402 int *j_At = At.
GetJ();
404 for (
int i = 0; i <= ncols_A; i++)
408 for (
int i = 0; i < nnz_A; i++)
412 for (
int i = 1; i < ncols_A; i++)
414 i_At[i+1] += i_At[i];
417 for (
int i = 0; i < nrows_A; i++)
418 for (
int j = i_A[i]; j < i_A[i+1]; j++)
420 j_At[i_At[j_A[j]]++] = i;
422 for (
int i = ncols_A; i > 0; i--)
438 At.
MakeI((_ncols_A < 0) ? (A.
Max() + 1) : _ncols_A);
439 for (
int i = 0; i < A.
Size(); i++)
444 for (
int i = 0; i < A.
Size(); i++)
454 const int *i_A = A.
GetI();
455 const int *j_A = A.
GetJ();
456 const int *i_B = B.
GetI();
457 const int *j_B = B.
GetJ();
458 const int nrows_A = A.
Size();
459 const int nrows_B = B.
Size();
460 const int ncols_A = A.
Width();
461 const int ncols_B = B.
Width();
463 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
464 <<
", nrows_B = " << nrows_B);
468 for (i = 0; i < ncols_B; i++)
474 for (i = 0; i < nrows_A; i++)
476 for (j = i_A[i]; j < i_A[i+1]; j++)
479 for (l = i_B[k]; l < i_B[k+1]; l++)
482 if (B_marker[m] != i)
493 for (i = 0; i < ncols_B; i++)
501 for (i = 0; i < nrows_A; i++)
504 for (j = i_A[i]; j < i_A[i+1]; j++)
507 for (l = i_B[k]; l < i_B[k+1]; l++)
510 if (B_marker[m] != i)
530 Table(dim, connections_per_row)
560 Rows =
new Node*[nrows];
561 for (
int i = 0; i < nrows; i++)
569 int DSTable::Push_(
int r,
int c)
571 MFEM_ASSERT(r >= 0 && r < NumRows,
572 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
574 for (n = Rows[r]; n != NULL; n = n->Prev)
581 #ifdef MFEM_USE_MEMALLOC
582 n = NodesMem.
Alloc ();
587 n->Index = NumEntries;
590 return (NumEntries++);
593 int DSTable::Index(
int r,
int c)
const
595 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
600 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
612 #ifdef MFEM_USE_MEMALLOC
615 for (
int i = 0; i < NumRows; i++)
617 Node *na, *nb = Rows[i];
int Size() const
Logical size of the array.
void SetSize(int dim, int connections_per_row)
Set the size and the number of connections for the table.
int operator()(int i, int j) const
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
void SortRows()
Sort the column (TYPE II) indices in each row.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
void SetDims(int rows, int nnz)
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
void Save(std::ostream &out) const
void AddConnections(int r, const int *c, int nc)
int Width() const
Returns the number of TYPE II elements (after Finalize() is called).
void Print(std::ostream &out=std::cout, int width=4) const
Prints the table to stream out.
int operator()(int i, int j) const
void MakeFromList(int nrows, const Array< Connection > &list)
void AddConnection(int r, int c)
void Transpose(const Table &A, Table &At, int _ncols_A)
Transpose a Table.
void Assign(const T *)
Copy data from a pointer. Size() elements are copied.
int Size() const
Returns the number of TYPE I elements.
void PrintMatlab(std::ostream &out) const
STable(int dim, int connections_per_row=3)
Creates table with fixed number of connections.
void Swap(Array< T > &, Array< T > &)
int size
size is the number of TYPE I elements.
void AddAColumnInRow(int r)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
void SetIJ(int *newI, int *newJ, int newsize=-1)
void Copy(Table ©) const
Table()
Creates an empty table.