DSDP
dsdpdsmat.c
Go to the documentation of this file.
1 #include "dsdpdsmat_impl.h"
2 #include "dsdpdsmat.h"
3 #include "dsdpsys.h"
8 #define DSDPNoOperationError(a); { DSDPSETERR1(1,"Delta S Matrix type: %s, Operation not defined\n",(a).dsdpops->matname); }
9 #define DSDPChkMatError(a,b); { if (b){ DSDPSETERR1(b,"Delta S Matrix type: %s,\n",(a).dsdpops->matname); } }
10 
11 #undef __FUNCT__
12 #define __FUNCT__ "DSDPDSMatGetType"
13 int DSDPDSMatGetType(DSDPDSMat A, int *id){
14  DSDPFunctionBegin;
15  *id=A.dsdpops->id;
16  DSDPFunctionReturn(0);
17 }
18 
19 
20 #undef __FUNCT__
21 #define __FUNCT__ "DSDPDSMatSetData"
22 
31 int DSDPDSMatSetData(DSDPDSMat *M, struct DSDPDSMat_Ops* ops, void*data){
32  int info;
33  DSDPFunctionBegin;
34  (*M).dsdpops=ops;
35  (*M).matdata=data;
36  info=DSDPDSMatTest(*M); DSDPChkMatError(*M,info);
37  DSDPFunctionReturn(0);
38 }
39 
40 
41 #undef __FUNCT__
42 #define __FUNCT__ "DSDPDSMatGetSize"
43 
51  int info;
52  DSDPFunctionBegin;
53  if (A.dsdpops->matgetsize){
54  info=(A.dsdpops->matgetsize)(A.matdata,n); DSDPChkMatError(A,info);
55  } else {
56  DSDPNoOperationError(A);
57  }
58  DSDPFunctionReturn(0);
59 }
60 
61 
62 #undef __FUNCT__
63 #define __FUNCT__ "DSDPDSMatDestroy"
64 
71  int info;
72  DSDPFunctionBegin;
73  if (!(*A).dsdpops){ return 0;}
74  if ((*A).dsdpops->matdestroy){
75  info=((*A).dsdpops->matdestroy)((*A).matdata); DSDPChkMatError(*A,info);
76  } else {
77  /* DSDPNoOperationError(1); */
78  }
79  info=DSDPDSMatInitialize(A); DSDPCHKERR(info);
80  DSDPFunctionReturn(0);
81 }
82 
83 
84 #undef __FUNCT__
85 #define __FUNCT__ "DSDPDSMatView"
86 
93  int info;
94  if (A.dsdpops->matview){
95  info=(A.dsdpops->matview)(A.matdata); DSDPChkMatError(A,info);
96  } else {
97  printf("No viewer available for matrix type: %s",A.dsdpops->matname);
98  }
99  DSDPFunctionReturn(0);
100 }
101 
102 
103 #undef __FUNCT__
104 #define __FUNCT__ "DSDPDSMatZeroEntries"
105 
111  int info;
112  DSDPFunctionBegin;
113  if (A.dsdpops->matzeroentries){
114  info=(A.dsdpops->matzeroentries)(A.matdata); DSDPChkMatError(A,info);
115  } else {
116  DSDPNoOperationError(A);
117  }
118  DSDPFunctionReturn(0);
119 }
120 
121 #undef __FUNCT__
122 #define __FUNCT__ "DSDPDSMatSetArray"
123 
131  int info,n,nn;
132  double *ds;
133  DSDPFunctionBegin;
134  if (A.dsdpops->matseturmat){
135  info=DSDPVMatGetSize(T,&n);DSDPCHKERR(info);
136  info=DSDPVMatGetArray(T, &ds, &nn); DSDPCHKERR(info);
137  info=(A.dsdpops->matseturmat)(A.matdata,ds,nn,n); DSDPChkMatError(A,info);
138  info=DSDPVMatRestoreArray(T, &ds, &nn); DSDPCHKERR(info);
139  } else {
140  DSDPNoOperationError(A);
141  }
142  DSDPFunctionReturn(0);
143 }
144 
145 #undef __FUNCT__
146 #define __FUNCT__ "DSDPDSMatMult"
147 
155  int n,info;
156  double *x,*y;
157 
158  DSDPFunctionBegin;
159  if (A.dsdpops->matmult){
160  info=SDPConeVecGetArray(X,&x); DSDPCHKERR(info);
161  info=SDPConeVecGetArray(Y,&y); DSDPCHKERR(info);
162  info=SDPConeVecGetSize(Y,&n); DSDPCHKERR(info);
163  info=(A.dsdpops->matmult)(A.matdata,x,y,n); DSDPChkMatError(A,info);
164  info=SDPConeVecRestoreArray(X,&x); DSDPCHKERR(info);
165  info=SDPConeVecRestoreArray(Y,&y); DSDPCHKERR(info);
166  } else {
167  DSDPNoOperationError(A);
168  }
169  DSDPFunctionReturn(0);
170 }
171 
172 #undef __FUNCT__
173 #define __FUNCT__ "DSDPDSVecVec"
174 
181 int DSDPDSMatVecVec(DSDPDSMat A, SDPConeVec X, double *vAv){
182  int n,info;
183  double *x;
184 
185  DSDPFunctionBegin;
186  if (A.dsdpops->matvecvec){
187  info=SDPConeVecGetArray(X,&x); DSDPCHKERR(info);
188  info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info);
189  info=(A.dsdpops->matvecvec)(A.matdata,x,n,vAv); DSDPChkMatError(A,info);
190  info=SDPConeVecRestoreArray(X,&x); DSDPCHKERR(info);
191  } else {
192  DSDPNoOperationError(A);
193  }
194  DSDPFunctionReturn(0);
195 }
196 
197 #undef __FUNCT__
198 #define __FUNCT__ "DSDPDSMatCheck"
199 int DSDPDSMatCheck(DSDPDSMat DS,SDPConeVec W1,SDPConeVec W2,DSDPVMat T){
200  DSDPFunctionBegin;
201  DSDPFunctionReturn(0);
202 }
203 
204 
205 static struct DSDPDSMat_Ops dsdpmatops2;
206 static const char* dsmatname="NOT SET YET";
207 #undef __FUNCT__
208 #define __FUNCT__ "DSDPDSMatOpsInitialize"
209 
215  aops->matseturmat=0;
216  aops->matview=0;
217  aops->matdestroy=0;
218  aops->matgetsize=0;
219  aops->matzeroentries=0;
220  aops->matmult=0;
221  aops->mattest=0;
222  aops->matvecvec=0;
223  aops->id=0;
224  aops->matname=dsmatname;
225  return 0;
226 }
227 
228 #undef __FUNCT__
229 #define __FUNCT__ "DSDPDSMatTest"
230 int DSDPDSMatTest(DSDPDSMat A){
231  int info;
232  DSDPFunctionBegin;
233  if (A.dsdpops==0 || A.dsdpops==&dsdpmatops2){
234  } else if (A.dsdpops->mattest){
235  DSDPLogInfo(0,120,"Start to set DS Matrix\n");
236  info=(A.dsdpops->mattest)(A.matdata); DSDPChkMatError(A,info);
237  DSDPLogInfo(0,120,"Done set DS Matrix\n");
238  } else {
239  /*
240  DSDPNoOperationError(A);
241  */
242  }
243  DSDPFunctionReturn(0);
244 }
245 
246 
247 #undef __FUNCT__
248 #define __FUNCT__ "DSDPDSMatInitialize"
249 
255  int info;
256  DSDPFunctionBegin;
257  info=DSDPDSMatOpsInitialize(&dsdpmatops2); DSDPCHKERR(info);
258  info=DSDPDSMatSetData(B, &dsdpmatops2, 0); DSDPCHKERR(info);
259  DSDPFunctionReturn(0);
260 }
261 
int DSDPVMatGetArray(DSDPVMat X, double **v, int *nn)
Get the array that stores the matrix.
Definition: dsdpxmat.c:211
Error handling, printing, and profiling.
int DSDPDSMatSetArray(DSDPDSMat A, DSDPVMat T)
Set values into the matrix.
Definition: dsdpdsmat.c:130
int DSDPVMatGetSize(DSDPVMat X, int *n)
Get number of rows and columns.
Definition: dsdpxmat.c:65
int DSDPVMatRestoreArray(DSDPVMat X, double **v, int *nn)
Restore the array that stores the matrix.
Definition: dsdpxmat.c:233
The interface between the SDPCone and the Delta S matrix.
int DSDPDSMatGetSize(DSDPDSMat A, int *n)
Set the opaque pointer and function pointers to the matrix.
Definition: dsdpdsmat.c:50
Structure of function pointers that each SDP Delta S matrix type (sparse, dense, diagonal,...
int DSDPDSMatInitialize(DSDPDSMat *B)
Set pointers to null.
Definition: dsdpdsmat.c:254
Vector whose length corresponds to dimension of a block in a cone.
Definition: sdpconevec.h:13
int DSDPDSMatOpsInitialize(struct DSDPDSMat_Ops *aops)
Set pointers to null.
Definition: dsdpdsmat.c:214
int DSDPDSMatZeroEntries(DSDPDSMat A)
Zero the entries in the matrix.
Definition: dsdpdsmat.c:110
int DSDPDSMatVecVec(DSDPDSMat A, SDPConeVec X, double *vAv)
Compute the product x' A x.
Definition: dsdpdsmat.c:181
int DSDPDSMatDestroy(DSDPDSMat *A)
Free the data structure.
Definition: dsdpdsmat.c:70
Symmetric Delta S matrix for one block in the semidefinite cone.
Symmetric Delta S matrix for one block in the semidefinite cone.
Definition: dsdpdsmat.h:23
Dense symmetric matrix for one block in the semidefinite cone.
Definition: dsdpxmat.h:17
int DSDPDSMatMult(DSDPDSMat A, SDPConeVec X, SDPConeVec Y)
Set values into the matrix.
Definition: dsdpdsmat.c:154
int DSDPDSMatView(DSDPDSMat A)
Print the matrix.
Definition: dsdpdsmat.c:92