示例#1
0
/*! change the matrix into an identity matrix */
inline zgbmatrix& zgbmatrix::identity()
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(m!=n){
    ERROR_REPORT;
    std::cerr << "Only square matrix can be a identity matrix." << std::endl
              << "The matrix size was " << m << "x" << n << "." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  for(long i=0; i<(kl+ku+1)*n; i++){ array[i] =comple(0.0,0.0); }
  for(long i=0; i<m; i++){ operator()(i,i) =comple(1.0,0.0); }
  
  return *this;
}
示例#2
0
/*! change the matrix into a zero matrix */
inline zgbmatrix& zgbmatrix::zero()
{VERBOSE_REPORT;
  for(long i=0; i<(kl+ku+1)*n; i++){
    array[i] =comple(0.0,0.0);
  }
  return *this;
}
inline zgematrix_small<m,n>& zgematrix_small<m,n>::zero()
{VERBOSE_REPORT;
  for(long k=0; k<m*n; k++){
    array[k] =comple(0.,0.);
  }
  return *this;
}
示例#4
0
/*! zrovector*zhematrix operator */
inline _zrovector operator*(const zrovector& vec, const zhematrix& mat)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(vec.l!=mat.n){
    ERROR_REPORT;
    std::cerr << "These vector and matrix can not make a product." << std::endl
              << "Your input was (" << vec.l << ") * (" << mat.n << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zrovector newvec(mat.n);
  zhemv_( 'l', mat.n, comple(1.0,0.0), mat.array, mat.n,
          vec.array, 1, comple(0.0,0.0), newvec.array, 1 );
  
  return _(newvec);
}
示例#5
0
/*! cast to _zhsmatrix */
inline _zhsmatrix dssmatrix::to_zhsmatrix() const
{VERBOSE_REPORT;
  zhsmatrix newmat(n,data.size());
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat.put(it->i, it->j, comple(it->v,0.0));
  }
  
  return _(newmat);
}
示例#6
0
/*! _zgematrix*zcovector operator */
inline _zcovector operator*(const _zgematrix& mat, const zcovector& vec)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(mat.n!=vec.l){
    ERROR_REPORT;
    std::cerr << "These matrix and vector can not make a product." << std::endl
              << "Your input was (" << mat.m << "x" << mat.n << ") * (" << vec.l << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zcovector newvec(mat.m);
  zgemv_( 'n', mat.m, mat.n, comple(1.0,0.0), mat.array, mat.m,
          vec.array, 1, comple(0.0,0.0), newvec.array, 1 );
  
  mat.destroy();
  return _(newvec);
}
示例#7
0
/*! zhematrix*zgematrix operator */
inline _zgematrix operator*(const zhematrix& matA, const zgematrix& matB)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.m){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a product." << std::endl
              << "Your input was (" << matA.n << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG

  zgematrix newmat( matA.n, matB.n );
  zhemm_( 'l', 'l', matA.n, matB.n, comple(1.0,0.0), 
          matA.array, matA.n, matB.array, matB.m, 
          comple(0.0,0.0), newmat.array, newmat.m );
  
  return _(newmat);
}
示例#8
0
/*! cast to _zgbmatrix */
inline _zgbmatrix dgbmatrix::to_zgbmatrix() const
{VERBOSE_REPORT;
  zgbmatrix newmat(m,n,kl,ku);
  for(long i=0; i<(kl+ku+1)*n; i++){
    newmat.array[i] =comple(array[i],0.0);
  }
  
  return _(newmat);
}
示例#9
0
/*! zgematrix*=_zgematrix operator */
inline zgematrix& zgematrix::operator*=(const _zgematrix& mat)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(n!=mat.m){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a product." << std::endl
              << "Your input was (" << m << "x" << n << ") *= (" << mat.m << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zgematrix newmat( m, mat.n );
  zgemm_( 'n', 'n', m, mat.n, n, comple(1.0,0.0), array, m,
          mat.array, mat.m, comple(0.0,0.0), newmat.array, m );
  
  swap(*this,newmat);
  mat.destroy();
  return *this;
}
示例#10
0
/*! cast to _zgematrix */
inline _zgematrix _dgematrix::to_zgematrix() const
{VERBOSE_REPORT;
  zgematrix newmat(m,n);
  for(long i=0; i<m*n; i++){
    newmat.array[i] =comple(array[i],0.0);
  }
  
  destroy();
  return _(newmat);
}
示例#11
0
/*! cast to _zcovector */
inline _zcovector _dcovector::to_zcovector() const
{VERBOSE_REPORT;
  zcovector newvec(l);
  
  for(long i=0; i<l; i++){
    newvec.array[i] =comple(array[i], 0.);
  }
  
  destroy();
  return _(newvec);
}
示例#12
0
/*! cast to _zhematrix */
inline _zhematrix dsymatrix::to_zhematrix() const
{VERBOSE_REPORT;
  zhematrix newmat(n);
  for(long i=0; i<n; i++){
    for(long j=0; j<=i; j++){
      newmat(i,j) =comple((*this)(i,j),0.0);
    }
  }
  
  return _(newmat);
}
示例#13
0
/*
 * address
 */
static char *address(sed_commands_t *commands, char *expbuf,
                     PRStatus* status)
{
    char   *rcp;
    PRInt64 lno;
    sed_comp_args compargs;

    *status = PR_SUCCESS;
    if(*commands->cp == '$') {
        if (expbuf > &commands->respace[RESIZE-2]) {
            command_errf(commands, XP_GetAdminStr(DBT_TMMES), commands->linebuf);
            *status = PR_FAILURE;
            return NULL;
        }
        commands->cp++;
        *expbuf++ = CEND;
        *expbuf++ = CCEOF;
        return(expbuf);
    }
    if (*commands->cp == '/' || *commands->cp == '\\' ) {
        if ( *commands->cp == '\\' )
            commands->cp++;
        commands->sseof = *commands->cp++;
        return(comple(commands, &compargs, (char *) 0, expbuf, commands->reend,
                      commands->sseof));
    }

    rcp = commands->cp;
    lno = 0;

    while(*rcp >= '0' && *rcp <= '9')
        lno = lno*10 + *rcp++ - '0';

    if(rcp > commands->cp) {
        if (expbuf > &commands->respace[RESIZE-3]) {
            command_errf(commands, XP_GetAdminStr(DBT_TMMES), commands->linebuf);
            *status = PR_FAILURE;
            return NULL;
        }
        *expbuf++ = CLNUM;
        *expbuf++ = commands->nlno;
        commands->tlno[commands->nlno++] = lno;
        if(commands->nlno >= SED_NLINES) {
            command_errf(commands, XP_GetAdminStr(DBT_TMLNMES), commands->linebuf);
            *status = PR_FAILURE;
            return NULL;
        }
        *expbuf++ = CCEOF;
        commands->cp = rcp;
        return(expbuf);
    }
    return(NULL);
}
示例#14
0
/*
 * fcomp
 */
static int fcomp(sed_commands_t *commands, PRFileDesc *fin)
{
    char *p, *op, *tp;
    sed_reptr_t *pt, *pt1;
    int i, ii;
    sed_label_t *lpt;
    char fnamebuf[PATH_MAX];
    PRStatus status;
    sed_comp_args compargs;

    op = commands->lastre;
    if (!commands->linebuf) {
        commands->linebuf = (char *)pool_calloc(commands->pool, LBSIZE + 1, 1);
    }

    if (rline(commands, fin, commands->linebuf,
              (commands->linebuf + LBSIZE + 1)) < 0)
        return 0;
    if (*commands->linebuf == '#') {
        if (commands->linebuf[1] == 'n')
            commands->nflag = 1;
    }
    else {
        commands->cp = commands->linebuf;
        goto comploop;
    }

    for (;;) {
        if (rline(commands, fin, commands->linebuf,
                  (commands->linebuf + LBSIZE + 1)) < 0)
            break;

        commands->cp = commands->linebuf;

comploop:
        while (*commands->cp == ' ' || *commands->cp == '\t')
            commands->cp++;
        if (*commands->cp == '\0' || *commands->cp == '#')
            continue;
        if (*commands->cp == ';') {
            commands->cp++;
            goto comploop;
        }

        p = address(commands, commands->rep->ad1, &status);
        if (status != PR_SUCCESS) {
            command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
            return -1;
        }

        if (p == commands->rep->ad1) {
            if (op)
                commands->rep->ad1 = op;
            else {
                command_errf(commands, XP_GetAdminStr(DBT_NRMES));
                return -1;
            }
        } else if (p == 0) {
            p = commands->rep->ad1;
            commands->rep->ad1 = 0;
        } else {
            op = commands->rep->ad1;
            if (*commands->cp == ',' || *commands->cp == ';') {
                commands->cp++;
                commands->rep->ad2 = p;
                p = address(commands, commands->rep->ad2, &status);
                if ((status != PR_SUCCESS) || (p == 0)) {
                    command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
                    return -1;
                }
                if (p == commands->rep->ad2)
                    commands->rep->ad2 = op;
                else
                    op = commands->rep->ad2;
            } else
                commands->rep->ad2 = 0;
        }

        if(p > &commands->respace[RESIZE-1]) {
            command_errf(commands, XP_GetAdminStr(DBT_TMMES));
            return -1;
        }

        while (*commands->cp == ' ' || *commands->cp == '\t')
            commands->cp++;

swit:
        switch(*commands->cp++) {
        default:
            command_errf(commands, XP_GetAdminStr(DBT_UCMES), commands->linebuf);
            return -1;

        case '!':
            commands->rep->negfl = 1;
            goto swit;

        case '{':
            commands->rep->command = BCOM;
            commands->rep->negfl = !(commands->rep->negfl);
            commands->cmpend[commands->depth++] = &commands->rep->lb1;
            commands->rep = alloc_reptr(commands);
            commands->rep->ad1 = p;
            if (*commands->cp == '\0')
                continue;
            goto comploop;

        case '}':
            if (commands->rep->ad1) {
                command_errf(commands, XP_GetAdminStr(DBT_AD0MES), commands->linebuf);
                return -1;
            }

            if (--commands->depth < 0) {
                command_errf(commands, XP_GetAdminStr(DBT_TMCMES));
                return -1;
            }
            *commands->cmpend[commands->depth] = commands->rep;

            commands->rep->ad1 = p;
            continue;

        case '=':
            commands->rep->command = EQCOM;
            if (commands->rep->ad2) {
                command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf);
                return -1;
            }
            break;

        case ':':
            if (commands->rep->ad1) {
                command_errf(commands, XP_GetAdminStr(DBT_AD0MES), commands->linebuf);
                return -1;
            }

            while (*commands->cp++ == ' ');
            commands->cp--;

            tp = commands->lab->asc;
            while ((*tp++ = *commands->cp++)) {
                if (tp >= &(commands->lab->asc[8])) {
                    command_errf(commands, XP_GetAdminStr(DBT_LTLMES), commands->linebuf);
                    return -1;
                }
            }
            *--tp = '\0';

            if ((lpt = search(commands)) != NULL) {
                if (lpt->address) {
                    command_errf(commands, XP_GetAdminStr(DBT_DLMES), commands->linebuf);
                    return -1;
                }
                dechain(lpt, commands->rep);
            } else {
                commands->lab->chain = 0;
                lpt = commands->lab;
                if (++commands->lab >= commands->labend) {
                    command_errf(commands, XP_GetAdminStr(DBT_TMLMES), commands->linebuf);
                    return -1;
                }
            }
            lpt->address = commands->rep;
            commands->rep->ad1 = p;

            continue;

        case 'a':
            commands->rep->command = ACOM;
            if (commands->rep->ad2) {
                command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf);
                return -1;
            }
            if (*commands->cp == '\\')
                commands->cp++;
            if (*commands->cp++ != '\n') {
                command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
                return -1;
            }
            commands->rep->re1 = p;
            p = text(commands, commands->rep->re1, commands->reend);
            if (p == NULL)
                return -1;
            break;

        case 'c':
            commands->rep->command = CCOM;
            if (*commands->cp == '\\') commands->cp++;
            if (*commands->cp++ != ('\n')) {
                command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
                return -1;
            }
            commands->rep->re1 = p;
            p = text(commands, commands->rep->re1, commands->reend);
            if (p == NULL)
                return -1;
            break;

        case 'i':
            commands->rep->command = ICOM;
            if (commands->rep->ad2) {
                command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf);
                return -1;
            }
            if (*commands->cp == '\\') commands->cp++;
            if (*commands->cp++ != ('\n')) {
                command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
                return -1;
            }
            commands->rep->re1 = p;
            p = text(commands, commands->rep->re1, commands->reend);
            if (p == NULL)
                return -1;
            break;

        case 'g':
            commands->rep->command = GCOM;
            break;

        case 'G':
            commands->rep->command = CGCOM;
            break;

        case 'h':
            commands->rep->command = HCOM;
            break;

        case 'H':
            commands->rep->command = CHCOM;
            break;

        case 't':
            commands->rep->command = TCOM;
            goto jtcommon;

        case 'b':
            commands->rep->command = BCOM;
jtcommon:
            while (*commands->cp++ == ' ');
            commands->cp--;

            if (*commands->cp == '\0') {
                if ((pt = commands->labtab->chain) != NULL) {
                    while ((pt1 = pt->lb1) != NULL)
                        pt = pt1;
                    pt->lb1 = commands->rep;
                } else
                    commands->labtab->chain = commands->rep;
                break;
            }
            tp = commands->lab->asc;
            while ((*tp++ = *commands->cp++))
                if (tp >= &(commands->lab->asc[8])) {
                    command_errf(commands, XP_GetAdminStr(DBT_LTLMES), commands->linebuf);
                    return -1;
                }
            commands->cp--;
            *--tp = '\0';

            if ((lpt = search(commands)) != NULL) {
                if (lpt->address) {
                    commands->rep->lb1 = lpt->address;
                } else {
                    pt = lpt->chain;
                    while ((pt1 = pt->lb1) != NULL)
                        pt = pt1;
                    pt->lb1 = commands->rep;
                }
            } else {
                commands->lab->chain = commands->rep;
                commands->lab->address = 0;
                if (++commands->lab >= commands->labend) {
                    command_errf(commands, XP_GetAdminStr(DBT_TMLMES), commands->linebuf);
                    return -1;
                }
            }
            break;

        case 'n':
            commands->rep->command = NCOM;
            break;

        case 'N':
            commands->rep->command = CNCOM;
            break;

        case 'p':
            commands->rep->command = PCOM;
            break;

        case 'P':
            commands->rep->command = CPCOM;
            break;

        case 'r':
            commands->rep->command = RCOM;
            if (commands->rep->ad2) {
                command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf);
                return -1;
            }
            if (*commands->cp++ != ' ') {
                command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
                return -1;
            }
            commands->rep->re1 = p;
            p = text(commands, commands->rep->re1, commands->reend);
            if (p == NULL)
                return -1;
            break;

        case 'd':
            commands->rep->command = DCOM;
            break;

        case 'D':
            commands->rep->command = CDCOM;
            commands->rep->lb1 = commands->ptrspace;
            break;

        case 'q':
            commands->rep->command = QCOM;
            if (commands->rep->ad2) {
                command_errf(commands, XP_GetAdminStr(DBT_AD1MES), commands->linebuf);
                return -1;
            }
            break;

        case 'l':
            commands->rep->command = LCOM;
            break;

        case 's':
            commands->rep->command = SCOM;
            commands->sseof = *commands->cp++;
            commands->rep->re1 = p;
            p = comple(commands, &compargs, (char *) 0, commands->rep->re1,
                       commands->reend, commands->sseof);
            if (p == NULL)
                return -1;
            if (p == commands->rep->re1) {
                if (op)
                    commands->rep->re1 = op;
                else {
                    command_errf(commands, XP_GetAdminStr(DBT_NRMES));
                    return -1;
                }
            } else 
                op = commands->rep->re1;
            commands->rep->rhs = p;

            p = compsub(commands, &compargs, commands->rep->rhs);
            if ((p) == NULL)
                return -1;

            if (*commands->cp == 'g') {
                commands->cp++;
                commands->rep->gfl = 999;
            } else if (commands->gflag)
                commands->rep->gfl = 999;

            if (*commands->cp >= '1' && *commands->cp <= '9') {
                i = *commands->cp - '0';
                commands->cp++;
                while (1) {
                    ii = *commands->cp;
                    if (ii < '0' || ii > '9')
                        break;
                    i = i*10 + ii - '0';
                    if (i > 512) {
                        command_errf(commands, XP_GetAdminStr(DBT_TOOBIG), commands->linebuf);
                        return -1;
                    }
                    commands->cp++;
                }
                commands->rep->gfl = i;
            }

            if (*commands->cp == 'p') {
                commands->cp++;
                commands->rep->pfl = 1;
            }

            if (*commands->cp == 'P') {
                commands->cp++;
                commands->rep->pfl = 2;
            }

            if (*commands->cp == 'w') {
                commands->cp++;
                if (*commands->cp++ !=  ' ') {
                    command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
                    return -1;
                }
                if (text(commands, fnamebuf, &fnamebuf[PATH_MAX]) == NULL) {
                    command_errf(commands, XP_GetAdminStr(DBT_FNTL), commands->linebuf);
                    return -1;
                }
                for (i = commands->nfiles - 1; i >= 0; i--)
                    if (strcmp(fnamebuf,commands->fname[i]) == 0) {
                        commands->rep->findex = i;
                        goto done;
                    }
                if (commands->nfiles >= NWFILES) {
                    command_errf(commands, XP_GetAdminStr(DBT_TMWFMES));
                    return -1;
                }
                commands->fname[commands->nfiles] = (char *)
                            pool_strdup(commands->pool, (const char *)fnamebuf);
                if (commands->fname[commands->nfiles] == NULL) {
                    command_errf(commands, XP_GetAdminStr(DBT_OOMMES));
                    return -1;
                }
                commands->rep->findex = commands->nfiles++;
            }
            break;

        case 'w':
            commands->rep->command = WCOM;
            if (*commands->cp++ != ' ') {
                command_errf(commands, XP_GetAdminStr(DBT_SMMES), commands->linebuf);
                return -1;
            }
            if (text(commands, fnamebuf, &fnamebuf[PATH_MAX]) == NULL) {
                command_errf(commands, XP_GetAdminStr(DBT_FNTL), commands->linebuf);
                return -1;
            }
            for (i = commands->nfiles - 1; i >= 0; i--)
                if (strcmp(fnamebuf, commands->fname[i]) == 0) {
                    commands->rep->findex = i;
                    goto done;
                }
            if (commands->nfiles >= NWFILES) {
                command_errf(commands, XP_GetAdminStr(DBT_TMWFMES));
                return -1;
            }
            if ((commands->fname[commands->nfiles] =
                        (char *)pool_strdup(commands->pool, fnamebuf)) == NULL) {
                command_errf(commands, XP_GetAdminStr(DBT_OOMMES));
                return -1;
            }
            commands->rep->findex = commands->nfiles++;
            break;

        case 'x':
            commands->rep->command = XCOM;
            break;

        case 'y':
            commands->rep->command = YCOM;
            commands->sseof = *commands->cp++;
            commands->rep->re1 = p;
            p = ycomp(commands, commands->rep->re1);
            if (p == NULL)
                return -1;
            break;
        }
done:
        commands->rep = alloc_reptr(commands);

        commands->rep->ad1 = p;

        if (*commands->cp++ != '\0') {
            if (commands->cp[-1] == ';')
                goto comploop;
            command_errf(commands, XP_GetAdminStr(DBT_CGMES), commands->linebuf);
            return -1;
        }
    }
    commands->rep->command = 0;
    commands->lastre = op;

    return 0;
}