'GSL: how to get LDLT decomposition in GSL

I want to get the matrix l and d of matrix Q from LDLT decomposition. The same result of scipy.linalg.ldl(),here is the code:

#include <gsl/gsl_math.h>                                                                                                                                                                                        #include <gsl/gsl_sf.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_errno.h>
                                                                                                                                                                                                                 int main() {
      const int dim = 3;
      double pars[3] = { 0, 0, 0 };
      double Q[9] = {
          2,-1,0,
          -1,3,-1,
          0,-1,4
      };
      int i=0,j=0;

      // Gaussian Multivariate distribution
      gsl_matrix *L = gsl_matrix_calloc(dim, dim);
      gsl_vector *S = gsl_vector_calloc(dim);
      gsl_permutation * perm = gsl_permutation_calloc(dim);

      for(i=0;i<dim*dim;i++) L->data[i]=Q[i];

>>    gsl_linalg_ldlt_decomp(L);

      for(i=0;i<3;i++){
          for(j=0;j<3;j++){
              printf("%.4f ", L->data[i*3+j]);
          }
          printf("\n");
      }

      printf("\n S=");
      for(i=0;i<3;i++)
          printf("%.4f ", S->data[i]);
      printf("\n");
  }

my compile args is gcc ldl.c -lm -llapack -lblas -lgsl

But it returns;

ldl.c: In function ‘main’:
ldl.c:39:5: warning: implicit declaration of function ‘gsl_linalg_ldlt_decomp’; did you mean ‘gsl_linalg_PTLQ_decomp’? [-Wimplicit-function-declaration]
   39 |     gsl_linalg_ldlt_decomp(L);
      |     ^~~~~~~~~~~~~~~~~~~~~~
      |     gsl_linalg_PTLQ_decomp
/usr/bin/ld: /tmp/ccSWXMMb.o: in function `main':
ldl.c:(.text+0x170): undefined reference to `gsl_linalg_ldlt_decomp'
collect2: error: ld returned 1 exit status

WHy ? What shoud I do?



Solution 1:[1]

You would be better off using spark + spark cassandra connector combination to do this task. With Spark you can do joins in memory and write the data back to Cassandra or any text file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manish Khandelwal