dsdpdatamat.c
Go to the documentation of this file.
#include "dsdpdatamat_impl.h"
#include "dsdpdatamat.h"
#include "dsdpsys.h"
#define DSDPNoOperationError(a); { DSDPSETERR1(1,"Data natrix type: %s, Operation not defined\n",(a).dsdpops->matname); }
#define DSDPChkDataError(a,b); { if (b){ DSDPSETERR1(b,"Data natrix type: %s,\n",(a).dsdpops->matname);} }
static struct DSDPDataMat_Ops dsdpdatamatdefault;
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatSetData"
int DSDPDataMatSetData(DSDPDataMat *A, struct DSDPDataMat_Ops* ops, void*data){
int info;
DSDPFunctionBegin;
(*A).dsdpops=ops;
(*A).matdata=data;
if (ops==NULL){
(*A).dsdpops=&dsdpdatamatdefault;
}
info = DSDPDataMatOpsInitialize(&dsdpdatamatdefault); DSDPCHKERR(info);
info=DSDPDataMatTest(*A);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
static char datamatnoname[20]="MATRIX NOT SET";
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatOpsInitialize"
int DSDPDataMatOpsInitialize(struct DSDPDataMat_Ops* dops){
DSDPFunctionBegin;
if (dops==NULL) return 0;
dops->matfactor1=0;
dops->matfactor2=0;
dops->matgetrank=0;
dops->matgeteig=0;
dops->matvecvec=0;
dops->matdot=0;
dops->mataddrowmultiple=0;
dops->mataddallmultiple=0;
dops->matdestroy=0;
dops->matview=0;
dops->matrownz=0;
dops->matnnz=0;
dops->matfnorm2=0;
dops->id=0;
dops->matname=datamatnoname;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatInitialize"
int DSDPDataMatInitialize(DSDPDataMat *A){
int info;
DSDPFunctionBegin;
info = DSDPDataMatOpsInitialize(&dsdpdatamatdefault); DSDPCHKERR(info);
info = DSDPDataMatSetData(A, &dsdpdatamatdefault,0); DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatTest"
int DSDPDataMatTest(DSDPDataMat A){
int info;
DSDPFunctionBegin;
if (A.dsdpops==0 || A.dsdpops==&dsdpdatamatdefault){
} else if (A.dsdpops->mattest){
info=(A.dsdpops->mattest)(A.matdata); DSDPChkDataError(A,info);
} else {
/*
DSDPNoOperationError(A);
*/
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatGetType"
int DSDPDataMatGetType(DSDPDataMat A, int *id){
DSDPFunctionBegin;
*id=A.dsdpops->id;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatGetRank"
int DSDPDataMatGetRank(DSDPDataMat A, int *rank, int n){
int info;
DSDPFunctionBegin;
if (A.dsdpops->matgetrank){
info=(A.dsdpops->matgetrank)(A.matdata,rank,n); DSDPChkDataError(A,info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatCountNonzeros"
int DSDPDataMatCountNonzeros(DSDPDataMat A, int *nnz, int n){
int info;
DSDPFunctionBegin;
if (A.dsdpops->matnnz){
info=(A.dsdpops->matnnz)(A.matdata,nnz,n); DSDPChkDataError(A,info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatFNorm2"
int DSDPDataMatFNorm2(DSDPDataMat A, int n, double *fnorm2){
int info;
DSDPFunctionBegin;
if (A.dsdpops->matfnorm2){
*fnorm2=0.0;
info=(A.dsdpops->matfnorm2)(A.matdata,n,fnorm2); DSDPChkDataError(A,info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatGetEig"
int DSDPDataMatGetEig(DSDPDataMat A, int rr, SDPConeVec V, DSDPIndex S, double *eigenvalue){
int info,n;
double *vv;
DSDPFunctionBegin;
if (A.dsdpops->matgeteig){
info=SDPConeVecGetArray(V,&vv); DSDPCHKERR(info);
info=SDPConeVecGetSize(V,&n); DSDPCHKERR(info);
info=(A.dsdpops->matgeteig)(A.matdata,rr, eigenvalue, vv,n,S.indx+1,S.indx); DSDPChkDataError(A,info);
info=SDPConeVecRestoreArray(V,&vv); DSDPCHKERR(info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatFactor"
int DSDPDataMatFactor(DSDPDataMat A, SDPConeVec W, double*dworknn, int nn0,
double *dwork3n, int nd, int* iwork, int ni){
int info,n;
double *dvecwork;
DSDPFunctionBegin;
if (A.dsdpops->matfactor1){
info=(A.dsdpops->matfactor1)(A.matdata); DSDPChkDataError(A,info);
} else if (A.dsdpops->matfactor2){
info=SDPConeVecGetSize(W,&n);
info=SDPConeVecGetArray(W,&dvecwork);
info=(A.dsdpops->matfactor2)(A.matdata,dworknn,nn0,dvecwork,n,dwork3n,nd,iwork,ni); DSDPChkDataError(A,info);
info=SDPConeVecRestoreArray(W,&dvecwork);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatDot"
int DSDPDataMatDot(DSDPDataMat A, double x[], int nn, int n, double *v){
int info;
DSDPFunctionBegin;
if (A.dsdpops->matdot){
info=(A.dsdpops->matdot)(A.matdata,x,nn,n,v); DSDPChkDataError(A,info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatVecVec"
int DSDPDataMatVecVec(DSDPDataMat A, SDPConeVec W, double *v){
int info,n;
double *x;
DSDPFunctionBegin;
if (A.dsdpops->matvecvec){
info=SDPConeVecGetSize(W,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(W,&x); DSDPCHKERR(info);
info=(A.dsdpops->matvecvec)(A.matdata,x,n,v); DSDPChkDataError(A,info);
info=SDPConeVecRestoreArray(W,&x); DSDPCHKERR(info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatMultiply"
/*
\fn int DSDPDataMatMultiply(DSDPDataMat A, SDPConeVec V1, SDPConeVec V2);
\brief Compute V2 = A*V1;
\param A symmetric data matrix
\param V1 in vector
\param V2 the product
Not needed.
*/
int DSDPDataMatMultiply(DSDPDataMat A, SDPConeVec V1, SDPConeVec V2){
int info,n;
double *vv1,*vv2;
DSDPFunctionBegin;
if (A.dsdpops->matmultiply){
info=SDPConeVecGetSize(V1,&n); DSDPCHKERR(info);
info=SDPConeVecGetArray(V1,&vv1); DSDPCHKERR(info);
info=SDPConeVecGetArray(V2,&vv2); DSDPCHKERR(info);
info=(A.dsdpops->matmultiply)(A.matdata,vv1,vv2,n); DSDPChkDataError(A,info);
info=SDPConeVecRestoreArray(V1,&vv1); DSDPCHKERR(info);
info=SDPConeVecRestoreArray(V2,&vv2); DSDPCHKERR(info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatGetRowNonzeros"
int DSDPDataMatGetRowNonzeros(DSDPDataMat A, int nrow, int nmax, int *nz, int *nnz){
int i,info;
DSDPFunctionBegin;
if (A.dsdpops->matrownz){
info=(A.dsdpops->matrownz)(A.matdata,nrow,nz,nnz,nmax); DSDPChkDataError(A,info);
} else {
*nnz=nmax;
for (i=0;i<nmax;i++){
nz[i]++;
}
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatAddRowMultipleToVector"
int DSDPDataMatAddRowMultipleToVector(DSDPDataMat A, int nrow, double ytmp, SDPConeVec R){
int info,n;
double *vv;
DSDPFunctionBegin;
if (A.dsdpops->mataddrowmultiple){
info=SDPConeVecGetArray(R,&vv);DSDPCHKERR(info);
info=SDPConeVecGetSize(R,&n);DSDPCHKERR(info);
info=(A.dsdpops->mataddrowmultiple)(A.matdata,nrow,ytmp,vv,n); DSDPChkDataError(A,info);
info=SDPConeVecRestoreArray(R,&vv);DSDPCHKERR(info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatAddMultiple"
int DSDPDataMatAddMultiple(DSDPDataMat A, double ytmp, double *v, int nn, int n){
int info;
DSDPFunctionBegin;
if (A.dsdpops->mataddallmultiple){
info=(A.dsdpops->mataddallmultiple)(A.matdata,ytmp,v,nn,n); DSDPChkDataError(A,info);
} else {
DSDPNoOperationError(A);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatView"
int DSDPDataMatView(DSDPDataMat A){
int info;
DSDPFunctionBegin;
if (A.dsdpops->matview){
info=(A.dsdpops->matview)(A.matdata); DSDPChkDataError(A,info);
} else {
printf("No matrix view available for matrix type %s.\n",A.dsdpops->matname);
}
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPDataMatDestroy"
int DSDPDataMatDestroy(DSDPDataMat* A){
int info;
DSDPFunctionBegin;
if ( (*A).dsdpops->matdestroy){
info=((*A).dsdpops->matdestroy)((*A).matdata); DSDPChkDataError(*A,info);
} else {
/* DSDPNoOperationError(*A); */
}
info=DSDPDataMatInitialize(A); DSDPCHKERR(info);
/* info=DSDPZeroMatCreate(0,A); DSDPCHKERR(info); */
DSDPFunctionReturn(0);
}
DSDPDataMatAddMultiple
int DSDPDataMatAddMultiple(DSDPDataMat A, double ytmp, double *v, int nn, int n)
Add a multiple the data matrix to the array.
Definition dsdpdatamat.c:402
DSDPDataMatVecVec
int DSDPDataMatVecVec(DSDPDataMat A, SDPConeVec W, double *v)
Compute w' A w.
Definition dsdpdatamat.c:297
DSDPDataMatDestroy
int DSDPDataMatDestroy(DSDPDataMat *A)
Free the data structures.
Definition dsdpdatamat.c:444
DSDPDataMatGetRowNonzeros
int DSDPDataMatGetRowNonzeros(DSDPDataMat A, int nrow, int nmax, int *nz, int *nnz)
Get sparsity pattern of a row of the matrix.
Definition dsdpdatamat.c:355
DSDPDataMatGetEig
int DSDPDataMatGetEig(DSDPDataMat A, int rr, SDPConeVec V, DSDPIndex S, double *eigenvalue)
Get an eigenvalue/vector pair.
Definition dsdpdatamat.c:204
DSDPDataMatOpsInitialize
int DSDPDataMatOpsInitialize(struct DSDPDataMat_Ops *dops)
Initialize the table of function pointers for SDP Data matrices.
Definition dsdpdatamat.c:47
DSDPDataMatView
int DSDPDataMatView(DSDPDataMat A)
Print matrix.
Definition dsdpdatamat.c:423
DSDPDataMatSetData
int DSDPDataMatSetData(DSDPDataMat *A, struct DSDPDataMat_Ops *ops, void *data)
Set the opaque pointer and function pointers to the matrix.
Definition dsdpdatamat.c:25
DSDPDataMatGetRank
int DSDPDataMatGetRank(DSDPDataMat A, int *rank, int n)
Get the number of nonzero eigenvalues/eigenvectors for the matrix.
Definition dsdpdatamat.c:129
DSDPDataMatDot
int DSDPDataMatDot(DSDPDataMat A, double x[], int nn, int n, double *v)
Compute inner product of data with a dense matrix.
Definition dsdpdatamat.c:273
DSDPDataMatCountNonzeros
int DSDPDataMatCountNonzeros(DSDPDataMat A, int *nnz, int n)
Compute the square of the Frobenius norm.
Definition dsdpdatamat.c:152
DSDPDataMatFNorm2
int DSDPDataMatFNorm2(DSDPDataMat A, int n, double *fnorm2)
Compute the square of the Frobenius norm.
Definition dsdpdatamat.c:175
DSDPDataMatTest
int DSDPDataMatTest(DSDPDataMat A)
Test validity of matrix.
Definition dsdpdatamat.c:96
DSDPDataMatFactor
int DSDPDataMatFactor(DSDPDataMat A, SDPConeVec W, double *dworknn, int nn0, double *dwork3n, int nd, int *iwork, int ni)
Do eigenvalue/vector or other factorization.
Definition dsdpdatamat.c:240
DSDPDataMatInitialize
int DSDPDataMatInitialize(DSDPDataMat *A)
Set pointers to NULL;.
Definition dsdpdatamat.c:78
dsdpdatamat.h
The interface between the SDPCone and the data matrices.
dsdpdatamat_impl.h
Structure of function pointers that each SDP data matrix type (sparse, dense, constant,...
dsdpsys.h
Error handling, printing, and profiling.
DSDPDataMat_C
Symmetric data matrix for one block in the semidefinite cone.
Definition dsdpdatamat.h:15
DSDPDataMat_Ops
Table of function pointers that operate on the data matrix.
Definition dsdpdatamat_impl.h:15
SDPConeVec_C
Vector whose length corresponds to dimension of a block in a cone.
Definition sdpconevec.h:13