dsdpdualmat.c
Go to the documentation of this file.
#include "dsdpdualmat_impl.h"
#include "dsdpdualmat.h"
#include "dsdpsys.h"
#define DSDPNoOperationError(a); { DSDPSETERR1(1,"Dual natrix type: %s, Operation not defined\n",(a).dsdpops->matname);}
#define DSDPChkDMatError(a,b); { if (b){ DSDPSETERR1(b,"Dual natrix type: %s,\n",(a).dsdpops->matname);} }
static int sdpdualsolve=0,sdpdualinvert=0;
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatEventZero"
int DSDPDualMatEventZero(void){
DSDPFunctionBegin;
sdpdualinvert=0;sdpdualsolve=0;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatEventInitialize"
int DSDPDualMatEventInitialize(void){
DSDPFunctionBegin;
if (sdpdualsolve==0){DSDPEventLogRegister("SDP SSolve",&sdpdualsolve);}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatGetType"
int DSDPDualMatGetType(DSDPDualMat S, int *id){
DSDPFunctionBegin;
*id=S.dsdpops->id;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatSetData"
int DSDPDualMatSetData(DSDPDualMat *S, struct DSDPDualMat_Ops* ops, void*data){
int info;
DSDPFunctionBegin;
(*S).dsdpops=ops;
(*S).matdata=data;
info=DSDPDualMatTest(*S);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatDestroy"
int DSDPDualMatDestroy(DSDPDualMat *S){
int info;
DSDPFunctionBegin;
if ( S && (*S).dsdpops && (*S).dsdpops->matdestroy){
info=((*S).dsdpops->matdestroy)((*S).matdata); DSDPChkDMatError(*S,info);
} else {
/*
DSDPNoOperationError(*S);
*/
}
info=DSDPDualMatSetData(S,0,0); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatGetSize"
int DSDPDualMatGetSize(DSDPDualMat S,int*n){
int info;
DSDPFunctionBegin;
if (S.dsdpops->matgetsize){
info=(S.dsdpops->matgetsize)(S.matdata,n); DSDPChkDMatError(S,info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatGetArray"
int DSDPDualMatGetArray(DSDPDualMat S, double **v, int *n){
int info;
DSDPFunctionBegin;
if (S.dsdpops->matgetarray){
info=(S.dsdpops->matgetarray)(S.matdata,v,n); DSDPChkDMatError(S,info);
} else {
*v=0;
*n=0;
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatLogDeterminant"
int DSDPDualMatLogDeterminant(DSDPDualMat S,double *logdet){
int info;
DSDPFunctionBegin;
if (S.dsdpops->matlogdet){
info=(S.dsdpops->matlogdet)(S.matdata,logdet); DSDPChkDMatError(S,info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatView"
int DSDPDualMatView(DSDPDualMat S){
int info;
DSDPFunctionBegin;
if (S.dsdpops->matview){
info=(S.dsdpops->matview)(S.matdata); DSDPChkDMatError(S,info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatSetArray"
int DSDPDualMatSetArray(DSDPDualMat S, DSDPVMat T){
double *ss;
int info,n,nn;
DSDPFunctionBegin;
if (S.dsdpops->matseturmat){
info=DSDPVMatGetSize(T,&n); DSDPCHKERR(info);
info=DSDPVMatGetArray(T,&ss,&nn); DSDPCHKERR(info);
info=(S.dsdpops->matseturmat)(S.matdata,ss,nn,n); DSDPChkDMatError(S,info);
info=DSDPVMatRestoreArray(T,&ss,&nn); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatInvert"
int DSDPDualMatInvert(DSDPDualMat S){
int info;
DSDPFunctionBegin;
/* DSDPEventLogBegin(sdpdualinvert); */
if (S.dsdpops->matinvert){
info=(S.dsdpops->matinvert)(S.matdata); DSDPChkDMatError(S,info);
} else {
DSDPNoOperationError(S);
}
/* DSDPEventLogEnd(sdpdualinvert); */
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatInverseAdd"
int DSDPDualMatInverseAdd(DSDPDualMat S, double alpha, DSDPVMat T){
int info,n,nn;
double *ss;
DSDPFunctionBegin;
if (S.dsdpops->matinverseadd){
info=DSDPVMatGetSize(T,&n); DSDPCHKERR(info);
info=DSDPVMatGetArray(T,&ss,&nn); DSDPCHKERR(info);
info=(S.dsdpops->matinverseadd)(S.matdata,alpha,ss,nn,n); DSDPChkDMatError(S,info);
info=DSDPVMatRestoreArray(T,&ss,&nn); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatInverseMultiply"
int DSDPDualMatInverseMultiply(DSDPDualMat S, DSDPIndex IS, SDPConeVec B, SDPConeVec X){
int info,n;
double *bb,*xx;
DSDPFunctionBegin;
DSDPEventLogBegin(sdpdualsolve);
if (S.dsdpops->matinversemultiply){
info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info);
info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info);
info=(S.dsdpops->matinversemultiply)(S.matdata,IS.indx+1,IS.indx[0],bb,xx,n); DSDPChkDMatError(S,info);
info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPEventLogEnd(sdpdualsolve);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatCholeskySolveForward"
int DSDPDualMatCholeskySolveForward(DSDPDualMat S, SDPConeVec B, SDPConeVec X){
int info,n;
double *bb,*xx;
DSDPFunctionBegin;
if (S.dsdpops->matsolveforward){
info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info);
info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info);
info=(S.dsdpops->matsolveforward)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info);
info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatDualMatCholeskySolveBackward"
int DSDPDualMatCholeskySolveBackward(DSDPDualMat S, SDPConeVec B, SDPConeVec X){
int info,n;
double *bb,*xx;
DSDPFunctionBegin;
if (S.dsdpops->matsolvebackward){
info=SDPConeVecGetSize(X,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info);
info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info);
info=(S.dsdpops->matsolvebackward)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info);
info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatCholeskyFactor"
int DSDPDualMatCholeskyFactor(DSDPDualMat S,DSDPTruth *psdefinite){
int info;
int flag;
DSDPFunctionBegin;
if (S.dsdpops->matcholesky){
info=(S.dsdpops->matcholesky)(S.matdata,&flag); DSDPChkDMatError(S,info);
} else {
DSDPNoOperationError(S);
}
if (flag) *psdefinite=DSDP_FALSE;
else *psdefinite=DSDP_TRUE;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatCholeskyForwardMultiply"
int DSDPDualMatCholeskyForwardMultiply(DSDPDualMat S, SDPConeVec B, SDPConeVec X){
int info,n;
double *bb,*xx;
DSDPFunctionBegin;
if (S.dsdpops->matforwardmultiply){
info=SDPConeVecGetSize(B,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info);
info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info);
info=(S.dsdpops->matforwardmultiply)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info);
info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatCholeskyBackwardMultiply"
int DSDPDualMatCholeskyBackwardMultiply(DSDPDualMat S, SDPConeVec B, SDPConeVec X){
int info,n;
double *bb,*xx;
DSDPFunctionBegin;
if (S.dsdpops->matbackwardmultiply){
info=SDPConeVecGetSize(B,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(B,&bb); DSDPCHKERR(info);
info=SDPConeVecGetArray(X,&xx); DSDPCHKERR(info);
info=(S.dsdpops->matbackwardmultiply)(S.matdata,bb,xx,n); DSDPChkDMatError(S,info);
info=SDPConeVecRestoreArray(X,&xx); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(B,&bb); DSDPCHKERR(info);
} else {
DSDPNoOperationError(S);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatIsFull"
int DSDPDualMatIsFull(DSDPDualMat S, DSDPTruth *full){
int info,flag=0;
DSDPFunctionBegin;
*full=DSDP_FALSE;
if (S.dsdpops->matfull){
info=(S.dsdpops->matfull)(S.matdata,&flag); DSDPChkDMatError(S,info);
} else {
DSDPNoOperationError(S);
}
if (flag) *full=DSDP_TRUE;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatCheck"
int DSDPDualMatCheck(DSDPDualMat SS, SDPConeVec W1, SDPConeVec W2, DSDPIndex IS, DSDPVMat XX){
DSDPFunctionBegin;
DSDPFunctionReturn(0);
}
static const char* dualmatname="NOT SET YET";
int DSDPDualMatOpsInitialize(struct DSDPDualMat_Ops* sops){
if (sops==NULL) return 0;
sops->matseturmat=0;
sops->matgetarray=0;
sops->matcholesky=0;
sops->matsolveforward=0;
sops->matsolvebackward=0;
sops->matinvert=0;
sops->matinverseadd=0;
sops->matinversemultiply=0;
sops->matforwardmultiply=0;
sops->matbackwardmultiply=0;
sops->matfull=0;
sops->matdestroy=0;
sops->matgetsize=0;
sops->matview=0;
sops->matlogdet=0;
sops->matname=dualmatname;
return 0;
}
static struct DSDPDualMat_Ops dsdpdualmatopsdefault;
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatTest"
int DSDPDualMatTest(DSDPDualMat S){
int info;
DSDPFunctionBegin;
if (S.dsdpops==0 || S.dsdpops==&dsdpdualmatopsdefault){
} else if (S.dsdpops->mattest){
info=(S.dsdpops->mattest)(S.matdata); DSDPChkDMatError(S,info);
} else {
/*
DSDPNoOperationError(S);
*/
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDualMatInitialize"
int DSDPDualMatInitialize(DSDPDualMat *S){
int info;
DSDPFunctionBegin;
info=DSDPDualMatOpsInitialize(&dsdpdualmatopsdefault);DSDPCHKERR(info);
info=DSDPDualMatSetData(S,&dsdpdualmatopsdefault,0); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
DSDPTruth
DSDPTruth
Boolean variables.
Definition dsdpbasictypes.h:19
DSDP_FALSE
@ DSDP_FALSE
Definition dsdpbasictypes.h:19
DSDP_TRUE
@ DSDP_TRUE
Definition dsdpbasictypes.h:19
DSDPDualMatInitialize
int DSDPDualMatInitialize(DSDPDualMat *S)
Set pointers to null.
Definition dsdpdualmat.c:471
DSDPDualMatInverseAdd
int DSDPDualMatInverseAdd(DSDPDualMat S, double alpha, DSDPVMat T)
Add a multiple of the inverse to T.
Definition dsdpdualmat.c:209
DSDPDualMatView
int DSDPDualMatView(DSDPDualMat S)
Print the matrix.
Definition dsdpdualmat.c:140
DSDPDualMatCholeskyFactor
int DSDPDualMatCholeskyFactor(DSDPDualMat S, DSDPTruth *psdefinite)
Factor the matrix.
Definition dsdpdualmat.c:320
DSDPDualMatCholeskyBackwardMultiply
int DSDPDualMatCholeskyBackwardMultiply(DSDPDualMat S, SDPConeVec B, SDPConeVec X)
Multiply by triangular matrix.
Definition dsdpdualmat.c:373
DSDPDualMatCholeskyForwardMultiply
int DSDPDualMatCholeskyForwardMultiply(DSDPDualMat S, SDPConeVec B, SDPConeVec X)
Multiply by triangular matrix.
Definition dsdpdualmat.c:346
DSDPDualMatLogDeterminant
int DSDPDualMatLogDeterminant(DSDPDualMat S, double *logdet)
Free the matrix structure.
Definition dsdpdualmat.c:122
DSDPDualMatOpsInitialize
int DSDPDualMatOpsInitialize(struct DSDPDualMat_Ops *sops)
Set pointers to null.
Definition dsdpdualmat.c:423
DSDPDualMatCholeskySolveBackward
int DSDPDualMatCholeskySolveBackward(DSDPDualMat S, SDPConeVec B, SDPConeVec X)
Backward triangular solve.
Definition dsdpdualmat.c:295
DSDPDualMatDestroy
int DSDPDualMatDestroy(DSDPDualMat *S)
Free the matrix structure.
Definition dsdpdualmat.c:65
DSDPDualMatCholeskySolveForward
int DSDPDualMatCholeskySolveForward(DSDPDualMat S, SDPConeVec B, SDPConeVec X)
Forward triangular solve.
Definition dsdpdualmat.c:267
DSDPDualMatSetData
int DSDPDualMatSetData(DSDPDualMat *S, struct DSDPDualMat_Ops *ops, void *data)
Set the opaque pointer and function pointers to the matrix.
Definition dsdpdualmat.c:49
DSDPDualMatIsFull
int DSDPDualMatIsFull(DSDPDualMat S, DSDPTruth *full)
Factor the matrix.
Definition dsdpdualmat.c:397
DSDPDualMatGetSize
int DSDPDualMatGetSize(DSDPDualMat S, int *n)
Free the matrix structure.
Definition dsdpdualmat.c:87
DSDPDualMatInverseMultiply
int DSDPDualMatInverseMultiply(DSDPDualMat S, DSDPIndex IS, SDPConeVec B, SDPConeVec X)
Multiply the inverse by a vector or solve the system of equations.
Definition dsdpdualmat.c:236
DSDPDualMatSetArray
int DSDPDualMatSetArray(DSDPDualMat S, DSDPVMat T)
Print the matrix.
Definition dsdpdualmat.c:160
DSDPDualMatInvert
int DSDPDualMatInvert(DSDPDualMat S)
Invert the matrix.
Definition dsdpdualmat.c:186
dsdpdualmat.h
The interface between the SDPCone and the matrix S.
dsdpdualmat_impl.h
Structure of function pointers that each symmetric positive definite matrix type (dense,...
dsdpsys.h
Error handling, printing, and profiling.
DSDPVMatGetArray
int DSDPVMatGetArray(DSDPVMat X, double **v, int *nn)
Get the array that stores the matrix.
Definition dsdpxmat.c:211
DSDPVMatGetSize
int DSDPVMatGetSize(DSDPVMat X, int *n)
Get number of rows and columns.
Definition dsdpxmat.c:65
DSDPVMatRestoreArray
int DSDPVMatRestoreArray(DSDPVMat X, double **v, int *nn)
Restore the array that stores the matrix.
Definition dsdpxmat.c:233
DSDPDualMat_C
Represents an S matrix for one block in the semidefinite cone.
Definition dsdpdualmat.h:18
DSDPDualMat_Ops
Table of function pointers that operate on the S matrix.
Definition dsdpdualmat_impl.h:13
DSDPVMat_C
Dense symmetric matrix for one block in the semidefinite cone.
Definition dsdpxmat.h:17
SDPConeVec_C
Vector whose length corresponds to dimension of a block in a cone.
Definition sdpconevec.h:13