hmops.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int C2F() ishm (void)
int C2F() intehm (void)
int C2F() intihm (void)


Function Documentation

int C2F() intehm ( void   ) 

Definition at line 638 of file hmops.c.

References create_index_vector(), CreateVar, Fin, get_hmat(), H, i, j, l, lc, LhsVar, lr, m, n, NOT_REAL_or_CMPLX_or_BOOL_or_INT, OLD_HYPERMAT, P, PutLhsVar, ReshapeHMat, and Rhs.

00639 {
00640   /* 
00641    *  Extraction routine for an hypermatrix of type REAL_OR_COMPLEX, BOOLEAN
00642    *  and INTEGER (the 6 types of scilab ints) 
00643    *
00644    *    He = ehm ( v_1, v_2, ..., v_nb_iv, H ) 
00645    *
00646    */
00647   HyperMat H, He;
00648   int dec, i, k, l, m, n, mn, ntot, ind_max;
00649   int *j, ier, one=1, zero=0, ltot, nb_index_vectors, final_dimsize, lr, lc;
00650   int *P, *Pe;
00651   short int *siP, *siPe;
00652   char  *cP, *cPe;
00653 
00654 /*   CheckLhs(minlhs,maxlhs); */
00655 
00656   if ( Rhs < 2 ) 
00657     {
00658       Scierror(999," an hypermat extraction must have at least 2 args ");
00659       return(0);
00660     };
00661 
00662   if ( ! get_hmat(Rhs, &H) )
00663     {
00664       Scierror(999," argument is not an hypermatrix ");
00665       return 0;
00666     }
00667   else if ( H.type == NOT_REAL_or_CMPLX_or_BOOL_or_INT  || H.type == OLD_HYPERMAT )
00668     {
00669       /*  do the extraction with the macro %hm_e  */
00670       Fin = -Fin;
00671       return 0;
00672     }
00673 
00674   nb_index_vectors = Rhs-1;
00675   if ( H.dimsize <  nb_index_vectors )
00676     {
00677       Scierror(999," incompatible hypermat extraction ");
00678       return 0;
00679     }
00680   else if ( H.dimsize > nb_index_vectors )  /* reshape H */
00681     {
00682       ReshapeHMat(Rhs+1, &H, nb_index_vectors );
00683       dec = Rhs+1;
00684     }
00685   else
00686     dec = Rhs;
00687 
00688   if ( H.size == 0 )   /* the hypermat is empty => return an empty matrix ? */
00689     {
00690       CreateVar(dec+1, "d", &zero, &zero, &l);
00691       LhsVar(1) = dec+1;
00692       PutLhsVar();
00693       return 0;
00694     }
00695  
00696 
00697   ntot = 1;   /* will be the nb of elts of the extracted hmat or mat */
00698   for ( i = 1 ; i <= nb_index_vectors ; i++ )
00699     {  
00700       ier = create_index_vector(i, dec+i, &mn, H.dims[i-1], &ind_max);
00701       if ( ier == 0  ||  ind_max > H.dims[i-1] )
00702         {
00703           Scierror(999,"bad (%d th) index in hypermat extraction ",i); return 0;
00704         }
00705       if ( mn == 0 )   /* the vector index is [] => we return an empty matrix */
00706         {
00707           CreateVar(dec+i+1, "d", &zero, &zero, &l);
00708           LhsVar(1) = dec+i+1;
00709           PutLhsVar();
00710           return 0;
00711         }
00712       ntot *= mn; 
00713     }
00714 
00715   /*  For the Matlab compatibility : an hypermatrix of profil n1 x ... x nj x ... x nk 
00716    *  with  nj > 1 and nj+1 = ... = nk = 1 becomes an hypermatrix of profil n1 x ... x nj 
00717    *  Moreover, in scilab, if nj <= 2, we get in fact a matrix.
00718    */
00719   final_dimsize = nb_index_vectors;
00720   while (final_dimsize > 1 && get_length(dec + final_dimsize) == 1)
00721     final_dimsize--;
00722   if ( final_dimsize > 2 )   /* we create an hypermatrix for the extraction result */
00723     {
00724       He.dimsize = final_dimsize;
00725       He.size = ntot;
00726       He.it = H.it;
00727       He.type = H.type;
00728       CreateHMat(dec+Rhs, &He);
00729       for ( k = 0 ; k < final_dimsize ; k++ )
00730         He.dims[k] = get_length(dec+k+1);
00731     }
00732   else                /* we create a matrix  for the extraction result */
00733     {
00734       m = get_length(dec+1); 
00735       if (final_dimsize > 1)
00736         n = get_length(dec+2);
00737       else
00738         n = 1;
00739       switch (H.type)
00740         {
00741         case (SCI_REAL_OR_CMPLX):
00742           CreateCVar(dec+Rhs, "d", &(H.it), &m, &n, &lr, &lc); 
00743           He.R = stk(lr); 
00744           if ( H.it == 1 ) He.I = stk(lc);
00745           break;
00746         case (SCI_BOOLEAN):
00747           CreateVar(dec+Rhs, "b", &m, &n, &lr); 
00748           He.P = (void *) istk(lr);
00749           break;
00750         case (SCI_INTEGER):
00751           lr = H.it;
00752           CreateVar(dec+Rhs, "I", &m, &n, &lr);
00753           He.P = (void *) istk(lr);
00754           break;
00755         }
00756     }
00757 
00758   /* indices computing */
00759   ltot = 4; CreateVar(dec+Rhs+1, "I", &ntot, &one, &ltot); j = istk(ltot);
00760   compute_indices(dec, nb_index_vectors, H.dims, j);
00761 
00762   /*  fill the resulting hypermatrix or matrix  */
00763   switch ( H.type )
00764     {
00765     case (SCI_REAL_OR_CMPLX) :
00766       for ( k = 0 ; k < ntot ; k++ )
00767         He.R[k] = H.R[j[k]];
00768       if (H.it == 1)
00769         for ( k = 0 ; k < ntot ; k++ )
00770           He.I[k] = H.I[j[k]];
00771       break;
00772       
00773     case (SCI_BOOLEAN) :     /* (sci_boolean stored with 4 bytes) */
00774       Pe = (int *) He.P ; P = (int *) H.P;
00775       for ( k = 0 ; k < ntot ; k++ )
00776         Pe[k] = P[j[k]];
00777       break;
00778 
00779     case (SCI_INTEGER) :
00780       if ( H.it == SCI_INT32  ||  H.it == SCI_UINT32 )
00781         {
00782           Pe = (int *) He.P; P = (int *) H.P;
00783           for ( k = 0 ; k < ntot ; k++ )
00784             Pe[k] = P[j[k]];
00785         }
00786       else if ( H.it == SCI_INT16  ||  H.it == SCI_UINT16 )
00787         {
00788           siPe = (short int *) He.P; siP = (short int *) H.P;
00789           for ( k = 0 ; k < ntot ; k++ )
00790             siPe[k] = siP[j[k]];
00791         }
00792       else    /* SCI_INT8 and SCI_UINT8 : 1 Byte int */
00793         {
00794           cPe = (char *) He.P; cP = (char *) H.P;
00795           for ( k = 0 ; k < ntot ; k++ )
00796             cPe[k] = cP[j[k]];
00797         }
00798       break;
00799     }
00800   
00801   LhsVar(1) = dec+Rhs;
00802   PutLhsVar();
00803   return 0;
00804 }

Here is the call graph for this function:

int C2F() intihm ( void   ) 

Definition at line 807 of file hmops.c.

References A, B, compute_indices(), create_index_vector(), CreateVar, Fin, get_hmat(), get_mat_as_hmat(), i, ilp, istk, j, NOT_REAL_or_CMPLX_or_BOOL_or_INT, OLD_HYPERMAT, ReshapeHMat, Rhs, SCI_INT16, SCI_INT32, SCI_INTEGER, SCI_REAL_OR_CMPLX, SCI_UINT16, SCI_UINT32, and topk.

00808 {
00809   /* 
00810       une routine d'insertion pour hypermatrice : cas le plus
00811       simple :   A( vi1, ..., vik ) = B
00812 
00813         ihm ( vi1, vi2, ..., vik, B, A ) 
00814 
00815       avec des vecteurs d'indices classiques vi1, vi2, ....
00816       et B une hypermatrice ou bien une matrice
00817    */
00818 
00819   HyperMat A, B;
00820   int i, k,/* l, li, m, n,*/ ntot, mn,/* err_neg,*/ iconf, ind_max;
00821   int nb_index_vectors, B_is_scalar;
00822   int *j,/* nd,*/ one=1, ltot, il, dec/*, Top_save*/;
00823   int *PA, *PB;
00824   short int *siPA, *siPB;
00825   char *cPA, *cPB;
00826   int ilp, topk;
00827 
00828 /*   CheckLhs(minlhs,maxlhs); */
00829 
00830   if ( Rhs < 3 ) 
00831     {
00832       Scierror(999," an hypermat insertion must have at least 3 args ");
00833       return 0;
00834     };
00835   nb_index_vectors = Rhs - 2;
00836 
00837   if ( ! get_hmat(Rhs, &A) )
00838     {
00839       Scierror(999," argument is not an hypermatrix ");
00840       return 0;
00841     }
00842   else if ( A.type == NOT_REAL_or_CMPLX_or_BOOL_or_INT  || A.type == OLD_HYPERMAT )
00843     {
00844       /* do the job by the %x_i_hm macro family */
00845       Fin = -Fin;
00846       return 0;
00847     }
00848 
00849   if ( ! get_hmat(Rhs-1, &B) )   /* B is not an hypermat => try if it is a matrix */
00850     if ( ! get_mat_as_hmat(Rhs-1, &B) )  /* it is not a matrix of type 1, 4 or 8 */
00851       {
00852         /* it stays some authorized possibilities like A(....) = B with B a polynomial
00853          * matrix and A a real hypermatrix => try the %x_i_hm macro family 
00854          */
00855         Fin = -Fin;
00856         return 0;
00857       }
00858 
00859 
00860   if ( A.type !=  B.type || A.it != B.it || B.size == 0  || A.dimsize <  nb_index_vectors ) 
00861     {
00862       /*  do the job by the %x_i_hm macro family */
00863       Fin = -Fin;
00864       return 0;
00865     }
00866 
00867   if ( B.size == 1 )
00868     B_is_scalar = 1;
00869   else
00870     B_is_scalar = 0;
00871 
00872 
00873   if ( A.dimsize > nb_index_vectors )
00874     {
00875       ReshapeHMat(Rhs+1, &A, nb_index_vectors);
00876       dec = Rhs+1;
00877     }
00878   else
00879     dec = Rhs;
00880 
00881 
00882   /* get the index vectors */
00883   ntot = 1;
00884   iconf = 0;
00885   for ( i = 1 ; i <= nb_index_vectors ; i++ )
00886     {  
00887       if (! create_index_vector(i, dec+i, &mn, A.dims[i-1], &ind_max)) return 0;
00888       if ( mn == 0 )   /* the i th index vector is [] */
00889         {
00890           if ( B_is_scalar )
00891             /* nothing append (strange but reproduces the Matlab behavior) */
00892             goto the_end;
00893           else   /* B have at least 2 elts */
00894             {
00895               Scierror(999," bad hypermat insertion "); return 0;
00896             }
00897         }
00898       else if ( ind_max > A.dims[i-1] )
00899         {
00900           /* we have to enlarge the hypermat : do the job by the %x_i_hm macro family */
00901           Fin = -Fin;
00902           return 0;
00903         }
00904       else if ( !B_is_scalar  &&  mn != 1 )  /* do the conformity test */
00905         {
00906           while ( iconf < B.dimsize  &&  B.dims[iconf] == 1 )
00907             iconf++;
00908           if ( iconf >= B.dimsize  ||  B.dims[iconf] != mn )
00909             {
00910               Scierror(999," bad hypermat insertion ");
00911               return 0;
00912             }
00913           iconf++;
00914         }
00915       ntot *= mn; 
00916     }
00917   /* to finish the conformity test */
00918   if ( !B_is_scalar &&  ntot != B.size )
00919     {
00920       Scierror(999," bad hypermat insertion ");
00921       return 0;
00922     }
00923 
00924   /* indices computing */
00925   ltot = 4; CreateVar(dec+Rhs-1, "I", &ntot, &one, &ltot); j = istk(ltot);
00926   compute_indices(dec, nb_index_vectors, A.dims, j);
00927 
00928   
00929   /*   modify in place the hypermatrix A  */
00930   switch ( A.type )
00931     {
00932     case (SCI_REAL_OR_CMPLX) :
00933       if ( B_is_scalar )
00934         {
00935           for ( k = 0 ; k < ntot ; k++ ) A.R[j[k]] = B.R[0];
00936           if (A.it == 1)
00937             for ( k = 0 ; k < ntot ; k++ ) A.I[j[k]] = B.I[0];
00938         }
00939       else
00940         {
00941           for ( k = 0 ; k < ntot ; k++ ) A.R[j[k]] = B.R[k];
00942           if (A.it == 1)
00943             for ( k = 0 ; k < ntot ; k++ ) A.I[j[k]] = B.I[k];
00944         }
00945       break;
00946       
00947     case (SCI_BOOLEAN) :
00948       PA = (int *) A.P ; PB = (int *) B.P;
00949       if ( B_is_scalar )
00950         for ( k = 0 ; k < ntot ; k++ ) PA[j[k]] = PB[0];
00951       else
00952         for ( k = 0 ; k < ntot ; k++ ) PA[j[k]] = PB[k];
00953       break;
00954 
00955     case (SCI_INTEGER) :
00956       if ( A.it == SCI_INT32  ||  A.it == SCI_UINT32 )
00957         {
00958           PA = (int *) A.P ; PB = (int *) B.P;
00959           if ( B_is_scalar )
00960             for ( k = 0 ; k < ntot ; k++ ) PA[j[k]] = PB[0];
00961           else
00962             for ( k = 0 ; k < ntot ; k++ ) PA[j[k]] = PB[k];
00963         }
00964       else if ( A.it == SCI_INT16  ||  A.it == SCI_UINT16 )
00965         {
00966           siPA = (short int *) A.P; siPB = (short int *) B.P;
00967           if ( B_is_scalar )
00968             for ( k = 0 ; k < ntot ; k++ ) siPA[j[k]] = siPB[0];
00969           else
00970             for ( k = 0 ; k < ntot ; k++ ) siPA[j[k]] = siPB[k];
00971         }
00972       else   /* 1 Byte int */
00973         {
00974           cPA = (char *) A.P; cPB = (char *) B.P;
00975           if ( B_is_scalar )
00976             for ( k = 0 ; k < ntot ; k++ ) cPA[j[k]] = cPB[0];
00977           else
00978             for ( k = 0 ; k < ntot ; k++ ) cPA[j[k]] = cPB[k];
00979         }
00980       break;
00981     }
00982 
00983 /*
00984  *  ici j'essaie de faire le boulot de putlhsvar
00985  *  le code se base sur  setref (SCI/system/createref.f)
00986  *  on met une variable speciale "en Top" (le nouveau
00987  *  Top = Top-Rhs+1) qui indique en fait que l'on a
00988  *  modifié "en place" la variable topk.
00989  *  Les instructions  LhsVar(1) = 0; et Nbvars = 0;
00990  *  permettent a priori de sortir "convenablement"
00991  *  de putlhsvar.
00992  */
00993  the_end:
00994   il = iadr(*Lstk(Top));
00995   topk = *istk(il + 2);
00996   Top = Top - Rhs + 1;
00997   ilp = iadr(*Lstk(Top));
00998   *istk(ilp) = -1;
00999   *istk(ilp+1) = -1;
01000   *istk(ilp+2) = topk;
01001   if ( topk > 0 )
01002     *istk(ilp+3) = *Lstk(topk+1) - *Lstk(topk);
01003   else
01004     *istk(ilp+3) = 0;
01005   *Lstk(Top+1) = sadr(ilp+4);
01006 
01007   LhsVar(1) = 0;
01008   Nbvars = 0;
01009 
01010   return 0;
01011 }

Here is the call graph for this function:

int C2F() ishm ( void   ) 

Definition at line 182 of file hmops.c.

References iadr, il1, istk, Lstk, sadr, SCI_MLIST, SCI_STRING, and Top.

00183 {
00184   /* teste si l'argument en Top est une hypermatrice */
00185   int il, il1, il2;
00186   il = iadr(*Lstk( Top )); 
00187   if ( *istk(il) < 0 )
00188     il = iadr(*istk(il+1));
00189           
00190   if ( *istk(il) != SCI_MLIST )
00191     return 0;
00192   else if ( *istk(il+1) != 3 )  /* a hm mlist must have 3 fields */
00193     return 0;
00194 
00195   /*  get the pointer of the first and second fields */
00196   il1 = sadr(il+6);
00197   il2 = il1 + *istk(il+3) - 1;
00198   il1 = iadr(il1); il2 = iadr(il2);
00199 
00200   /*  test if the first field is a matrix string with 3 components
00201    *  and that the first is "hm" (ie 17 22  in scilab char code)
00202    */
00203   if ( (*istk(il1) != SCI_STRING)  |  ((*istk(il1+1))*(*istk(il1+2)) != 3)  )
00204     return 0;
00205   else if ( *istk(il1+5)-1 != 2 )  /* 1 str must have 2 chars */
00206     return 0;
00207   else if ( *istk(il1+8) != 17  || *istk(il1+9) != 22 )
00208     return 0;
00209 
00210   return 1;
00211 }      


Generated on Sun Mar 4 15:17:52 2007 for Scilab [trunk] by  doxygen 1.5.1