Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactory readprob with functions usable for Julia wrapper #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ int sdp(int n, int k, struct blockmatrix C, double *a, double constant_offset,
double *dy, double *dy1, double *Fp, int printlevel,
struct paramstruc parameters);

int parametrized_sdp(int n, int k, struct blockmatrix C, double *a,
struct constraintmatrix *constraints, double constant_offset,
struct blockmatrix *pX, double **py, struct blockmatrix *pZ,
double *ppobj, double *pdobj, int printlevel, struct paramstruc params);

int easy_sdp(int n, int k, struct blockmatrix C, double *a,
struct constraintmatrix *constraints, double constant_offset,
struct blockmatrix *pX, double **py, struct blockmatrix *pZ,
Expand Down
122 changes: 122 additions & 0 deletions lib/debug-mat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include <stdio.h>
#include "blockmat.h"


void printb(struct blockrec b) {
int i;
int size;
printf("blockrec:\n");
printf(" blockcategory: %d\n", (int) b.blockcategory);
printf(" blocksize: %d\n", b.blocksize);
printf(" data.vec: %p\n", b.data.vec);
if (b.blocksize <= 16) {
switch (b.blockcategory) {
case MATRIX:
size = b.blocksize * b.blocksize;
for (i = 0; i < size; i++)
printf(" %f\n", b.data.vec[i]);
break;
case DIAG:
for (i = 1; i <= b.blocksize; i++)
printf(" %f\n", b.data.vec[i]);
break;
default:
fprintf(stderr, "UNKNOWN blockcat: %d",
(int) b.blockcategory);
}
}
}


void printb_(struct blockrec *b) {
printb(*b);
}


void print_sizeof() {
printf("sizeof(void*) %d\n",
(int) sizeof(void*));
printf("sizeof(int) %d\n",
(int) sizeof(int));
printf("sizeof(enum blockcat) %d\n",
(int) sizeof(enum blockcat));
printf("sizeof(struct blockrec) %d\n",
(int) sizeof(struct blockrec));
printf("sizeof(struct blockmatrix) %d\n",
(int) sizeof(struct blockmatrix));
printf("sizeof(struct sparseblock) %d\n",
(int) sizeof(struct sparseblock));
}



void printm(struct blockmatrix A) {
int blk;
printf("A.nblocks = %d\n", A.nblocks);
printf("A.blocks = %p\n", A.blocks);
for (blk=1; blk <= A.nblocks; blk++) {
printf("block[%d]: %p\n", blk, &A.blocks[blk]);
printb(A.blocks[blk]);
}

}

FILE *fid;

void print_sparse_block(struct sparseblock *b) {
int i;
fid = stdout;
fprintf(fid, "\n* Printing block: %p\n", b);
if (b == NULL)
return;
fprintf(fid, " next: %p\n", b->next);
fprintf(fid, " nextbyblock: %p\n", b->nextbyblock);
fprintf(fid, " constraintnum: %d\n", b->constraintnum);
fprintf(fid, " blocknum: %d\n", b->blocknum);
fprintf(fid, " blocksize: %d\n", b->blocksize);
fprintf(fid, " numentries: %d\n", b->numentries);
if (b->blocksize <= 30) {
for (i = 1; i <= b->numentries; i++) {
fprintf(fid, " block[%d, %d] = %f\n",
b->iindices[i],
b->jindices[i],
b->entries[i]);
}
} else {
fprintf(fid, " TOO LARGE\n");
}
print_sparse_block(b->next);
}

void print_constraints(int k,
struct constraintmatrix *constraints)
{
int i, j;
fid = stdout;
struct sparseblock *p;

fprintf(fid, "constraints == %p\n", constraints);

for (i=1; i<=k; i++)
{
fprintf(fid, "\n\nprinting constraints[%d].blocks\n", i);
p=constraints[i].blocks;
while (p != NULL)
{
fprintf(fid, "p == %p\n\n", p);
print_sparse_block(p);
fprintf(fid, "\n");
for (j=1; j<=p->numentries; j++)
{
fprintf(fid, "i=%d, j=%d\n", i, j);
fprintf(fid,"%d %d %d %d %f \n",
i,
p->blocknum,
p->iindices[j],
p->jindices[j],
p->entries[j]);
};
p=p->next;
};
};
}
33 changes: 24 additions & 9 deletions lib/easysdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,33 @@ int easy_sdp(n,k,C,a,constraints,constant_offset,pX,py,pZ,ppobj,pdobj)
struct blockmatrix *pZ;
double *ppobj;
double *pdobj;
{
struct paramstruc params;
int printlevel;
/*
* Initialize the parameters.
*/
initparams(&params,&printlevel);
return parametrized_sdp(n,k,C,a,constraints,constant_offset,pX,py,pZ,ppobj,pdobj,printlevel,params);
}

int parametrized_sdp(n,k,C,a,constraints,constant_offset,pX,py,pZ,ppobj,pdobj,printlevel,params)
int n;
int k;
struct blockmatrix C;
double *a;
struct constraintmatrix *constraints;
double constant_offset;
struct blockmatrix *pX;
double **py;
struct blockmatrix *pZ;
double *ppobj;
double *pdobj;
int printlevel;
struct paramstruc params;
{
int ret;
struct constraintmatrix fill;
struct paramstruc params;
struct blockmatrix work1;
struct blockmatrix work2;
struct blockmatrix work3;
Expand All @@ -53,7 +76,6 @@ int easy_sdp(n,k,C,a,constraints,constant_offset,pX,py,pZ,ppobj,pdobj)
double *dy1;
double *rhs;
double *besty;
int printlevel;
int ldam;
struct sparseblock **byblocks;
struct sparseblock *ptr;
Expand All @@ -68,13 +90,6 @@ int easy_sdp(n,k,C,a,constraints,constant_offset,pX,py,pZ,ppobj,pdobj)
int denseblocks;
int numblocks;

/*
* Initialize the parameters.
*/

initparams(&params,&printlevel);


/*
* Allocate working storage
*/
Expand Down
Loading