zoukankan      html  css  js  c++  java
  • clapack在android上移植

    参考

    https://www.cnblogs.com/hrlnw/p/4128217.html

    1.从https://github.com/simonlynen/android_libs这个网址下载代码。

    如何在android上进行android库编译

    https://blog.csdn.net/h3c4lenovo/article/details/10364679

    1 设置ndk环境
    export ANDROID_NDK_HOME=/DATA/Android/Ndk/android-ndk-r13b
    export PATH=$PATH:$ANDROID_NDK_HOME
    #ANDROID_NDK_HOME=/DATA/share/software/android-ndk-r16

    2 make 与gcc确保无问题
    make -v
    gcc -v

    3 写好jni文件

    4 编译ndk-build

    5 android工程调用


    #如果同时编译32和64未版本,或会导致32位的库打包到64位中,需要单独编译,
    #./obj/local/arm64-v8a/libtestlapack.so: error adding symbols: File in wrong format

    导致32位的库打包到64位中,
    [arm64-v8a] Prebuilt : libtestlapack.so <= jni/lapack/lib/armeabi-v7a/
    [arm64-v8a] Install : libtestlapack.so => libs/arm64-v8a/libtestlapack.so
    [arm64-v8a] Compile++ : mtcnn_facedetect <= similaritytrans.cpp

    #include <stdio.h>
    #include <string.h>
    #include <jni.h>
    #include <complex>
    #include <sstream>
    #include <string>
    #include <android/log.h>
    #define TAG "log"
    #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,TAG ,__VA_ARGS__)
    
    
    // #ifndef JNIEXPORT
    // #define JNIEXPORT
    // #endif
    
    // #ifndef JNICALL
    // #define JNICALL
    // #endif
    
    static long dgesvd(char *jobu, char *jobvt, long *m, long *n, 
        double *a, long *lda, double *s, double *u, long *
        ldu, double *vt, long *ldvt, double *work, long *lwork)
    {
        // int dgesvd_(char *jobu, char *jobvt, integer *m, integer *n, 
        // doublereal *a, integer *lda, doublereal *s, doublereal *u, integer *
        // ldu, doublereal *vt, integer *ldvt, doublereal *work, integer *lwork, 
        // integer *info)
    
        extern int dgesvd_(char *jobu, char *jobvt, long *m, long *n, 
        double *a, long *lda, double *s, double *u, long *
        ldu, double *vt, long *ldvt, double *work, long *lwork, 
        long *info);
    
        long info;
        dgesvd_("A", "A", m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, &info);
        return info;
    }
    
    
    #define mymax(a,b) (a) > (b) ? (a) : (b)
    #define mymin(a,b) (a) < (b) ? (a) : (b)
    
    
    void transposeMatrix(double *A, int row, int col)
    {
        for(int i =0; i < row; ++i)
        {
            for (int j = i; j < col; ++j)
            {
                double temp = A[i * col + j];
                A[i * col + j] = A[j * col + i];
                A[j *col + i] = temp;
            }
        }
    }
    
    int GetLapackSVD(double *a, double *u, double *s, double *vt)
    {
       //double a[2*2] = {4 , 4 , -3 ,  3};
       //这个函数,这里要特别注意储存方式(column major)!!
       transposeMatrix(a,2,2);
       long m,n;
       long lda,ldu,ldvt,lwork;
       m = 2;
       n = 2;
       lda = 2;
       ldu = 2;
       ldvt = 2;
       //https://blog.csdn.net/versuna/article/details/8246377
       lwork = 10;//mymax(3*mymin(m, n)+mymax(m, n), 5*mymin(m,n));
       LOGD("#lwork = %d", lwork);
       double work[1*lwork];
       char jobu = 'A';
       char jobvt = 'A';
       dgesvd(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork);
       return 0;
    }
    
    int main()
    {
        double a[4];
        double u[4];
        double s[2];
        double vt[4];
    }

    在贴一段内部代码

    /*****************************************************************************
       Copyright (c) 2014, Intel Corp.
       All rights reserved.
     
       Redistribution and use in source and binary forms, with or without
       modification, are permitted provided that the following conditions are met:
     
         * Redistributions of source code must retain the above copyright notice,
           this list of conditions and the following disclaimer.
         * Redistributions in binary form must reproduce the above copyright
           notice, this list of conditions and the following disclaimer in the
           documentation and/or other materials provided with the distribution.
         * Neither the name of Intel Corporation nor the names of its contributors
           may be used to endorse or promote products derived from this software
           without specific prior written permission.
     
       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
       AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
       LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
       THE POSSIBILITY OF SUCH DAMAGE.
     *****************************************************************************
     * Contents: Native high-level C interface to LAPACK function dgesdd
     * Author: Intel Corporation
     * Generated November 2015
     *****************************************************************************/
     
     #include "lapacke_utils.h"
     
     lapack_int LAPACKE_dgesdd( int matrix_layout, char jobz, lapack_int m,
                                lapack_int n, double* a, lapack_int lda, double* s,
                                double* u, lapack_int ldu, double* vt,
                                lapack_int ldvt )
     {
         lapack_int info = 0;
         lapack_int lwork = -1;
         lapack_int* iwork = NULL;
         double* work = NULL;
         double work_query;
         if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) {
             LAPACKE_xerbla( "LAPACKE_dgesdd", -1 );
             return -1;
         }
     #ifndef LAPACK_DISABLE_NAN_CHECK
         if( LAPACKE_get_nancheck() ) {
             /* Optionally check input matrices for NaNs */
             if( LAPACKE_dge_nancheck( matrix_layout, m, n, a, lda ) ) {
                 return -5;
             }
         }
     #endif
         /* Allocate memory for working array(s) */
         iwork = (lapack_int*)
             LAPACKE_malloc( sizeof(lapack_int) * MAX(1,8*MIN(m,n)) );
         if( iwork == NULL ) {
             info = LAPACK_WORK_MEMORY_ERROR;
             goto exit_level_0;
         }
         /* Query optimal working array(s) size */
         info = LAPACKE_dgesdd_work( matrix_layout, jobz, m, n, a, lda, s, u, ldu, vt,
                                     ldvt, &work_query, lwork, iwork );
         if( info != 0 ) {
             goto exit_level_1;
         }
         lwork = (lapack_int)work_query;
         /* Allocate memory for work arrays */
         work = (double*)LAPACKE_malloc( sizeof(double) * lwork );
         if( work == NULL ) {
             info = LAPACK_WORK_MEMORY_ERROR;
             goto exit_level_1;
         }
         /* Call middle-level interface */
         info = LAPACKE_dgesdd_work( matrix_layout, jobz, m, n, a, lda, s, u, ldu, vt,
                                     ldvt, work, lwork, iwork );
         /* Release memory and exit */
         LAPACKE_free( work );
     exit_level_1:
         LAPACKE_free( iwork );
     exit_level_0:
         if( info == LAPACK_WORK_MEMORY_ERROR ) {
             LAPACKE_xerbla( "LAPACKE_dgesdd", info );
         }
         return info;
     }
  • 相关阅读:
    学习C#的一些笔记
    SQL高级应用
    SQL SERVER 视图
    ES5 Study
    面试官技巧
    WebServicexml操作
    用JS和HTML写自己的文本编辑器
    解决Win7 x64 VS2010调试网站出现 vs2010 未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
    Microsoft.Practices.Unity实现代码依赖注入、XML依赖注入和AOP切面编程
    无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方法
  • 原文地址:https://www.cnblogs.com/adong7639/p/9316371.html
Copyright © 2011-2022 走看看