DSDP
sdpconevec.c
Go to the documentation of this file.
1 #include "dsdpsys.h"
2 #include "sdpconevec.h"
3 #include "dsdplapack.h"
9 #define SDPConeVecCheck(a,b) {if (a.dim != b.dim) return 1; if (a.dim>0 && (a.val==NULL || b.val==NULL) ) return 2;}
10 static int nvecs=0;
11 
12 #undef __FUNCT__
13 #define __FUNCT__ "SDPConeVecCreate"
14 int SDPConeVecCreate(int n ,SDPConeVec *V){
15  int info;
16  V->dim=n;
17  if (n>0){
18  nvecs++;
19  DSDPCALLOC2(&(V->val),double,n,&info);DSDPCHKERR(info);
20  } else {
21  V->val=NULL;
22  }
23  return 0;
24 }
25 
26 #undef __FUNCT__
27 #define __FUNCT__ "SDPConeVecDestroy"
28 int SDPConeVecDestroy(SDPConeVec *V){
29  int info;
30  if ((*V).val){
31  DSDPFREE(&(*V).val,&info);DSDPCHKERR(info);
32  nvecs--;
33  }
34 
35  (*V).dim=0;
36  (*V).val=0;
37  return 0;
38 }
39 
40 #undef __FUNCT__
41 #define __FUNCT__ "SDPConeVecView"
42 
50  int i;
51  for (i=0; i<V.dim; i++){
52  printf("%3.3e ",V.val[i]);
53  }
54  printf("\n");
55  return 0;
56 }
57 
58 #undef __FUNCT__
59 #define __FUNCT__ "SDPConeVecZero"
60 
68  int n=V.dim;
69  double *v=V.val;
70  memset((void*)v,0,n*sizeof(double));
71  return 0;
72 }
73 
74 
75 #undef __FUNCT__
76 #define __FUNCT__ "SDPConeVecNormalize"
77 
85  int info;
86  double vnorm;
87  info = SDPConeVecNorm2(V,&vnorm);DSDPCHKERR(info);
88  if (vnorm==0){ return 1;}
89  vnorm=1.0/(vnorm);
90  info = SDPConeVecScale(vnorm,V);DSDPCHKERR(info);
91  return 0;
92 }
93 
94 #undef __FUNCT__
95 #define __FUNCT__ "SDPConeVecCopy"
96 
104 
105  int n=v1.dim;
106  double *val1=v1.val,*val2=v2.val;
107  SDPConeVecCheck(v1,v2);
108  if (val1!=val2){
109  memcpy(val2,val1,n*sizeof(double));
110  }
111  return 0;
112 }
113 
114 
115 #undef __FUNCT__
116 #define __FUNCT__ "SDPConeVecDot"
117 
125 int SDPConeVecDot(SDPConeVec V1, SDPConeVec V2, double *ans){
126  ffinteger ione=1, nn=V1.dim;
127  double *v1=V1.val,*v2=V2.val;
128  *ans=ddot(&nn,v1,&ione,v2,&ione);
129  if (*ans!=*ans) return 1;
130  return 0;
131 }
132 
133 
134 #undef __FUNCT__
135 #define __FUNCT__ "SDPConeVecNorm2"
136 
143 int SDPConeVecNorm2( SDPConeVec VV, double *vnorm){
144  ffinteger ione=1,nn=VV.dim;
145  double dd,*v=VV.val;
146  dd=dnrm2(&nn,v,&ione);
147  *vnorm = dd;
148  if (*vnorm!=*vnorm) return 1;
149  return 0;
150 }
151 
152 #undef __FUNCT__
153 #define __FUNCT__ "SDPConeVecScale"
154 
161 int SDPConeVecScale(double alpha, SDPConeVec VV){
162  ffinteger ione=1,nn=VV.dim;
163  double *v=VV.val;
164  dscal(&nn,&alpha,v,&ione);
165  return 0;
166 }
167 
168 #undef __FUNCT__
169 #define __FUNCT__ "SDPConeVecAXPY"
170 
178 int SDPConeVecAXPY(double alpha, SDPConeVec x, SDPConeVec y){
179  ffinteger ione=1,nn=x.dim;
180  double *yy=y.val,*xx=x.val;
181  if (alpha==0) return 0;
182  daxpy(&nn,&alpha,xx,&ione,yy,&ione);
183  return 0;
184 }
185 
186 #undef __FUNCT__
187 #define __FUNCT__ "SDPConeVecDuplicate"
188 
196  int info,n=V1.dim;
197  info = SDPConeVecCreate(n ,V2);DSDPCHKERR(info);
198  return 0;
199 }
200 
201 
202 #undef __FUNCT__
203 #define __FUNCT__ "SDPConeVecSet"
204 
211 int SDPConeVecSet(double alpha, SDPConeVec V){
212 
213  int i,n=V.dim;
214  double *val=V.val;
215 
216  if (alpha==0.0){
217  memset((void*)val,0,n*sizeof(double));
218  return 0;
219  }
220  for (i=0; i<n; ++i){
221  val[i]= alpha;
222  }
223  return 0;
224 }
225 
226 #undef __FUNCT__
227 #define __FUNCT__ "DSDPIndexInitialize"
228 
234 int DSDPIndexInitialize(DSDPIndex *IS){
235  DSDPFunctionBegin;
236  IS->indx=0;
237  DSDPFunctionReturn(0);
238 }
239 #undef __FUNCT__
240 #define __FUNCT__ "DSDPIndexCreate"
241 
248 int DSDPIndexCreate(int n,DSDPIndex *IS){
249  int info,*is;
250  DSDPFunctionBegin;
251  DSDPCALLOC2(&is,int,n+1,&info);
252  IS->indx=is;is[0]=0;
253  DSDPFunctionReturn(0);
254 }
255 
256 #undef __FUNCT__
257 #define __FUNCT__ "DSDPIndexDestroy"
258 
264 int DSDPIndexDestroy(DSDPIndex *IS){
265  int info;
266  DSDPFunctionBegin;
267  DSDPFREE(&IS->indx,&info);DSDPCHKERR(info);
268  DSDPFunctionReturn(0);
269 }
270 
271 #undef __FUNCT__
272 #define __FUNCT__ "DSDPIndexView"
273 
279 int DSDPIndexView(DSDPIndex IS){
280  int i;
281  DSDPFunctionBegin;
282  printf("Index Set with %d indices.\n",IS.indx[0]);
283  for (i=0;i<IS.indx[0];i++){
284  printf(" %d",IS.indx[i+1]);
285  }
286  printf(" \n");
287  DSDPFunctionReturn(0);
288 }
int SDPConeVecScale(double alpha, SDPConeVec VV)
Compute the Euclidean norm.
Definition: sdpconevec.c:161
int SDPConeVecZero(SDPConeVec V)
Zero the elements of the vector.
Definition: sdpconevec.c:67
Error handling, printing, and profiling.
int SDPConeVecCopy(SDPConeVec v1, SDPConeVec v2)
Copy v1 to v2.
Definition: sdpconevec.c:103
Each block of the SDPCone has two vectors of appropriate size.
int DSDPIndexInitialize(DSDPIndex *IS)
Set structure pointers to 0.
Definition: sdpconevec.c:234
int SDPConeVecView(SDPConeVec V)
Print the elements of the vector.
Definition: sdpconevec.c:49
Vector whose length corresponds to dimension of a block in a cone.
Definition: sdpconevec.h:13
int SDPConeVecNormalize(SDPConeVec V)
Scale the vector to norm of 1.
Definition: sdpconevec.c:84
int SDPConeVecSet(double alpha, SDPConeVec V)
Set each element of vector to this number.
Definition: sdpconevec.c:211
int SDPConeVecNorm2(SDPConeVec VV, double *vnorm)
Compute the Euclidean norm.
Definition: sdpconevec.c:143
int SDPConeVecDot(SDPConeVec V1, SDPConeVec V2, double *ans)
Inner product of two vectors.
Definition: sdpconevec.c:125
int DSDPIndexDestroy(DSDPIndex *IS)
Deallocate memory.
Definition: sdpconevec.c:264
int SDPConeVecDuplicate(SDPConeVec V1, SDPConeVec *V2)
Allocate another vector with the same structure as the first.
Definition: sdpconevec.c:195
int DSDPIndexCreate(int n, DSDPIndex *IS)
Allocate array for indices.
Definition: sdpconevec.c:248
DSDP uses BLAS and LAPACK for many of its operations.
int DSDPIndexView(DSDPIndex IS)
Print indices.
Definition: sdpconevec.c:279
int SDPConeVecAXPY(double alpha, SDPConeVec x, SDPConeVec y)
Add a multiple of X to Y.
Definition: sdpconevec.c:178