Example #1
0
File: svd_f.c Project: rrjudd/jvsip
svdObj_f* svdInit_f(vsip_length m, vsip_length n)
{
    svdObj_f *s=malloc(sizeof(svdObj_f));
    if(m < n){
        printf("Column length must not be less than row length");
        return NULL;
    }
    if(!s) {
        printf("\nfailed to allocate svd object\n");
        return NULL;
    }
    s->init=0;
    if(!(s->t = vsip_vcreate_f(m,VSIP_MEM_NONE))){
        s->ts = NULL; s->init++;
    } else {
        if(!(s->ts = vsip_vcloneview_f(s->t))) s->init++;
    }
    if(!(s->B=vsip_mcreate_f(m,n,VSIP_ROW,VSIP_MEM_NONE))){ 
        s->Bs = NULL; s->bs=NULL; s->init++;
    } else {
        if(!(s->Bs=vsip_mcloneview_f(s->B))) s->init++;
        if(!(s->bs=vsip_mrowview_f(s->B,0))) s->init++;
    }
    if(!(s->L=meye_f(m))){ 
        s->Ls=NULL; s->init++;
    } else {
        if(!(s->Ls = vsip_mcloneview_f(s->L))) s->init++;
        if(!(s->ls_two = vsip_mrowview_f(s->Ls,0))) s->init++;
        if(!(s->ls_one = vsip_mrowview_f(s->Ls,0))) s->init++;
    }
    if(!(s->R=meye_f(n))){
        s->Rs=NULL; s->init++;
    } else {
        if(!(s->Rs = vsip_mcloneview_f(s->R))) s->init++;
        if(!(s->rs_two = vsip_mrowview_f(s->Rs,0))) s->init++;
        if(!(s->rs_one = vsip_mrowview_f(s->Rs,0))) s->init++;
    }
    if(!(s->indx_L=vsip_vcreate_vi(n,VSIP_MEM_NONE))) s->init++;
    if(!(s->indx_R=vsip_vcreate_vi(n,VSIP_MEM_NONE))) s->init++;
    if(!(s->d = vsip_vcreate_f(n,VSIP_MEM_NONE))){
        s->init++; s->ds = NULL;
    } else { 
        if(!(s->ds = vsip_vcloneview_f(s->d))) s->init++;
    }
    if(!(s->f = vsip_vcreate_f(n-1,VSIP_MEM_NONE))){
        s->init++; s->fs = NULL;
    } else { 
        if(!(s->fs = vsip_vcloneview_f(s->f))) s->init++;
    }
    if(s->init) svdFinalize_f(s);
    return s;
}
/* $Id: example16.c,v 2.0 2003/02/22 15:27:32 judd Exp $ */

#include<vsip.h>
#define L 20 /* A length*/
int main(){vsip_init((void*)0);
{
    vsip_vview_f*   a = vsip_vcreate_f(L,0);
    vsip_vview_f*   b = vsip_vcreate_f(L,0);
    vsip_vview_vi*  ab_vi = vsip_vcreate_vi(L,0);
    vsip_vview_bl*  ab_bl= vsip_vcreate_bl(L,0);
    int i;
    vsip_length N;
    /* make up some data */
    vsip_vramp_f(0,2 * M_PI/(L-1),a);
    vsip_vcos_f(a,b);
    /* find out where b is greater than zero */
    vsip_vfill_f(0,a);
    vsip_vlgt_f(b,a,ab_bl);
    /* find the index where b is greater than zero */
    if((N = vsip_vindexbool(ab_bl,ab_vi))){
        /* make a vector of those points where b is greater than zero*/
        vsip_vgather_f(b,ab_vi,vsip_vputlength_f(a,N));
        /*print out the results */
        printf("Index   Value\n");
        for(i=0; i<N; i++)
           printf("%li      %6.3f\n",
             vsip_vget_vi(ab_vi,i),
             vsip_vget_f(a,i));
     }   
     else{ printf("Zero Length Index");
     }   
     vsip_valldestroy_f(a);
     vsip_valldestroy_f(b);
     vsip_valldestroy_vi(ab_vi);
     vsip_valldestroy_bl(ab_bl);
     } vsip_finalize((void*)0); return 0;
}
Example #3
0
int main()
{
  vsip_vview_d *dataA;
  vsip_vview_d *dataB;
  vsip_vview_vi *Index;
  vsip_vview_bl *dataBl;
  int i;
  vsip_length N;

  vsip_init((void *)0);
  dataA = vsip_vcreate_d(L, VSIP_MEM_NONE);
  dataB = vsip_vcreate_d(L, VSIP_MEM_NONE);
  Index = vsip_vcreate_vi(L, VSIP_MEM_NONE);
  dataBl= vsip_vcreate_bl(L, VSIP_MEM_NONE);
  /* make up some data */
  vsip_vramp_d(0,2 * PI/(L-1),dataA);
  vsip_vcos_d(dataA,dataB);
  /* find out where dataB is greater than zero */
  vsip_vfill_d(0,dataA);
  vsip_vlgt_d(dataB,dataA,dataBl);
  /* find the index where dataB is greater than zero */
  if((N = vsip_vindexbool(dataBl,Index)))
  {
    /* make a vector of those points where dataB is greater than zero*/
    vsip_vgather_d(dataB,Index,vsip_vputlength_d(dataA,N));
    /*print out the results */
    printf("Index Value\n");
    for(i=0; i<N; i++)
      printf("%li %6.3f\n",
	     vsip_vget_vi(Index,i),
	     vsip_vget_d(dataA,i));
  }
  else
  {
    printf("Zero Length Index");
    exit(0);
  }
  vsip_vfill_d(0,dataB);
  vsip_vscatter_d(dataA,dataB,Index);
  for(i=0; i<L; i++)
    printf("%6.3f\n",vsip_vget_d(dataB,i));
  /*recover the data space*/
  vsip_blockdestroy_d(vsip_vdestroy_d(dataA));
  vsip_blockdestroy_d(vsip_vdestroy_d(dataB));
  vsip_blockdestroy_vi(vsip_vdestroy_vi(Index));
  vsip_blockdestroy_bl(vsip_vdestroy_bl(dataBl));
  vsip_finalize((void *)0);
  return 0;
}