DSDP
|
00001 #include "dsdpdualmat_impl.h" 00002 #include "dsdpdualmat.h" 00003 #include "dsdpsys.h" 00004 00010 #define DSDPNoOperationError(a); { DSDPSETERR1(1,"Dual natrix type: %s, Operation not defined\n",(a).dsdpops->matname);} 00011 #define DSDPChkDMatError(a,b); { if (b){ DSDPSETERR1(b,"Dual natrix type: %s,\n",(a).dsdpops->matname);} } 00012 00013 static int sdpdualsolve=0,sdpdualinvert=0; 00014 00015 #undef __FUNCT__ 00016 #define __FUNCT__ "DSDPDualMatEventZero" 00017 int DSDPDualMatEventZero(void){ 00018 DSDPFunctionBegin; 00019 sdpdualinvert=0;sdpdualsolve=0; 00020 DSDPFunctionReturn(0); 00021 } 00022 00023 #undef __FUNCT__ 00024 #define __FUNCT__ "DSDPDualMatEventInitialize" 00025 int DSDPDualMatEventInitialize(void){ 00026 DSDPFunctionBegin; 00027 if (sdpdualsolve==0){DSDPEventLogRegister("SDP SSolve",&sdpdualsolve);} 00028 DSDPFunctionReturn(0); 00029 } 00030 00031 #undef __FUNCT__ 00032 #define __FUNCT__ "DSDPDualMatGetType" 00033 int DSDPDualMatGetType(DSDPDualMat S, int *id){ 00034 DSDPFunctionBegin; 00035 *id=S.dsdpops->id; 00036 DSDPFunctionReturn(0); 00037 } 00038 00039 #undef __FUNCT__ 00040 #define __FUNCT__ "DSDPDualMatSetData" 00041 00049 int DSDPDualMatSetData(DSDPDualMat *S, struct DSDPDualMat_Ops* ops, void*data){ 00050 int info; 00051 DSDPFunctionBegin; 00052 (*S).dsdpops=ops; 00053 (*S).matdata=data; 00054 info=DSDPDualMatTest(*S);DSDPCHKERR(info); 00055 DSDPFunctionReturn(0); 00056 } 00057 00058 #undef __FUNCT__ 00059 #define __FUNCT__ "DSDPDualMatDestroy" 00060 00065 int DSDPDualMatDestroy(DSDPDualMat *S){ 00066 int info; 00067 DSDPFunctionBegin; 00068 if ( S && (*S).dsdpops && (*S).dsdpops->matdestroy){ 00069 info=((*S).dsdpops->matdestroy)((*S).matdata); DSDPChkDMatError(*S,info); 00070 } else { 00071 /* 00072 DSDPNoOperationError(*S); 00073 */ 00074 } 00075 info=DSDPDualMatSetData(S,0,0); DSDPCHKERR(info); 00076 DSDPFunctionReturn(0); 00077 } 00078 00079 #undef __FUNCT__ 00080 #define __FUNCT__ "DSDPDualMatGetSize" 00081 00087 int DSDPDualMatGetSize(DSDPDualMat S,int*n){ 00088 int info; 00089 DSDPFunctionBegin; 00090 if (S.dsdpops->matgetsize){ 00091 info=(S.dsdpops->matgetsize)(S.matdata,n); DSDPChkDMatError(S,info); 00092 } else { 00093 DSDPNoOperationError(S); 00094 } 00095 DSDPFunctionReturn(0); 00096 } 00097 00098 #undef __FUNCT__ 00099 #define __FUNCT__ "DSDPDualMatGetArray" 00100 int DSDPDualMatGetArray(DSDPDualMat S, double **v, int *n){ 00101 int info; 00102 DSDPFunctionBegin; 00103 if (S.dsdpops->matgetarray){ 00104 info=(S.dsdpops->matgetarray)(S.matdata,v,n); DSDPChkDMatError(S,info); 00105 } else { 00106 *v=0; 00107 *n=0; 00108 } 00109 DSDPFunctionReturn(0); 00110 } 00111 00112 00113 #undef __FUNCT__ 00114 #define __FUNCT__ "DSDPDualMatLogDeterminant" 00115 00122 int DSDPDualMatLogDeterminant(DSDPDualMat S,double *logdet){ 00123 int info; 00124 DSDPFunctionBegin; 00125 if (S.dsdpops->matlogdet){ 00126 info=(S.dsdpops->matlogdet)(S.matdata,logdet); DSDPChkDMatError(S,info); 00127 } else { 00128 DSDPNoOperationError(S); 00129 } 00130 DSDPFunctionReturn(0); 00131 } 00132 00133 #undef __FUNCT__ 00134 #define __FUNCT__ "DSDPDualMatView" 00135 00140 int DSDPDualMatView(DSDPDualMat S){ 00141 int info; 00142 DSDPFunctionBegin; 00143 if (S.dsdpops->matview){ 00144 info=(S.dsdpops->matview)(S.matdata); DSDPChkDMatError(S,info); 00145 } else { 00146 DSDPNoOperationError(S); 00147 } 00148 DSDPFunctionReturn(0); 00149 } 00150 00151 00152 #undef __FUNCT__ 00153 #define __FUNCT__ "DSDPDualMatSetArray" 00154 00160 int DSDPDualMatSetArray(DSDPDualMat S, DSDPVMat T){ 00161 double *ss; 00162 int info,n,nn; 00163 DSDPFunctionBegin; 00164 if (S.dsdpops->matseturmat){ 00165 info=DSDPVMatGetSize(T,&n); DSDPCHKERR(info); 00166 info=DSDPVMatGetArray(T,&ss,&nn); DSDPCHKERR(info); 00167 info=(S.dsdpops->matseturmat)(S.matdata,ss,nn,n); DSDPChkDMatError(S,info); 00168 info=DSDPVMatRestoreArray(T,&ss,&nn); DSDPCHKERR(info); 00169 } else { 00170 DSDPNoOperationError(S); 00171 } 00172 DSDPFunctionReturn(0); 00173 } 00174 00175 00176 #undef __FUNCT__ 00177 #define __FUNCT__ "DSDPDualMatInvert" 00178 00186 int DSDPDualMatInvert(DSDPDualMat S){ 00187 int info; 00188 DSDPFunctionBegin; 00189 /* DSDPEventLogBegin(sdpdualinvert); */ 00190 if (S.dsdpops->matinvert){ 00191 info=(S.dsdpops->matinvert)(S.matdata); DSDPChkDMatError(S,info); 00192 } else { 00193 DSDPNoOperationError(S); 00194 } 00195 /* DSDPEventLogEnd(sdpdualinvert); */ 00196 DSDPFunctionReturn(0); 00197 } 00198 00199 #undef __FUNCT__ 00200 #define __FUNCT__ "DSDPDualMatInverseAdd" 00201 00209 int DSDPDualMatInverseAdd(DSDPDualMat S, double alpha, DSDPVMat T){ 00210 int info,n,nn; 00211 double *ss; 00212 DSDPFunctionBegin; 00213 if (S.dsdpops->matinverseadd){ 00214 info=DSDPVMatGetSize(T,&n); DSDPCHKERR(info); 00215 info=DSDPVMatGetArray(T,&ss,&nn); DSDPCHKERR(info); 00216 info=(S.dsdpops->matinverseadd)(S.matdata,alpha,ss,nn,n); DSDPChkDMatError(S,info); 00217 info=DSDPVMatRestoreArray(T,&ss,&nn); DSDPCHKERR(info); 00218 } else { 00219 DSDPNoOperationError(S); 00220 } 00221 DSDPFunctionReturn(0); 00222 } 00223 00224 00225 #undef __FUNCT__ 00226 #define __FUNCT__ "DSDPDualMatInverseMultiply" 00227 00236 int DSDPDualMatInverseMultiply(DSDPDualMat S, DSDPIndex IS, SDPConeVec B, SDPConeVec X){ 00237 int info,n; 00238 double *bb,*xx; 00239 DSDPFunctionBegin; 00240 DSDPEventLogBegin(sdpdualsolve); 00241 if (S.dsdpops->matinversemultiply){ 00242 info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info); 00243 info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info); 00244 info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info); 00245 info=(S.dsdpops->matinversemultiply)(S.matdata,IS.indx+1,IS.indx[0],bb,xx,n); DSDPChkDMatError(S,info); 00246 info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info); 00247 info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info); 00248 } else { 00249 DSDPNoOperationError(S); 00250 } 00251 DSDPEventLogEnd(sdpdualsolve); 00252 DSDPFunctionReturn(0); 00253 } 00254 00255 00256 #undef __FUNCT__ 00257 #define __FUNCT__ "DSDPDualMatCholeskySolveForward" 00258 00267 int DSDPDualMatCholeskySolveForward(DSDPDualMat S, SDPConeVec B, SDPConeVec X){ 00268 int info,n; 00269 double *bb,*xx; 00270 DSDPFunctionBegin; 00271 if (S.dsdpops->matsolveforward){ 00272 info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info); 00273 info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info); 00274 info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info); 00275 info=(S.dsdpops->matsolveforward)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info); 00276 info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info); 00277 info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info); 00278 } else { 00279 DSDPNoOperationError(S); 00280 } 00281 DSDPFunctionReturn(0); 00282 } 00283 00284 #undef __FUNCT__ 00285 #define __FUNCT__ "DSDPDualMatDualMatCholeskySolveBackward" 00286 00295 int DSDPDualMatCholeskySolveBackward(DSDPDualMat S, SDPConeVec B, SDPConeVec X){ 00296 int info,n; 00297 double *bb,*xx; 00298 DSDPFunctionBegin; 00299 if (S.dsdpops->matsolvebackward){ 00300 info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info); 00301 info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info); 00302 info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info); 00303 info=(S.dsdpops->matsolvebackward)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info); 00304 info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info); 00305 info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info); 00306 } else { 00307 DSDPNoOperationError(S); 00308 } 00309 DSDPFunctionReturn(0); 00310 } 00311 00312 #undef __FUNCT__ 00313 #define __FUNCT__ "DSDPDualMatCholeskyFactor" 00314 00320 int DSDPDualMatCholeskyFactor(DSDPDualMat S,DSDPTruth *psdefinite){ 00321 int info; 00322 int flag; 00323 DSDPFunctionBegin; 00324 if (S.dsdpops->matcholesky){ 00325 info=(S.dsdpops->matcholesky)(S.matdata,&flag); DSDPChkDMatError(S,info); 00326 } else { 00327 DSDPNoOperationError(S); 00328 } 00329 if (flag) *psdefinite=DSDP_FALSE; 00330 else *psdefinite=DSDP_TRUE; 00331 DSDPFunctionReturn(0); 00332 } 00333 00334 00335 #undef __FUNCT__ 00336 #define __FUNCT__ "DSDPDualMatCholeskyForwardMultiply" 00337 00346 int DSDPDualMatCholeskyForwardMultiply(DSDPDualMat S, SDPConeVec B, SDPConeVec X){ 00347 int info,n; 00348 double *bb,*xx; 00349 DSDPFunctionBegin; 00350 if (S.dsdpops->matforwardmultiply){ 00351 info=SDPConeVecGetSize(B,&n); DSDPCHKERR(info); 00352 info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info); 00353 info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info); 00354 info=(S.dsdpops->matforwardmultiply)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info); 00355 info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info); 00356 info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info); 00357 } else { 00358 DSDPNoOperationError(S); 00359 } 00360 DSDPFunctionReturn(0); 00361 } 00362 #undef __FUNCT__ 00363 #define __FUNCT__ "DSDPDualMatCholeskyBackwardMultiply" 00364 00373 int DSDPDualMatCholeskyBackwardMultiply(DSDPDualMat S, SDPConeVec B, SDPConeVec X){ 00374 int info,n; 00375 double *bb,*xx; 00376 DSDPFunctionBegin; 00377 if (S.dsdpops->matbackwardmultiply){ 00378 info=SDPConeVecGetSize(B,&n); DSDPCHKERR(info); 00379 info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info); 00380 info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info); 00381 info=(S.dsdpops->matbackwardmultiply)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info); 00382 info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info); 00383 info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info); 00384 } else { 00385 DSDPNoOperationError(S); 00386 } 00387 DSDPFunctionReturn(0); 00388 } 00389 #undef __FUNCT__ 00390 #define __FUNCT__ "DSDPDualMatIsFull" 00391 00397 int DSDPDualMatIsFull(DSDPDualMat S, DSDPTruth *full){ 00398 int info,flag=0; 00399 DSDPFunctionBegin; 00400 *full=DSDP_FALSE; 00401 if (S.dsdpops->matfull){ 00402 info=(S.dsdpops->matfull)(S.matdata,&flag); DSDPChkDMatError(S,info); 00403 } else { 00404 DSDPNoOperationError(S); 00405 } 00406 if (flag) *full=DSDP_TRUE; 00407 DSDPFunctionReturn(0); 00408 } 00409 00410 #undef __FUNCT__ 00411 #define __FUNCT__ "DSDPDataMatCheck" 00412 int DSDPDualMatCheck(DSDPDualMat SS, SDPConeVec W1, SDPConeVec W2, DSDPIndex IS, DSDPVMat XX){ 00413 DSDPFunctionBegin; 00414 DSDPFunctionReturn(0); 00415 } 00416 00417 static const char* dualmatname="NOT SET YET"; 00423 int DSDPDualMatOpsInitialize(struct DSDPDualMat_Ops* sops){ 00424 if (sops==NULL) return 0; 00425 sops->matseturmat=0; 00426 sops->matgetarray=0; 00427 sops->matcholesky=0; 00428 sops->matsolveforward=0; 00429 sops->matsolvebackward=0; 00430 sops->matinvert=0; 00431 sops->matinverseadd=0; 00432 sops->matinversemultiply=0; 00433 sops->matforwardmultiply=0; 00434 sops->matbackwardmultiply=0; 00435 sops->matfull=0; 00436 sops->matdestroy=0; 00437 sops->matgetsize=0; 00438 sops->matview=0; 00439 sops->matlogdet=0; 00440 sops->matname=dualmatname; 00441 return 0; 00442 } 00443 00444 00445 static struct DSDPDualMat_Ops dsdpdualmatopsdefault; 00446 00447 #undef __FUNCT__ 00448 #define __FUNCT__ "DSDPDualMatTest" 00449 int DSDPDualMatTest(DSDPDualMat S){ 00450 int info; 00451 DSDPFunctionBegin; 00452 if (S.dsdpops==0 || S.dsdpops==&dsdpdualmatopsdefault){ 00453 } else if (S.dsdpops->mattest){ 00454 info=(S.dsdpops->mattest)(S.matdata); DSDPChkDMatError(S,info); 00455 } else { 00456 /* 00457 DSDPNoOperationError(S); 00458 */ 00459 } 00460 DSDPFunctionReturn(0); 00461 } 00462 00463 00464 #undef __FUNCT__ 00465 #define __FUNCT__ "DSDPDualMatInitialize" 00466 00471 int DSDPDualMatInitialize(DSDPDualMat *S){ 00472 int info; 00473 DSDPFunctionBegin; 00474 info=DSDPDualMatOpsInitialize(&dsdpdualmatopsdefault);DSDPCHKERR(info); 00475 info=DSDPDualMatSetData(S,&dsdpdualmatopsdefault,0); DSDPCHKERR(info); 00476 DSDPFunctionReturn(0); 00477 } 00478