zoukankan      html  css  js  c++  java
  • lapacke svd实例

    参考

    intel MTK实例

    https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/lapacke_dgesvd_row.c.htm  

    http://www.netlib.org/lapack/explore-html/d0/dee/lapacke__dgesvd_8c.html

    https://blog.csdn.net/helei001/article/details/18447001

    查询函数

    http://www.netlib.org/lapack/explore-html/de/ddd/lapacke_8h_source.html  

    c接口

    http://www.netlib.org/lapack/lapacke.html

    原理

    http://www.netlib.org/lapack/lug/node53.html

    #include <stdio.h>
    #include <lapacke.h>
     
    
    void print_matrix(double *src, int m, int n)
    {
       for(int i =0 ;i < m; ++i)
       {
          for(int j = 0; j < n;++j)
          {
             printf("%lf ", src[i * n + j] );
          }
          printf("
    " );
       }
       printf("
    " );
    }
    
    int main (int argc, const char * argv[])
    {
       double a[2*2] = {4.0,4.0,-3.0,3.0};
       int matrix_layout = LAPACK_ROW_MAJOR;
       char jobz = 'N';
       lapack_int info,m,n,lda,ldu,ldvt;
       m = 2;
       n = 2;
       lda = 2;
       ldu = 2;
       ldvt = 2;
       double s[4];
       double u[4];
       double vt[4];
       double superb[4];
       // lapack_int   LAPACKE_dgesvd (int matrix_layout, char jobu, char jobvt, 
       //  lapack_int m, lapack_int n, double *a, lapack_int lda, 
       //  double *s, double *u, lapack_int ldu, double *vt,
       //   lapack_int ldvt, double *superb)
       info =  LAPACKE_dgesvd( matrix_layout, 'A', 'A', m,
                                n, a, lda, s,
                                u, ldu, vt,
                                ldvt, superb);
    
       printf("%d
    ",info);
       print_matrix(s,2,2);
       print_matrix(u,2,2);
       print_matrix(vt,2,2);
       return 0;
    
    }

    $ gfortran main.c -llapacke -llapack -lrefblas && ./a.out
    0
    5.656854 4.242641
    0.000000 0.000000

    -1.000000 0.000000
    0.000000 1.000000

    -0.707107 -0.707107
    -0.707107 0.707107

  • 相关阅读:
    《软件工程》-第三章随笔
    《软件工程》-第二章随笔
    《软件工程》-第一章随笔
    软件工程——理论、方法与实践③
    软件工程——理论、方法与实践②
    软件工程——理论、方法与实践①
    爬虫之SCRAPY
    爬虫之 App 爬取
    flask bootstrap
    爬虫之协程,selenium
  • 原文地址:https://www.cnblogs.com/adong7639/p/9296435.html
Copyright © 2011-2022 走看看