Esempio n. 1
0
/**IsEqualFunction
* Used to test a couple of Scilab variable of type 11 or 13 (function) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualFunction(double *d1, double *d2)
{
    int l,n;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0])) return 0;
    l=1;
    /* Check the number of output args */
    if (id1[l] != id2[l]) return 0;
    /* Check the output args names*/
    n = id1[l];   l++;
    if ( !IsEqualIntegerArray(n*nsiz, id1+l, id2+l) ) return 0;
    l += n*nsiz;

    /* Check the number of input args */
    if (id1[l] != id2[l]) return 0;
    /* Check the input args names*/
    n = id1[l];   l++;
    if ( !IsEqualIntegerArray(n*nsiz, id1+l, id2+l) ) return 0;
    l += n*nsiz;

    /* Check the number of int in instructions */
    if (id1[l] != id2[l]) return 0;
    n = id1[l];   l++;
    if ( !IsEqualIntegerArray(n, id1+l, id2+l) ) return 0;


    return 1;
}
Esempio n. 2
0
/**IsEqualPolyMat
* Used to test a couple of Scilab variable of type 2 (matrix of polynomials) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualPolyMat(double *d1, double *d2)
{
    int l,n;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0])) return 0;

    /* Check the number of rows */
    if (id1[1] != id2[1]) return 0;

    /* Check the number of columns */
    if (id1[2] != id2[2]) return 0;

    /* Check the real/complex flag */
    if (id1[3] != id2[3]) return 0;
    /* Check the formal variable name */
    if ( !IsEqualIntegerArray(4, id1+4, id2+4) ) return 0;


    /* Check the array of "pointers" */
    n = id1[1]*id1[2];
    if ( !IsEqualIntegerArray(n, id1+8, id2+8) ) return 0;

    /* Check the array of double precision numbers */
    l = (n + 10)/2;/* the beginning of first field in th double array */

    /* check the array of numbers */
    if ( !IsEqualDoubleArray(id1[8+n]-1, d1+l, d2+l) ) return 0;

    return 1;
}
Esempio n. 3
0
/**IsEqualBoolSparseMat
* Used to test a couple of Scilab variable of type 6 (Boolean sparse matrix) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualBoolSparseMat(double *d1, double *d2) /* a faire */
{
    int l,nel;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0])) return 0;

    /* Check the number of rows */
    if (id1[1] != id2[1]) return 0;

    /* Check the number of columns */
    if (id1[2] != id2[2]) return 0;


    /* Check the number of non zero elements */
    if (id1[4] != id2[4]) return 0;
    nel = id1[4];
    l = 5;
    /* Check the array of number of non zero element per row */
    if ( !IsEqualIntegerArray(id1[1], id1+l, id2+l) ) return 0;
    l += id1[1];

    /* Check the column index of non zero elements */
    if ( !IsEqualIntegerArray(nel, id1+l, id2+l) ) return 0;

    return 1;
}
Esempio n. 4
0
/**IsEqualLib
* Used to test a couple of Scilab variable of type library (14) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualLib(double *d1, double *d2)
{
    int n,l;
    int nclas=29;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0])) return 0;

    /* Check the path length */
    if (id1[1] != id2[1]) return 0;

    /* Check the path" */
    n = id1[1];
    if (!IsEqualIntegerArray(n, id1+2, id2+2)) return 0;
    l = n+2;

    /* Check the number of names */
    if (id1[l] != id2[l]) return 0;
    n = id1[l];l++;

    /* check the table */
    if (!IsEqualIntegerArray(nclas, id1+l, id2+l)) return 0;
    l += nclas;
    /* Check the sequence of names */
    if (!IsEqualIntegerArray(n*nsiz, id1+l, id2+l)) return 0;

    return 1;
}
Esempio n. 5
0
/**IsEqualMatlabSparseMat
* Used to test a couple of Scilab variable of type 7 (Matlab sparse matrix) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualMatlabSparseMat(double *d1, double *d2) /* a faire */
{
    int l, nel;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0]))
    {
        return 0;
    }

    /* Check the number of rows */
    if (id1[1] != id2[1])
    {
        return 0;
    }

    /* Check the number of columns */
    if (id1[2] != id2[2])
    {
        return 0;
    }

    /* Check the real/complex flag */
    if (id1[3] != id2[3])
    {
        return 0;
    }

    /* Check the number of non zero elements */
    if (id1[4] != id2[4])
    {
        return 0;
    }
    nel = id1[4];
    l = 5;
    /* Check the array of number of non zero element per column */
    if ( !IsEqualIntegerArray(id1[2], id1 + l, id2 + l) )
    {
        return 0;
    }
    l += id1[2];

    /* Check the column index of non zero elements */
    if ( !IsEqualIntegerArray(nel, id1 + l, id2 + l) )
    {
        return 0;
    }
    l += nel;

    /* Check the non zero elements */
    l = (l + 1) / 2;
    if ( !IsEqualDoubleArray(nel * (id1[3] + 1), d1 + l, d2 + l) )
    {
        return 0;
    }

    return 1;
}
Esempio n. 6
0
/**IsEqualBoolMat
* Used to test a couple of Scilab variable of type 4 (boolean) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualBoolMat(double *d1, double *d2)
{
    int n;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0]))
    {
        return 0;
    }

    /* Check the number of rows */
    if (id1[1] != id2[1])
    {
        return 0;
    }

    /* Check the number of columns */
    if (id1[2] != id2[2])
    {
        return 0;
    }

    /* Check the data */
    n = id1[1] * id1[2]; /* number of double precision floating point numbers */
    /* check the array of numbers */
    if (!IsEqualIntegerArray(n, id1 + 3, id2 + 3))
    {
        return 0;
    }
    return 1;
}
Esempio n. 7
0
/**IsEqualStringMat
* Used to test a couple of Scilab variable of type 10 (string) for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualStringMat(double *d1, double *d2)
{
    int n;
    int *id1 = (int *) d1;
    int *id2 = (int *) d2;

    /* Check the type */
    if ((id1[0] != id2[0]))
    {
        return 0;
    }

    /* Check the number of rows */
    if (id1[1] != id2[1])
    {
        return 0;
    }

    /* Check the number of columns */
    if (id1[2] != id2[2])
    {
        return 0;
    }

    /* Check the array of "pointers" */
    n = id1[1] * id1[2];
    if ( !IsEqualIntegerArray(n + 1, id1 + 4, id2 + 4) )
    {
        return 0;
    }

    /* Check the array of character codes (int)  */
    if (!IsEqualIntegerArray(id1[4 + n] - 1, id1 + 5 + n, id2 + 5 + n))
    {
        return 0;
    }
    return 1;
}
Esempio n. 8
0
/**IsEqualList
* Used to test a couple of Scilab variable of type list, tlist or mlist for equality
* @param double *d1: pointer on the beginning of the first variable structure
* @param double *d2: pointer on the beginning of the first variable structure
* @return 0 is the variables differ and 1 if they are identical, -1 for recursion purpose, -2 for allocatopn problem
* @author Serge Steer
* @see IsEqualVar
*/
int IsEqualList(double *d1, double *d2)
{
    /* This code does not use simple recursion, because of possible need of
    * call to Scilab for evaluation of overloading function
    * The redusion is emulated using the Rrec data structure to memorize the path
    * to the current element.
    */
    int l,k,res,nelt;
    int *id1, *id2;
    int *ip1, *ip2;
    double *p1, *p2;
    int krec;

    initStackParameters();

    if (Rstk[Pt]==914||Rstk[Pt]==915) { /* coming back after evaluation of overloading function */
        /* Restore context */
        krec = Pstk[Pt];
        MaxRec = Ids[4 + Pt * nsiz] ;
        memcpy(&Rrec,&(Ids[5 + Pt * nsiz]),sizeof(RecursionRecordPtr)); /* recover Rrec pointer */
        k = Rrec[krec].k;
        d1 = Rrec[krec].d1;     /* pointer on the sub-level list 1*/
        d2 = Rrec[krec].d2;     /* pointer on the sub-level list 2*/
        id1 = (int *) d1;
        id2 = (int *) d2;
        nelt = id1[1];
        goto SETLEVEL;
    }
    else { /* regular entry */
        krec = 0;

    }

STARTLEVEL:
    /* the objects pointed to by d1 and d2 are lists */
    /* set current level context */
    if (AllocRecIfRequired(krec)==-2) return -2;

    Rrec[krec].d1 = d1;
    Rrec[krec].d2 = d2;
    Rrec[krec].k  = 0;

    /* check the type */
    id1 = (int *) d1;
    id2 = (int *) d2;
    if ((id1[0] != id2[0])) return 0;
    /* check the number of elements */
    if (id1[1] != id2[1]) return 0;
    nelt = id1[1];

    /* check the array of "pointers" on list elements*/
    if (!IsEqualIntegerArray(nelt+1, id1+2, id2+2)) return 0;

    /*DEBUG_LIST("STARTLEVEL nelt=%d\n",nelt);*/

    k = 0;
SETLEVEL:
    /* check the list elements */
    ip1=id1+2;
    ip2=id2+2;

    l = (nelt + 4)/2; /* the beginning of first field in the double array */
    p1=d1+l;
    p2=d2+l;

ELEMENT:
    if (k >= nelt) { /* no more element to compare */
        if (krec > 0 ) { /* end of a sub-level */
            /* restore upper level context*/
            krec--;
            /*DEBUG_LIST("Sublist ELEMENT  index=%d finished, previous restored from krec=%d\n",k+1,krec);*/

            d1 = Rrec[krec].d1;
            d2 = Rrec[krec].d2;
            k =  Rrec[krec].k+1;
            /* rebuild pointers */
            id1 = (int *) d1;
            id2 = (int *) d2;
            nelt = id1[1];
            /*DEBUG_LIST("back to lower level nelt=%d  index=%d krec=%d\n",nelt,k+1,krec);*/

            goto  SETLEVEL;
        }
        else /* end of main level */
            return 1;
    }
    /* compare next element */
    if (ip1[k]==ip1[k+1]) {/* undefined element nothing to check */
        k++;
        goto ELEMENT;
    }
    d1 = p1+ip1[k]-1;
    d2 = p2+ip2[k]-1;
    id1=(int *)d1;
    id2=(int *)d2;

    if (id1[0]!=15 && id1[0]!=16&& id1[0]!=17) { /* elements which are not lists */
        res = IsEqualVar(d1, ip1[k+1]-ip1[k], d2, ip2[k+1]-ip2[k]);
        /*DEBUG_LIST("Regular ELEMENT  index=%d res=%d\n",k+1,res);*/
        if (!res) return 0;
        if (res == -1) { /*overloading function evaluation required */
            /* preserve context */
            Pstk[Pt] = krec;
            Ids[4 + Pt * nsiz] = MaxRec;
            /* Store Rrec pointer into Ids[5 + Pt * nsiz] and Ids[6 + Pt * nsiz] */
            memcpy(&(Ids[5 + Pt * nsiz]),&Rrec,sizeof(RecursionRecordPtr));
            return -1;
        }
        k++;
        goto ELEMENT;

    }
    else { /* sub list found*/
        /*DEBUG_LIST("Sublist ELEMENT  index=%d started, previous stored in krec=%d\n",k+1,krec);*/

        Rrec[krec].k  = k;
        krec++;

        goto STARTLEVEL;
    }
}