mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix many long to int conversion warnings:
- fix usage of Index (API) versus StorageIndex (when multiple indexes are stored) - use StorageIndex(val) when the input has already been check - use internal::convert_index<StorageIndex>(val) when val is potentially unsafe (directly comes from user input)
This commit is contained in:
@@ -41,10 +41,10 @@ template<typename T0, typename T1> inline bool amd_marked(const T0* w, const T1&
|
||||
template<typename T0, typename T1> inline void amd_mark(const T0* w, const T1& j) { return w[j] = amd_flip(w[j]); }
|
||||
|
||||
/* clear w */
|
||||
template<typename Index>
|
||||
static Index cs_wclear (Index mark, Index lemax, Index *w, Index n)
|
||||
template<typename StorageIndex>
|
||||
static StorageIndex cs_wclear (StorageIndex mark, StorageIndex lemax, StorageIndex *w, StorageIndex n)
|
||||
{
|
||||
Index k;
|
||||
StorageIndex k;
|
||||
if(mark < 2 || (mark + lemax < 0))
|
||||
{
|
||||
for(k = 0; k < n; k++)
|
||||
@@ -56,10 +56,10 @@ static Index cs_wclear (Index mark, Index lemax, Index *w, Index n)
|
||||
}
|
||||
|
||||
/* depth-first search and postorder of a tree rooted at node j */
|
||||
template<typename Index>
|
||||
Index cs_tdfs(Index j, Index k, Index *head, const Index *next, Index *post, Index *stack)
|
||||
template<typename StorageIndex>
|
||||
StorageIndex cs_tdfs(StorageIndex j, StorageIndex k, StorageIndex *head, const StorageIndex *next, StorageIndex *post, StorageIndex *stack)
|
||||
{
|
||||
Index i, p, top = 0;
|
||||
StorageIndex i, p, top = 0;
|
||||
if(!head || !next || !post || !stack) return (-1); /* check inputs */
|
||||
stack[0] = j; /* place j on the stack */
|
||||
while (top >= 0) /* while (stack is not empty) */
|
||||
@@ -87,41 +87,39 @@ Index cs_tdfs(Index j, Index k, Index *head, const Index *next, Index *post, Ind
|
||||
* \returns the permutation P reducing the fill-in of the input matrix \a C
|
||||
* The input matrix \a C must be a selfadjoint compressed column major SparseMatrix object. Both the upper and lower parts have to be stored, but the diagonal entries are optional.
|
||||
* On exit the values of C are destroyed */
|
||||
template<typename Scalar, typename Index>
|
||||
void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, PermutationMatrix<Dynamic,Dynamic,Index>& perm)
|
||||
template<typename Scalar, typename StorageIndex>
|
||||
void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,StorageIndex>& C, PermutationMatrix<Dynamic,Dynamic,StorageIndex>& perm)
|
||||
{
|
||||
using std::sqrt;
|
||||
|
||||
Index d, dk, dext, lemax = 0, e, elenk, eln, i, j, k, k1,
|
||||
k2, k3, jlast, ln, dense, nzmax, mindeg = 0, nvi, nvj, nvk, mark, wnvi,
|
||||
ok, nel = 0, p, p1, p2, p3, p4, pj, pk, pk1, pk2, pn, q, t;
|
||||
StorageIndex d, dk, dext, lemax = 0, e, elenk, eln, i, j, k, k1,
|
||||
k2, k3, jlast, ln, dense, nzmax, mindeg = 0, nvi, nvj, nvk, mark, wnvi,
|
||||
ok, nel = 0, p, p1, p2, p3, p4, pj, pk, pk1, pk2, pn, q, t, h;
|
||||
|
||||
std::size_t h;
|
||||
|
||||
Index n = C.cols();
|
||||
dense = std::max<Index> (16, Index(10 * sqrt(double(n)))); /* find dense threshold */
|
||||
dense = std::min<Index> (n-2, dense);
|
||||
StorageIndex n = StorageIndex(C.cols());
|
||||
dense = std::max<StorageIndex> (16, StorageIndex(10 * sqrt(double(n)))); /* find dense threshold */
|
||||
dense = (std::min)(n-2, dense);
|
||||
|
||||
Index cnz = C.nonZeros();
|
||||
StorageIndex cnz = StorageIndex(C.nonZeros());
|
||||
perm.resize(n+1);
|
||||
t = cnz + cnz/5 + 2*n; /* add elbow room to C */
|
||||
C.resizeNonZeros(t);
|
||||
|
||||
// get workspace
|
||||
ei_declare_aligned_stack_constructed_variable(Index,W,8*(n+1),0);
|
||||
Index* len = W;
|
||||
Index* nv = W + (n+1);
|
||||
Index* next = W + 2*(n+1);
|
||||
Index* head = W + 3*(n+1);
|
||||
Index* elen = W + 4*(n+1);
|
||||
Index* degree = W + 5*(n+1);
|
||||
Index* w = W + 6*(n+1);
|
||||
Index* hhead = W + 7*(n+1);
|
||||
Index* last = perm.indices().data(); /* use P as workspace for last */
|
||||
ei_declare_aligned_stack_constructed_variable(StorageIndex,W,8*(n+1),0);
|
||||
StorageIndex* len = W;
|
||||
StorageIndex* nv = W + (n+1);
|
||||
StorageIndex* next = W + 2*(n+1);
|
||||
StorageIndex* head = W + 3*(n+1);
|
||||
StorageIndex* elen = W + 4*(n+1);
|
||||
StorageIndex* degree = W + 5*(n+1);
|
||||
StorageIndex* w = W + 6*(n+1);
|
||||
StorageIndex* hhead = W + 7*(n+1);
|
||||
StorageIndex* last = perm.indices().data(); /* use P as workspace for last */
|
||||
|
||||
/* --- Initialize quotient graph ---------------------------------------- */
|
||||
Index* Cp = C.outerIndexPtr();
|
||||
Index* Ci = C.innerIndexPtr();
|
||||
StorageIndex* Cp = C.outerIndexPtr();
|
||||
StorageIndex* Ci = C.innerIndexPtr();
|
||||
for(k = 0; k < n; k++)
|
||||
len[k] = Cp[k+1] - Cp[k];
|
||||
len[n] = 0;
|
||||
@@ -138,7 +136,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
|
||||
elen[i] = 0; // Ek of node i is empty
|
||||
degree[i] = len[i]; // degree of node i
|
||||
}
|
||||
mark = internal::cs_wclear<Index>(0, 0, w, n); /* clear w */
|
||||
mark = internal::cs_wclear<StorageIndex>(0, 0, w, n); /* clear w */
|
||||
elen[n] = -2; /* n is a dead element */
|
||||
Cp[n] = -1; /* n is a root of assembly tree */
|
||||
w[n] = 0; /* n is a dead element */
|
||||
@@ -253,7 +251,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
|
||||
elen[k] = -2; /* k is now an element */
|
||||
|
||||
/* --- Find set differences ----------------------------------------- */
|
||||
mark = internal::cs_wclear<Index>(mark, lemax, w, n); /* clear w if necessary */
|
||||
mark = internal::cs_wclear<StorageIndex>(mark, lemax, w, n); /* clear w if necessary */
|
||||
for(pk = pk1; pk < pk2; pk++) /* scan 1: find |Le\Lk| */
|
||||
{
|
||||
i = Ci[pk];
|
||||
@@ -323,7 +321,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
|
||||
}
|
||||
else
|
||||
{
|
||||
degree[i] = std::min<Index> (degree[i], d); /* update degree(i) */
|
||||
degree[i] = std::min<StorageIndex> (degree[i], d); /* update degree(i) */
|
||||
Ci[pn] = Ci[p3]; /* move first node to end */
|
||||
Ci[p3] = Ci[p1]; /* move 1st el. to end of Ei */
|
||||
Ci[p1] = k; /* add k as 1st element in of Ei */
|
||||
@@ -331,12 +329,12 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
|
||||
h %= n; /* finalize hash of i */
|
||||
next[i] = hhead[h]; /* place i in hash bucket */
|
||||
hhead[h] = i;
|
||||
last[i] = Index(h); /* save hash of i in last[i] */
|
||||
last[i] = h; /* save hash of i in last[i] */
|
||||
}
|
||||
} /* scan2 is done */
|
||||
degree[k] = dk; /* finalize |Lk| */
|
||||
lemax = std::max<Index>(lemax, dk);
|
||||
mark = internal::cs_wclear<Index>(mark+lemax, lemax, w, n); /* clear w */
|
||||
lemax = std::max<StorageIndex>(lemax, dk);
|
||||
mark = internal::cs_wclear<StorageIndex>(mark+lemax, lemax, w, n); /* clear w */
|
||||
|
||||
/* --- Supernode detection ------------------------------------------ */
|
||||
for(pk = pk1; pk < pk2; pk++)
|
||||
@@ -384,12 +382,12 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
|
||||
if((nvi = -nv[i]) <= 0) continue;/* skip if i is dead */
|
||||
nv[i] = nvi; /* restore nv[i] */
|
||||
d = degree[i] + dk - nvi; /* compute external degree(i) */
|
||||
d = std::min<Index> (d, n - nel - nvi);
|
||||
d = std::min<StorageIndex> (d, n - nel - nvi);
|
||||
if(head[d] != -1) last[head[d]] = i;
|
||||
next[i] = head[d]; /* put i back in degree list */
|
||||
last[i] = -1;
|
||||
head[d] = i;
|
||||
mindeg = std::min<Index> (mindeg, d); /* find new minimum degree */
|
||||
mindeg = std::min<StorageIndex> (mindeg, d); /* find new minimum degree */
|
||||
degree[i] = d;
|
||||
Ci[p++] = i; /* place i in Lk */
|
||||
}
|
||||
@@ -422,7 +420,7 @@ void minimum_degree_ordering(SparseMatrix<Scalar,ColMajor,Index>& C, Permutation
|
||||
}
|
||||
for(k = 0, i = 0; i <= n; i++) /* postorder the assembly tree */
|
||||
{
|
||||
if(Cp[i] == -1) k = internal::cs_tdfs<Index>(i, k, head, next, perm.indices().data(), w);
|
||||
if(Cp[i] == -1) k = internal::cs_tdfs<StorageIndex>(i, k, head, next, perm.indices().data(), w);
|
||||
}
|
||||
|
||||
perm.indices().conservativeResize(n);
|
||||
|
||||
Reference in New Issue
Block a user