Skip to content

Commit b5dee77

Browse files
committed
Factorisation uses only Int64
1 parent aa72227 commit b5dee77

35 files changed

+889
-846
lines changed

highs/ipm/hipo/auxiliary/Auxiliary.cpp

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,129 +4,129 @@
44

55
namespace hipo {
66

7-
void counts2Ptr(std::vector<Int>& ptr, std::vector<Int>& w) {
7+
void counts2Ptr(std::vector<Int64>& ptr, std::vector<Int64>& w) {
88
// Given the column counts in the vector w (of size n),
99
// compute the column pointers in the vector ptr (of size n+1),
1010
// and copy the first n pointers back into w.
1111

12-
Int temp_nz{};
13-
Int n = w.size();
14-
for (Int j = 0; j < n; ++j) {
12+
Int64 temp_nz{};
13+
Int64 n = w.size();
14+
for (Int64 j = 0; j < n; ++j) {
1515
ptr[j] = temp_nz;
1616
temp_nz += w[j];
1717
w[j] = ptr[j];
1818
}
1919
ptr[n] = temp_nz;
2020
}
2121

22-
void inversePerm(const std::vector<Int>& perm, std::vector<Int>& iperm) {
22+
void inversePerm(const std::vector<Int64>& perm, std::vector<Int64>& iperm) {
2323
// Given the permutation perm, produce the inverse permutation iperm.
2424
// perm[i] : i-th entry to use in the new order.
2525
// iperm[i]: where entry i is located in the new order.
2626

27-
for (Int i = 0; i < perm.size(); ++i) {
27+
for (Int64 i = 0; i < perm.size(); ++i) {
2828
iperm[perm[i]] = i;
2929
}
3030
}
3131

32-
void subtreeSize(const std::vector<Int>& parent, std::vector<Int>& sizes) {
32+
void subtreeSize(const std::vector<Int64>& parent, std::vector<Int64>& sizes) {
3333
// Compute sizes of subtrees of the tree given by parent
3434

35-
Int n = parent.size();
35+
Int64 n = parent.size();
3636
sizes.assign(n, 1);
3737

38-
for (Int i = 0; i < n; ++i) {
39-
Int k = parent[i];
38+
for (Int64 i = 0; i < n; ++i) {
39+
Int64 k = parent[i];
4040
if (k != -1) sizes[k] += sizes[i];
4141
}
4242
}
4343

44-
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
45-
std::vector<Int>& ptrT, std::vector<Int>& rowsT) {
44+
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
45+
std::vector<Int64>& ptrT, std::vector<Int64>& rowsT) {
4646
// Compute the transpose of the matrix and return it in rowsT and ptrT
4747

48-
Int n = ptr.size() - 1;
48+
Int64 n = ptr.size() - 1;
4949

50-
std::vector<Int> work(n);
50+
std::vector<Int64> work(n);
5151

5252
// count the entries in each row into work
53-
for (Int i = 0; i < ptr.back(); ++i) {
53+
for (Int64 i = 0; i < ptr.back(); ++i) {
5454
++work[rows[i]];
5555
}
5656

5757
// sum row sums to obtain pointers
5858
counts2Ptr(ptrT, work);
5959

60-
for (Int j = 0; j < n; ++j) {
61-
for (Int el = ptr[j]; el < ptr[j + 1]; ++el) {
62-
Int i = rows[el];
60+
for (Int64 j = 0; j < n; ++j) {
61+
for (Int64 el = ptr[j]; el < ptr[j + 1]; ++el) {
62+
Int64 i = rows[el];
6363

6464
// entry (i,j) becomes entry (j,i)
65-
Int pos = work[i]++;
65+
Int64 pos = work[i]++;
6666
rowsT[pos] = j;
6767
}
6868
}
6969
}
7070

71-
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
72-
const std::vector<double>& val, std::vector<Int>& ptrT,
73-
std::vector<Int>& rowsT, std::vector<double>& valT) {
71+
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
72+
const std::vector<double>& val, std::vector<Int64>& ptrT,
73+
std::vector<Int64>& rowsT, std::vector<double>& valT) {
7474
// Compute the transpose of the matrix and return it in rowsT, ptrT and valT
7575

76-
Int n = ptr.size() - 1;
76+
Int64 n = ptr.size() - 1;
7777

78-
std::vector<Int> work(n);
78+
std::vector<Int64> work(n);
7979

8080
// count the entries in each row into work
81-
for (Int i = 0; i < ptr.back(); ++i) {
81+
for (Int64 i = 0; i < ptr.back(); ++i) {
8282
++work[rows[i]];
8383
}
8484

8585
// sum row sums to obtain pointers
8686
counts2Ptr(ptrT, work);
8787

88-
for (Int j = 0; j < n; ++j) {
89-
for (Int el = ptr[j]; el < ptr[j + 1]; ++el) {
90-
Int i = rows[el];
88+
for (Int64 j = 0; j < n; ++j) {
89+
for (Int64 el = ptr[j]; el < ptr[j + 1]; ++el) {
90+
Int64 i = rows[el];
9191

9292
// entry (i,j) becomes entry (j,i)
93-
Int pos = work[i]++;
93+
Int64 pos = work[i]++;
9494
rowsT[pos] = j;
9595
valT[pos] = val[el];
9696
}
9797
}
9898
}
9999

100-
void childrenLinkedList(const std::vector<Int>& parent, std::vector<Int>& head,
101-
std::vector<Int>& next) {
100+
void childrenLinkedList(const std::vector<Int64>& parent,
101+
std::vector<Int64>& head, std::vector<Int64>& next) {
102102
// Create linked lists of children in elimination tree.
103103
// parent gives the dependencies of the tree,
104104
// head[node] is the first child of node,
105105
// next[head[node]] is the second child,
106106
// next[next[head[node]]] is the third child...
107107
// until -1 is reached.
108108

109-
Int n = parent.size();
109+
Int64 n = parent.size();
110110
head.assign(n, -1);
111111
next.assign(n, -1);
112-
for (Int node = n - 1; node >= 0; --node) {
112+
for (Int64 node = n - 1; node >= 0; --node) {
113113
if (parent[node] == -1) continue;
114114
next[node] = head[parent[node]];
115115
head[parent[node]] = node;
116116
}
117117
}
118118

119-
void reverseLinkedList(std::vector<Int>& head, std::vector<Int>& next) {
119+
void reverseLinkedList(std::vector<Int64>& head, std::vector<Int64>& next) {
120120
// Reverse the linked list of children of each node.
121121
// If a node has children (a -> b -> c -> -1), the reverse list contains
122122
// children (c -> b -> a -> -1).
123123

124-
const Int n = head.size();
124+
const Int64 n = head.size();
125125

126-
for (Int node = 0; node < n; ++node) {
127-
Int prev_node = -1;
128-
Int curr_node = head[node];
129-
Int next_node = -1;
126+
for (Int64 node = 0; node < n; ++node) {
127+
Int64 prev_node = -1;
128+
Int64 curr_node = head[node];
129+
Int64 next_node = -1;
130130

131131
while (curr_node != -1) {
132132
next_node = next[curr_node];
@@ -139,18 +139,18 @@ void reverseLinkedList(std::vector<Int>& head, std::vector<Int>& next) {
139139
}
140140
}
141141

142-
void dfsPostorder(Int node, Int& start, std::vector<Int>& head,
143-
const std::vector<Int>& next, std::vector<Int>& order) {
142+
void dfsPostorder(Int64 node, Int64& start, std::vector<Int64>& head,
143+
const std::vector<Int64>& next, std::vector<Int64>& order) {
144144
// Perform depth first search starting from root node and order the nodes
145145
// starting from the value start. head and next contain the linked list of
146146
// children.
147147

148-
std::stack<Int> stack;
148+
std::stack<Int64> stack;
149149
stack.push(node);
150150

151151
while (!stack.empty()) {
152-
const Int current = stack.top();
153-
const Int child = head[current];
152+
const Int64 current = stack.top();
153+
const Int64 child = head[current];
154154

155155
if (child == -1) {
156156
// no children left to order,
@@ -166,9 +166,9 @@ void dfsPostorder(Int node, Int& start, std::vector<Int>& head,
166166
}
167167
}
168168

169-
void processEdge(Int j, Int i, const std::vector<Int>& first,
170-
std::vector<Int>& maxfirst, std::vector<Int>& delta,
171-
std::vector<Int>& prevleaf, std::vector<Int>& ancestor) {
169+
void processEdge(Int64 j, Int64 i, const std::vector<Int64>& first,
170+
std::vector<Int64>& maxfirst, std::vector<Int64>& delta,
171+
std::vector<Int64>& prevleaf, std::vector<Int64>& ancestor) {
172172
// Process edge of skeleton matrix.
173173
// Taken from Tim Davis "Direct Methods for Sparse Linear Systems".
174174

@@ -181,21 +181,21 @@ void processEdge(Int j, Int i, const std::vector<Int>& first,
181181
maxfirst[i] = first[j];
182182

183183
// previous leaf of ith row subtree
184-
Int jprev = prevleaf[i];
184+
Int64 jprev = prevleaf[i];
185185

186186
// A(i,j) is in the skeleton matrix
187187
delta[j]++;
188188

189189
if (jprev != -1) {
190190
// find least common ancestor of jprev and j
191-
Int q = jprev;
191+
Int64 q = jprev;
192192
while (q != ancestor[q]) {
193193
q = ancestor[q];
194194
}
195195

196196
// path compression
197-
Int sparent;
198-
for (Int s = jprev; s != q; s = sparent) {
197+
Int64 sparent;
198+
for (Int64 s = jprev; s != q; s = sparent) {
199199
sparent = ancestor[s];
200200
ancestor[s] = q;
201201
}
@@ -208,18 +208,18 @@ void processEdge(Int j, Int i, const std::vector<Int>& first,
208208
prevleaf[i] = j;
209209
}
210210

211-
double getDiagStart(Int n, Int k, Int nb, Int n_blocks, std::vector<Int>& start,
212-
bool triang) {
211+
Int64 getDiagStart(Int64 n, Int64 k, Int64 nb, Int64 n_blocks,
212+
std::vector<Int64>& start, bool triang) {
213213
// start position of diagonal blocks for blocked dense formats
214214
start.assign(n_blocks, 0);
215-
for (Int i = 1; i < n_blocks; ++i) {
215+
for (Int64 i = 1; i < n_blocks; ++i) {
216216
start[i] = start[i - 1] + nb * (n - (i - 1) * nb);
217217
if (triang) start[i] -= nb * (nb - 1) / 2;
218218
}
219219

220-
Int jb = std::min(nb, k - (n_blocks - 1) * nb);
221-
double result = (double)start.back() + (double)(n - (n_blocks - 1) * nb) * jb;
222-
if (triang) result -= (double)jb * (jb - 1) / 2;
220+
Int64 jb = std::min(nb, k - (n_blocks - 1) * nb);
221+
Int64 result = start.back() + (n - (n_blocks - 1) * nb) * jb;
222+
if (triang) result -= jb * (jb - 1) / 2;
223223
return result;
224224
}
225225

highs/ipm/hipo/auxiliary/Auxiliary.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@
1111

1212
namespace hipo {
1313

14-
void counts2Ptr(std::vector<Int>& ptr, std::vector<Int>& w);
15-
void inversePerm(const std::vector<Int>& perm, std::vector<Int>& iperm);
16-
void subtreeSize(const std::vector<Int>& parent, std::vector<Int>& sizes);
17-
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
18-
std::vector<Int>& ptrT, std::vector<Int>& rowsT);
19-
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
20-
const std::vector<double>& val, std::vector<Int>& ptrT,
21-
std::vector<Int>& rowsT, std::vector<double>& valT);
22-
void childrenLinkedList(const std::vector<Int>& parent, std::vector<Int>& head,
23-
std::vector<Int>& next);
24-
void reverseLinkedList(std::vector<Int>& head, std::vector<Int>& next);
25-
void dfsPostorder(Int node, Int& start, std::vector<Int>& head,
26-
const std::vector<Int>& next, std::vector<Int>& order);
27-
void processEdge(Int j, Int i, const std::vector<Int>& first,
28-
std::vector<Int>& maxfirst, std::vector<Int>& delta,
29-
std::vector<Int>& prevleaf, std::vector<Int>& ancestor);
30-
double getDiagStart(Int n, Int k, Int nb, Int n_blocks, std::vector<Int>& start,
31-
bool triang = false);
14+
void counts2Ptr(std::vector<Int64>& ptr, std::vector<Int64>& w);
15+
void inversePerm(const std::vector<Int64>& perm, std::vector<Int64>& iperm);
16+
void subtreeSize(const std::vector<Int64>& parent, std::vector<Int64>& sizes);
17+
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
18+
std::vector<Int64>& ptrT, std::vector<Int64>& rowsT);
19+
void transpose(const std::vector<Int64>& ptr, const std::vector<Int64>& rows,
20+
const std::vector<double>& val, std::vector<Int64>& ptrT,
21+
std::vector<Int64>& rowsT, std::vector<double>& valT);
22+
void childrenLinkedList(const std::vector<Int64>& parent,
23+
std::vector<Int64>& head, std::vector<Int64>& next);
24+
void reverseLinkedList(std::vector<Int64>& head, std::vector<Int64>& next);
25+
void dfsPostorder(Int64 node, Int64& start, std::vector<Int64>& head,
26+
const std::vector<Int64>& next, std::vector<Int64>& order);
27+
void processEdge(Int64 j, Int64 i, const std::vector<Int64>& first,
28+
std::vector<Int64>& maxfirst, std::vector<Int64>& delta,
29+
std::vector<Int64>& prevleaf, std::vector<Int64>& ancestor);
30+
Int64 getDiagStart(Int64 n, Int64 k, Int64 nb, Int64 n_blocks,
31+
std::vector<Int64>& start, bool triang = false);
3232

3333
template <typename T>
34-
void permuteVector(std::vector<T>& v, const std::vector<Int>& perm) {
34+
void permuteVector(std::vector<T>& v, const std::vector<Int64>& perm) {
3535
// Permute vector v according to permutation perm.
3636
std::vector<T> temp_v(v);
37-
for (Int i = 0; i < v.size(); ++i) v[i] = temp_v[perm[i]];
37+
for (Int64 i = 0; i < v.size(); ++i) v[i] = temp_v[perm[i]];
3838
}
3939

4040
template <typename T>
41-
void permuteVectorInverse(std::vector<T>& v, const std::vector<Int>& iperm) {
41+
void permuteVectorInverse(std::vector<T>& v, const std::vector<Int64>& iperm) {
4242
// Permute vector v according to inverse permutation iperm.
4343
std::vector<T> temp_v(v);
44-
for (Int i = 0; i < v.size(); ++i) v[iperm[i]] = temp_v[i];
44+
for (Int64 i = 0; i < v.size(); ++i) v[iperm[i]] = temp_v[i];
4545
}
4646

4747
template <typename T>

0 commit comments

Comments
 (0)