Ejemplo n.º 1
0
static bool cleanOut(const char* dir) {
	printf("cleanOut(%s)\n", dir);
	MAHandle list = maFileListStart(dir, "*");
	MAT(list);
	char buf[2048];
	int dirLen = strlen(dir);
	strcpy(buf, dir);
	int freeBufSpace = sizeof(buf) - dirLen;
	while(1) {
		int res;
		MAHandle fh;
		char* fileName = buf + dirLen;
		res = maFileListNext(list, fileName, freeBufSpace);
		MAT_CUSTOM(res, (_res < 0 || _res >= freeBufSpace));
		if(res == 0)
			return true;
		if(fileName[res-1] == '/') {
			if(!cleanOut(buf))
				return false;
		}
		MAT(fh = maFileOpen(buf, MA_ACCESS_READ_WRITE));
		res = maFileDelete(fh);
		MAASSERT(maFileClose(fh) == 0);
		MAT(res);
	}
	MAASSERT(maFileListClose(list) == 0);
	return true;
}
Ejemplo n.º 2
0
int test(lua_State *L) {
	float data[12] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.};
	float out_data[12];
	
	VecN<float, 6> *v_in = (VecN<float, 6> *)data;
	VecN<float, 6> *v_out = (VecN<float, 6> *)out_data;
	for(int i=0; i < 2; i++) {
		int oo[] = {1, 0};
		int ii[] = {0, 1};
		MAT(v_out) = MAT(v_in)+MAT(v_in);
		swizzle(MAT(v_out), MAT(v_in), 2, oo, ii);
		v_in++;
		v_out++;
	}
	
	for(int j=0; j < 12; j++) {
		printf("j: %f\n", out_data[j]);
	}
	
	/*
	Vec3<char> v1c(64, 123, 5);
	v1c = v1c*0.5;
	printf("t: %d %d %d\n", v1c.x, v1c.y, v1c.z);
	*/
	return 0;
}
Ejemplo n.º 3
0
static int _equalf(CMATRIX *a, double f)
{
	bool result;
	
	if (COMPLEX(a))
	{
		if (f == 0.0)
			return gsl_matrix_complex_isnull(CMAT(a));
		
		gsl_matrix_complex *m = gsl_matrix_complex_alloc(WIDTH(a), HEIGHT(a));
		gsl_matrix_complex_set_identity(m);
		gsl_matrix_complex_scale(m, gsl_complex_rect(f, 0));
		result = gsl_matrix_complex_equal(CMAT(a), m);
		gsl_matrix_complex_free(m);
	}
	else
	{
		if (f == 0.0)
			return gsl_matrix_isnull(MAT(a));
		
		gsl_matrix *m = gsl_matrix_alloc(WIDTH(a), HEIGHT(a));
		gsl_matrix_set_identity(m);
		gsl_matrix_scale(m, f);
		result = gsl_matrix_equal(MAT(a), m);
		gsl_matrix_free(m);
	}
	
	return result;
}
Ejemplo n.º 4
0
float getPixelValue(struct matrix* image,uint32 imgPosX,uint32 imgPosY,
		uint32 filterPosX,uint32 filterPosY,uint8 mode)
{
	float pixelValue = 0.0;
	// add the image and filter position
	sint32 imgCurrentPosX = imgPosX+filterPosX;
	sint32 imgCurrentPosY = imgPosY+filterPosY;

	// check whether the resulting added position lies outside the image boundary
	if((imgCurrentPosX < 0) ||
		(imgCurrentPosX > (image->numberOfRows-1)) ||
		(imgCurrentPosY < 0) ||
		(imgCurrentPosY > (image->numberOfColumns-1)))
	{
			// values outside the bounds of the image are the nearest array borders
			if(mode == MODE_REPLICATE)
			{
				imgCurrentPosX = ((imgCurrentPosX < 0) ? 0 : (imgCurrentPosX > image-> numberOfRows-1) ? (image-> numberOfRows-1) : imgCurrentPosX);
				imgCurrentPosY = ((imgCurrentPosY < 0) ? 0 : (imgCurrentPosY > image-> numberOfColumns-1) ? (image-> numberOfColumns-1) : imgCurrentPosY);

				pixelValue = MAT(image,imgCurrentPosX,imgCurrentPosY);
			}
			// values outside the bounds of the image are mirror reflecting the array across the border
			else if(mode == MODE_SYMMETRIC)
			{
				if(imgCurrentPosX < 0 || imgCurrentPosX > image->numberOfRows-1)
				{
					imgCurrentPosX = (image->numberOfRows -1) - (mod(imgCurrentPosX,image->numberOfRows));
				}
				if(imgCurrentPosY < 0 || imgCurrentPosY > image->numberOfColumns-1)
				{
					imgCurrentPosY = (image->numberOfColumns -1) - (mod(imgCurrentPosY,image->numberOfColumns));
				}

				pixelValue = MAT(image,imgCurrentPosX,imgCurrentPosY);
			}
			// values outside the bounds of the image are periodic
			else if(mode == MODE_CIRCULAR)
			{
				if(imgCurrentPosX < 0 || imgCurrentPosX > image->numberOfRows-1)
				{
					imgCurrentPosX = mod(imgCurrentPosX,image->numberOfRows);
				}
				if(imgCurrentPosY < 0 || imgCurrentPosY > image->numberOfColumns-1)
				{
					imgCurrentPosY = mod(imgCurrentPosY,image->numberOfColumns);
				}

				pixelValue = MAT(image,imgCurrentPosX,imgCurrentPosY);
			}
	}
	//  If the postion is inside the image bound,use the current position's value
	else
	{
		pixelValue = MAT(image,imgCurrentPosX,imgCurrentPosY);
	}

	return pixelValue;

}
Ejemplo n.º 5
0
mxArray *rmat2mx(int m, int n, rmulti **A, int LDA)
{
  const char *field_names[]={"prec","sign","exp","digits"};
  mwSize dims[2]={m,n},scalar[2]={1,1},size[2]={1,1};
  mxArray *ret=NULL,*value=NULL;
  int i,j,k;
  ret=mxCreateStructArray(2,dims,4,field_names);
  for(j=0; j<n; j++){
    for(i=0; i<m; i++){
      // prec
      value=mxCreateNumericArray(2,scalar,mxINT64_CLASS,mxREAL);
      (*(int64_t*)mxGetData(value))=MAT(A,i,j,LDA)->_mpfr_prec;
      mxSetField(ret,j*m+i,"prec",value);
      // sign
      value=mxCreateNumericArray(2,scalar,mxINT32_CLASS,mxREAL);
      (*(int32_t*)mxGetData(value))=MAT(A,i,j,LDA)->_mpfr_sign;
      mxSetField(ret,j*m+i,"sign",value);
      // exp
      value=mxCreateNumericArray(2,scalar,mxINT64_CLASS,mxREAL);
      (*(int64_t*)mxGetData(value))=MAT(A,i,j,LDA)->_mpfr_exp;
      mxSetField(ret,j*m+i,"exp",value);
      // digits
      size[1]=rget_size(MAT(A,i,j,LDA));
      value=mxCreateNumericArray(2,size,mxUINT64_CLASS,mxREAL);
      for(k=0; k<size[1]; k++){ ((uint64_t*)mxGetData(value))[k]=MAT(A,i,j,LDA)->_mpfr_d[k]; }
      mxSetField(ret,j*m+i,"digits",value);
    }
  }
  return ret;
}
Ejemplo n.º 6
0
int main( int argc , char *argv[] )
{
   int n,nn , ii ;
   sqrmat *KK , *AA , *AAtr, *CH ;
   double *mat, *nat , val ;

   if( argc < 2 ) exit(1) ;
   n=nn = (int)strtod(argv[1],NULL); if( nn < 2 ) exit(1);

   INIT_SQRMAT(KK,nn) ; mat = KK->mat ;
   for( ii=1 ; ii < nn ; ii++ ){
     MAT(ii,ii-1) = (double)ii ;
     MAT(ii-1,ii) = (double)(ii*ii) ;
   }
   DUMP_SQRMAT("KK",KK) ;
   val = sm_lndet_iktk(KK) ; printf("ln[det[]] = %g\n",val) ;

   AA = sm_iktk( KK ) ;
   DUMP_SQRMAT("[I-K'][I-K]",AA) ;

   ii = sm_choleski( AA ) ;
   if( ii < 1 ) exit(1) ;
   DUMP_SQRMAT("Choleski",AA) ;

   AAtr = sm_transpose(AA) ;
   CH   = sm_mult( AA , AAtr ) ;
   DUMP_SQRMAT("[Ch][Ch']",CH) ;

   exit(0) ;
}
Ejemplo n.º 7
0
long int igraph_i_layout_mergegrid_get_sphere(igraph_i_layout_mergegrid_t *grid,
        igraph_real_t x, igraph_real_t y, igraph_real_t r) {
    long int cx, cy;
    long int i,j;
    long int ret;

    if (x-r <= grid->minx || x+r >= grid->maxx ||
            y-r <= grid->miny || y+r >= grid->maxy) {
        ret=-1;
    } else {
        igraph_i_layout_mergegrid_which(grid, x, y, &cx, &cy);

        ret=MAT(cx, cy)-1;

#define DIST(i,j) (DIST2(grid->minx+(cx+(i))*grid->deltax, \
			 grid->miny+(cy+(j))*grid->deltay))

        for (i=0; ret<0 && cx+i<grid->stepsx && DIST(i,0)<r; i++) {
            for (j=0; ret<0 && cy+j<grid->stepsy && DIST(i,j)<r; j++) {
                ret=MAT(cx+i,cy+j)-1;
            }
        }

#undef DIST
#define DIST(i,j) (DIST2(grid->minx+(cx+(i))*grid->deltax, \
                         grid->miny+(cy-(j)+1)*grid->deltay))

        for (i=0; ret<0 && cx+i<grid->stepsx && DIST(i,0)<r; i++) {
            for (j=1; ret<0 && cy-j>0 && DIST(i,j)<r; j++) {
                ret=MAT(cx+i,cy-j)-1;
            }
        }

#undef DIST
#define DIST(i,j) (DIST2(grid->minx+(cx-(i)+1)*grid->deltax, \
			 grid->miny+(cy+(j))*grid->deltay))

        for (i=1; ret<0 && cx-i>0 && DIST(i,0)<r; i++) {
            for (j=0; ret<0 && cy+j<grid->stepsy && DIST(i,j)<r; j++) {
                ret=MAT(cx-i,cy+j)-1;
            }
        }

#undef DIST
#define DIST(i,j) (DIST2(grid->minx+(cx-(i)+1)*grid->deltax, \
			 grid->miny+(cy-(j)+1)*grid->deltay))

        for (i=1; ret<0 && cx+i>0 && DIST(i,0)<r; i++) {
            for (j=1; ret<0 && cy+i>0 && DIST(i,j)<r; j++) {
                ret=MAT(cx-i,cy-j)-1;
            }
        }

#undef DIST

    }

    return ret;
}
Ejemplo n.º 8
0
void set_tprob_recrate(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data)
{
    args_t *args = (args_t*) data;
    double ci = (pos - prev_pos) * args->rec_rate;
    MAT(hmm->curr_tprob,2,STATE_HW,STATE_HW) *= 1-ci;
    MAT(hmm->curr_tprob,2,STATE_HW,STATE_AZ) *= ci;
    MAT(hmm->curr_tprob,2,STATE_AZ,STATE_HW) *= ci;
    MAT(hmm->curr_tprob,2,STATE_AZ,STATE_AZ) *= 1-ci;
}
Ejemplo n.º 9
0
void set_tprob_genmap(hmm_t *hmm, uint32_t prev_pos, uint32_t pos, void *data)
{
    args_t *args = (args_t*) data;
    double ci = get_genmap_rate(args, pos - prev_pos, pos);
    MAT(hmm->curr_tprob,2,STATE_HW,STATE_HW) *= 1-ci;
    MAT(hmm->curr_tprob,2,STATE_HW,STATE_AZ) *= ci;
    MAT(hmm->curr_tprob,2,STATE_AZ,STATE_HW) *= ci;
    MAT(hmm->curr_tprob,2,STATE_AZ,STATE_AZ) *= 1-ci;
}
Ejemplo n.º 10
0
static CMATRIX *MATRIX_copy(CMATRIX *_object)
{
	CMATRIX *copy = MATRIX_create(WIDTH(THIS), HEIGHT(THIS), COMPLEX(THIS), FALSE);
	if (COMPLEX(THIS))
		gsl_matrix_complex_memcpy(CMAT(copy), CMAT(THIS));
	else
		gsl_matrix_memcpy(MAT(copy), MAT(THIS));
	
	return copy;
}
Ejemplo n.º 11
0
void rmat_cauchy(int m, int n, rmulti **A, int LDA)
{
  int i,j;
  for(j=0; j<n; j++){
    for(i=0; i<m; i++){
      rset_si(MAT(A,i,j,LDA),i+j+1);
      rinv(MAT(A,i,j,LDA),MAT(A,i,j,LDA));
    }
  }
}
Ejemplo n.º 12
0
void mx2cmat(int m, int n, cmulti **A, int LDA, const mxArray *src)
{
  mwSize size[2]={1,1};
  mxArray *value=NULL;
  int i,j,k;

  for(j=0; j<n; j++){
    for(i=0; i<m; i++){
      // real part
      // prec
      value=mxGetField(src,j*m+i,"r_prec");
      if(value!=NULL && mxIsInt64(value)){ rround(C_R(MAT(A,i,j,LDA)),(*(int64_t*)mxGetData(value))); }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'prec'."); }
      // sign
      value=mxGetField(src,j*m+i,"r_sign");
      if(value!=NULL && mxIsInt32(value)){ C_R(MAT(A,i,j,LDA))->_mpfr_sign=(*(int32_t*)mxGetData(value)); }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'sign'."); }
      // exp
      value=mxGetField(src,j*m+i,"r_exp");
      if(value!=NULL && mxIsInt64(value)){ C_R(MAT(A,i,j,LDA))->_mpfr_exp=(*(int64_t*)mxGetData(value)); }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'exp'."); }
      // digits
      value=mxGetField(src,j*m+i,"r_digits");
      if(value!=NULL && mxIsUint64(value)){
	for(k=0; k<rget_size(C_R(MAT(A,i,j,LDA))); k++){
	  C_R(MAT(A,i,j,LDA))->_mpfr_d[k]=((uint64_t*)mxGetData(value))[k];
	}
      }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'digits'."); }

      // imaginary part
      // prec
      value=mxGetField(src,j*m+i,"i_prec");
      if(value!=NULL && mxIsInt64(value)){ rround(C_I(MAT(A,i,j,LDA)),(*(int64_t*)mxGetData(value))); }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'prec'."); }
      // sign
      value=mxGetField(src,j*m+i,"i_sign");
      if(value!=NULL && mxIsInt32(value)){ C_I(MAT(A,i,j,LDA))->_mpfr_sign=(*(int32_t*)mxGetData(value)); }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'sign'."); }
      // exp
      value=mxGetField(src,j*m+i,"i_exp");
      if(value!=NULL && mxIsInt64(value)){ C_I(MAT(A,i,j,LDA))->_mpfr_exp=(*(int64_t*)mxGetData(value)); }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'exp'."); }
      // digits
      value=mxGetField(src,j*m+i,"i_digits");
      if(value!=NULL && mxIsUint64(value)){
	for(k=0; k<rget_size(C_I(MAT(A,i,j,LDA))); k++){
	  C_I(MAT(A,i,j,LDA))->_mpfr_d[k]=((uint64_t*)mxGetData(value))[k];
	}
      }
      else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'digits'."); }
    }
  }
  return;
}
Ejemplo n.º 13
0
int igraph_i_layout_merge_place_sphere(igraph_i_layout_mergegrid_t *grid,
                                       igraph_real_t x, igraph_real_t y, igraph_real_t r,
                                       long int id) {
    long int cx, cy;
    long int i, j;

    igraph_i_layout_mergegrid_which(grid, x, y, &cx, &cy);

    MAT(cx, cy)=id+1;

#define DIST(i,j) (DIST2(grid->minx+(cx+(i))*grid->deltax, \
			 grid->miny+(cy+(j))*grid->deltay))

    for (i=0; cx+i<grid->stepsx && DIST(i,0)<r; i++) {
        for (j=0; cy+j<grid->stepsy && DIST(i,j)<r; j++) {
            MAT(cx+i,cy+j)=id+1;
        }
    }

#undef DIST
#define DIST(i,j) (DIST2(grid->minx+(cx+(i))*grid->deltax, \
                         grid->miny+(cy-(j)+1)*grid->deltay))

    for (i=0; cx+i<grid->stepsx && DIST(i,0)<r; i++) {
        for (j=1; cy-j>0 && DIST(i,j)<r; j++) {
            MAT(cx+i,cy-j)=id+1;
        }
    }

#undef DIST
#define DIST(i,j) (DIST2(grid->minx+(cx-(i)+1)*grid->deltax, \
			 grid->miny+(cy+(j))*grid->deltay))

    for (i=1; cx-i>0 && DIST(i,0)<r; i++) {
        for (j=0; cy+j<grid->stepsy && DIST(i,j)<r; j++) {
            MAT(cx-i,cy+j)=id+1;
        }
    }

#undef DIST
#define DIST(i,j) (DIST2(grid->minx+(cx-(i)+1)*grid->deltax, \
			 grid->miny+(cy-(j)+1)*grid->deltay))

    for (i=1; cx-i>0 && DIST(i,0)<r; i++) {
        for (j=1; cy-j>0 && DIST(i,j)<r; j++) {
            MAT(cx-i,cy-j)=id+1;
        }
    }

#undef DIST
#undef DIST2

    return 0;
}
Ejemplo n.º 14
0
void icetMatrixTranspose(const IceTDouble *matrix_in, IceTDouble *matrix_out)
{
    int rowIdx;
    for (rowIdx = 0; rowIdx < 4; rowIdx++) {
        int columnIdx;
        for (columnIdx = 0; columnIdx < 4; columnIdx++) {
            MAT(matrix_out, rowIdx, columnIdx)
                = MAT(matrix_in, columnIdx, rowIdx);
        }
    }
}
Ejemplo n.º 15
0
// B=H*A, H=I-alpha*h*h'
void zhouseholder_left(int m, int n, dcomplex *A, int LDA, int k, const dcomplex *h, double alpha)
{
  dcomplex zalpha,*p=NULL;
  p=zvec_allocate(m);
  // p=A'*h
  zvec_lintr_ct(n,m-k,p,&MAT(A,k,0,LDA),LDA,&h[k]);
  // B=H*A=A-alpha*h*(A'*h)'=A-alpha*h*p'
  Z_SET(zalpha,-alpha,0);
  zmat_rank1op(m-k,n,&MAT(A,k,0,LDA),LDA,zalpha,&h[k],p);
  // done
  p=zvec_free(p);
}
Ejemplo n.º 16
0
static bool writeFile(MAHandle fh, MAHandle data, int dataOffset, int dataLen) {
	int exists;

	MAT(exists = maFileExists(fh));
	if(exists) {
		MAT(maFileTruncate(fh, 0));
	} else {
		MAT(maFileCreate(fh));
	}
	MAT(maFileWriteFromData(fh, data, dataOffset, dataLen));
	return true;
}
Ejemplo n.º 17
0
void icetMatrixMultiply(IceTDouble *C, const IceTDouble *A, const IceTDouble *B)
{
    int row, column, k;

    for (row = 0; row < 4; row++) {
        for (column = 0; column < 4; column++) {
            MAT(C, row, column) = 0.0;
            for (k = 0; k < 4; k++) {
                MAT(C, row, column) += MAT(A, row, k) * MAT(B, k, column);
            }
        }
    }
}
Ejemplo n.º 18
0
    vector<size_t> Other<R>::argsort(const vector<Mat<R>>& v) {
        // https://www.linux.com/news/software/developer/81090-c-the-gpu-and-thrust-sorting-numbers-on-the-gpu
        // should switch to gpu when more than 10,000 elements to sort.
        // initialize original index locations
        vector<size_t> idx(v.size());
        for (size_t i = 0; i != idx.size(); ++i) idx[i] = i;

        // sort indexes based on comparing values in v
        sort(idx.begin(), idx.end(),
           [&v](size_t i1, size_t i2) {return MAT(v[i1])(0) < MAT(v[i2])(0);});

        return idx;
    }
Ejemplo n.º 19
0
sqrmat * sm_transpose( sqrmat *A )
{
   sqrmat *B ; int n=A->n , i,j ; double *mat,*nat ;
   INIT_SQRMAT(B,n) ;
   mat = A->mat ; nat = B->mat ;
   for( i=0 ; i < n ; i++ ){
     NAT(i,i) = MAT(i,i) ;
     for( j=0 ; j < i ; j++ ){
       NAT(i,j) = MAT(j,i) ; NAT(j,i) = MAT(i,j) ;
     }
   }
   return B ;
}
Ejemplo n.º 20
0
struct matrix* imfilter(struct matrix* image,struct matrix* filter,uint8 operation,uint8 mode){

	float tempResult ;
	float tempPixelValue = 0.0;
	struct matrix* filteredImage = createMatrix(image->numberOfRows,image->numberOfColumns);

#ifdef DEBUG
	//For debugging initialised a temporary matrix with boundary padded
	// according to the mode given
	struct matrix* tempMatrix = createMatrix(filter->numberOfRows,filter->numberOfColumns);
#endif
	//Iterate the rows of the image
	for (uint16 i = 0; i < image->numberOfRows; ++i) {
		//Iterate the columns of the image
		for (uint16 j = 0; j < image->numberOfColumns; ++j) {
				tempResult = 0.0;
				//Iterate the rows of the filter
				for (int l = 0; l < filter->numberOfRows; ++l) {
					//Iterate the columns of the filter
					for (int m = 0; m < filter->numberOfColumns; ++m) {
						// get the pixel value for the given filter mask position(l,m)
						tempPixelValue = getPixelValue(image,i,j,l-(filter->numberOfRows/2),m-(filter->numberOfColumns/2),mode);
#ifdef DEBUG
						MAT(tempMatrix,l,m) = tempPixelValue;
#endif
						// for convolution operation the filter should be inverted
						if(operation == CONVOLUTION_OPERATION)
						{
							tempResult = tempResult + (tempPixelValue * MAT(filter,(filter->numberOfRows-1-l),(filter->numberOfColumns-1-m)));
						}
						// for correlation the filter should be used as it is
						else
						{
							tempResult = tempResult + (tempPixelValue * MAT(filter,l,m));
						}
					}
				}
#ifdef DEBUG
				printMatrix(tempMatrix);
#endif
				MAT(filteredImage,i,j) = tempResult;

		}
	}

#ifdef DEBUG
	printMatrix(filteredImage);
#endif

	return filteredImage;
}
Ejemplo n.º 21
0
/* NOTE: Have to remove/deal-with colormaterial crossovers, probably
 * later on - in the meantime just store everything.  
 */
static void GLAPIENTRY _save_Materialfv( GLenum face, GLenum pname, 
			       const GLfloat *params )
{
   GET_CURRENT_CONTEXT( ctx ); 
   TNLcontext *tnl = TNL_CONTEXT(ctx);

   switch (pname) {
   case GL_EMISSION:
      MAT( _TNL_ATTRIB_MAT_FRONT_EMISSION, 4, face, params );
      break;
   case GL_AMBIENT:
      MAT( _TNL_ATTRIB_MAT_FRONT_AMBIENT, 4, face, params );
      break;
   case GL_DIFFUSE:
      MAT( _TNL_ATTRIB_MAT_FRONT_DIFFUSE, 4, face, params );
      break;
   case GL_SPECULAR:
      MAT( _TNL_ATTRIB_MAT_FRONT_SPECULAR, 4, face, params );
      break;
   case GL_SHININESS:
      MAT( _TNL_ATTRIB_MAT_FRONT_SHININESS, 1, face, params );
      break;
   case GL_COLOR_INDEXES:
      MAT( _TNL_ATTRIB_MAT_FRONT_INDEXES, 3, face, params );
      break;
   case GL_AMBIENT_AND_DIFFUSE:
      MAT( _TNL_ATTRIB_MAT_FRONT_AMBIENT, 4, face, params );
      MAT( _TNL_ATTRIB_MAT_FRONT_DIFFUSE, 4, face, params );
      break;
   default:
      _mesa_compile_error( ctx, GL_INVALID_ENUM, "glMaterialfv" );
      return;
   }
}
Ejemplo n.º 22
0
static int _equal(CMATRIX *a, CMATRIX *b)
{
	if (WIDTH(a) != WIDTH(b) || HEIGHT(a) != HEIGHT(b))
		return FALSE;
	
	if (COMPLEX(a) || COMPLEX(b))
	{
		MATRIX_ensure_complex(a);
		MATRIX_ensure_complex(b);
		return gsl_matrix_complex_equal(CMAT(a), CMAT(b));
	}
	else
		return gsl_matrix_equal(MAT(a), MAT(b));
}
Ejemplo n.º 23
0
static void
set_companion_matrix (const double *a, size_t nc, double *m)
{
  size_t i, j;

  for (i = 0; i < nc; i++)
    for (j = 0; j < nc; j++)
      MAT (m, i, j, nc) = 0.0;

  for (i = 1; i < nc; i++)
    MAT (m, i, i - 1, nc) = 1.0;

  for (i = 0; i < nc; i++)
    MAT (m, i, nc - 1, nc) = -a[i] / a[nc];
}
static void
setup_test_matrix(struct matrix *A)
{
  // the test matrix is diagonal, which isn't really good,
  // a more general case would be better.
  for (int i = 0; i < A->m; i++) {
    for (int j = 0; j < A->n; j++) {
      if (i == j) {
        MAT(A, i, j) = i;
      } else {
        MAT(A, i, j) = 0;
      }
    }
  }
}
Ejemplo n.º 25
0
static bool matrix_determinant(CMATRIX *m, COMPLEX_VALUE *det) 
{
  int sign = 0; 
	int size = WIDTH(m);
	
	if (size != HEIGHT(m))
		return TRUE;
	
  gsl_permutation *p = gsl_permutation_calloc(size);
	
	if (COMPLEX(m))
	{
		gsl_matrix_complex *tmp = gsl_matrix_complex_alloc(size, size);
		gsl_matrix_complex_memcpy(tmp, CMAT(m));
		gsl_linalg_complex_LU_decomp(tmp, p, &sign);
		det->z = gsl_linalg_complex_LU_det(tmp, sign);
		gsl_matrix_complex_free(tmp);
	}
	else
	{
		gsl_matrix *tmp = gsl_matrix_alloc(size, size);
		gsl_matrix_memcpy(tmp, MAT(m));
		gsl_linalg_LU_decomp(tmp, p, &sign);
		det->x = gsl_linalg_LU_det(tmp, sign);
		det->z.dat[1] = 0;
		gsl_matrix_free(tmp);
	}
	
  gsl_permutation_free(p);
  return FALSE;
}
Ejemplo n.º 26
0
// Uses root buffer as scratch space.
// On success, writes full path of created directory to root.
// \param root Buffer that, on entry, contains directory path where searching should start.
// \param rootLen Length of string in root, excluding the terminating zero.
// \param name Name of the directory to create. Must end with '/'.
// \param bufLen Length of the buffer pointed to by \a root, in bytes.
static bool makeDir(char* root, int rootLen, const char* name, int bufLen) {
	// find a root path
	printf("makeDir(%s)\n", root);
	MAHandle list = maFileListStart(root, "*");
	MAT(list);
	int freeBufSpace = bufLen - rootLen;
	while(1) {
		int res;
		res = maFileListNext(list, root + rootLen, freeBufSpace);
		MAT_CUSTOM(res, _res < 0 || _res >= freeBufSpace);
		if(res == 0)
			return false;
		int resLen = rootLen + res;
		if(root[resLen-1] == '/') {
			MAASSERT(resLen + (int)strlen(name) < bufLen);
			//printf("Dir: '%s'\n", file.c_str());
			strcpy(root + resLen, name);
			if(tryToMake(root))
				return true;
			root[resLen] = 0;
			if(makeDir(root, resLen, name, bufLen))
				return true;
		}
	}
}
Ejemplo n.º 27
0
/**
 @brief    密行列AをHessenberg型行列Bに相似変換する.
 @param[in]  n    正方行列A,Bのサイズ
 @param[in]  A    行列
 @param[in]  LDA  Aの第1次元
 @param[out] B    相似変換により得られたHessenberg型行列
 @param[in]  LDB  Bの第1次元
 */
void chsnbrg_simtr(int n, cmulti **B, int LDB, cmulti **A, int LDA)
{
  int i,prec=53;
  rmulti *alpha=NULL;
  cmulti **h=NULL;
  // allocate
  prec=cmat_get_prec_max(n,n,B,LDB);
  alpha=rallocate_prec(prec);
  h=cvec_allocate_prec(n,prec);
  // copy
  cmat_copy(n,n,B,LDB,A,LDA);
  // compute
  for(i=0; i<n-2; i++){
    // Householder vector
    chouseholder_vec(n,i+1,h,alpha,&COL(B,i,LDB));
    // similarity transformation
    chouseholder_right(n,n,B,LDB,B,LDB,i+1,h,alpha);
    chouseholder_left(n,n,B,LDB,B,LDB,i+1,h,alpha);
    // set lower part as zeros
    cvec_set_zeros(n-2-i,&MAT(B,i+2,i,LDB));
  }
  // done
  alpha=rfree(alpha);
  h=cvec_free(n,h);
}
Ejemplo n.º 28
0
/**
 @brief ハウスホルダー変換を左から作用 B=H*A, H=I-alpha*h*h'
 @details h[0]=0; ...; h[k-1]=0; h[k]=-s*xi; h[k+1]=x[k+1]; ...; h[n-1]=x[n-1];
 @param[in]  m     行列Aの行の個数.
 @param[in]  n     行列Aの列の個数.
 @param[in]  k     第k要素が基準.
 @param[in]  h     ハウスホルダー・ベクトル.
 @param[in]  alpha ハウスホルダー・ベクトルの規格化定数.
 @param[out] B     変換された行列B.
*/
void rhouseholder_left(int m, int n, rmulti **B, int LDB, rmulti **A, int LDA, int k, rmulti **h, rmulti *alpha)
{
  int prec;
  rmulti *a=NULL,**p=NULL;
  // allocate
  prec=rmat_get_prec_max(m,n,B,LDB);
  a=rallocate_prec(prec);
  p=rvec_allocate_prec(m,prec);
  // p=A'*h
  rvec_lintr_t(m-k,n,p,&MAT(A,k,0,LDA),LDA,&h[k]);
  // B=H*A=A-alpha*h*(A'*h)'=A-alpha*h*p'
  rneg(a,alpha);
  rmat_rank1op(m-k,n,&MAT(B,k,0,LDB),LDB,&MAT(A,k,0,LDA),LDA,a,&h[k],p);
  // done
  a=rfree(a);
  p=rvec_free(m,p);
}
Ejemplo n.º 29
0
// y=y+A*x
void dvec_add_lintr(int m, int n, double *y, const double *A, int LDA, const double *x){
  int i,j;
  for(i=0; i<m; i++){
    for(j=0; j<n; j++){
      y[i]+=MAT(A,i,j,LDA)*x[j];
    }
  }
}
Ejemplo n.º 30
0
// y=y-A'*x
void dvec_sub_lintr_t(int m, int n, double *y, const double *A, int LDA, const double *x){
  int i,j;
  for(j=0; j<n; j++){
    for(i=0; i<m; i++){
      y[j]-=MAT(A,i,j,LDA)*x[i];
    }
  }
}