コード例 #1
0
int main(int argc,char **argv){
  float *mat;
  int row,col,acc;
  readmat(argv[1],&mat,&row,&col,&acc);
  printf("%d,%d,%d\n",row,col,acc);
  printf("%f\n",mat[row-1]);

  return 0;
}
コード例 #2
0
ファイル: matrix_mul.c プロジェクト: sagar55/MyProg
 main()
{
int n,**a,**b,**ree;
cout<<"\n\t\tSTRASSEN'S MATRIX MULTIPLICATION USING D AND C";
cout<<"\n\t\t...............................";
cout<<"\nEnter the order of matrix:";
cin>>n;
cout<<"\nEnter the first matrix element:";
a=readmat(n);
cout<<"\nEnter the second matrix";
b=readmat(n);
ree=strassen(a,b,n);
cout<<"\nFirst matrix\n";
dismat(a,n);
cout<<"\nSecond matrix\n";
dismat(b,n);
cout<<"\nResult matrix\n";
dismat(ree,n);
free(ree);
getch();
}
コード例 #3
0
ファイル: matperm.c プロジェクト: gap-packages/cohomolo
int 
main (int argc, char *argv[])
{ short nm,nv,i,j,pt,perm,*p1,*p2,*q1,arg;
  char inf[80],outf[80],err; int x;
/* Defaults: inf=gpname.inmat  outf=gpname.inperm  */
  arg=1; err=0;
  if (argc<=arg) { err=1; goto error;}
  strcpy(inf,argv[1]); strcat(inf,"."); strcpy(outf,inf);
  arg++; if (argc<=arg) strcat(inf,"inmat"); else strcat(inf,argv[arg]);
  arg++; if (argc<=arg) strcat(outf,"inperm"); else strcat(outf,argv[arg]);
  if ((ip=fopen(inf,"r"))==0)
  { fprintf(stderr,"Cannot open %s.\n",inf); exit(1); }
  fscanf(ip,"%hd%hd%hd",&prime,&dim,&nmat);
  if (prime>mpr) {fprintf(stderr,"prime too big. Increase MPR.\n"); exit(1);}
  if (dim>mdim) {fprintf(stderr,"dim too big. Increase MDIM.\n"); exit(1);}
  if (nmat>mm) {fprintf(stderr,"Too many mats. Increase MM.\n"); exit(1); }
  setpinv();
  nm=nmat+1; nv=(nm+2)*dim;
  if (nv>=mv) {fprintf(stderr,"Too many vectors. Increase MV.\n"); exit(1);}
  x=(nv+1)*dim;
  if (x>msp-marg) {fprintf(stderr,"Out of space. Increase MSP.\n"); exit(1);}
/* Set matrix pointers as in mcp.c */
  for (i=0;i<=nv;i++) vec[i]=mspace-1+i*dim;
  for (i=0;i<=nmat;i++) { mat[i]=vec-1+i*dim; if (i>0) readmat(mat[i]); }
  fclose(ip);
  endsp=mspace+msp-marg;
  spm=mat[0]; spv=spm[1]; sp=vec-1+nm*dim; imsp=sp+dim; fptr=vec[nv];
  for (i=1;i<=nmat;i++) {pptr[i]=fptr; fptr+=MPT; }
  if (fptr>=endsp) {fprintf(stderr,"Out of space. Increase MSP.\n"); exit(1);}
reenter:
  printf("Input dim of orbit space (-1 for orbit of vector):    ");
  scanf("%hd",&ordim);
  if (ordim< -1 || ordim==0 || ordim>dim)
  { printf("Inappropriate dimension.\n"); while (getchar()!='\n');goto reenter;}
  else if (ordim== -1) { ordim=1; orvec=1; } else orvec=0;
  printf("Input generating vectors of orbit space.\n");
  for (i=1;i<=ordim;i++)
  { p1=imsp[i]; for (j=1;j<=dim;j++) scanf("%hd",p1+j); }
  npt=1;
  if (orvec==0) normalize();
  encode(); spptr[1]=fptr; fptr=nfptr;
  if (fptr>=endsp) {fprintf(stderr,"Out of space. Increase MSP.\n"); exit(1);}

  for (pt=1;pt<=npt;pt++)
  { decode(pt);
    for (perm=1;perm<=nmat;perm++)
    { for (j=1;j<=ordim;j++) im(sp[j],imsp[j],mat[perm]);
      if (orvec==0) normalize(); encode();
      for (i=1;i<=npt;i++)
      { p1=fptr; p2=nfptr; q1=spptr[i]+1;
        while (++p1<=p2) { if (*p1!= *q1) break; q1++; }
        if (p1>p2) break;
      }
      pptr[perm][pt]=i;
      if (i>npt)
      { npt++; if (npt>mpt) {fprintf(stderr,"Too many points.\n"); exit(1); }
        spptr[npt]=fptr; fptr=nfptr;
        if (fptr>=endsp)
        {fprintf(stderr,"Out of space. Increase MSP.\n"); exit(1);}
if (npt%10==0) printf("npt=%d.\n",npt);
      }
    }
  }
  op=fopen(outf,"w"); fprintf(op,"%4d%4d%4d%4d\n",npt,nmat,0,0);
  for (i=1;i<=nmat;i++)
  if (npt>=1000)
  { for (j=1;j<=npt;j++) fprintf(op,"%5d",pptr[i][j]); fprintf(op,"\n"); }
  else
  { for (j=1;j<=npt;j++) fprintf(op,"%4d",pptr[i][j]); fprintf(op,"\n"); }
error:
  if (err)
  { fprintf(stderr,"Usage:    matperm gpname [inf] [outf]\n");
    exit(1);
  }
  exit(0);
}
コード例 #4
0
ファイル: nqp2b.c プロジェクト: fingolfin/gap-osx-binary
intact()
/* In case act, appropriate quotient of H^i(P,M) is computed */
{ int a,b,c,d,i,j,k,l,len,m,n,x,f1,f2,*p,*p1,*q,*q1,*r,*r1,*ia,*ib,*v1,
        **bim,**cbim,**imcg,**cimcg,**dp,*null;
  char pow,nz;
  strcpy(inf1,inf0);
  if (norm)
  { if (ch1) strcpy(inf1,outcopy);
    if (ingp(1)== -1) return(-1);
    if (ch1) strcpy(inf1,inf0);
    cbno=1; bim=mat[cbno]; onng=nng;
    for (i=1;i<=dim;i++) {for (j=1;j<=dim;j++) bim[i][j]=0;bim[i][i]=1; }
  }
/* It is now time to read in the full pcp for the Frattini extension of P
   again, in order to compute the action on it. Before doing this, we must
   save all necessary information about Q. intg and cintg are already safely
   at the back of rel., and the cohomolgy gens of Q will also be copied there.
   The definitions of the gens of Q will be copied to sd1 and sd2, but a
   slightly messy method has been used to save long definitions.
*/
  p=d1; q=p+exp+dim+onng; v1=sd1+1;
  while (++p<=q) *(v1++)= *p;
  nsd1=sd1+exp+dim;
  p=d2; q=p+exp+dim+onng; v1=sd2+1;
  while (++p<=q) *(v1++)= *p;
  nsd2=sd2+exp+dim;
  if (ch1)
  { for (i=exp+1;i<=exp+dim+nng;i++)
    { p= (sd1[i]==0) ? 0 : *(comptr[sd1[i]]+sd2[i]);
      if (p!=0)
      { l= *p; if (i<=exp+dim) l-=2;
        if (l>0)
        { sd1[i]= -sd1[i]; q=p+l;
          while (q>p) {*rpb= *q; q--; rpb--;}
          *rpb=l; cintg[i]=rpb; rpb--;
        }
      }
    }
  }
  else
  for (i=1;i<=exp1;i++) if (sd1[i]!=0)
  { p= sd1[i]==sd2[i] ? *powptr[sd1[i]] : *(comptr[sd1[i]]+sd2[i]);
    l= *p;
    if (l>2)
    { sd1[i]= -sd1[i]; q=p+l-2;
      while (q>p) {*rpb= *q; q--; rpb--; }
      *rpb=l-2; cintg[i]=rpb; rpb--;
    }
  }
  inng=onng; intexp=exp;
  if (ch1==0)
  { p=wt; q=p+facexp; v1=swt+1;
    while (++p<=q) *(v1++)= *p;
    inteno=extno; intcpd=chpdim; intfe=facexp;
    if (norm==0)
    { for (i=1;i<=onng;i++) if ((p=inteno[i])!=0)
      { q=p+ *p; rpb-=(*p+1); v1=rpb;
        while (p<=q) *(++v1)= *(p++);
        inteno[i]=rpb+1;
      }
      ptrsp-=onng;
    }
  }
  rsp=rpb-rel+1;
  if (norm==0 || ch1) if (ingp(1)== -1) return(-1);
  printf("Reading conj matrix.\n");
/* matrix of dcrep is read and multiplied by action base change matrix */
  bim=mat[cbno]; cbim=mat[cbno+1];
  ip=fopen(inf4,"r"); fseek(ip,inf4offset,0);
  readmat(mat[cbno+2]);
  inf4offset=ftell(ip); fclose(ip);
  *cp=2; cp[1]=cbno; cp[2]=cbno+2; prod(cp,cbim);
  if (ch1)
  { printf("Computing action.\n"); wf=rpf; null=0;
    for (i=1;i<=dim;i++) *(++npcb2)=0;
    if (npcb2-pcptr>=ptrsp)
    { fprintf(stderr,"Out of ptrsp. Increase PTRSP.\n"); return(-1); }
    for (i=intexp+1;i<=intexp+dim+inng;i++)
    { wc=wf-2; a=sd1[i]; if (a==0) continue;
      b=sd2[i]; zero(nexpnt,enexpnt);
      if (a<0)
      { p=cintg[i]; q=p + *p -1;
        while (q>p) { entvec(npcb[*q-intexp],bim[*q-intexp],-*(q+1)); q-=2;}
      }
      ia=bim[abs(a)-intexp]; ib=intg[b];
      entvec(null,ia,-1); enter(ib,-1); entvec(null,ia,1); enter(ib,1);
      zero(expnt,eexpnt); collect(wc,wf,1);
      wc=wf-2;
      if (a<0)
      { p=cintg[i]; q=p + *p -1;
        while (q>p) { entvec(null,cbim[*q-intexp],-*(q+1)); q-=2;}
      }
      ia=cbim[abs(a)-intexp]; ib=cintg[b];
      entvec(null,ia,-1); enter(ib,-1); entvec(null,ia,1); enter(ib,1);
      zero(expnt,eexpnt); collect(wc,wf,-1);
      if (i<=intexp+dim)
      { l=0;
        for (j=nng;j>=1;j--) if ((k=nexpnt[j])!=0)
        { if (k<0) k+=prime; *rpb=k; *(rpb-1)=j; rpb-=2; l+=2; }
        if (l!=0) { npcb[i-intexp]= rpb; *rpb=l; *(rpb-1)=0; rpb-=2; }
      }
      else if ((l=prnrel())== -1 || l==0) return(l);
    }
    printf("End of this action. Present dimension=%d\n",nng);
    fflush(stdout);
    if (nng==0) return(2);
  }
  else
  { printf("Computing Frattini embeddings.\n");
/* Now intg and cintg are computed as strings in gens of P for the gens of Q */
    for (i=1;i<=exp1;i++) if (i>intfe || swt[i]>1)
    { wf=rpf; a=sd1[i]; b=sd2[i]; wc=wf-2; pow = abs(a)==b;
/* a<0 means a long def */
      if (a<0)
      { p=cintg[i]; q=p+ *p-1;
        while (q>p) { enter(intg[*q],-*(q+1)); q-=2; }
      }
      ia=intg[abs(a)]; ib=intg[b];
      if (pow) enter(ia,prime);
      else
      { enter(ia,-1); enter(ib,-1); enter(ia,1); enter(ib,1); }
      zero(expnt,eexpnt);
      if (wc>=wf) collect(wc,wf,1);
      l=0;
      for (k=exp;k>=1;k--) if ((x=expnt[k])!=0)
      { *rpb=x; *(rpb-1)=k; rpb-=2; l+=2; }
      *rpb=l; intg[i]=rpb; rpb--; wc=wf-2;
      if (a<0)
      { a= -a; p=cintg[i]; q=p+ *p-1;
        while (q>p) { enter(cintg[*q],-*(q+1)); q-=2; }
      }
      ia=cintg[a]; ib=cintg[b];
      if (pow) enter(ia,prime);
      else
      { enter(ia,-1); enter(ib,-1); enter(ia,1); enter(ib,1); }
      zero(expnt,eexpnt);
      if (wc>=wf) collect(wc,wf,1);
      l=0;
      for (k=exp;k>=1;k--) if ((x=expnt[k])!=0)
      { *rpb=x; *(rpb-1)=k; rpb-=2; l+=2; }
      *rpb=l; cintg[i]=rpb; rpb--;
      if (rpb-rpf<marg)
      { fprintf(stderr,"Out of space. Increase RSP.\n"); return(-1); }
    }
    printf("Computing images of cohomology gens.\n");
/* Now images of cohomology gens of Q and its conjugte are computed as strings,
   and stored in imcg and cimcg.
*/

    imcg=pcb; cimcg=imcg+inng;
    if (pcb+2*(inng+nng)-pcptr>=ptrsp)
    { fprintf(stderr,"Out of ptr space. Increase PTRSP.\n"); return(-1); }
    for (i=1;i<=inng;i++)
    { a=nsd1[i]-intexp; b=nsd2[i];
      zero(rpf,rpf+nng);
      p=bim[a]; p1=p+dim+1; q=intg[b]; q1=q+ *q;
      while (--p1>p) if ((f1= *p1)!=0)
      { c=p1-p+exp; q=intg[b];
        while (++q<q1)
        { d= *(q++); f2= *q;
          if ((r= *(comptr[c]+d))!=0)
          { r1=r+ *r; while (++r<r1) {rpf[*r]+= (*(r+1)*f1*f2); r++; }}
        }
      }
      p=rpf; p1=p+nng;
      while (++p<=p1) *p%=prime;
      len=0;
      for (j=1;j<=nng;j++) if (rpf[j]!=0) len+=2;
      rpb-=len; imcg[i]=rpb; *rpb=len; compress(rpb,rpf,nng); rpb--;
      zero(rpf,rpf+nng);
      p=cbim[a]; p1=p+dim+1; q=cintg[b]; q1=q+ *q;
      while (--p1>p) if ((f1= *p1)!=0)
      { c=p1-p+exp; q=cintg[b];
        while (++q<q1)
        { d= *(q++); f2= *q;
          if ((r= *(comptr[c]+d))!=0)
          { r1=r+ *r; while (++r<r1) {rpf[*r]+= (*(r+1)*f1*f2); r++; }}
        }
      }
      p=rpf; p1=p+nng;
      while (++p<=p1) *p%=prime;
      len=0;
      for (j=1;j<=nng;j++) if (rpf[j]!=0) len+=2;
      rpb-=len; cimcg[i]=rpb; *rpb=len; compress(rpb,rpf,nng); rpb--;
      if (rpb-rpf-marg>rsp)
      { fprintf(stderr,"Out of space. Increase RSP.\n"); return(-1); }
    }
    printf("Computing Sub-cohomology generators.\n");
/* Finally we are ready to compute gens of the subgroup of H^2(P,M) to be
   factored out. These will be put into echelon form.
*/
    for (i=1;i<=inng;i++) if ((p=inteno[i])!=0)
    { zero(nexpnt,enexpnt); p1=p+ *p;
      while (--p1>p)
      { a= *p1; f1= *(p1+1); p1--; q=rpf; q1=q+nng; r=q1; r1=nexpnt;
        expand(imcg[a],q,nng); expand(cimcg[a],r,nng);
        while (++q<=q1) { r++; r1++; *r1+=(f1* *q); *r1-=(f1* *r);}
      }
      r=nexpnt; nz=0; r1=r+nng;
      while (++r<=r1) {*r%=prime; if (*r!=0) nz=1; }
      if (nz)
      { for (m=1;m<=nng;m++) if ((n=nexpnt[m])!=0)
        { if (n<0) {n+=prime; nexpnt[m]=n;}
          if ((q=subno[m])!=0)
          { n=prime-n; r=q+ *q;
            while (++q<r) {q1=nexpnt+ *q;q++; *q1+= (n* *q); *q1%=prime;}
          }
        }
        for (m=1;m<=nng;m++) if ((n=nexpnt[m])!=0)
        { n=pinv[n]; q=nexpnt+m-1; r=nexpnt+nng;
          while (++q<=r) {*q *=n; *q%=prime; }
          chsdim++; printf("chsdim=%2d,    bno=%2d\n",chsdim,m);
          for (l=1;l<=nng;l++) if ((p=subno[l])!=0)
          { r=rpb-nng; expand(p,r,nng);
            if ((n=r[m])!=0)
            { n=prime-n; q=r+nng; q1=nexpnt+1; r1=r;
              while (++r1<=q) {*r1+=(n* *q1); *r1%=prime; q1++;}
              len=0;
              for (n=1;n<=nng;n++) if (r[n]!=0) len+=2;
              if (len> *p) {p=rpf; subno[l]=p; rpf+=(len+1); }
              *p=len; compress(p,r,nng);
            }
          }
          subno[m]=rpf;
          len=0;
          for (n=1;n<=nng;n++) if (nexpnt[n]!=0) len+=2;
          *rpf=len; compress(rpf,nexpnt,nng); rpf+=(len+1);
          if (rpb-rpf<marg)
          { fprintf(stderr,"Out of space. Increase RSP.\n"); return(-1); }
          break;
        }
      }
    }
    printf("End of this action. chpdim,chsdim=%d,%d\n\n",chpdim,chsdim);
    fflush(stdout);
    if (chpdim==chsdim) return(2);
  }
  strcpy(outf1,inf0); onng=nng; outgp();
  return(0);
}
コード例 #5
0
ファイル: qrm_test_c.c プロジェクト: MihaiLupoiu/AMPI
int main(){
  struct _qrm_spmat_type_c qrm_mat;
  int i, kh;
  char transp;
  _qrm_data_c *b, *x, *r;
  double t1, ta, tf, ts;
  _qrm_real_c rnrm, onrm, anrm, bnrm, xnrm;

  printf("==================================\n");
  _qrm_spmat_init_c(&qrm_mat);

  printf("==================================\n");

  readmat("cage9.mtx", &qrm_mat);

  qrm_gseti_c("qrm_dunit", -1);


  /* qrm_mat.icntl[QRM_ORDERING_] = QRM_SCOTCH_; */
  _qrm_pseti_c(&qrm_mat, "qrm_ordering",qrm_scotch_);

  /* qrm_mat.icntl[QRM_KEEPH_]    = QRM_YES_; */
  _qrm_pseti_c(&qrm_mat, "qrm_keeph",qrm_yes_);


  if(qrm_mat.m < qrm_mat.n){
    transp = 't';
  } else {
    transp = 'n';
  }

  printf("\nStarting the analysis\n");
  t1 = qrm_swtime();
  _qrm_analyse_c(&qrm_mat, transp);
  ta = qrm_swtime()-t1;

  printf("Starting the factorization\n");
  t1 = qrm_swtime();
  _qrm_factorize_c(&qrm_mat, transp);
  tf = qrm_swtime()-t1;
  
  _qrm_pgeti_c(&qrm_mat, "qrm_keeph", &kh);

  if(kh == qrm_yes_ ){
    x = (_qrm_data_c *)malloc(qrm_mat.n*sizeof(_qrm_data_c));
    b = (_qrm_data_c *)malloc(qrm_mat.m*sizeof(_qrm_data_c));
    r = (_qrm_data_c *)malloc(qrm_mat.m*sizeof(_qrm_data_c));
    
    for(i=0; i<qrm_mat.m; i++){
      b[i] = _qrm_one_c;
      r[i] = _qrm_one_c;
    }

    for(i=0; i<qrm_mat.n; i++){
      x[i] = _qrm_zero_c;
    }

    printf("Starting the solve\n");
    t1 = qrm_swtime();
    if(transp == 'n'){
      _qrm_apply_c(&qrm_mat, 't', b, 1);
      _qrm_solve_c(&qrm_mat, 'n', b, x, 1);
    } else if (transp == 't') {
      _qrm_solve_c(&qrm_mat, 't', b, x, 1);
      _qrm_apply_c(&qrm_mat, 'n', x, 1);
    }
    ts = qrm_swtime()-t1;

    printf("Error checking\n");

    _qrm_residual_norm_c(&qrm_mat, r, x, 1, &rnrm);
    _qrm_residual_orth_c(&qrm_mat, r, 1, &onrm);
    _qrm_vecnrm_c(x, qrm_mat.n, 1, '2', &xnrm);
    _qrm_vecnrm_c(b, qrm_mat.m, 1, '2', &bnrm);
    _qrm_matnrm_c(&qrm_mat, 'f', &anrm);

    printf("||A||          =  %10.5e\n",anrm);
    printf("||b||          =  %10.5e\n",bnrm);
    printf("||x||          =  %10.5e\n",xnrm);
    printf("||r||/||A||    =  %10.5e\n",rnrm);
    printf("||A^tr||/||r|| =  %10.5e\n",onrm);

    
    free(x); free(b); free(r);
  }

  qrm_err_check_c();

  printf("\n\nTime to do the analysis      : %e\n",ta);
  printf("Time to do the factorization : %e\n",tf);
  printf("Time to do the solve         : %e\n",ts);
  printf("Nonzeros in R                : %ld\n",qrm_mat.gstats[qrm_nnz_r_]);
  printf("Nonzeros in H                : %ld\n",qrm_mat.gstats[qrm_nnz_h_]);
  printf("Total flops at facto         : %ld\n",qrm_mat.gstats[qrm_facto_flops_]);
  
  _qrm_spmat_destroy_c(&qrm_mat);
  free(qrm_mat.irn); free(qrm_mat.jcn); free(qrm_mat.val);

  return 1;

}