sdpconevec.c
Go to the documentation of this file.
#include "dsdpsys.h"
#include "sdpconevec.h"
#include "dsdplapack.h"
#define SDPConeVecCheck(a,b) {if (a.dim != b.dim) return 1; if (a.dim>0 && (a.val==NULL || b.val==NULL) ) return 2;}
static int nvecs=0;
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecCreate"
int SDPConeVecCreate(int n ,SDPConeVec *V){
int info;
V->dim=n;
if (n>0){
nvecs++;
DSDPCALLOC2(&(V->val),double,n,&info);DSDPCHKERR(info);
} else {
V->val=NULL;
}
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecDestroy"
int SDPConeVecDestroy(SDPConeVec *V){
int info;
if ((*V).val){
DSDPFREE(&(*V).val,&info);DSDPCHKERR(info);
nvecs--;
}
(*V).dim=0;
(*V).val=0;
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecView"
int SDPConeVecView(SDPConeVec V){
int i;
for (i=0; i<V.dim; i++){
printf("%3.3e ",V.val[i]);
}
printf("\n");
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecZero"
int SDPConeVecZero(SDPConeVec V){
int n=V.dim;
double *v=V.val;
memset((void*)v,0,n*sizeof(double));
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecNormalize"
int SDPConeVecNormalize(SDPConeVec V){
int info;
double vnorm;
info = SDPConeVecNorm2(V,&vnorm);DSDPCHKERR(info);
if (vnorm==0){ return 1;}
vnorm=1.0/(vnorm);
info = SDPConeVecScale(vnorm,V);DSDPCHKERR(info);
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecCopy"
int SDPConeVecCopy( SDPConeVec v1, SDPConeVec v2){
int n=v1.dim;
double *val1=v1.val,*val2=v2.val;
SDPConeVecCheck(v1,v2);
if (val1!=val2){
memcpy(val2,val1,n*sizeof(double));
}
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecDot"
int SDPConeVecDot(SDPConeVec V1, SDPConeVec V2, double *ans){
ffinteger ione=1, nn=V1.dim;
double *v1=V1.val,*v2=V2.val;
*ans=ddot(&nn,v1,&ione,v2,&ione);
if (*ans!=*ans) return 1;
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecNorm2"
int SDPConeVecNorm2( SDPConeVec VV, double *vnorm){
ffinteger ione=1,nn=VV.dim;
double dd,*v=VV.val;
dd=dnrm2(&nn,v,&ione);
*vnorm = dd;
if (*vnorm!=*vnorm) return 1;
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecScale"
int SDPConeVecScale(double alpha, SDPConeVec VV){
ffinteger ione=1,nn=VV.dim;
double *v=VV.val;
dscal(&nn,&alpha,v,&ione);
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecAXPY"
int SDPConeVecAXPY(double alpha, SDPConeVec x, SDPConeVec y){
ffinteger ione=1,nn=x.dim;
double *yy=y.val,*xx=x.val;
if (alpha==0) return 0;
daxpy(&nn,&alpha,xx,&ione,yy,&ione);
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecDuplicate"
int SDPConeVecDuplicate(SDPConeVec V1,SDPConeVec *V2){
int info,n=V1.dim;
info = SDPConeVecCreate(n ,V2);DSDPCHKERR(info);
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "SDPConeVecSet"
int SDPConeVecSet(double alpha, SDPConeVec V){
int i,n=V.dim;
double *val=V.val;
if (alpha==0.0){
memset((void*)val,0,n*sizeof(double));
return 0;
}
for (i=0; i<n; ++i){
val[i]= alpha;
}
return 0;
}
#undef __FUNCT__
#define __FUNCT__ "DSDPIndexInitialize"
int DSDPIndexInitialize(DSDPIndex *IS){
DSDPFunctionBegin;
IS->indx=0;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPIndexCreate"
int DSDPIndexCreate(int n,DSDPIndex *IS){
int info,*is;
DSDPFunctionBegin;
DSDPCALLOC2(&is,int,n+1,&info);
IS->indx=is;is[0]=0;
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPIndexDestroy"
int DSDPIndexDestroy(DSDPIndex *IS){
int info;
DSDPFunctionBegin;
DSDPFREE(&IS->indx,&info);DSDPCHKERR(info);
DSDPFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "DSDPIndexView"
int DSDPIndexView(DSDPIndex IS){
int i;
DSDPFunctionBegin;
printf("Index Set with %d indices.\n",IS.indx[0]);
for (i=0;i<IS.indx[0];i++){
printf(" %d",IS.indx[i+1]);
}
printf(" \n");
DSDPFunctionReturn(0);
}
dsdplapack.h
DSDP uses BLAS and LAPACK for many of its operations.
dsdpsys.h
Error handling, printing, and profiling.
SDPConeVecAXPY
int SDPConeVecAXPY(double alpha, SDPConeVec x, SDPConeVec y)
Add a multiple of X to Y.
Definition sdpconevec.c:178
SDPConeVecDuplicate
int SDPConeVecDuplicate(SDPConeVec V1, SDPConeVec *V2)
Allocate another vector with the same structure as the first.
Definition sdpconevec.c:195
SDPConeVecNorm2
int SDPConeVecNorm2(SDPConeVec VV, double *vnorm)
Compute the Euclidean norm.
Definition sdpconevec.c:143
SDPConeVecCopy
int SDPConeVecCopy(SDPConeVec v1, SDPConeVec v2)
Copy v1 to v2.
Definition sdpconevec.c:103
DSDPIndexDestroy
int DSDPIndexDestroy(DSDPIndex *IS)
Deallocate memory.
Definition sdpconevec.c:264
SDPConeVecView
int SDPConeVecView(SDPConeVec V)
Print the elements of the vector.
Definition sdpconevec.c:49
DSDPIndexCreate
int DSDPIndexCreate(int n, DSDPIndex *IS)
Allocate array for indices.
Definition sdpconevec.c:248
DSDPIndexView
int DSDPIndexView(DSDPIndex IS)
Print indices.
Definition sdpconevec.c:279
SDPConeVecScale
int SDPConeVecScale(double alpha, SDPConeVec VV)
Compute the Euclidean norm.
Definition sdpconevec.c:161
SDPConeVecZero
int SDPConeVecZero(SDPConeVec V)
Zero the elements of the vector.
Definition sdpconevec.c:67
SDPConeVecDot
int SDPConeVecDot(SDPConeVec V1, SDPConeVec V2, double *ans)
Inner product of two vectors.
Definition sdpconevec.c:125
SDPConeVecNormalize
int SDPConeVecNormalize(SDPConeVec V)
Scale the vector to norm of 1.
Definition sdpconevec.c:84
SDPConeVecSet
int SDPConeVecSet(double alpha, SDPConeVec V)
Set each element of vector to this number.
Definition sdpconevec.c:211
DSDPIndexInitialize
int DSDPIndexInitialize(DSDPIndex *IS)
Set structure pointers to 0.
Definition sdpconevec.c:234
sdpconevec.h
Each block of the SDPCone has two vectors of appropriate size.
SDPConeVec_C
Vector whose length corresponds to dimension of a block in a cone.
Definition sdpconevec.h:13