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,"
183 const int *jp = GetRow(i), n = RowSize(i);
186 for (
int j = 0; j < n; j++)
206 MFEM_ASSERT( i >=0 && i<size,
"Index out of bounds. i = "<<i);
208 for (
int k = I[i], end = I[i+1]; k < end; k++)
219 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
227 int i, j, end, sum = 0, n = 0, newI = 0;
229 for (i=0; i<I[size]; i++)
237 int *NewJ =
new int[sum];
239 for (i=0; i<size; i++)
242 for (j=I[i]; j<end; j++)
244 if (J[j] == -1) {
break; }
256 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
265 int nnz = list.
Size();
270 for (
int i = 0, k = 0; i <= size; i++)
273 while (k < nnz && list[k].from == i)
283 int width = -1, nnz = (size >= 0) ? I[size] : 0;
284 for (
int k = 0; k < nnz; k++)
285 if (J[k] > width) { width = J[k]; }
293 for (i = 0; i < size; i++)
295 out <<
"[row " << i <<
"]\n";
296 for (j = I[i]; j < I[i+1]; j++)
298 out << setw(5) << J[j];
299 if ( !((j+1-I[i]) % width) )
304 if ((j-I[i]) % width)
315 for (i = 0; i < size; i++)
316 for (j = I[i]; j < I[i+1]; j++)
318 out << i <<
" " << J[j] <<
" 1. \n";
330 for (i = 0; i <= size; i++)
334 for (i = 0; i < I[size]; i++)
352 int * i_copy =
new int[size+1];
353 int * j_copy =
new int[I[size]];
355 memcpy(i_copy, I,
sizeof(
int)*(size+1));
356 memcpy(j_copy, J,
sizeof(
int)*I[size]);
358 copy.
SetIJ(i_copy, j_copy, size);
375 if (size < 0 || I == NULL) {
return 0; }
376 return (size+1 + I[size]) *
sizeof(int);
381 if (I) {
delete [] I; }
382 if (J) {
delete [] J; }
387 const int *i_A = A.
GetI();
388 const int *j_A = A.
GetJ();
389 const int nrows_A = A.
Size();
390 const int ncols_A = (_ncols_A < 0) ? A.
Width() : _ncols_A;
391 const int nnz_A = i_A[nrows_A];
395 int *i_At = At.
GetI();
396 int *j_At = At.
GetJ();
398 for (
int i = 0; i <= ncols_A; i++)
402 for (
int i = 0; i < nnz_A; i++)
406 for (
int i = 1; i < ncols_A; i++)
408 i_At[i+1] += i_At[i];
411 for (
int i = 0; i < nrows_A; i++)
412 for (
int j = i_A[i]; j < i_A[i+1]; j++)
414 j_At[i_At[j_A[j]]++] = i;
416 for (
int i = ncols_A; i > 0; i--)
432 At.
MakeI((_ncols_A < 0) ? (A.
Max() + 1) : _ncols_A);
433 for (
int i = 0; i < A.
Size(); i++)
438 for (
int i = 0; i < A.
Size(); i++)
448 const int *i_A = A.
GetI();
449 const int *j_A = A.
GetJ();
450 const int *i_B = B.
GetI();
451 const int *j_B = B.
GetJ();
452 const int nrows_A = A.
Size();
453 const int nrows_B = B.
Size();
454 const int ncols_A = A.
Width();
455 const int ncols_B = B.
Width();
457 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
458 <<
", nrows_B = " << nrows_B);
462 for (i = 0; i < ncols_B; i++)
468 for (i = 0; i < nrows_A; i++)
470 for (j = i_A[i]; j < i_A[i+1]; j++)
473 for (l = i_B[k]; l < i_B[k+1]; l++)
476 if (B_marker[m] != i)
487 for (i = 0; i < ncols_B; i++)
495 for (i = 0; i < nrows_A; i++)
498 for (j = i_A[i]; j < i_A[i+1]; j++)
501 for (l = i_B[k]; l < i_B[k+1]; l++)
504 if (B_marker[m] != i)
524 Table(dim, connections_per_row)
554 Rows =
new Node*[nrows];
555 for (
int i = 0; i < nrows; i++)
563 int DSTable::Push_(
int r,
int c)
565 MFEM_ASSERT(r >= 0 && r < NumRows,
566 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
568 for (n = Rows[r]; n != NULL; n = n->Prev)
575 #ifdef MFEM_USE_MEMALLOC
576 n = NodesMem.
Alloc ();
581 n->Index = NumEntries;
584 return (NumEntries++);
587 int DSTable::Index(
int r,
int c)
const
589 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
594 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
606 #ifdef MFEM_USE_MEMALLOC
609 for (
int i = 0; i < NumRows; i++)
611 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 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.
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.