Beispiel #1
0
taucs_ccs_matrix *taucs_dtl(ccs_augment_nonpositive_offdiagonals) (taucs_ccs_matrix * A) {
#ifdef TAUCS_CORE_COMPLEX
	assert(0);
#else
	int n, i, j;
	int *tmp;
	taucs_ccs_matrix *A_tmp;

	if (!(A->flags & TAUCS_SYMMETRIC) || !(A->flags & TAUCS_LOWER)) {
		taucs_printf("taucs_ccs_augment_nonpositive_offdiagonal: matrix not symmetric or not lower\n");
		return NULL;
	}

	n = A->n;

	tmp = (int *) taucs_calloc((2 * n + 1), sizeof(int));
	if (!tmp) {
		taucs_printf("taucs_ccs_augment_nonpositive_offdiagonal: out of memory\n");
		return NULL;
	}

	A_tmp = taucs_dtl(ccs_create) (2 * n, 2 * n, 2 * (A->colptr[n]));
	if (A_tmp == NULL) {
		taucs_free(tmp);
		return NULL;
	}
	A_tmp->flags |= TAUCS_SYMMETRIC | TAUCS_LOWER;

	for (i = 0; i < n; i++) {
		for (j = A->colptr[i]; j < A->colptr[i + 1]; j++) {
			if ((i == A->rowind[j]) || (A->taucs_values[j] < 0)) {
				tmp[i]++;
				tmp[i + n]++;
			} else {
				tmp[i]++;
				tmp[A->rowind[j]]++;
			}
		}
	}

	A_tmp->colptr[0] = 0;
	for (i = 0; i < 2 * n; i++)
		A_tmp->colptr[i + 1] = A_tmp->colptr[i] + tmp[i];
	for (i = 0; i < 2 * n; i++)
		tmp[i] = A_tmp->colptr[i];

	for (i = 0; i < n; i++) {
		for (j = A->colptr[i]; j < A->colptr[i + 1]; j++) {
			if ((i == A->rowind[j]) || (A->taucs_values[j] < 0)) {
				A_tmp->rowind[tmp[i]] = A->rowind[j];
				A_tmp->taucs_values[tmp[i]++] = A->taucs_values[j];
				A_tmp->rowind[tmp[i + n]] = A->rowind[j] + n;
				A_tmp->taucs_values[tmp[i + n]++] = A->taucs_values[j];
			} else {
				A_tmp->rowind[tmp[i]] = A->rowind[j] + n;
				A_tmp->taucs_values[tmp[i]++] = -A->taucs_values[j];
				A_tmp->rowind[tmp[A->rowind[j]]] = i + n;
				A_tmp->taucs_values[tmp[A->rowind[j]]++] = -A->taucs_values[j];
			}
		}
	}
	taucs_free(tmp);

	return A_tmp;
#endif
	/*
	 * added omer
	 */
	return NULL;
}
Beispiel #2
0
taucs_ccs_matrix* 
taucs_dtl(ccs_read_ccs)(char* filename,int flags)
{
  FILE* f;
  taucs_ccs_matrix*  m;

  /*
  int*    clen; 
  int*    is; 
  int*    js;
  taucs_datatype* vs;
  int ncols, nrows, nnz;
  int i,ip,j,k,n;
  */
  /* taucs_datatype dv;*/
  /* double         di,dj;*/

  int i,ip,j,N,*pointers;

  f = fopen(filename ,"r");

  if (f == NULL) {
    taucs_printf("taucs_ccs_read_ccs: could not open ccs file %s\n",filename);
    return NULL;
  }

  fscanf(f,"%d",&N);

  pointers = (int*) taucs_malloc((N+1)*sizeof(int));
  for(i=0; i<N+1; ++i) {
    fscanf(f,"%d",&pointers[i]);
  }

  m = taucs_dtl(ccs_create)(N, N, pointers[N]);
  for (i=0; i<=N; i++) (m->colptr)[i] = pointers[i];

  for(i=0; i<pointers[N]; ++i)
    fscanf(f,"%d",(m->rowind)+i);

#ifdef TAUCS_CORE_DOUBLE  
  for(i=0; i<pointers[N]; ++i)
    fscanf(f,"%lg",(m->taucs_values)+i);
#endif
  
#ifdef TAUCS_CORE_SINGLE  
  for(i=0; i<pointers[N]; ++i)
    fscanf(f,"%g",(m->taucs_values)+i);
#endif
  
#ifdef TAUCS_CORE_DCOMPLEX  
  for(i=0; i<pointers[N]; ++i) {
    taucs_real_datatype dv_r;
    taucs_real_datatype dv_i;
    fscanf(f,"%lg+%lgi",&dv_r,&dv_i);
    (m->taucs_values)[i] = taucs_complex_create(dv_r,dv_i);
  }
#endif
  
#ifdef TAUCS_CORE_SCOMPLEX
  for(i=0; i<pointers[N]; ++i) {
    taucs_real_datatype dv_r;
    taucs_real_datatype dv_i;
    fscanf(f,"%g+%gi",&dv_r,&dv_i);
    (m->taucs_values)[i] = taucs_complex_create(dv_r,dv_i);
  }
#endif
  
  if (flags & TAUCS_SYMMETRIC) {
    m->flags  = TAUCS_SYMMETRIC | TAUCS_LOWER;
    for (j=0; j<N; j++) {
      for (ip=(m->colptr)[j]; ip<(m->colptr)[j+1]; ip++) {
	i = (m->rowind)[ip];
	assert(i >= j);
      }
    }
  } else
    m->flags  = 0;

#ifdef TAUCS_CORE_DOUBLE
  m->flags |= TAUCS_DOUBLE;
#endif

#ifdef TAUCS_CORE_SINGLE
  m->flags |= TAUCS_SINGLE;
#endif

#ifdef TAUCS_CORE_DCOMPLEX
  m->flags |= TAUCS_DCOMPLEX;
#endif

#ifdef TAUCS_CORE_SCOMPLEX
  m->flags |= TAUCS_SCOMPLEX;
#endif

  taucs_free(pointers);
  
  taucs_printf("taucs_ccs_read_ccs: read %s, n=%d\n",filename,m->n);

  return m;
} 
Beispiel #3
0
taucs_ccs_matrix *taucs_dtl(ccs_permute_symmetrically) (taucs_ccs_matrix * A, int *perm, int *invperm) {
	taucs_ccs_matrix *PAPT;
	int n;
	int nnz;

	/*
	 * int* colptr;
	 */
	int *len;
	int i, j, ip, I, J;
	taucs_datatype AIJ;

	assert(A->flags & TAUCS_SYMMETRIC || A->flags & TAUCS_HERMITIAN);
	assert(A->flags & TAUCS_LOWER);

	n = A->n;
	nnz = (A->colptr)[n];

	PAPT = taucs_dtl(ccs_create) (n, n, nnz);
	if (!PAPT)
		return NULL;

	/*
	 * PAPT->flags = TAUCS_SYMMETRIC | TAUCS_LOWER;
	 */
	PAPT->flags = A->flags;

	len = (int *) taucs_malloc(n * sizeof(int));
	/*
	 * colptr = (int*) taucs_malloc(n * sizeof(int));
	 */
	if (!len) {
		taucs_printf("taucs_ccs_permute_symmetrically: out of memory\n");
		taucs_ccs_free(PAPT);
		return NULL;
	}

	for (j = 0; j < n; j++)
		len[j] = 0;

	for (j = 0; j < n; j++) {
		for (ip = (A->colptr)[j]; ip < (A->colptr)[j + 1]; ip++) {
			/*
			 * i = (A->rowind)[ip] - (A->indshift);
			 */
			i = (A->rowind)[ip];

			I = invperm[i];
			J = invperm[j];

			if (I < J) {
				int T = I;

				I = J;
				J = T;
			}

			len[J]++;

		}
	}

	(PAPT->colptr)[0] = 0;
	for (j = 1; j <= n; j++)
		(PAPT->colptr)[j] = (PAPT->colptr)[j - 1] + len[j - 1];

	for (j = 0; j < n; j++)
		len[j] = (PAPT->colptr)[j];

	for (j = 0; j < n; j++) {
		for (ip = (A->colptr)[j]; ip < (A->colptr)[j + 1]; ip++) {
			/*
			 * i = (A->rowind)[ip] - (A->indshift);
			 */
			i = (A->rowind)[ip];
			AIJ = (A->taucs_values)[ip];

			I = invperm[i];
			J = invperm[j];

			if (I < J) {
				int T = I;

				I = J;
				J = T;
				if (A->flags & TAUCS_HERMITIAN)
					AIJ = taucs_conj(AIJ);
			}

			/*
			 * (PAPT->rowind)[ len[J] ] = I + (PAPT->indshift);
			 */
			(PAPT->rowind)[len[J]] = I;
			(PAPT->taucs_values)[len[J]] = AIJ;

			len[J]++;
		}
	}

	taucs_free(len);
	return PAPT;
}