43 if (_ext==0) {
d->
p=NULL;
return; };
45 d->
p=(
double*)malloc(_ext*
sizeof(
double));
46 if (
d->
p==NULL) { printf(
"memory allocation error\n"); getchar(); exit(253); }
67 else memcpy(
d->
p,dd,n*
sizeof(
double));
76 memcpy(
d->
p ,a,a.
sz()*
sizeof(double));
77 memcpy(
d->
p+a.
sz(),
b,b.
sz()*
sizeof(double));
87 printf(
"do not use this function ('setExternalData'): it's too dangerous.\n");
96 if (
d->
p) memset(
d->
p+i,0,_n*
sizeof(
double));
103 d->
p=(
double*)realloc(
d->
p,new_extention*
sizeof(
double));
104 if (
d->
p==NULL) { printf(
"memory allocation error\n"); getchar(); exit(253); }
129 d->
p=(
double*)realloc(
d->
p,
d->
n*
sizeof(
double));
130 if (
d->
p==NULL) { printf(
"memory allocation error\n"); getchar(); exit(253); }
137 if (Q.
d==
d)
return 1;
142 while (i--)
if (*(cP++))
return 0;
146 if (
sz() != Q.
sz())
return 0;
148 double *cP =
d->
p, *cQ = Q.
d->
p;
153 if (*cP!=*cQ)
return 0;
165 if (!N || !
d->
p) { printf(
"]\n");
return; }
168 while (--N) printf(
"%f,",*(up++));
217 if (_n==0) _n=r.
sz();
219 if (_n) memcpy(
d->
p,r.
d->
p,_n*
sizeof(
double));
229 if (
sz()==0)
return 0;
230 double *
x=
d->
p, sum=0;
238 double *xp=
d->
p, sum=0;
240 while (ni--) sum+=
sqr(*(xp++));
258 double *xp1=
d->
p, *xp2=v.
d->
p, sum=-1.0;
266 double *xp1=
d->
p, sum=-1.0;
274 if (
sz()==0)
return 0;
275 double *xp1=
d->
p, *xp2=v.
d->
p, sum=0;
277 while (ni--) sum+=
condorAbs(*(xp1++)-*(xp2++));
285 while (ni--) *(xp++)*=a;
292 double *xs=
d->
p, *xd=R;
293 while (ni--) *(xd++)=a * (*(xs++));
301 printf(
"error in V^t * M.\n"); getchar(); exit(254);
305 double sum, *dv=(*this), **dm=M, *dd=vR;
311 while (
i--) sum+=dv[
i]*dm[
i][szr];
321 printf(
"(matrix_diagonal * matrix) error");
322 getchar(); exit(249);
324 double **p1=M,*p2=(*this);
334 double *xp1=
d->
p, *xp2=v.
d->
p, sum=0;
336 while (ni--) { sum+=*(xp1++) * *(xp2++); };
342 if (
sz()==0)
return 0;
351 if (
sz()==0)
return 0;
362 while (ni--)
if (*(xp++)!=0)
return false;
370 double *xp1=r.
d->
p, *xp2=v.
d->
p, *xp3=
d->
p;
372 *(xp1++)+=*(xp3++)-*(xp2++);
379 double *xb=(*this), *r=rescaling;
380 while (i--) xb[
i]*=r[
i];
387 while (i--) xb[
i]=1/xb[
i];
394 double *xp1=r.
d->
p, *xp2=v.
d->
p, *xp3=
d->
p;
396 *(xp1++)+=*(xp3++)+*(xp2++);
403 double *xp1=
d->
p, *xp2=v.
d->
p;
404 while (ni--) *(xp1++)-=*(xp2++);
411 double *xp1=
d->
p, *xp2=v.
d->
p;
412 while (ni--) *(xp1++)+=*(xp2++);
419 double *xp1=
d->
p, *xp2=v.
d->
p;
420 if (a==1.0)
while (ni--) *(xp1++)+= *(xp2++);
421 else while (ni--) *(xp1++)+=a * (*(xp2++));
427 double *xp1=
d->
p, *xp2=((
double**)m)[
i];
428 while (ni--) *(xp1++)+=a * (*(xp2++));
434 std::ifstream ifp(filename,
std::ios::in | std::ios::binary);
435 ifp.read(reinterpret_cast<char*>(&_n),
sizeof(
int));
437 ifp.read(reinterpret_cast<char*>(
d->
p),
d->
n*
sizeof(
double));
444 if (ascii) f=fopen(filename,
"w");
else f=fopen(filename,
"wb");
447 printf(
"Cannot write to '%s'\n",filename);
456 char header[32]=
"CONDORVBv1.0";
461 if (ascii!=2)
fprintf(f,
"CONDORVAv1.0\n");
464 for (i=0; i<
sz()-1; i++)
fprintf(f,
"%.16e\t",pp[i]);
469 fwrite(header,
sizeof(
char),13,f);
470 fwrite(&
d->
n,
sizeof(
int),1, f);
471 fwrite(
d->
p,
d->
n*
sizeof(
double),1, f);
477 if (n==0) n=v.
sz()-ii;
479 memcpy(
d->
p+i, ((
double*)v)+ii, n*
sizeof(
double));
487 while (n--) *(p++)=dd;
494 double *ps=(*this), *pd=ps;
496 if (s>0) { n-=s; pd+=s; }
497 else { n+=s; ps+=s; }
498 memmove(pd,ps,n*
sizeof(
double));
503 int i,
n=
sz(), *ii=viP;
507 printf(
"error in permutation IN: sizes don't agree.\n"); getchar(); exit(255);
510 double *ps=(*this), *pd=vR;
518 int i,
n=
sz(), *ii=viP;
522 printf(
"error in permutation IN: sizes don't agree.\n"); getchar(); exit(255);
525 double *ps=(*this), *pd=vR;
536 return (((c>=
'0')&&(c<=
'9'))||
545 char *tline=line,*oldtline=NULL;
549 while ((*tline!=
EOL1)&&(*tline!=
EOL2))
551 while ((*tline==
' ')||
552 (*tline==
'\t'))tline++;
553 if ((*tline==
EOL1)||(*tline==
EOL2)||(*tline==0))
break;
570 if (gn==0) {
alloc(0,0);
return; };
579 char *tline=line, *oldtline;
582 while ((*tline==
' ')||
583 (*tline==
'\t'))tline++;
606 if (*tline) { *tline=
'\0'; tline++; }
607 dp[
k]=atof(oldtline);
614 FILE *
f=fopen(saveFileName,
"rb+");
619 t.
save(saveFileName,0);
629 t.
save(saveFileName,0);
632 fwrite(
d->
p,
sizeof(
double)*nc,1,f);
634 fseek(f,13,SEEK_SET);
635 if (fread(&nlfile,
sizeof(
int),1,f) !=
sizeof(
int)) {
636 std::cerr <<
"error while appending to file " << saveFileName << std::endl; exit(255);
639 fseek(f,13,SEEK_SET);
640 fwrite(&nlfile,
sizeof(
unsigned), 1, f);
void permutIn(Vector vR, VectorInt viP)
void appendToMatrixFile(char *saveFileName, char **names=NULL)
void setColNames(char **c, int nc=0)
void save(char *filename, char ascii)
int equals(const Vector Q)
double LnftyDistance(Vector v)
void prepareExtend(int new_extention)
Vector operator-=(Vector v)
double euclidianDistance(Vector v)
void oneByOneMutiply(Vector r)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
void setExternalData(int _n, double *dd)
char * getFromLine(char *line)
void zero(int _i=0, int _n=0)
Vector operator+=(Vector v)
Vector operator+(Vector v)
void alloc(int n, int ext)
void transposeAndMultiply(Vector vR, Matrix M)
Vector operator-(Vector v)
double L1Distance(Vector v)
void addInPlace(double a, Vector v)
void diagonalizeAndMultiply(Matrix M)
void save(char *filename, char ascii)
double scalarProduct(Vector v)
void setPart(int i, Vector v, int n=0, int ii=0)
void permutOut(Vector vR, VectorInt viP)
struct Vector::VectorDataTag VectorData
void destroyCurrentBuffer()
static Vector emptyVector
Vector & operator=(const Vector &P)
fprintf(glob_prnt.io, "\)
void copyFrom(Vector r, int _n=0)