Skip to content

Commit c72bfef

Browse files
committed
tclosure matbe ready
1 parent 17ad9f1 commit c72bfef

8 files changed

Lines changed: 32 additions & 11 deletions

File tree

b128.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ size_t mshow_stats(size_t size, size_t asize, const b128mat_t *a, const char *mn
4949
// check if two b128 compressed matrices :a and :b are equal
5050
// if a==b return -1
5151
// if a!=b return the row index>=0 containing the first difference
52-
int mequals(size_t size, const b128mat_t *a, const b128mat_t *b);
52+
int mequals_plain(size_t size, const b128mat_t *a, const b128mat_t *b);
5353
// sum two b128 matrices a and b writing the result to c
5454
// multiplication is done replacing scalar + by logical or
5555
void msum(size_t asize, const b128mat_t *a, const b128mat_t *b, b128mat_t *c);

b128ops.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,23 @@ size_t mshow_stats(size_t size, size_t asize, const b128mat_t *a, const char *mn
159159
// check if two b128 compressed matrices :a and :b are equal
160160
// if a==b return -1
161161
// if a!=b return the row index>=0 containing the first difference
162-
int mequals(size_t size, const b128mat_t *a, const b128mat_t *b)
162+
int mequals_plain(size_t size, const b128mat_t *a, const b128mat_t *b)
163163
{
164164
(void) size;
165165
assert(a!=NULL && b!=NULL);
166-
assert(a->size!=b->size);
166+
assert(a->size==b->size);
167167
for(size_t i=0; i<a->size*a->colb; i++)
168168
if(a->b[i]!=b->b[i]) return (int) (i/a->colb); // return row number of first difference
169169
return -1;
170170
}
171171

172+
// as above but return true if a and b are equal, false otherwise
173+
bool mequals(const b128mat_t *a, const b128mat_t *b) {
174+
assert(a!=NULL && b!=NULL);
175+
if(a->size != b->size) return false; // cannot say
176+
return mequals_plain(0, a, b) < 0;
177+
}
178+
172179

173180

174181
// matrix addition

k2.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ void mmake_pointer(const k2mat_t *a, k2mat_t *c);
136136
// if :a or :b have backp or main_diag, result is unknow and return INT32_MAX
137137
// otherwise if a==b return -d, where d>0 is the number of levels traversed
138138
// if a!=b return the level>=0 containing the first difference
139-
// Note that the results of sum and product operations never have backpoiners
140-
int mequals(size_t size, const k2mat_t *a, const k2mat_t *b);
139+
// Note that the results of sum and product operations never have backpointers
140+
int mequals_plain(size_t size, const k2mat_t *a, const k2mat_t *b);
141+
// as above but return a bool
142+
bool mequals(const k2mat_t *a, const k2mat_t *b);
141143
// return number of levels in the k2tree associated to a
142144
int k2tree_levels(size_t size, const k2mat_t *a);
143145
// copy the (submatrix) :a to :b resolving all backpointers and main_diag_1 flag

k2cpdf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int main(int argc, char* argv[]) {
164164
printf(" %zd (input) vs %zd (decompressed)\n",nz,nz_check_a);
165165
exit(1);
166166
}
167-
int d = mequals(a.fullsize, &a, &check_a);
167+
int d = mequals_plain(a.fullsize, &a, &check_a);
168168
if(d < 0) {
169169
if(verbose) printf("## Correct decompression!\n");
170170
} else {

k2io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ size_t mshow_stats(const k2mat_t *a, const char *mname,FILE *file) {
100100
fprintf(file," Tree size: %zu bytes, %zu bits, Bits x nonzero: %lf\n",
101101
(pos+1)/2 , 4*pos, 4.0*(double)(pos)/(double) nz);
102102
fprintf(file, " Total space (bits): %zu, Bits x nonzero: %lf\n",
103-
pos * 4 + bits_r + bits_p, (double) (pos * 4 + bits_r + bits_p) / (double) nz);
103+
pos * 4 + bits_r + bits_p + bits_sub, (double) (pos * 4 + bits_r + bits_p + bits_sub) / (double) nz);
104104
return nz;
105105
}
106106

k2ops.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int k2tree_equals_rec(size_t size, const k2mat_t *a, size_t *posa,
116116
// note: here all 0's matrices are considered of depth 1 even if they are empty
117117
// only the tree strucure is considered, not the main diagonal flag or backpointers
118118
// TODO: use k2copy_normalize to compare any pair of matrices
119-
int mequals(size_t size, const k2mat_t *a, const k2mat_t *b)
119+
int mequals_plain(size_t size, const k2mat_t *a, const k2mat_t *b)
120120
{
121121
assert(size>=2*MMsize);
122122
assert(a!=NULL && b!=NULL);
@@ -139,6 +139,15 @@ int mequals(size_t size, const k2mat_t *a, const k2mat_t *b)
139139
}
140140

141141

142+
// as above but return true if a and b are equal, false otherwise
143+
// todo: delete mequals_plain and use this one everywhere
144+
bool mequals(const k2mat_t *a, const k2mat_t *b) {
145+
assert(a!=NULL && b!=NULL);
146+
if(a->fullsize != b->fullsize) return false;
147+
if(a->realsize != b->realsize) return false;
148+
return mequals_plain(a->fullsize, a, b) < 0;
149+
}
150+
142151
// return number of levels in the k2_tree storing matrix :a
143152
// only the tree structure is considered, not the main_diagonal flag or backpointers
144153
// note: root with no children: 1 level

k2tclosure.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ int main (int argc, char **argv) {
130130
assert(a.backp==NULL);
131131
#endif
132132

133+
int iter=0;
133134
while(true) {
135+
if(verbose) printf("## Iteration %d\n", iter); iter++;
134136
#ifdef K2MAT
135137
// compute subtree info and write to file
136138
vu64_t z; // resizable array to contain the subtree sizes
@@ -149,6 +151,7 @@ int main (int argc, char **argv) {
149151
if(node_limit < min_node_limit) node_limit = min_node_limit; // minimum node limit (ensure at least 2 levels)
150152
if(verbose) printf("Computing sizes for subtrees larger than %zu nodes\n", node_limit);
151153
p = k2dfs_sizes_limit(a.fullsize,&a,&pos,&z,(size_t)node_limit); // visit tree, compute and save subtree sizes in z
154+
node_limit =0; // reset for next iterqation
152155
}
153156
a.subtinfo_size = z.n;
154157
a.subtinfoarray = a.subtinfo = z.v; // save subtree info in a
@@ -162,13 +165,13 @@ int main (int argc, char **argv) {
162165
if(verbose) printf("Multiplying (A+I)A\n");
163166
mmult(&b,&a,&aIa); // aIa = (a+I)a
164167
if(verbose) printf("Checking if fixed point\n");
165-
int eq = mequals(a.fullsize, &a,&aIa);
166-
if(eq <0) break;
168+
if(mequals(&a,&aIa)==true) break;
167169
k2mat_t temp = a; a = aIa; aIa = temp; // swap a and aIa for the next iteration
168170
matrix_free(&aIa);
169171
}
170172
if(verbose) printf("Fixed point reached, stopping\n");
171173
if(verbose) mshow_stats(&aIa,"Transitive closure matrix",stdout);
174+
msave_to_file(&aIa, oname);
172175
// done
173176
matrix_free(&aIa);
174177
matrix_free(&a);

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ k2pagerank.o: k2pagerank.c k2.h
4141
k2cpdf.x: k2cpdf.o k2ops.o bbm.o vu64.o pointers.o rank_0000.o libsais/liblibsais.a
4242
$(CC) $(LDFLAGS) -o $@ $^
4343

44-
k2ops.o: k2ops.c k2text.c k2aux.c minimats.c k2.h bbm.h
44+
k2ops.o: k2ops.c k2text.c k2aux.c k2io.c minimats.c k2.h bbm.h
4545
$(CC) $(CFLAGS) $(EXTRA) -c -o $@ $<
4646

4747
pointers.o: pointers.c pointers.h

0 commit comments

Comments
 (0)