Skip to content

Commit 158affb

Browse files
committed
comparing b128 annd k2
1 parent 4cea446 commit 158affb

10 files changed

Lines changed: 35 additions & 83 deletions

File tree

.github/workflows/c.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,22 @@ jobs:
2424
- name: run
2525
run: ./prodtest.sh web cnr80k eu80k goo80k goo120k
2626

27-
- name: uncomporess
27+
- name: uncompress
2828
run: |
2929
./k2sparse.x -d web/cnr80k.k2 -o web/cnr80k.txt
3030
./k2sparse.x -d web/eu80k.k2 -o web/eu80k.txt
3131
./k2sparse.x -d web/goo80k.k2 -o web/goo80k.txt
32-
./k2sparse.x -d web/goo120k.k2 -o web/goo120k.txt
32+
./k2sparse.x -d web/goo120k.k2 -o web/goo120k.txt
33+
34+
- name: b128 test
35+
util/sparsetr -s 40000 web/cnr80k.txt -o web/cnr40k.txt
36+
./b128sparse.x -s 40000 web/cnr40k.txt -o web/cnr40k.b128
37+
./b128unary.x web/cnr40k.b128
38+
./matrixcmp.x web/cnr40k.txt web/cnr40k.b128.0.txt
39+
./k2sparse.x web/cnr40k.txt -o web/cnr40k.k2
40+
./k2unary.x web/cnr40k.k2
41+
./matrixcmp.x web/cnr40k.txt web/cnr40k.k2.0.txt
42+
./matrixcmp.x web/cnr40k.b128.1sq.txt web/cnr40k.k2.1sq.txt
3343

3444
- name: big transpose test
3545
run: ./sumtest.sh web/*.txt

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"request": "launch",
3636
"program": "${fileDirname}/k2unary.x",
3737
//"args": [ "-o", "tmp/poli3.2", "-I", "tmp/poli3.ck2.p", "tmp/poli3.ck2"
38-
// "args": [ "-o", "web/cnr80k.txt.2", "web/cnr80k.txt.k2"
39-
"args": [ "-o", "web/cnr80k.txt.2", "web/cnr80k.txt.ck2", "-I", "web/cnr80k.txt.ck2.p"
38+
"args": [ "-o", "web/goo120k.txt.2", "web/goo120k.txt.k2"
39+
// "args": [ "-o", "web/cnr80k.txt.2", "web/cnr80k.txt.ck2", "-I", "web/cnr80k.txt.ck2.p"
4040
],
4141
"stopAtEntry": true,
4242
"cwd": "${fileDirname}",

k2aux.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,15 @@ k2mat_t k2jump(size_t size, const k2mat_t *a)
529529
// the submatrices are not minimats since we are not at the last level of the tree
530530
// :a is not all 0's, it could be all 1's
531531
// note: a could be open ended
532-
// backpointer should have been already followed
532+
// backpointers should have been already followed
533533
// main_diag_1 if present is transmitted to the diagonmal submatrices
534534
void k2split_k2(const k2mat_t *a, k2mat_t b[2][2])
535535
{
536536
assert(a!=NULL && b!=NULL);
537537
size_t size = a->fullsize;
538538
assert(size>2*MMsize);
539539
assert(size%2==0);
540-
assert(a->main_diag_1==false || a->realsize>0); // if main_dag real size mus be well defined
540+
assert(a->main_diag_1==false || a->realsize>0); // if main_diag real size mus be well defined
541541
assert(a->open_ended || !k2is_empty(a)); // k2is_empty cannot be called for an open ended matrix
542542
// init size
543543
for(int i=0;i<4;i++) {
@@ -618,7 +618,7 @@ void k2split_k2(const k2mat_t *a, k2mat_t b[2][2])
618618
subt_size[0] = k2treesize(a)-1;
619619
else { // if treesize not available compute subtree size with a visit
620620
size_t next=pos;
621-
k2dfs_visit_fast(size/2,a,&next);
621+
k2dfs_visit_fast(size/2,a,&next); // it would do the same visit later
622622
subt_size[0] = next - pos;
623623
}
624624
}
@@ -629,9 +629,9 @@ void k2split_k2(const k2mat_t *a, k2mat_t b[2][2])
629629
int i=k/2; int j=k%2;
630630
if(root & (1<<k)) { // k-th child is non empty
631631
if(a->subtinfo || nchildren==1) next = pos + subt_size[child]; // jump to end of submatrix
632-
else k2dfs_visit_fast(size/2,a,&next); // move to end of submatrix
633-
k2clone_submatrix(a, pos, next, &b[i][j]); // create pointer to submatrix
634-
pos = next; // advance to next item
632+
else k2dfs_visit_fast(size/2,a,&next); // move to end of submatrix
633+
k2clone_submatrix(a, pos, next, &b[i][j]); // create pointer to submatrix
634+
pos = next; // advance to next item
635635
if(a->subtinfo) {
636636
b[i][j].subtinfo = subt_info[child]; // save subtinfo if available
637637
b[i][j].subtinfo_size = subt_info_size[child++]; // save subtinfo_size and advance child
@@ -650,7 +650,7 @@ void k2split_k2(const k2mat_t *a, k2mat_t b[2][2])
650650
b[1][1].realsize = a->realsize - size/2;
651651
}
652652
else {
653-
b[0][0].realsize = size/2; // b[1][1] has not main_diag_1
653+
b[0][0].realsize = a->realsize; // b[1][1] has not main_diag_1
654654
}
655655
assert(b[0][0].realsize <= b[0][0].fullsize);
656656
assert(b[1][1].realsize <= b[1][1].fullsize);

k2ops.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void k2copy_normalise(const k2mat_t *a, k2mat_t *b)
210210
// if :a has main diag build ad-hoc identity
211211
// and normalize by multiplication
212212
if(a->main_diag_1) {
213-
k2mat_t c = mat_identity(a->realsize);
213+
k2mat_t c = mat_identity(a);
214214
mmult(a,&c,b);
215215
k2_free(&c);
216216
}
@@ -243,9 +243,7 @@ k2mat_t mat_zero(const k2mat_t *b) {
243243

244244
// creates a size x size identity matrix
245245
k2mat_t mat_identity(const k2mat_t *b) {
246-
k2mat_t a = K2MAT_INITIALIZER;
247-
a.realsize = b->realsize;
248-
a.fullsize = b->fullsize;
246+
k2mat_t a = mat_zero(b);
249247
madd_identity(&a);
250248
return a;
251249
}
@@ -714,7 +712,7 @@ void mvmult_slow(size_t asize, const k2mat_t *a, size_t size, double *x, double
714712
// the case in which :a or b: are empty (all 0's or Identity) is handled in the caller
715713
// the case size==2*MMsize is handled in the caller
716714
// main_diag_1 flag is handled by k2split_k2()
717-
// :a or b: can be backpointers, the are habdled by k2jump
715+
// :a or b: can be backpointers, they are handled by k2jump
718716
static void split_and_rec(size_t size, const k2mat_t *a, const k2mat_t *b, k2mat_t *c)
719717
{
720718
assert(size>2*MMsize);

k2text.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,8 @@ static void mdecode_to_textfile(FILE *outfile, size_t msize, size_t i, size_t j,
970970
assert(c->offset==0); // we are never working on submatrices
971971
assert(size%2==0 && size>=2*MMsize);
972972
assert(i%MMsize==0 && j%MMsize==0);
973-
assert(i<msize+2*size && j<msize+2*size);
973+
// assert(i<msize+2*size && j<msize+2*size); // I can remember why the +2*size was needed, see following line
974+
assert(i<msize && j<msize);
974975
assert(!c->main_diag_1 || i==j); // if main_diag_1 is on we must be on a diagonal submatrix
975976

976977
if(size==2*MMsize) { // base case

k2unary.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
bool Use_all_ones_node; // not used: added for compatibility with k2mat
3030
bool Extended_edf; // not used: added for compatibility with k2mat
3131
#endif
32-
// used by both matrix types
33-
#define default_ext ".unary"
3432

3533
// static functions at the end of the file
3634
static void usage_and_exit(char *name);
@@ -115,16 +113,16 @@ int main (int argc, char **argv) {
115113

116114
// add main diagonal 1's
117115
madd_identity(&a);
118-
// printf("Caution: madd_identity may add 1's also outside the original matrix size!\n");
119116
sprintf(oname,"%s.1.txt",outfile);
117+
if(verbose) mshow_stats(&a,oname,stdout);
120118
mwrite_to_textfile(&a, oname);
121119

122-
// squaring
120+
// squaring (using a single copy of the :a matrix)
123121
k2mat_t asq = K2MAT_INITIALIZER;
124122
mmult(&a,&a,&asq);
125123
if(verbose) mshow_stats(&asq,"(A+I)^2",stdout);
126124
sprintf(oname,"%s.1sq.txt",outfile);
127-
msave_to_file(&asq,oname);
125+
mwrite_to_textfile(&asq,oname);
128126

129127
// done
130128
matrix_free(&a);
@@ -141,16 +139,14 @@ static void usage_and_exit(char *name)
141139
fprintf(stderr,"Usage:\n\t %s [options] infile\n\n",name);
142140
fprintf(stderr,"Demo of unary operations on the compressed matrices stored in infile\n\n");
143141
fputs("Options:\n",stderr);
144-
fprintf(stderr,"\t-n do not write output file, only show stats\n");
145-
fprintf(stderr,"\t-o out outfile name (def. infile%s)\n",default_ext);
142+
fprintf(stderr,"\t-o out outfile base name (def. infile)\n");
146143
#ifdef K2MAT
147144
fprintf(stderr,"\t-i info infile subtree info file\n");
148145
fprintf(stderr,"\t-I info infile backpointers file\n");
149146
fprintf(stderr,"\t-r size rank block size for k2 compression (def. 64)\n");
150147
fprintf(stderr,"\t-e compute subtree info on the fly (def. no)\n");
151148
fprintf(stderr,"\t-x do not compact new 1's submatrices in the result matrix\n");
152149
#endif
153-
fprintf(stderr,"\t-q use a single copy when squaring a matrix\n");
154150
fprintf(stderr,"\t-h show this help message\n");
155151
fprintf(stderr,"\t-v verbose\n\n");
156152
exit(1);

minimats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void minimat_to_bbm(uint8_t *m, size_t msize, size_t i, size_t j, size_t size, m
267267
// :size is the size of the minimat :a
268268
void minimat_to_text(FILE *f, size_t msize, size_t i, size_t j, size_t size, minimat_t a) {
269269
assert(size==MMsize);
270-
assert(i<msize+2*size && j<msize+2*size);
270+
assert(i<msize+2*size && j<msize+2*size); // again, why the + 2*size
271271
for(size_t ii=0; ii<size; ii++)
272272
for(size_t jj=0; jj<size; jj++)
273273
if(i+ii<msize && j+jj<msize) { // inside the matrix

submatrix.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

sumtest.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ do
4343

4444
# testing k2unary.x ie A+0 and A+I
4545
echo "===== add diagonal to sparse matrix: $f"
46-
$timecmd -f"$tf" ./sparsetr.py -d -o $f.sparse.1 $f
46+
$timecmd -f"$tf" util/sparsetr.py -d -o $f.sparse.1 $f
4747

4848
echo "===== compress and check matrix $f in formats k2 and k4"
4949
$timecmd -f"$tf" ./k2sparse.x -cv -o $f.k2 $f
5050
$timecmd -f"$tf" ./k2sparse.x -c -o $f.k4 -m4 $f
5151

52-
echo "==== add 0, add I and compute (A+I)^2==="
52+
echo "==== add 0, add I and compute (A+I)^2 ==="
5353
$timecmd -f"$tf" ./k2unary.x -o $f.2 $f.k2
5454
$timecmd -f"$tf" ./k2unary.x -o $f.4 $f.k4
5555

@@ -68,10 +68,10 @@ do
6868

6969
# testing k2sum.x A+A^t
7070
echo "===== transpose sparse matrix: $f"
71-
$timecmd -f"$tf" ./sparsetr.py -t -o sparse.tr $f
71+
$timecmd -f"$tf" util/sparsetr.py -t -o sparse.tr $f
7272
# this is A+A^t = A^t + A
7373
echo "===== make symmetric sparse matrix: $f"
74-
$timecmd -f"$tf" ./sparsetr.py -S -o sparse.sym $f
74+
$timecmd -f"$tf" util/sparsetr.py -S -o sparse.sym $f
7575

7676
echo "===== compress transposed matrix $f in formats k2 and k4"
7777
$timecmd -f"$tf" ./k2sparse.x -o $f.tr.k2 sparse.tr
File renamed without changes.

0 commit comments

Comments
 (0)