Exemplo n.º 1
0
INT_VECTOR int_vec_copy(INT_VECTOR a, INT_VECTOR result)
{
    int i, m;
    m = Int_VecLen(a);
    if(result==NULL) if((result = int_vec_creat(m, UNDEFINED))==NULL) int_vec_error(INT_VEC_MALLOC);
    for(i=0; i<m; ++i) result[i] = a[i];
    return result;
}
Exemplo n.º 2
0
INT_VECTOR mat_get_sub_vector(INT_VECTOR a, INT_VECTOR indices)
{
    int i, n;
    INT_VECTOR subvec;
    n = Int_VecLen(indices);
    subvec = int_vec_creat(n, UNDEFINED);
    for(i=0; i<n; ++i)subvec[i] = a[indices[i]];
    return subvec;
}
Exemplo n.º 3
0
INT_VECTOR int_vec_divs_inv(INT_VECTOR A, int s, INT_VECTOR result)
{
    int i, m;
    m = Int_VecLen(A);
    if(result==NULL) if((result = int_vec_creat(m, UNDEFINED))==NULL)
            int_vec_error(INT_VEC_MALLOC);
    #pragma omp parallel for
    for(i=0; i<m; ++i) result[i] = s/A[i];
    return result;
}
Exemplo n.º 4
0
INT_VECTOR int_vec_div(INT_VECTOR A, INT_VECTOR B, INT_VECTOR result)
{
    int i, m;
    m = Int_VecLen(A);
    if(result==NULL) if((result = int_vec_creat(m, UNDEFINED))==NULL)
            int_vec_error(INT_VEC_MALLOC);
    if(m!=Int_VecLen(B)) gen_error(GEN_SIZEMISMATCH);
    #pragma omp parallel for
    for(i=0; i<m; ++i) result[i] = A[i]/B[i];
    return result;
}
Exemplo n.º 5
0
INT_VECTOR int_vec_permute_vect(int n, int k, INT_VECTOR result)
{
    int i, j, d;
    if(result== NULL) if((result = int_vec_creat(k, SERIES_INT_VECTOR))==NULL)
            return int_vec_error(INT_VEC_MALLOC);
    for(i=0; i<n-1; i++)
    {
        j = result[i];
        d = i + (rand()%(n-i));
        result[i] = result[d];
        result[d] = j;
    }
    return result;
}
Exemplo n.º 6
0
INT_VECSTACK __int_vecstack_creat(int len)
{
    INT_VECSTACK int_vecstack;
    int i;
    if((int_vecstack = (INT_VECTOR *)malloc( sizeof(INT_VECTOR)*(1+len)))==NULL)
        return (int_vecstack_error(INT_VECSTACK_MALLOC));

    for(i=0; i<=len; ++i)
    {
        int_vecstack[i]= NULL;
    }
    int_vecstack[0] = int_vec_creat(1,0);
    int_vecstack[0][0] = len;
    return (int_vecstack+1);
}
Exemplo n.º 7
0
INT_VECTOR int_vec_randperm(int n, INT_VECTOR result)
{
    int i, j;
    int t = 0;
    if(result==NULL) if((result = int_vec_creat(n, UNDEFINED))==NULL)
            return int_vec_error(INT_VEC_MALLOC);
    if(!MAT_SET_SEED)mat_set_seed(0);
    for(i=0; i<n; ++i)
        result[i] = i;
    for(i=0; i<n; ++i)
    {
        j = rand()%(n-i)+i;
        t = result[j];
        result[j] =result[i];
        result[i] = t;
    }
    return result;
}
Exemplo n.º 8
0
INT_VECTOR int_vec_concat(INT_VECTOR a, INT_VECTOR b, INT_VECTOR result)
{
    int i, m, n;
    m = Int_VecLen(a);
    n = Int_VecLen(b);
    if(result==NULL)
    {
        if((result = int_vec_creat(m+n, UNDEFINED))==NULL) return NULL;
    }
    else
    {
        if(Int_VecLen(result)!=(m+n)) return int_vec_error(INT_VEC_SIZEMISMATCH);
    }
    #pragma omp parallel for
    for(i=0; i<m; ++i) result[i] = a[i];
    #pragma omp parallel for
    for(i=0; i<n; ++i) result[i+m] = b[i];
    return result;
}
Exemplo n.º 9
0
INT_VECTOR int_vec_unique(INT_VECTOR a)
{
    int i, l, uni_l = 0;
    mtype *ordered = NULL, **p_ordered;
    INT_VECTOR int_ordered = NULL;
    MAT_TREE s;
    p_ordered = &ordered;
    l = Int_VecLen(a);
    s = mat_bs_make_null();
    for (i = 0; i<l; ++i)
    {
        s = mat_bs_insert((mtype)a[i],s);
    }
    uni_l = mat_bs_inorder(s, uni_l, p_ordered);
    int_ordered = int_vec_creat(uni_l, UNDEFINED);
    for(i = 0; i< uni_l; ++i) int_ordered[i] = (int)ordered[i];
    free(ordered);
    s = mat_bs_free(s);
    return int_ordered;
}