dsdpxmat.c
Go to the documentation of this file.
#include "dsdpxmat_impl.h"
#include "dsdpxmat.h"
#include "dsdpsys.h"
#define DSDPNoOperationError(a); { DSDPSETERR1(1,"X Matrix type: %s, Operation not defined. Perhaps no X matrix has been set.\n",(a).dsdpops->matname); }
#define DSDPChkMatError(a,b); { if (b){ DSDPSETERR1(b,"X Matrix type: %s,\n",(a).dsdpops->matname);} }
static int sdpxmatevent=0;
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatEventZero"
int DSDPVMatEventZero(void){
DSDPFunctionBegin;
sdpxmatevent=0;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatEventInitialize"
int DSDPVMatEventInitialize(void){
DSDPFunctionBegin;
if (sdpxmatevent==0){DSDPEventLogRegister("SDP X+vv'",&sdpxmatevent);}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatSetData"
int DSDPVMatSetData(DSDPVMat *X, struct DSDPVMat_Ops* ops, void*data){
int info;
DSDPFunctionBegin;
(*X).dsdpops=ops;
(*X).matdata=data;
info=DSDPVMatTest(*X);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatGetType"
int DSDPVMatGetType(DSDPVMat X, int *id){
DSDPFunctionBegin;
*id=X.dsdpops->id;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatGetSize"
int DSDPVMatGetSize(DSDPVMat X,int*n){
int info;
DSDPFunctionBegin;
if (X.dsdpops->matgetsize){
info=(X.dsdpops->matgetsize)(X.matdata,n); DSDPChkMatError(X,info);
} else {
/*
DSDPNoOperationError(X);
*/
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatDestroy"
int DSDPVMatDestroy(DSDPVMat *X){
int info;
DSDPFunctionBegin;
if (!(*X).dsdpops){ return 0;}
if ((*X).dsdpops->matdestroy){
info=((*X).dsdpops->matdestroy)((*X).matdata); DSDPChkMatError(*X,info);
} else {
/* DSDPNoOperationError(*X); */
}
info=DSDPVMatInitialize(X); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatView"
int DSDPVMatView(DSDPVMat X){
int info;
if (X.dsdpops->matview){
info=(X.dsdpops->matview)(X.matdata); DSDPChkMatError(X,info);
} else {
printf("No viewer available for matrix type: %d",X.dsdpops->id);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatZeroEntries"
int DSDPVMatZeroEntries(DSDPVMat X){
int info;
DSDPFunctionBegin;
if (X.dsdpops->matzeroentries){
info=(X.dsdpops->matzeroentries)(X.matdata); DSDPChkMatError(X,info);
} else {
DSDPNoOperationError(X);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatScaleDiagonal"
int DSDPVMatScaleDiagonal(DSDPVMat X, double dscale){
int info;
DSDPFunctionBegin;
if (X.dsdpops->matscalediagonal){
info=(X.dsdpops->matscalediagonal)(X.matdata,dscale); DSDPChkMatError(X,info);
} else {
DSDPNoOperationError(X);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatShiftDiagonal"
int DSDPVMatShiftDiagonal(DSDPVMat X, double dadd){
int info;
DSDPFunctionBegin;
if (X.dsdpops->matshiftdiagonal){
info=(X.dsdpops->matshiftdiagonal)(X.matdata,dadd); DSDPChkMatError(X,info);
} else {
DSDPNoOperationError(X);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatNormF2"
int DSDPVMatNormF2(DSDPVMat X, double*normf2){
int info,n;
double *dd;
DSDPFunctionBegin;
if (X.dsdpops->matfnorm2){
info=DSDPVMatGetArray(X,&dd,&n); DSDPCHKERR(info);
info=(X.dsdpops->matfnorm2)(X.matdata,n,normf2); DSDPChkMatError(X,info);
info=DSDPVMatRestoreArray(X,&dd,&n); DSDPCHKERR(info);
} else {
DSDPNoOperationError(X);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatGetArray"
int DSDPVMatGetArray(DSDPVMat X, double **v, int *nn){
int info;
DSDPFunctionBegin;
if (X.dsdpops->matgeturarray){
info=(X.dsdpops->matgeturarray)(X.matdata,v,nn); DSDPChkMatError(X,info);
} else {
*v=0;
*nn=0;
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatRestoreArray"
int DSDPVMatRestoreArray(DSDPVMat X, double **v, int *nn){
int info;
DSDPFunctionBegin;
if (X.dsdpops->matrestoreurarray){
info=(X.dsdpops->matrestoreurarray)(X.matdata,v,nn); DSDPChkMatError(X,info);
} else {
*v=0;
*nn=0;
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatMinEigenvalue"
int DSDPVMatMinEigenvalue(DSDPVMat X, SDPConeVec W1, SDPConeVec W2, double *mineig){
int n,info;
double *w,*iwork;
DSDPFunctionBegin;
if (X.dsdpops->matmineig){
info=SDPConeVecGetSize(W1,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(W1,&w); DSDPCHKERR(info);
info=SDPConeVecGetArray(W2,&iwork); DSDPCHKERR(info);
info=(X.dsdpops->matmineig)(X.matdata,w,iwork,n,mineig); DSDPChkMatError(X,info);
info=SDPConeVecRestoreArray(W1,&w); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(W2,&iwork); DSDPCHKERR(info);
} else {
DSDPNoOperationError(X);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatAddOuterProduct"
int DSDPVMatAddOuterProduct(DSDPVMat X, double alpha, SDPConeVec V){
int info,n;
double *v;
DSDPFunctionBegin;
DSDPEventLogBegin(sdpxmatevent);
info=SDPConeVecGetSize(V,&n); DSDPCHKERR(info);
if (X.dsdpops->mataddouterproduct){
info=SDPConeVecGetArray(V,&v); DSDPCHKERR(info);
info=(X.dsdpops->mataddouterproduct)(X.matdata,alpha,v,n); DSDPChkMatError(X,info);
info=SDPConeVecRestoreArray(V,&v); DSDPCHKERR(info);
} else {
DSDPNoOperationError(X);
}
DSDPEventLogEnd(sdpxmatevent);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatMult"
int DSDPVMatMult(DSDPVMat X, SDPConeVec Z, SDPConeVec Y){
int info,n;
double *z,*y;
DSDPFunctionBegin;
info=SDPConeVecGetSize(Y,&n); DSDPCHKERR(info);
if (X.dsdpops->matmult){
info=SDPConeVecGetArray(Z,&z); DSDPCHKERR(info);
info=SDPConeVecGetArray(Y,&y); DSDPCHKERR(info);
info=(X.dsdpops->matmult)(X.matdata,z,y,n); DSDPChkMatError(X,info);
info=SDPConeVecRestoreArray(Z,&z); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(Y,&y); DSDPCHKERR(info);
} else {
DSDPNoOperationError(X);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatCheck"
int DSDPVMatCheck(DSDPVMat X, SDPConeVec W1, SDPConeVec W2){
int info,i,n,nn;
double *xx,eig,eps=1e-13,one=1.0;
double fnorm0,fnorm1,fnorm2,fnorm3,fnorm4;
DSDPFunctionBegin;
info=DSDPVMatGetSize(X,&n);DSDPCHKERR(info);
info=SDPConeVecSet(one,W1);DSDPCHKERR(info);
info=DSDPVMatAddOuterProduct(X,1.23456,W1);DSDPCHKERR(info);
info=DSDPVMatZeroEntries(X);DSDPCHKERR(info);
info=DSDPVMatNormF2(X,&fnorm0);DSDPCHKERR(info);
if (fabs(fnorm0)>eps){ printf("Check DSDPVMatZero of DSDPVMatNorm\n");}
info=SDPConeVecSet(one,W1);DSDPCHKERR(info);
info=DSDPVMatAddOuterProduct(X,1.0,W1);DSDPCHKERR(info);
info=DSDPVMatNormF2(X,&fnorm1);DSDPCHKERR(info);
if (fabs(fnorm1-n*n)>eps) printf("Check DSDPVMatZero()\n");
info=DSDPVMatGetArray(X,&xx,&nn);DSDPCHKERR(info);
for (i=0;i<nn;i++){xx[i]=1.0;}
info=DSDPVMatRestoreArray(X,&xx,&nn);DSDPCHKERR(info);
info=DSDPVMatNormF2(X,&fnorm2);DSDPCHKERR(info);
if (fabs(fnorm2-n*n)>eps) printf("Check DSDPXGetArray()\n");
info=DSDPVMatAddOuterProduct(X,-1.0,W1);DSDPCHKERR(info);
info=DSDPVMatNormF2(X,&fnorm3);DSDPCHKERR(info);
info=DSDPVMatZeroEntries(X);DSDPCHKERR(info);
info=DSDPVMatAddOuterProduct(X,1.0,W1);DSDPCHKERR(info);
info=DSDPVMatScaleDiagonal(X,2.0);DSDPCHKERR(info);
info=DSDPVMatZeroEntries(X);DSDPCHKERR(info);
info=DSDPVMatAddOuterProduct(X,1.0,W1);DSDPCHKERR(info);
info=DSDPVMatShiftDiagonal(X,1.0);DSDPCHKERR(info);
info=DSDPVMatNormF2(X,&fnorm4);DSDPCHKERR(info);
info=DSDPVMatMult(X,W1,W2);DSDPCHKERR(info);
info=DSDPVMatMinEigenvalue(X,W1,W2,&eig);DSDPCHKERR(info);
if (fabs(fnorm0)>eps) printf("Check DSDPVMatZero()\n");
DSDPFunctionReturn(0);
}
static struct DSDPVMat_Ops dsdpmatops2;
static const char *urmatname="NOT SET YET";
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatOpsInitialize"
int DSDPVMatOpsInitialize(struct DSDPVMat_Ops*aops){
aops->matgetsize=0;
aops->matzeroentries=0;
aops->matfnorm2=0;
aops->mataddouterproduct=0;
aops->matmult=0;
aops->matgeturarray=0;
aops->matrestoreurarray=0;
aops->matview=0;
aops->matdestroy=0;
aops->matmineig=0;
aops->matshiftdiagonal=0;
aops->matscalediagonal=0;
aops->id=0;
aops->matname=urmatname;
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatTest"
int DSDPVMatTest(DSDPVMat X){
int info;
DSDPFunctionBegin;
if (X.dsdpops==0 || X.dsdpops==&dsdpmatops2){
} else if (X.dsdpops->mattest){
info=(X.dsdpops->mattest)(X.matdata); DSDPChkMatError(X,info);
} else {
/*
DSDPNoOperationError(X);
*/
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatInitialize"
int DSDPVMatInitialize(DSDPVMat *B){
int info;
DSDPFunctionBegin;
info=DSDPVMatOpsInitialize(&dsdpmatops2); DSDPCHKERR(info);
info=DSDPVMatSetData(B, &dsdpmatops2, 0); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPVMatExist"
int DSDPVMatExist(DSDPVMat X,int *flag){
DSDPFunctionBegin;
if (X.dsdpops && X.dsdpops!=&dsdpmatops2) *flag=1;
else *flag=0;
DSDPFunctionReturn(0);
}
dsdpsys.h
Error handling, printing, and profiling.
DSDPVMatInitialize
int DSDPVMatInitialize(DSDPVMat *B)
Set pointers to null.
Definition dsdpxmat.c:424
DSDPVMatNormF2
int DSDPVMatNormF2(DSDPVMat X, double *normf2)
Compute square of Frobenius norm of matrix.
Definition dsdpxmat.c:186
DSDPVMatSetData
int DSDPVMatSetData(DSDPVMat *X, struct DSDPVMat_Ops *ops, void *data)
Set opaque pointer an function pointers.
Definition dsdpxmat.c:39
DSDPVMatGetArray
int DSDPVMatGetArray(DSDPVMat X, double **v, int *nn)
Get the array that stores the matrix.
Definition dsdpxmat.c:211
DSDPVMatTest
int DSDPVMatTest(DSDPVMat X)
Test validity of matrix.
Definition dsdpxmat.c:402
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
DSDPVMatShiftDiagonal
int DSDPVMatShiftDiagonal(DSDPVMat X, double dadd)
Add something to diagonal elements.
Definition dsdpxmat.c:166
DSDPVMatZeroEntries
int DSDPVMatZeroEntries(DSDPVMat X)
Zero matrix.
Definition dsdpxmat.c:125
DSDPVMatAddOuterProduct
int DSDPVMatAddOuterProduct(DSDPVMat X, double alpha, SDPConeVec V)
Add outer product of a vector to the matrix.
Definition dsdpxmat.c:275
DSDPVMatExist
int DSDPVMatExist(DSDPVMat X, int *flag)
Answer whether the array has been allocated or not.
Definition dsdpxmat.c:440
DSDPVMatMult
int DSDPVMatMult(DSDPVMat X, SDPConeVec Z, SDPConeVec Y)
Multiply X by a vector.
Definition dsdpxmat.c:301
DSDPVMatCheck
int DSDPVMatCheck(DSDPVMat X, SDPConeVec W1, SDPConeVec W2)
Test correctness of operations.
Definition dsdpxmat.c:327
DSDPVMatDestroy
int DSDPVMatDestroy(DSDPVMat *X)
Deallocate matrix.
Definition dsdpxmat.c:86
DSDPVMatScaleDiagonal
int DSDPVMatScaleDiagonal(DSDPVMat X, double dscale)
Scaling diagonal is useful for inner products and norms.
Definition dsdpxmat.c:147
DSDPVMatOpsInitialize
int DSDPVMatOpsInitialize(struct DSDPVMat_Ops *aops)
Set function pointers to null.
Definition dsdpxmat.c:377
DSDPVMatView
int DSDPVMatView(DSDPVMat X)
Print matrix.
Definition dsdpxmat.c:107
dsdpxmat.h
The interface between the SDPCone and the dense matrix array.
dsdpxmat_impl.h
Structure of function pointers that each dense matrix array type (upper full, packed symmetric,...
SDPConeVecSet
int SDPConeVecSet(double alpha, SDPConeVec V)
Set each element of vector to this number.
Definition sdpconevec.c:211
DSDPVMat_C
Dense symmetric matrix for one block in the semidefinite cone.
Definition dsdpxmat.h:17
DSDPVMat_Ops
Table of function pointers that operate on the dense matrix.
Definition dsdpxmat_impl.h:13
SDPConeVec_C
Vector whose length corresponds to dimension of a block in a cone.
Definition sdpconevec.h:13