Exemplo n.º 1
0
//TransformedDomainRecursiveFilter_Horizontal
void TDRF_H(float** channel, float** derivatives, float sigma, int h, int w){
    float a = expf(-sqrtf(2)/sigma);

    //V
    float** V = createArray(h,w);
    for (int row = 0; row < h; row++) {
        for (int col = 0; col < w; col++) {
                V[row][col] = powf(a,derivatives[row][col]);
        }
    }
    //LEFT->RIGHT FILTER
    for (int row = 0; row < h; row++) {
        for (int col = 1; col < w; col++) {
                channel[row][col] = channel[row][col] + V[row][col]*(channel[row][col - 1] - channel[row][col]);
        }
    }
    //RIGHT->LEFT FILTER
    for (int row = 0; row < h; row++) {
        for (int col = w-2; col >= 0; col--) {
                channel[row][col] = channel[row][col] + V[row][col+1]*(channel[row][col + 1] - channel[row][col]);
        }
    }

    destroyArray(V);
}
Exemplo n.º 2
0
int main(int argc, char** argv){

    char* path = NULL;
    char buffer[MAXSIZE] = {0};

    int fullOffset = 0;
    int lineNumber = 0;

    char str1[MAXSEQUENCE] = {0};
    char str2[MAXSEQUENCE] = {0};

    struct NWArray myarray;

    if(argc > 2){
        printf("Error too many arguments\n");
        return 1;
    }else if(argc == 2){
        path = argv[1];
        printf("Text file is : %s \n", path);
        printf("\n");
    }else if(argc < 2){
        printf("Error not enough arguments, path of text file is missing\n");
        return 1;
    }

    int sizeRead = 0;
    do{

// Acquisition of one line of "path" file in a buffer
        if((sizeRead = readLine(path, fullOffset, buffer, MAXSIZE) ) < 1){
            printf("This is the end of our program\n");
            break;
        }
        printf("Iteration : %d\nAcquired line is : %s\n", ++lineNumber, buffer);

// Separation of this buffer (according to " | ") in two strings
        parseLine(buffer, sizeRead, str1, str2, MAXSEQUENCE);

        fullOffset += sizeRead;

        printf("\t str1= %s", str1);
        printf("\t str2= %s\n", str2);


// Needleman Wunsh algorithm
        initArray(&myarray, strlen(str1)+1, strlen(str2)+1);
        NWAlgo(&myarray, str1, str2);
        printNW(&myarray);
        printf("The maximum combinaison that can be obtained is : ");
        printf("%d\n", cell_value(getCellXY(&myarray, strlen(str1), strlen(str2))));
        printf("\n");
        printf("-----------------------------------------------------------\n");
        printf("\n");
        destroyArray(&myarray);

    }while(sizeRead != 0);

    return 0;
}
static void FreeUserData(WebData wdata)
{
    int i, ngrp;

    ngrp = wdata->ngrp;
    for(i=0; i < ngrp; i++) {
        destroyMat((wdata->P)[i]);
        destroyArray((wdata->pivot)[i]);
    }
    N_VDestroy_Serial(wdata->rewt);
    free(wdata);
}
Exemplo n.º 4
0
/* Free user data memory */
static void FreeUserData(UserData data)
{
  int lx, ly;
  for (lx = 0; lx < MXSUB; lx++) {
    for (ly = 0; ly < MYSUB; ly++) {
      destroyMat((data->P)[lx][ly]);
      destroyMat((data->Jbd)[lx][ly]);
      destroyArray((data->pivot)[lx][ly]);
    }
  }
  free(data);
}
Exemplo n.º 5
0
static void FreeUserData(UserData data)
{
  int jx, jy;

  for (jx=0; jx < MX; jx++) {
    for (jy=0; jy < MY; jy++) {
      destroyMat((data->P)[jx][jy]);
      destroyMat((data->Jbd)[jx][jy]);
      destroyArray((data->pivot)[jx][jy]);
    }
  }

  free(data);
}
static void FreeUserData(UserData data)
{
  int jx, jz;

  for (jx=0; jx < MX; jx++) {
    for (jz=0; jz < MZ; jz++) {
      destroyMat((data->P)[jx][jz]);
      destroyMat((data->Jbd)[jx][jz]);
      destroyArray((data->pivot)[jx][jz]);
    }
  }

  free(data->p);

  free(data);
}
Exemplo n.º 7
0
static void FreeUserData(UserData webdata)
{
  int ix, jy;

  for (ix = 0; ix < MXSUB; ix++) {
    for (jy = 0; jy < MYSUB; jy++) {
      destroyMat((webdata->PP)[ix][jy]);
      destroyArray((webdata->pivot)[ix][jy]);
    }
  }

  destroyMat(webdata->acoef);
  N_VDestroy_Parallel(webdata->rates);
  N_VDestroy_Parallel(webdata->ewt);
  free(webdata);

}
Exemplo n.º 8
0
static void FreeUserData(UserData data)
{
  int jx, jy;
  
  for (jx=0; jx < MX; jx++) {
    for (jy=0; jy < MY; jy++) {
      destroyMat((data->P)[jx][jy]);
      destroyArray((data->pivot)[jx][jy]);
    }
  }
  
  destroyMat(acoef);
  free(bcoef);
  free(cox);
  free(coy);
  N_VDestroy_Serial(data->rates);
  free(data);
}
Exemplo n.º 9
0
void main(){
	//三维数组定义
	float dim_arr[2][3][2] = { { {5,12}, {1,5}, {7,9} }, { {2,9},{3,8},{15,25} } };
	int b,h,f;
	//输出三维数组
	printf("Printf the three array:\n");
	for(b=0;b<2;b++){
		printf("The %d dim is:\n",b+1);
		for(h=0;h<3;h++){
			printf(" The %d dim is:\n",h+1);
			for(f=0;f<2;f++){
				printf("%6.1f ",dim_arr[b][h][f]);
			}
			printf("\n");
		}
		printf("\n");
	}
	
	//二维数组定义
	Array Arr;
	Array *A = &Arr;
	int i,j,k,*p,dim=3,bound1=3,bound2=4,bound3=2;//a[3][4][2]数组
	elemType e,*p1;
	initArray(A,dim,bound1,bound2,bound3);//构造3*4*2的3三维数组A
	//顺序输出A->bounds维数
	p = A->bounds;
	printf("A->bounds=");
	for(i=0;i<dim;i++){
		printf("%3d ",*(p+i));
	}
	
	//顺序输出A->constants
	p = A->constants;
	printf("\nA->constants=");
	for(i=0;i<dim;i++){
		printf("%3d ",*(p+i));
	}
	
	printf("\n%d page %d row %d column in array list as the following:\n",bound1,bound2,bound3);
	for(i=0;i<bound1;i++){
		for(j=0;j<bound2;j++){
			for(k=0;k<bound3;k++){
				//将i*100+j*10+k赋值给A[i][j][k]
				assign(A,i*100+j*10+k,i,j,k);
				value(A,&e,i,j,k);//将A[i][j][k]的值赋给e
				printf("A[%d][%d][%d]=%2d  ",i,j,k,e);//输出A[i][j][k]
			}
			printf("\n");
		}
		printf("\n");
	}
	
	p1 = A->base;
	printf("\nA->base=\n");
	//顺序输出A->base
	for(i=0;i<bound1*bound2*bound3;i++){
		printf("%4d ",*(p1+i));
		if((i+1)%(bound2*bound3)==0) printf("\n");
	}
	//!(0+1)%(bound2*bound3) equal to 0;
	if(destroyArray(A)) printf("\nsuccess to destroy array!");
}
Exemplo n.º 10
0
/*
 * -----------------------------------------------------------------------------
 *  Main
 * -----------------------------------------------------------------------------
 */
int32_t main(int32_t aArgc, char *aArgv[])
{
    perfContext     sContext;

    struct timeval  sStart, sEnd;
    int32_t         sSeconds, sUseconds;

    uint32_t       *sArray;

    /*
     * Init
     */
    perfContextInit(&sContext);

    processArg(aArgc, aArgv, &sContext);

    /*
     * Allocate memory and load data
     */
    (void)fprintf(stderr, "Reading data...\n");
    createAndFillArray(&sContext);

    sArray = sContext.mArrayToSort;

    /*
     * Sort it!
     */
    (void)fprintf(stderr, "Start sorting...\n");
    (void)gettimeofday(&sStart, NULL);

    (*sContext.mSortFunc)(sArray, sContext.mCount, sizeof(uint32_t), compareFunc);

    (void)gettimeofday(&sEnd, NULL);
    (void)fprintf(stderr, "Completed sorting.\n");

    /*
     * Calculate time
     */
    sSeconds  = sEnd.tv_sec - sStart.tv_sec;
    sUseconds = sEnd.tv_usec - sStart.tv_usec;

    if (sUseconds < 0)
    {
        sSeconds--;
        sUseconds += 1000000;
    }

    (void)fprintf(stderr, "\nIt took %d.%06d seconds to sort %d elements.\n\n",
                  sSeconds, sUseconds, sContext.mCount);

    /*
     * Verify if option is set
     */
    if (sContext.mDoVerify == 1)
    {
        (void)fprintf(stderr, "Checking if resulting array is correctly sorted...... ");

        if (verifyArrayIsSorted(sArray, sContext.mCount) == 0)
        {
            (void)fprintf(stderr, "OK\n");
        }
        else
        {
            (void)fprintf(stderr, "FAIL\n");
        }
    }

    /*
     * Free memory
     */
    destroyArray(sArray);

    return 0;
}
Exemplo n.º 11
0
int main(int argc, char** argv) {

    float** testRedChannel = generateImageArray("red.txt");
    float** testGreenChannel = generateImageArray("green.txt");
    float** testBlueChannel = generateImageArray("blue.txt");

    int h = getImageWidth("red.txt");
    int w = getImageHeight("red.txt");
    printf("%i rows x %i columns\n", h, w);

    ///////////////////////////////////////////////////////////
    //////Compute the l1-norm distance of neighbor pixels./////
    ///////////////////////////////////////////////////////////

    float** dIcdxRed = diffH(testRedChannel, h,w);
    float** dIcdxGreen = diffH(testGreenChannel, h,w);
    float** dIcdxBlue = diffH(testBlueChannel, h,w);

    float** dIcdx = addChannels(dIcdxRed, dIcdxGreen, dIcdxBlue, h,w);
    destroyArray(dIcdxRed);
    destroyArray(dIcdxGreen);
    destroyArray(dIcdxBlue);

    float** dIcdyRed = diffV(testRedChannel, h,w);
    float** dIcdyGreen = diffV(testGreenChannel, h,w);
    float** dIcdyBlue = diffV(testBlueChannel, h,w);

    float** dIcdy = addChannels(dIcdyRed, dIcdyGreen, dIcdyBlue, h,w);
    destroyArray(dIcdyRed);
    destroyArray(dIcdyGreen);
    destroyArray(dIcdyBlue);

    ///////////////////////////////////////////////////////////
    ///////Compute the derivatives of the horizontal///////////
    ///////and vertical domain transforms./////////////////////
    ///////////////////////////////////////////////////////////

    float factor = sigma_s / sigma_r;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dIcdx[i][j] = 1 + factor * dIcdx[i][j];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dIcdy[i][j] = 1 + factor * dIcdy[i][j];
        }
    }
    ///The vertical pass is performed using a transposed image.
    float** dHdyT = transpose(dIcdy, h, w);
    destroyArray(dIcdy);

    ///////////////////////////////////////////////////////////
    ///////////////////Perform the filtering.//////////////////
    ///////////////////////////////////////////////////////////

    filtering(testRedChannel, dIcdx, dHdyT, h, w, 10);
    filtering(testGreenChannel, dIcdx, dHdyT, h, w, 10);
    filtering(testBlueChannel, dIcdx, dHdyT, h, w, 10);

    ///////////////////////////////////////////////////////////
    ///////////////////GENERATE OUTPUT IMAGE///////////////////
    ///////////////////////////////////////////////////////////

    generateImageFile(testRedChannel, "outred.txt", h, w);
    generateImageFile(testGreenChannel, "outgreen.txt", h, w);
    generateImageFile(testBlueChannel, "outblue.txt", h, w);

    ///////////////////////////////////////////////////////////
    ///////////////////////FREE MEMORY/////////////////////////
    ///////////////////////////////////////////////////////////

    destroyArray(dIcdx);
    destroyArray(dHdyT);
    destroyArray(testRedChannel);
    destroyArray(testGreenChannel);
    destroyArray(testBlueChannel);
    return 0;
}
Exemplo n.º 12
0
int main()
{ 
  void *mem;
  UserData webdata;
  N_Vector cc, cp, id;
  int iout, jx, jy, flag;
  long int maxl;
  realtype rtol, atol, t0, tout, tret;

  mem = NULL;
  webdata = NULL;
  cc = cp = id = NULL;

  /* Allocate and initialize user data block webdata. */

  webdata = (UserData) malloc(sizeof *webdata);
  webdata->rates = N_VNew_Serial(NEQ);
  webdata->acoef = newDenseMat(NUM_SPECIES, NUM_SPECIES);
  webdata->ewt = N_VNew_Serial(NEQ);
  for (jx = 0; jx < MX; jx++) {
    for (jy = 0; jy < MY; jy++) {
      (webdata->pivot)[jx][jy] = newLintArray(NUM_SPECIES);
      (webdata->PP)[jx][jy] = newDenseMat(NUM_SPECIES, NUM_SPECIES);
    }
  }

  InitUserData(webdata);

  /* Allocate N-vectors and initialize cc, cp, and id. */

  cc  = N_VNew_Serial(NEQ);
  if(check_flag((void *)cc, "N_VNew_Serial", 0)) return(1);

  cp  = N_VNew_Serial(NEQ);
  if(check_flag((void *)cp, "N_VNew_Serial", 0)) return(1);

  id  = N_VNew_Serial(NEQ);
  if(check_flag((void *)id, "N_VNew_Serial", 0)) return(1);
  
  SetInitialProfiles(cc, cp, id, webdata);
  
  /* Set remaining inputs to IDAMalloc. */
  
  t0 = ZERO;
  rtol = RTOL; 
  atol = ATOL;

  /* Call IDACreate and IDAMalloc to initialize IDA. */
  
  mem = IDACreate();
  if(check_flag((void *)mem, "IDACreate", 0)) return(1);

  flag = IDASetUserData(mem, webdata);
  if(check_flag(&flag, "IDASetUserData", 1)) return(1);

  flag = IDASetId(mem, id);
  if(check_flag(&flag, "IDASetId", 1)) return(1);

  flag = IDAInit(mem, resweb, t0, cc, cp);
  if(check_flag(&flag, "IDAInit", 1)) return(1);

  flag = IDASStolerances(mem, rtol, atol);
  if(check_flag(&flag, "IDASStolerances", 1)) return(1);

  webdata->ida_mem = mem;

  /* Call IDASpgmr to specify the IDA linear solver. */

  maxl = 16;                    /* max dimension of the Krylov subspace */
  flag = IDASpgmr(mem, maxl);
  if(check_flag(&flag, "IDASpgmr", 1)) return(1);

  flag = IDASpilsSetPreconditioner(mem, Precond, PSolve);
  if(check_flag(&flag, "IDASpilsSetPreconditioner", 1)) return(1);

  /* Call IDACalcIC (with default options) to correct the initial values. */

  tout = RCONST(0.001);
  flag = IDACalcIC(mem, IDA_YA_YDP_INIT, tout);
  if(check_flag(&flag, "IDACalcIC", 1)) return(1);
  
  /* Print heading, basic parameters, and initial values. */

  PrintHeader(maxl, rtol, atol);
  PrintOutput(mem, cc, ZERO);
  
  /* Loop over iout, call IDASolve (normal mode), print selected output. */
  
  for (iout = 1; iout <= NOUT; iout++) {
    
    flag = IDASolve(mem, tout, &tret, cc, cp, IDA_NORMAL);
    if(check_flag(&flag, "IDASolve", 1)) return(flag);
    
    PrintOutput(mem, cc, tret);
    
    if (iout < 3) tout *= TMULT; else tout += TADD;
    
  }
  
  /* Print final statistics and free memory. */  
  
  PrintFinalStats(mem);

  /* Free memory */

  IDAFree(&mem);

  N_VDestroy_Serial(cc);
  N_VDestroy_Serial(cp);
  N_VDestroy_Serial(id);


  destroyMat(webdata->acoef);
  N_VDestroy_Serial(webdata->rates);
  N_VDestroy_Serial(webdata->ewt);
  for (jx = 0; jx < MX; jx++) {
    for (jy = 0; jy < MY; jy ++) {
      destroyArray((webdata->pivot)[jx][jy]);
      destroyMat((webdata->PP)[jx][jy]);
    }
  }
  free(webdata);

  return(0);
}