IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 16, 2012, 7:51:21 AM (14 years ago)
Author:
eugene
Message:

parallelize gstar, update avmatch to work with merged vectors by index; remove elements from dvoshell.h which have moved to libdvo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/opihi/lib.shell/VectorOps.c

    r33476 r33543  
    338338  return (Nvectors);
    339339}
     340
     341// Take two arrays of vectors and merge equal named vectors.
     342// Output is a single array in (vec), with vectors lengths of len(vec) + len(invec)
     343// For ease, require that the order of the names match & number of vectors match
     344Vector **MergeVectors (Vector **vec, int *Nvec, Vector **invec, int Ninvec) {
     345
     346  int i, j;
     347
     348  if (vec == NULL) {
     349    *Nvec = Ninvec;
     350    return invec;
     351  }
     352
     353  myAssert (*Nvec == Ninvec, "programming error (1)");
     354
     355  for (i = 0; i < Ninvec; i++) {
     356    myAssert (!strcmp(vec[i]->name, invec[i]->name), "programming error (2)");
     357    myAssert (vec[i]->type == invec[i]->type, "programming error (2)");
     358
     359    int N = vec[i]->Nelements;
     360    if (vec[i]->type == OPIHI_FLT) {
     361      REALLOCATE (vec[i]->elements.Flt, opihi_flt, vec[i]->Nelements + invec[i]->Nelements);
     362      for (j = 0; j < invec[i]->Nelements; j++) {
     363        vec[i]->elements.Flt[N+j] = invec[i]->elements.Flt[j];
     364      }
     365    } else {
     366      REALLOCATE (vec[i]->elements.Int, opihi_int, vec[i]->Nelements + invec[i]->Nelements);
     367      for (j = 0; j < invec[i]->Nelements; j++) {
     368        vec[i]->elements.Int[N+j] = invec[i]->elements.Int[j];
     369      }
     370    }
     371    vec[i]->Nelements += invec[i]->Nelements;
     372  }
     373  return vec;
     374}
     375
     376// Take two arrays of vectors and merge equal named vectors, where the last vector
     377// specifies the element in the output vector.  All input vectors must have a max sequence
     378// value of Nelements.  Output is a single array in (vec), with vector lengths of
     379// Nelements for ease, require that the order of the names match & number of vectors match
     380Vector **MergeVectorsByIndex (Vector **vec, int *Nvec, Vector **invec, int Ninvec, int Nelements) {
     381
     382  int i, j;
     383
     384  // on first call, allocate a new vector, excluding the index
     385  int newArray = FALSE;
     386  if (vec == NULL) {
     387    ALLOCATE (vec, Vector *, Ninvec - 1);
     388    *Nvec = Ninvec - 1;
     389    newArray = TRUE;
     390  }
     391
     392  myAssert (*Nvec == Ninvec - 1, "programming error (1)");
     393
     394  // find the index vector
     395  int idx = Ninvec - 1;
     396  myAssert (!strcmp(invec[idx]->name, "index"), "failed to find index vector");
     397 
     398  for (i = 0; i < Ninvec - 1; i++) {
     399    // on first call, create the output vector
     400    if (newArray) {
     401      vec[i] = InitVector();
     402      strcpy (vec[i]->name, invec[i]->name);
     403      ResetVector (vec[i], invec[i]->type, Nelements);
     404      for (j = 0; j < Nelements; j++) {
     405        if (vec[i][0].type == OPIHI_FLT) {
     406          vec[i][0].elements.Flt[j] = NAN;
     407        } else {
     408          vec[i][0].elements.Int[j] = 0; // or NAN_INT?
     409        }
     410      }
     411    }
     412
     413    myAssert (!strcmp(vec[i]->name, invec[i]->name), "programming error (2)");
     414    myAssert (vec[i]->type == invec[i]->type, "programming error (2)");
     415
     416    // copy vector elements from input to output, matching location
     417    if (vec[i]->type == OPIHI_FLT) {
     418      for (j = 0; j < invec[i]->Nelements; j++) {
     419        int seq = invec[idx]->elements.Int[j];
     420        vec[i]->elements.Flt[seq] = invec[i]->elements.Flt[j];
     421      }
     422    } else {
     423      for (j = 0; j < invec[i]->Nelements; j++) {
     424        int seq = invec[idx]->elements.Int[j];
     425        vec[i]->elements.Int[seq] = invec[i]->elements.Int[j];
     426      }
     427    }
     428  }
     429  return vec;
     430}
     431
Note: See TracChangeset for help on using the changeset viewer.