IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20827


Ignore:
Timestamp:
Nov 24, 2008, 5:09:38 PM (17 years ago)
Author:
eugene
Message:

working on double vectors, other additions

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20081124/Ohana/src/libautocode/def/common.h

    r15007 r20827  
    3838# endif
    3939
    40 # define e_time unsigned int
     40# define e_time int
    4141# define e_void long long
    4242# define rawshort short
  • branches/eam_branch_20081124/Ohana/src/opihi/include/dvomath.h

    r15878 r20827  
    55
    66# define NCHARS 256
     7# define opihi_float float
     8# define opihi_int unsigned int
    79
    810enum {ANYVECTOR, NEWVECTOR, OLDVECTOR};
    911enum {ANYBUFFER, NEWBUFFER, OLDBUFFER};
     12enum {OPIHI_FLOAT, OPIHI_INT};
    1013
    1114typedef struct {                        /* representation of a variable (0-D) */
     
    1619typedef struct {                        /* representation of a vector (1-D) */
    1720  char name[1024];
     21  char type;
    1822  float *elements;
     23  unsigned int *elementsInt;
    1924  int Nelements;
    2025} Vector;
  • branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/VectorOps.c

    r16887 r20827  
    1818
    1919  for (i = 0; i < Nvectors; i++) {
    20     free (vectors[i][0].elements);
     20    if (vectors[i][0].elements) {
     21      free (vectors[i][0].elements);
     22    }
     23    if (vectors[i][0].elementsInt) {
     24      free (vectors[i][0].elementsInt);
     25    }
    2126    free (vectors[i]);
    2227  }
     
    2833
    2934  ALLOCATE (vec, Vector, 1);
    30   ALLOCATE (vec[0].elements, float, 1);
     35
     36  vec[0].elementsInt = NULL;
     37  ALLOCATE (vec[0].elements, opihi_float, 1);
     38  vec[0].type = OPIHI_FLOAT;                      /* is a float unless specified otherwise */
     39
    3140  bzero (vec[0].name, 1024);
    3241  vec[0].Nelements = 0;
     
    95104  if (i == Nvectors) return (FALSE);
    96105
    97   free (vectors[i][0].elements);
     106  if (vectors[i][0].elements)    free (vectors[i][0].elements);
     107  if (vectors[i][0].elementsInt) free (vectors[i][0].elementsInt);
    98108  free (vectors[i]);
    99109
     
    115125  if (i == Nvectors) return (FALSE);
    116126
    117   free (vectors[i][0].elements);
     127  if (vectors[i][0].elements)    free (vectors[i][0].elements);
     128  if (vectors[i][0].elementsInt) free (vectors[i][0].elementsInt);
    118129  free (vectors[i]);
    119130
     
    137148  free (out[0].elements);
    138149  out[0].Nelements = in[0].Nelements;
    139   ALLOCATE (out[0].elements, float, out[0].Nelements);
    140   memcpy (out[0].elements, in[0].elements, out[0].Nelements*sizeof(float));
     150  if (in[0].elements) {
     151    assert (in[0].type == OPIHI_FLOAT);
     152    ALLOCATE (out[0].elements, opihi_float, out[0].Nelements);
     153    memcpy (out[0].elements, in[0].elements, out[0].Nelements*sizeof(opihi_float));
     154    out[0].type = OPIHI_FLOAT;
     155  } else {
     156    assert (in[0].type == OPIHI_INT);
     157    ALLOCATE (out[0].elementsInt, opihi_int, out[0].Nelements);
     158    memcpy (out[0].elementsInt, in[0].elementsInt, out[0].Nelements*sizeof(opihi_int));
     159    out[0].type = OPIHI_INT;
     160  }
    141161  return (TRUE);
    142162}
     
    154174
    155175  free (out[0].elements);
    156   out[0].Nelements = in[0].Nelements;
    157   out[0].elements =  in[0].elements;
     176  out[0].Nelements   = in[0].Nelements;
     177  out[0].elements    = in[0].elements;
     178  out[0].elementsInt = in[0].elementsInt;
     179  out[0].type        = in[0].type;
    158180
    159181  /* delete vector entry from vector list, if it exists */
  • branches/eam_branch_20081124/Ohana/src/opihi/lib.shell/stack_math.c

    r18078 r20827  
    3535  out = OUT[0].ptr = (float *)OUT[0].vector[0].elements;
    3636
    37   switch (op[0]) {
     37// XXX this is not quite there:
     38// 1) do I drop the .ptr element of StackVar?
     39// 2) things below are using type from a StackVar to get the vector type -- wrong place
     40// 3) the temp would need lots of work -- is it worth it?
     41// 4) some operators force the output to be float -- we cannot use a single bit of code to
     42//    define the output type based on which is a float and which is not.  getting ugly.
     43// ??? how much more work to bring the MV, etc functions into shape ???
     44
     45# define VV_FUNC(OP) \
     46  if ((M1->type == OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { \
     47    // output must be float, can use either as a temp \
     48    opihi_float *M1 = V1[0].vector[0].elements; \
     49    opihi_float *M2 = V2[0].vector[0].elements; \
     50    for (i = 0; i < Nx; i++, out++, M1++, M2++) { \
     51        *out = *M1 OP *M2; \
     52    } \
     53    break; \
     54  } \
     55  if ((M1->type != OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { \
     56    // output must be float, can use M2 as a temp \
     57    opihi_float *M1 = V1[0].vector[0].elementsInt; \
     58    opihi_float *M2 = V2[0].vector[0].elements; \
     59    for (i = 0; i < Nx; i++, out++, M1++, M2++) { \
     60        *out = *M1 OP *M2; \
     61    } \
     62    break; \
     63  } \
     64  if ((M1->type == OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) { \
     65    // output must be float, can use M1 as a temp \
     66    opihi_float *M1 = V1[0].vector[0].elements; \
     67    opihi_float *M2 = V2[0].vector[0].elementsInt; \
     68    for (i = 0; i < Nx; i++, out++, M1++, M2++) { \
     69        *out = *M1 OP *M2; \
     70    } \
     71    break; \
     72  } \
     73  if ((M1->type != OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) { \
     74    // output may be int, can use either as temp \
     75    opihi_float *M1 = V1[0].vector[0].elementsInt; \
     76    opihi_float *M2 = V2[0].vector[0].elementsInt; \
     77    for (i = 0; i < Nx; i++, out++, M1++, M2++) { \
     78        *out = *M1 OP *M2; \
     79    } \
     80    break; \
     81  }
     82
     83  switch (op[0]) {
    3884  case '+':
    39     for (i = 0; i < Nx; i++, out++, M1++, M2++)
    40       *out = *M1 + *M2;
    41     break;
     85    VV_FUNC
     86
     87    if ((M1->type == OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) {
     88      // output must be float, can use either as a temp
     89      M1 = V1[0].vector[0].elements;
     90      M2 = V2[0].vector[0].elements;
     91      for (i = 0; i < Nx; i++, out++, M1++, M2++) {
     92        *out = *M1 + *M2;
     93      }
     94      break;
     95    }
     96    if ((M1->type != OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) {
     97      // output must be float, can use M2 as a temp
     98      M1 = V1[0].vector[0].elementsInt;
     99      M2 = V2[0].vector[0].elements;
     100      for (i = 0; i < Nx; i++, out++, M1++, M2++) {
     101        *out = *M1 + *M2;
     102      }
     103      break;
     104    }
     105    if ((M1->type == OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) {
     106      // output must be float, can use M1 as a temp
     107      M1 = V1[0].vector[0].elements;
     108      M2 = V2[0].vector[0].elementsInt;
     109      for (i = 0; i < Nx; i++, out++, M1++, M2++) {
     110        *out = *M1 + *M2;
     111      }
     112      break;
     113    }
     114    if ((M1->type != OPIHI_FLOAT) && (M2->type != OPIHI_FLOAT)) {
     115      // output may be int, can use either as temp
     116      M1 = V1[0].vector[0].elementsInt;
     117      M2 = V2[0].vector[0].elementsInt;
     118      for (i = 0; i < Nx; i++, out++, M1++, M2++) {
     119        *out = *M1 + *M2;
     120      }
     121      break;
     122    }
    42123  case '-':
    43124    for (i = 0; i < Nx; i++, out++, M1++, M2++)
Note: See TracChangeset for help on using the changeset viewer.