博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
clapack在android上移植
阅读量:5758 次
发布时间:2019-06-18

本文共 6495 字,大约阅读时间需要 21 分钟。

参考

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

如何在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 
#include
#include
#include
#include
#include
#include
#define TAG "log"#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,TAG ,__VA_ARGS__)// #ifndef JNIEXPORT// #define JNIEXPORT// #endif// #ifndef JNICALL// #define JNICALL// #endifstatic 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; }

 

你可能感兴趣的文章
FBX SDK在vs 2010下面的配置
查看>>
python3与python2的部分区别
查看>>
【BGP的基本配置】
查看>>
javascript之闭包深入理解(二)
查看>>
南京邮电大学java程序设计作业在线编程第五次作业
查看>>
[工具类]泛型集合转换为DataTable
查看>>
[MySql]锁表与解锁
查看>>
React:JSX
查看>>
python全栈开发笔记---------数据类型-----集合set
查看>>
uva-565-枚举
查看>>
自动文档摘要评价方法:Edmundson,ROUGE
查看>>
题解[ZJOI2007]矩阵游戏
查看>>
10个顶级Web移动开发JavaScript框架推荐
查看>>
<br/>属性
查看>>
Python中__get__ ,__getattr__ ,__getattribute__用法与区别?
查看>>
树的前、中、后序遍历
查看>>
org.apache.hadoop.hdfs.server.datanode.DataNode: Exception in receiveBlock for block
查看>>
平行宇宙和確定世界——讀阿諾爾德「常微分方程」前幾頁的感悟
查看>>
在Ubuntu上设置gmail邮件通知
查看>>
陶哲轩实分析 定义 7.2.1(形式无限级数) 的一点注记
查看>>