00001 #include "dsdpsys.h"
00002 #include "sdpconevec.h"
00003 #include "dsdplapack.h"
00009 #define SDPConeVecCheck(a,b) {if (a.dim != b.dim) return 1; if (a.dim>0 && (a.val==NULL || b.val==NULL) ) return 2;}
00010 static int nvecs=0;
00011
00012 #undef __FUNCT__
00013 #define __FUNCT__ "SDPConeVecCreate"
00014 int SDPConeVecCreate(int n ,SDPConeVec *V){
00015 int info;
00016 V->dim=n;
00017 if (n>0){
00018 nvecs++;
00019 DSDPCALLOC2(&(V->val),double,n,&info);DSDPCHKERR(info);
00020 } else {
00021 V->val=NULL;
00022 }
00023 return 0;
00024 }
00025
00026 #undef __FUNCT__
00027 #define __FUNCT__ "SDPConeVecDestroy"
00028 int SDPConeVecDestroy(SDPConeVec *V){
00029 int info;
00030 if ((*V).val){
00031 DSDPFREE(&(*V).val,&info);DSDPCHKERR(info);
00032 nvecs--;
00033 }
00034
00035 (*V).dim=0;
00036 (*V).val=0;
00037 return 0;
00038 }
00039
00040 #undef __FUNCT__
00041 #define __FUNCT__ "SDPConeVecView"
00042
00049 int SDPConeVecView(SDPConeVec V){
00050 int i;
00051 for (i=0; i<V.dim; i++){
00052 printf("%3.3e ",V.val[i]);
00053 }
00054 printf("\n");
00055 return 0;
00056 }
00057
00058 #undef __FUNCT__
00059 #define __FUNCT__ "SDPConeVecZero"
00060
00067 int SDPConeVecZero(SDPConeVec V){
00068 int n=V.dim;
00069 double *v=V.val;
00070 memset((void*)v,0,n*sizeof(double));
00071 return 0;
00072 }
00073
00074
00075 #undef __FUNCT__
00076 #define __FUNCT__ "SDPConeVecNormalize"
00077
00084 int SDPConeVecNormalize(SDPConeVec V){
00085 int info;
00086 double vnorm;
00087 info = SDPConeVecNorm2(V,&vnorm);DSDPCHKERR(info);
00088 if (vnorm==0){ return 1;}
00089 vnorm=1.0/(vnorm);
00090 info = SDPConeVecScale(vnorm,V);DSDPCHKERR(info);
00091 return 0;
00092 }
00093
00094 #undef __FUNCT__
00095 #define __FUNCT__ "SDPConeVecCopy"
00096
00103 int SDPConeVecCopy( SDPConeVec v1, SDPConeVec v2){
00104
00105 int n=v1.dim;
00106 double *val1=v1.val,*val2=v2.val;
00107 SDPConeVecCheck(v1,v2);
00108 if (val1!=val2){
00109 memcpy(val2,val1,n*sizeof(double));
00110 }
00111 return 0;
00112 }
00113
00114
00115 #undef __FUNCT__
00116 #define __FUNCT__ "SDPConeVecDot"
00117
00125 int SDPConeVecDot(SDPConeVec V1, SDPConeVec V2, double *ans){
00126 ffinteger ione=1, nn=V1.dim;
00127 double *v1=V1.val,*v2=V2.val;
00128 *ans=ddot(&nn,v1,&ione,v2,&ione);
00129 if (*ans!=*ans) return 1;
00130 return 0;
00131 }
00132
00133
00134 #undef __FUNCT__
00135 #define __FUNCT__ "SDPConeVecNorm2"
00136
00143 int SDPConeVecNorm2( SDPConeVec VV, double *vnorm){
00144 ffinteger ione=1,nn=VV.dim;
00145 double dd,*v=VV.val;
00146 dd=dnrm2(&nn,v,&ione);
00147 *vnorm = dd;
00148 if (*vnorm!=*vnorm) return 1;
00149 return 0;
00150 }
00151
00152 #undef __FUNCT__
00153 #define __FUNCT__ "SDPConeVecScale"
00154
00161 int SDPConeVecScale(double alpha, SDPConeVec VV){
00162 ffinteger ione=1,nn=VV.dim;
00163 double *v=VV.val;
00164 dscal(&nn,&alpha,v,&ione);
00165 return 0;
00166 }
00167
00168 #undef __FUNCT__
00169 #define __FUNCT__ "SDPConeVecAXPY"
00170
00178 int SDPConeVecAXPY(double alpha, SDPConeVec x, SDPConeVec y){
00179 ffinteger ione=1,nn=x.dim;
00180 double *yy=y.val,*xx=x.val;
00181 if (alpha==0) return 0;
00182 daxpy(&nn,&alpha,xx,&ione,yy,&ione);
00183 return 0;
00184 }
00185
00186 #undef __FUNCT__
00187 #define __FUNCT__ "SDPConeVecDuplicate"
00188
00195 int SDPConeVecDuplicate(SDPConeVec V1,SDPConeVec *V2){
00196 int info,n=V1.dim;
00197 info = SDPConeVecCreate(n ,V2);DSDPCHKERR(info);
00198 return 0;
00199 }
00200
00201
00202 #undef __FUNCT__
00203 #define __FUNCT__ "SDPConeVecSet"
00204
00211 int SDPConeVecSet(double alpha, SDPConeVec V){
00212
00213 int i,n=V.dim;
00214 double *val=V.val;
00215
00216 if (alpha==0.0){
00217 memset((void*)val,0,n*sizeof(double));
00218 return 0;
00219 }
00220 for (i=0; i<n; ++i){
00221 val[i]= alpha;
00222 }
00223 return 0;
00224 }
00225
00226 #undef __FUNCT__
00227 #define __FUNCT__ "DSDPIndexInitialize"
00228
00234 int DSDPIndexInitialize(DSDPIndex *IS){
00235 DSDPFunctionBegin;
00236 IS->indx=0;
00237 DSDPFunctionReturn(0);
00238 }
00239 #undef __FUNCT__
00240 #define __FUNCT__ "DSDPIndexCreate"
00241
00248 int DSDPIndexCreate(int n,DSDPIndex *IS){
00249 int info,*is;
00250 DSDPFunctionBegin;
00251 DSDPCALLOC2(&is,int,n+1,&info);
00252 IS->indx=is;is[0]=0;
00253 DSDPFunctionReturn(0);
00254 }
00255
00256 #undef __FUNCT__
00257 #define __FUNCT__ "DSDPIndexDestroy"
00258
00264 int DSDPIndexDestroy(DSDPIndex *IS){
00265 int info;
00266 DSDPFunctionBegin;
00267 DSDPFREE(&IS->indx,&info);DSDPCHKERR(info);
00268 DSDPFunctionReturn(0);
00269 }
00270
00271 #undef __FUNCT__
00272 #define __FUNCT__ "DSDPIndexView"
00273
00279 int DSDPIndexView(DSDPIndex IS){
00280 int i;
00281 DSDPFunctionBegin;
00282 printf("Index Set with %d indices.\n",IS.indx[0]);
00283 for (i=0;i<IS.indx[0];i++){
00284 printf(" %d",IS.indx[i+1]);
00285 }
00286 printf(" \n");
00287 DSDPFunctionReturn(0);
00288 }