void test_eigen_genherm_results (const gsl_matrix_complex * A, const gsl_matrix_complex * B, const gsl_vector * eval, const gsl_matrix_complex * evec, size_t count, const char * desc, const char * desc2) { const size_t N = A->size1; size_t i, j; gsl_vector_complex * x = gsl_vector_complex_alloc(N); gsl_vector_complex * y = gsl_vector_complex_alloc(N); /* check A v = lambda B v */ for (i = 0; i < N; i++) { double ei = gsl_vector_get (eval, i); gsl_vector_complex_const_view vi = gsl_matrix_complex_const_column(evec, i); double norm = gsl_blas_dznrm2(&vi.vector); /* check that eigenvector is normalized */ gsl_test_rel(norm, 1.0, N * GSL_DBL_EPSILON, "genherm(N=%u,cnt=%u), %s, normalized(%d), %s", N, count, desc, i, desc2); /* compute y = A z */ gsl_blas_zgemv (CblasNoTrans, GSL_COMPLEX_ONE, A, &vi.vector, GSL_COMPLEX_ZERO, y); /* compute x = B z */ gsl_blas_zgemv (CblasNoTrans, GSL_COMPLEX_ONE, B, &vi.vector, GSL_COMPLEX_ZERO, x); /* compute x = lambda B z */ gsl_blas_zdscal(ei, x); /* now test if y = x */ for (j = 0; j < N; j++) { gsl_complex xj = gsl_vector_complex_get (x, j); gsl_complex yj = gsl_vector_complex_get (y, j); gsl_test_rel(GSL_REAL(yj), GSL_REAL(xj), 1e9 * GSL_DBL_EPSILON, "genherm(N=%u,cnt=%u), %s, eigenvalue(%d,%d), real, %s", N, count, desc, i, j, desc2); gsl_test_abs(GSL_IMAG(yj), GSL_IMAG(xj), 1e9 * GSL_DBL_EPSILON, "genherm(N=%u,cnt=%u), %s, eigenvalue(%d,%d), imag, %s", N, count, desc, i, j, desc2); } } gsl_vector_complex_free(x); gsl_vector_complex_free(y); }
int gsl_linalg_complex_LU_refine (const gsl_matrix_complex * A, const gsl_matrix_complex * LU, const gsl_permutation * p, const gsl_vector_complex * b, gsl_vector_complex * x, gsl_vector_complex * residual) { if (A->size1 != A->size2) { GSL_ERROR ("matrix a must be square", GSL_ENOTSQR); } if (LU->size1 != LU->size2) { GSL_ERROR ("LU matrix must be square", GSL_ENOTSQR); } else if (A->size1 != LU->size2) { GSL_ERROR ("LU matrix must be decomposition of a", GSL_ENOTSQR); } else if (LU->size1 != p->size) { GSL_ERROR ("permutation length must match matrix size", GSL_EBADLEN); } else if (LU->size1 != b->size) { GSL_ERROR ("matrix size must match b size", GSL_EBADLEN); } else if (LU->size1 != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else if (singular (LU)) { GSL_ERROR ("matrix is singular", GSL_EDOM); } else { int status; /* Compute residual, residual = (A * x - b) */ gsl_vector_complex_memcpy (residual, b); { gsl_complex one = GSL_COMPLEX_ONE; gsl_complex negone = GSL_COMPLEX_NEGONE; gsl_blas_zgemv (CblasNoTrans, one, A, x, negone, residual); } /* Find correction, delta = - (A^-1) * residual, and apply it */ status = gsl_linalg_complex_LU_svx (LU, p, residual); { gsl_complex negone= GSL_COMPLEX_NEGONE; gsl_blas_zaxpy (negone, residual, x); } return status; } }
void CPMPChan::Run() { /// fetch data objects gsl_vector_complex invec = vin1.GetDataObj(); gsl_matrix_complex cmat = min2.GetDataObj(); // // gsl_vector_complex *tmp = gsl_vector_complex_alloc(N()); // // // extract the user channel matrix // // for (int i=0; i<N(); i++) { gsl_complex h = gsl_matrix_complex_get(&cmat,Cd(),(N()-i)%N()); for (int j=0; j<N(); j++) { gsl_matrix_complex_set(user_chan,j,(j+i) % N(),h); } } // cout << "User " << Cd() << " channel:" << endl; // gsl_matrix_complex_show(user_chan); // // // compute the output vector // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), user_chan, &invec, gsl_complex_rect(0,0), tmp); // cout << "User " << Cd() << " trasmitted vector:" << endl; // gsl_vector_complex_fprintf(stdout,&invec,"%f"); // cout << "User " << Cd() << " received vector:" << endl; // gsl_vector_complex_fprintf(stdout,tmp,"%f"); //////// production of data vout1.DeliverDataObj( *tmp ); }
static int cm_mul_cv(lua_State *L) { mMatComplex *m = qlua_checkMatComplex(L, 1); mVecComplex *v = qlua_checkVecComplex(L, 2); mVecComplex *r = qlua_newVecComplex(L, m->l_size); /* XXX assume GSL and QLA_D_Complex use compatible layout */ gsl_vector_complex_view vv = gsl_vector_complex_view_array((void *)&v->val[0], v->size); gsl_vector_complex_view vr = gsl_vector_complex_view_array((void *)&r->val[0], r->size); if (m->r_size != v->size) return luaL_error(L, "matrix size mismatch in m * v"); gsl_blas_zgemv(CblasNoTrans, GSL_COMPLEX_ONE, m->m, &vv.vector, GSL_COMPLEX_ZERO, &vr.vector); return 1; }
void MCPMPChan::Run() { /// fetch data objects gsl_matrix_complex inmat = min1.GetDataObj(); gsl_matrix_complex cmat = min2.GetDataObj(); // inmat : input signal matrix x(n) (NxM) // i // complex sample at time n from Tx number i // cmat : channel coeffs matrix h(n) (M**2xN) // ij // cmat matrix structure // // +- -+ // | h(0) . . . . h(n) | | // | 11 11 | | // | | | Rx1 // | h(0) . . . . h(n) | | // | 12 12 | | // | | // | h(0) . . . . h(n) | | // | 21 21 | | // | | | Rx2 // | h(0) . . . . h(n) | | // | 22 22 | | // +- -+ // // where h(n) represents the channel impulse response // ij // // at time n, from tx i to rx j // the matrix has MxM rows and N comumns. // The (i,j) channel is locater at row i*M+j // with i,j in the range [0,M-1] and rows counting from 0 // // gsl_matrix_complex_set_zero(outmat); for (int rx=0;rx<M();rx++) { //loop through Rx // // csubmat creates a view on cmat extracting the MxN submatrix for Rx number u // gsl_matrix_complex_const_view csubmat = gsl_matrix_complex_const_submatrix(&cmat,rx*M(),0,M(),N()); // // cut a slice of outmat // gsl_vector_complex_view outvec = gsl_matrix_complex_column(outmat,rx); for (int tx=0;tx<M();tx++) { // loop through Tx // // input signal from tx // gsl_vector_complex_view x = gsl_matrix_complex_column(&inmat,tx); gsl_vector_complex *tmp = gsl_vector_complex_alloc(N()); // // // extract the current tx-rx channel matrix // // for (int i=0; i<N(); i++) { gsl_complex h = gsl_matrix_complex_get(&csubmat.matrix,tx,(N()-i)%N()); for (int j=0; j<N(); j++) { gsl_matrix_complex_set(user_chan,j,(j+i) % N(),h); } } // cout << "Channel (" << tx << "-" << rx << "):" << endl; // gsl_matrix_complex_show(user_chan); // // compute the signal rx = H tx // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), user_chan, &x.vector, gsl_complex_rect(0,0), tmp); // // sum for each tx // gsl_vector_complex_add(&outvec.vector,tmp); gsl_vector_complex_free(tmp); } // tx loop for (int i=0; i< N(); i++) { gsl_complex noisesample = gsl_complex_rect( gsl_ran_gaussian(ran,noisestd), gsl_ran_gaussian(ran,noisestd)); gsl_complex ctmp = gsl_complex_add(gsl_vector_complex_get(&outvec.vector,i),noisesample); gsl_vector_complex_set(&outvec.vector,i,ctmp); } } // rx loop // cout << "received signals matrix (" << N() << "x" << M() << ")" << endl; // gsl_matrix_complex_show(outmat); //////// production of data mout1.DeliverDataObj( *outmat ); }
/** * C++ version of gsl_blas_zgemv(). * @param TransA Transpose type * @param alpha A constant * @param A A matrix * @param X A vector * @param beta Another constant * @param Y A vector * @return Error code on failure */ int zgemv( CBLAS_TRANSPOSE_t TransA, complex const& alpha, matrix_complex const& A, vector_complex const& X, complex const& beta, vector_complex& Y ){ return gsl_blas_zgemv( TransA, alpha.get(), A.get(), X.get(), beta.get(), Y.get() ); }
double Calculator::getIntensity(double Q) { std::complex<double> cppf1, cppf2; gsl_complex alpha, beta; gsl_complex gslf1, gslf2; int s; double avFactor; cppf1 = m_sf1->F(0.0, 0.0, Q, m_energy); cppf2 = m_sf2->F(0.0, 0.0, Q, m_energy); gslf1 = gsl_complex_rect(cppf1.real(), cppf1.imag()); gslf2 = gsl_complex_rect(cppf2.real(), cppf2.imag()); avFactor = exp(-2.0 / m_N); alpha = gsl_complex_rect (1.0, 0.0); beta = gsl_complex_rect (0.0, 0.0); /*set vector F (scattering factors)*/ gsl_vector_complex_set(F, 0, gslf1); gsl_vector_complex_set(F, 1, gslf2); /*set vector conj(F) (scattering factors)*/ gsl_vector_complex_set(Fconj, 0, gsl_complex_conjugate(gslf1)); gsl_vector_complex_set(Fconj, 1, gsl_complex_conjugate(gslf2)); /*set exp matrix*/ setMatrixExp(m_Exp, Q); /*find W = P * Exp * Ps * conj(F) vector:*/ /* (1) W = alpha * Ps * conj(F) + beta * W */ gsl_blas_zgemv (CblasNoTrans, alpha, m_Ps, Fconj, beta, W); /*printf("W(1):\n"); gsl_vector_complex_fprintf (stdout, W, "%g");*/ /* (2) W = alpha * Exp * tmp_vec + beta * W */ gsl_blas_zgemv (CblasNoTrans, alpha, m_Exp, W, beta, tmp_vec); /*printf("W(2):\n"); gsl_vector_complex_fprintf (stdout, tmp_vec, "%g");*/ /* (3) W = alpha * P * tmp_vec + beta * W */ gsl_blas_zgemv (CblasNoTrans, alpha, m_P, tmp_vec, beta, W); /*Find J0 = F.(Ps * conj(F)) */ gsl_blas_zgemv (CblasNoTrans, alpha, m_Ps, Fconj, beta, tmp_vec); gsl_blas_zdotu (F, tmp_vec, &J0); /*alpha = exp(-2 / N)*/ alpha = gsl_complex_rect (avFactor, 0.0); beta = gsl_complex_rect (0.0, 0.0); /*find T matrix: T = alpha * P * exp + beta * T*/ gsl_blas_zgemm (CblasNoTrans, CblasNoTrans, alpha, m_P, m_Exp, beta, T); /*printf("T:\n"); gsl_matrix_complex_fprintf (stdout, T, "%g");*/ /*Find Jns = F. (G * W) */ /*tmp_mat = I */ gsl_matrix_complex_set_identity (tmp_mat); /*tmp_mat = I - T */ gsl_matrix_complex_sub (tmp_mat, T); /*LU decomposition*/ gsl_linalg_complex_LU_decomp(tmp_mat, perm, &s); /*calculate product G * W = (I - T)^(-1) W directly using LU decomposition*/ gsl_linalg_complex_LU_solve (tmp_mat, perm, W, tmp_vec); /*calculate F.(G * W)*/ gsl_blas_zdotu (F, tmp_vec, &Jns); /*Find Js = F.(G^2 * (I - T^N) * W) however, this term should be negligible*/ /*result = N *(2 * Jns + J0) - Js */ alpha = gsl_complex_mul_real (Jns, 2.0 * avFactor); alpha = gsl_complex_add (alpha, J0); return m_N * m_I0 * GSL_REAL(alpha) * getPLGfactor(getTheta(Q)) + m_Ibg; }
void MBlockUser::Run() { // // Allocation Matrices // gsl_matrix_uint signature_frequencies=min2.GetDataObj(); gsl_matrix signature_powers=min3.GetDataObj(); // // input bits // gsl_matrix_uint inputbits = min1.GetDataObj(); // // outer loop: the users // for (int u=0;u<M();u++) { gsl_vector_complex_view tmpout = gsl_matrix_complex_column(outmat,u); // // // FETCH K INPUT SYMBOLS // // for (int j=0;j<K();j++) { symbol_id=0; //////// I take Nb bits from input and map it in new_symbol for (int i=0;i<Nb();i++) { symbol_id = (symbol_id << 1); // symbol_id += in1.GetDataObj(); symbol_id += gsl_matrix_uint_get(&inputbits,u,j*Nb()+i); } new_symbol = gsl_complex_polar(1.0, symbol_arg * double(gsl_vector_uint_get(gray_encoding, symbol_id))); gsl_vector_complex_set(tmp,j,new_symbol); } // // // SELECTION MATRIX UPDATE and POWER // // // gsl_matrix_complex_set_identity(selection_mat); gsl_matrix_complex_set_zero(selection_mat); for (int i=0;i<J(); i++) { unsigned int carrier=gsl_matrix_uint_get(&signature_frequencies,u,i); double power=gsl_matrix_get(&signature_powers,u,i); gsl_complex one=gsl_complex_polar(power,0.0); gsl_matrix_complex_set(selection_mat,carrier,i,one); } // // // PRECODING MATRIX UPDATE // // #ifdef GIANNAKIS_PRECODING double roarg=2.0*double(M_PI/N()); for (int i=0;i<J(); i++) { unsigned int carrier=gsl_matrix_uint_get(&signature_frequencies,u,i); for (int j=0; j<K(); j++) { gsl_complex ro=gsl_complex_polar(sqrt(1.0/double(J())),-j*carrier*roarg); gsl_matrix_complex_set(coding_mat,i,j,ro); } } #else double roarg=2.0*double(M_PI/J()); for (int i=0;i<J(); i++) { for (int j=0; j<K(); j++) { gsl_complex ro=gsl_complex_polar(sqrt(1.0/double(J())),-j*i*roarg); gsl_matrix_complex_set(coding_mat,i,j,ro); } } #endif #ifdef SHOW_MATRIX cout << endl << BlockName << " user: "******"coding matrix (theta) = " << endl; gsl_matrix_complex_show(coding_mat); cout << "T^h*T matrix = " << endl; gsl_matrix_complex_show(THT); cout << "T^h*T trace = " << GSL_REAL(trace) << ", " << GSL_IMAG(trace) << endl; gsl_matrix_complex_free(THT); #endif // // // PRECODING // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), coding_mat, tmp, gsl_complex_rect(0,0), tmp1); // // // CARRIER SELECTION // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), selection_mat, tmp1, gsl_complex_rect(0,0), tmp2); // // // IFFT TRANSFORM // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), transform_mat, tmp2, gsl_complex_rect(0,0), &tmpout.vector); // cout << "\n\n symbols (user " << u << ") = " << endl; // gsl_vector_complex_fprintf(stdout,tmp,"%f"); #ifdef SHOW_MATRIX cout << "\n\n symbols (user " << u << ") = " << endl; gsl_vector_complex_fprintf(stdout,tmp,"%f"); cout << "\n\n precoded = " << endl; gsl_vector_complex_fprintf(stdout,tmp1,"%f"); cout << "\n\n precoded selected = " << endl; gsl_vector_complex_fprintf(stdout,tmp2,"%f"); cout << "\n\n precoded selected transformed = " << endl; gsl_vector_complex_fprintf(stdout,&tmpout.vector,"%f"); #endif } // close user loop mout1.DeliverDataObj(*outmat); }
void test_eigen_nonsymm_results (const gsl_matrix * m, const gsl_vector_complex * eval, const gsl_matrix_complex * evec, size_t count, const char * desc, const char * desc2) { size_t i,j; size_t N = m->size1; gsl_vector_complex * x = gsl_vector_complex_alloc(N); gsl_vector_complex * y = gsl_vector_complex_alloc(N); gsl_matrix_complex * A = gsl_matrix_complex_alloc(N, N); /* we need a complex matrix for the blas routines, so copy m into A */ for (i = 0; i < N; ++i) { for (j = 0; j < N; ++j) { gsl_complex z; GSL_SET_COMPLEX(&z, gsl_matrix_get(m, i, j), 0.0); gsl_matrix_complex_set(A, i, j, z); } } for (i = 0; i < N; i++) { gsl_complex ei = gsl_vector_complex_get (eval, i); gsl_vector_complex_const_view vi = gsl_matrix_complex_const_column(evec, i); double norm = gsl_blas_dznrm2(&vi.vector); /* check that eigenvector is normalized */ gsl_test_rel(norm, 1.0, N * GSL_DBL_EPSILON, "nonsymm(N=%u,cnt=%u), %s, normalized(%d), %s", N, count, desc, i, desc2); gsl_vector_complex_memcpy(x, &vi.vector); /* compute y = m x (should = lambda v) */ gsl_blas_zgemv (CblasNoTrans, GSL_COMPLEX_ONE, A, x, GSL_COMPLEX_ZERO, y); /* compute x = lambda v */ gsl_blas_zscal(ei, x); /* now test if y = x */ for (j = 0; j < N; j++) { gsl_complex xj = gsl_vector_complex_get (x, j); gsl_complex yj = gsl_vector_complex_get (y, j); /* use abs here in case the values are close to 0 */ gsl_test_abs(GSL_REAL(yj), GSL_REAL(xj), 1e8*GSL_DBL_EPSILON, "nonsymm(N=%u,cnt=%u), %s, eigenvalue(%d,%d), real, %s", N, count, desc, i, j, desc2); gsl_test_abs(GSL_IMAG(yj), GSL_IMAG(xj), 1e8*GSL_DBL_EPSILON, "nonsymm(N=%u,cnt=%u), %s, eigenvalue(%d,%d), imag, %s", N, count, desc, i, j, desc2); } } gsl_matrix_complex_free(A); gsl_vector_complex_free(x); gsl_vector_complex_free(y); }
void test_eigen_herm_results (const gsl_matrix_complex * A, const gsl_vector * eval, const gsl_matrix_complex * evec, size_t count, const char * desc, const char * desc2) { const size_t N = A->size1; size_t i, j; gsl_vector_complex * x = gsl_vector_complex_alloc(N); gsl_vector_complex * y = gsl_vector_complex_alloc(N); /* check eigenvalues */ for (i = 0; i < N; i++) { double ei = gsl_vector_get (eval, i); gsl_vector_complex_const_view vi = gsl_matrix_complex_const_column(evec, i); gsl_vector_complex_memcpy(x, &vi.vector); /* compute y = m x (should = lambda v) */ gsl_blas_zgemv (CblasNoTrans, GSL_COMPLEX_ONE, A, x, GSL_COMPLEX_ZERO, y); for (j = 0; j < N; j++) { gsl_complex xj = gsl_vector_complex_get (x, j); gsl_complex yj = gsl_vector_complex_get (y, j); gsl_test_rel(GSL_REAL(yj), ei * GSL_REAL(xj), 1e8*GSL_DBL_EPSILON, "%s, eigenvalue(%d,%d), real, %s", desc, i, j, desc2); gsl_test_rel(GSL_IMAG(yj), ei * GSL_IMAG(xj), 1e8*GSL_DBL_EPSILON, "%s, eigenvalue(%d,%d), imag, %s", desc, i, j, desc2); } } /* check eigenvectors are orthonormal */ for (i = 0; i < N; i++) { gsl_vector_complex_const_view vi = gsl_matrix_complex_const_column(evec, i); double nrm_v = gsl_blas_dznrm2(&vi.vector); gsl_test_rel (nrm_v, 1.0, N * GSL_DBL_EPSILON, "%s, normalized(%d), %s", desc, i, desc2); } for (i = 0; i < N; i++) { gsl_vector_complex_const_view vi = gsl_matrix_complex_const_column(evec, i); for (j = i + 1; j < N; j++) { gsl_vector_complex_const_view vj = gsl_matrix_complex_const_column(evec, j); gsl_complex vivj; gsl_blas_zdotc (&vi.vector, &vj.vector, &vivj); gsl_test_abs (gsl_complex_abs(vivj), 0.0, 10.0 * N * GSL_DBL_EPSILON, "%s, orthogonal(%d,%d), %s", desc, i, j, desc2); } } gsl_vector_complex_free(x); gsl_vector_complex_free(y); } /* test_eigen_herm_results() */
void test_eigen_gen_results (const gsl_matrix * A, const gsl_matrix * B, const gsl_vector_complex * alpha, const gsl_vector * beta, const gsl_matrix_complex * evec, size_t count, const char * desc, const char * desc2) { const size_t N = A->size1; size_t i, j; gsl_matrix_complex *ma, *mb; gsl_vector_complex *x, *y; gsl_complex z_one, z_zero; ma = gsl_matrix_complex_alloc(N, N); mb = gsl_matrix_complex_alloc(N, N); y = gsl_vector_complex_alloc(N); x = gsl_vector_complex_alloc(N); /* ma <- A, mb <- B */ for (i = 0; i < N; ++i) { for (j = 0; j < N; ++j) { gsl_complex z; GSL_SET_COMPLEX(&z, gsl_matrix_get(A, i, j), 0.0); gsl_matrix_complex_set(ma, i, j, z); GSL_SET_COMPLEX(&z, gsl_matrix_get(B, i, j), 0.0); gsl_matrix_complex_set(mb, i, j, z); } } GSL_SET_COMPLEX(&z_one, 1.0, 0.0); GSL_SET_COMPLEX(&z_zero, 0.0, 0.0); /* check eigenvalues */ for (i = 0; i < N; ++i) { gsl_vector_complex_const_view vi = gsl_matrix_complex_const_column(evec, i); gsl_complex ai = gsl_vector_complex_get(alpha, i); double bi = gsl_vector_get(beta, i); /* compute x = alpha * B * v */ gsl_blas_zgemv(CblasNoTrans, z_one, mb, &vi.vector, z_zero, x); gsl_blas_zscal(ai, x); /* compute y = beta * A v */ gsl_blas_zgemv(CblasNoTrans, z_one, ma, &vi.vector, z_zero, y); gsl_blas_zdscal(bi, y); /* now test if y = x */ for (j = 0; j < N; ++j) { gsl_complex xj = gsl_vector_complex_get(x, j); gsl_complex yj = gsl_vector_complex_get(y, j); gsl_test_abs(GSL_REAL(yj), GSL_REAL(xj), 1e8*GSL_DBL_EPSILON, "gen(N=%u,cnt=%u), %s, eigenvalue(%d,%d), real, %s", N, count, desc, i, j, desc2); gsl_test_abs(GSL_IMAG(yj), GSL_IMAG(xj), 1e8*GSL_DBL_EPSILON, "gen(N=%u,cnt=%u), %s, eigenvalue(%d,%d), real, %s", N, count, desc, i, j, desc2); } } gsl_matrix_complex_free(ma); gsl_matrix_complex_free(mb); gsl_vector_complex_free(y); gsl_vector_complex_free(x); } /* test_eigen_gen_results() */
int gsl_linalg_complex_cholesky_decomp(gsl_matrix_complex *A) { const size_t N = A->size1; if (N != A->size2) { GSL_ERROR("cholesky decomposition requires square matrix", GSL_ENOTSQR); } else { size_t i, j; gsl_complex z; double ajj; for (j = 0; j < N; ++j) { z = gsl_matrix_complex_get(A, j, j); ajj = GSL_REAL(z); if (j > 0) { gsl_vector_complex_const_view aj = gsl_matrix_complex_const_subrow(A, j, 0, j); gsl_blas_zdotc(&aj.vector, &aj.vector, &z); ajj -= GSL_REAL(z); } if (ajj <= 0.0) { GSL_ERROR("matrix is not positive definite", GSL_EDOM); } ajj = sqrt(ajj); GSL_SET_COMPLEX(&z, ajj, 0.0); gsl_matrix_complex_set(A, j, j, z); if (j < N - 1) { gsl_vector_complex_view av = gsl_matrix_complex_subcolumn(A, j, j + 1, N - j - 1); if (j > 0) { gsl_vector_complex_view aj = gsl_matrix_complex_subrow(A, j, 0, j); gsl_matrix_complex_view am = gsl_matrix_complex_submatrix(A, j + 1, 0, N - j - 1, j); cholesky_complex_conj_vector(&aj.vector); gsl_blas_zgemv(CblasNoTrans, GSL_COMPLEX_NEGONE, &am.matrix, &aj.vector, GSL_COMPLEX_ONE, &av.vector); cholesky_complex_conj_vector(&aj.vector); } gsl_blas_zdscal(1.0 / ajj, &av.vector); } } /* Now store L^H in upper triangle */ for (i = 1; i < N; ++i) { for (j = 0; j < i; ++j) { z = gsl_matrix_complex_get(A, i, j); gsl_matrix_complex_set(A, j, i, gsl_complex_conjugate(z)); } } return GSL_SUCCESS; } } /* gsl_linalg_complex_cholesky_decomp() */
int lls_complex_fold(const gsl_matrix_complex *A, const gsl_vector_complex *b, lls_complex_workspace *w) { const size_t n = A->size1; if (A->size2 != w->p) { fprintf(stderr, "lls_complex_fold: A has wrong size2\n"); return GSL_EBADLEN; } else if (n != b->size) { fprintf(stderr, "lls_complex_fold: b has wrong size\n"); return GSL_EBADLEN; } else { int s = 0; double bnorm; #if 0 size_t i; gsl_vector_view wv = gsl_vector_subvector(w->w_robust, 0, n); if (w->niter > 0) { gsl_vector_complex_view rc = gsl_vector_complex_subvector(w->r_complex, 0, n); gsl_vector_view rv = gsl_vector_subvector(w->r, 0, n); /* calculate residuals with previously computed coefficients: r = b - A c */ gsl_vector_complex_memcpy(&rc.vector, b); gsl_blas_zgemv(CblasNoTrans, GSL_COMPLEX_NEGONE, A, w->c, GSL_COMPLEX_ONE, &rc.vector); /* compute Re(r) */ for (i = 0; i < n; ++i) { gsl_complex ri = gsl_vector_complex_get(&rc.vector, i); gsl_vector_set(&rv.vector, i, GSL_REAL(ri)); } /* calculate weights with robust weighting function */ gsl_multifit_robust_weights(&rv.vector, &wv.vector, w->robust_workspace_p); } else gsl_vector_set_all(&wv.vector, 1.0); /* compute final weights as product of input and robust weights */ gsl_vector_mul(wts, &wv.vector); #endif /* AHA += A^H A, using only the upper half of the matrix */ s = gsl_blas_zherk(CblasUpper, CblasConjTrans, 1.0, A, 1.0, w->AHA); if (s) return s; /* AHb += A^H b */ s = gsl_blas_zgemv(CblasConjTrans, GSL_COMPLEX_ONE, A, b, GSL_COMPLEX_ONE, w->AHb); if (s) return s; /* bHb += b^H b */ bnorm = gsl_blas_dznrm2(b); w->bHb += bnorm * bnorm; fprintf(stderr, "norm(AHb) = %.12e, bHb = %.12e\n", gsl_blas_dznrm2(w->AHb), w->bHb); if (!gsl_finite(w->bHb)) { fprintf(stderr, "bHb is NAN\n"); exit(1); } return s; } } /* lls_complex_fold() */