diff --git a/thirdparty/liblinear/HPKBUILD b/thirdparty/liblinear/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..7203f761acf3fd9171fb8bfb210999e91148b4a1 --- /dev/null +++ b/thirdparty/liblinear/HPKBUILD @@ -0,0 +1,64 @@ +# Contributor: 城meto +# Maintainer: 城meto + +pkgname=liblinear +pkgver=v246 +pkgrel=0 +pkgdesc="LIBLINEAR is a simple package for solving large-scale regularized linear classification, regression and outlier detection." +url="https://www.csie.ntu.edu.tw" +archs=("armeabi-v7a" "arm64-v8a") +license=("BSD-3-Clause") +depends=() +makedepends=() +source="https://codeload.github.com/cjlin1/$pkgname/tar.gz/refs/tags/$pkgver" +buildtools="make" + +autounpack=true +downloadpackage=true + +builddir=$pkgname-${pkgver:1} +packagename=$pkgname-$pkgver.tar.gz + +source envset.sh + +prepare() { + cp -rf $builddir $builddir-$ARCH-build/ + if [ $ARCH == "armeabi-v7a" ];then + setarm32ENV + elif [ $ARCH == "arm64-v8a" ];then + setarm64ENV + else + echo "$ARCH not support" + return -1 + fi +} + +build() { + make -j4 -C $builddir-$ARCH-build VERBOSE=1 >> $builddir-$ARCH-build/build.log 2>&1 + ret=$? + return $ret +} + +package() { + # Makefile 没有提供install,只能copy + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/include + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib + mkdir -p $LYCIUM_ROOT/usr/$pkgname/$ARCH/bin + find $builddir-$ARCH-build -name '*.a' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/lib/ \; + find ./$builddir-$ARCH-build -name '*.h' -exec cp -af {} $LYCIUM_ROOT/usr/$pkgname/$ARCH/include/ \; + cp -af $builddir-$ARCH-build/predict $LYCIUM_ROOT/usr/$pkgname/$ARCH/bin + cp -af $builddir-$ARCH-build/train $LYCIUM_ROOT/usr/$pkgname/$ARCH/bin +} + +check() { + echo "The test must be on an OpenHarmony device!" + # real test + # train heart_scale 生成heart_scale.model + # predict heart_scale.t heart_scale.model output 查看预测精度 +} + +# 清理环境 +cleanbuild(){ + rm -rf $builddir-armeabi-v7a-build $builddir-arm64-v8a-build + rm -rf $builddir # $packagename +} \ No newline at end of file diff --git a/thirdparty/liblinear/HPKCHECK b/thirdparty/liblinear/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..cb2de310edfc3c18dc6870454513cb81e8aa0fec --- /dev/null +++ b/thirdparty/liblinear/HPKCHECK @@ -0,0 +1,59 @@ +# Contributor: 城meto +# Maintainer: 城meto + +source HPKBUILD > /dev/null 2>&1 # 导入HPKBUILD文件 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log +total_count=0 +uint_count=0 # 用于统计测试用例成功执行个数 + +uint_test() { + ret=0 + cd ${builddir}-${ARCH}-build + ((total_count++)) + # 测试步骤,执行训练、预期结果 + echo "---------------------- Test $total_count: type$1 -- $2 ----------------------" >> ${logfile} 2>&1 + ./train -s $1 heart_scale >> ${logfile} 2>&1 + cp heart_scale heart_scale.t + ./predict heart_scale.t heart_scale.model output >> ${logfile} 2>&1 + ret=$? + + # 清空还原 + rm heart_scale.t + rm heart_scale.model + + # 输出结果 + if [ $ret -ne 0 ];then + echo "---------------------- FAIL ----------------------" >> ${logfile} 2>&1 + else + echo "---------------------- SUCCESS ----------------------" >> ${logfile} 2>&1 + ((uint_count++)) + fi + cd $OLDPWD + return $ret +} + +# 在OH环境执行测试的接口 +openharmonycheck() { + uint_count=0 + + echo "Unit Test Begin: " > ${logfile} 2>&1 + uint_test 0 "L2-regularized logistic regression (primal)" + uint_test 1 "L2-regularized L2-loss support vector classification (dual)" + uint_test 2 "L2-regularized L2-loss support vector classification (primal)" + uint_test 3 "L2-regularized L1-loss support vector classification (dual)" + uint_test 4 "support vector classification by Crammer and Singer" + uint_test 5 "L1-regularized L2-loss support vector classification" + uint_test 6 "L1-regularized logistic regression" + uint_test 7 "L2-regularized logistic regression (dual)" + uint_test 11 "L2-regularized L2-loss support vector regression (primal)" + uint_test 12 "L2-regularized L2-loss support vector regression (dual)" + uint_test 13 "L2-regularized L1-loss support vector regression (dual)" + uint_test 21 "one-class support vector machine (dual)" + + echo "Unit Test End: Success $uint_count, Total: $total_count" >> ${logfile} 2>&1 + if [ $uint_count -ne $total_count ];then + return -1 + else + return 0 + fi +} diff --git a/thirdparty/liblinear/OAT.xml b/thirdparty/liblinear/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..96937ea08644b79312d0ced7c0b3eb1e845108ee --- /dev/null +++ b/thirdparty/liblinear/OAT.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/thirdparty/liblinear/README.OpenSource b/thirdparty/liblinear/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..1440ddc82ed69c9858b9765fb1b05c42ee70d94b --- /dev/null +++ b/thirdparty/liblinear/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "liblinear", + "License": "BSD-3-Clause", + "License File": "COPYRIGHT", + "Version Number": "2.4.6", + "Owner": "myxuan475@126.com", + "Upstream URL": "https://codeload.github.com/cjlin1/liblinear/tar.gz/refs/tags/v246", + "Description": "LIBLINEAR is a simple package for solving large-scale regularized linear classification, regression and outlier detection." + } +] \ No newline at end of file diff --git a/thirdparty/liblinear/README_zh.md b/thirdparty/liblinear/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..1ee4d16f8724758cbf29013813a1c7223c1b1913 --- /dev/null +++ b/thirdparty/liblinear/README_zh.md @@ -0,0 +1,11 @@ +# liblinear三方库说明 +## 功能简介 +liblinear 是一个用于解决线性规划、回归算法和异常检测的库。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:2.4.6 +- 当前适配的功能:提供线性规划、SVM、异常检测等。 + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) \ No newline at end of file diff --git a/thirdparty/liblinear/SHA512SUM b/thirdparty/liblinear/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..e620229519851d756680e82a6ba174495fcd736d --- /dev/null +++ b/thirdparty/liblinear/SHA512SUM @@ -0,0 +1 @@ +f75cad393477eff7d2ebbc0927be37fd48cd4b08f5cc4196b3605b4822d4dda5edd65a2c190034fa349bc359b4da0bc90b6e507f57e7842fd7a048f88278654f liblinear-v246.tar.gz diff --git a/thirdparty/liblinear/docs/hap_integrate.md b/thirdparty/liblinear/docs/hap_integrate.md new file mode 100755 index 0000000000000000000000000000000000000000..adcb7311421cf070ef2c77509be71951cc231e6f --- /dev/null +++ b/thirdparty/liblinear/docs/hap_integrate.md @@ -0,0 +1,89 @@ +# liblinear集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 4.0.8.1 (API Version 10 Release)](https://gitee.com/link?target=http%3A%2F%2Fdownload.ci.openharmony.cn%2Fversion%2FMaster_Version%2FOpenHarmony_4.0.8.1%2F20230608_091058%2Fversion-Master_Version-OpenHarmony_4.0.8.1-20230608_091058-ohos-sdk-public.tar.gz) +- [DevEco Studio 3.1 Release](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2F81%2Fv3%2FtgRUB84wR72nTfE8Ir_xMw%2Fdevecostudio-windows-3.1.0.501.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230621T074329Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D22F6787DF6093ECB4D4E08F9379B114280E1F65DA710599E48EA38CB24F3DBF2) +- [准备三方库构建环境](../../../lycium/README.md#1编译环境准备) +- [准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/liblinear #三方库的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + +- 进入lycium 目录编译 + + 本仓库没有依赖库,可直接编译。 + ```shell + cd lycium + ./build.sh liblinear + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成64位三方库 + + ```shell + liblinear/arm64-v8a liblinear/armeabi-v7a + ``` +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,该库只有静态库,如下图所示: + + ![thirdparty_install_dir](pic/liblinear_js.png) + + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/liblinear/${OHOS_ARCH}/lib/blas.a) + + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/liblinear/${OHOS_ARCH}/include) + + #该库没有动态库,不需考虑打包问题 + ``` + 修改IDE的entry/build-profile.json5 文件,增加编译架构过滤:"abiFilters": ["arm64-v8a", "armeabi-v7a"], 如下图所示: + + ![liblinear_build](pic/liblinear_build.png) + + 然后,执行编译运行. + +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +进入到构建目录,执行如下命令ctest(arm64-v8a-build为构建64位的目录, armeabi-v7a-build为构建32位的目录) + +![liblinear_test](pic/liblinear_test.png) + +## 参考资料 + +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/liblinear/docs/pic/liblinear_build.png b/thirdparty/liblinear/docs/pic/liblinear_build.png new file mode 100755 index 0000000000000000000000000000000000000000..3a44fbf78c725c6d94bc99434b2eca64cf72b8a9 Binary files /dev/null and b/thirdparty/liblinear/docs/pic/liblinear_build.png differ diff --git a/thirdparty/liblinear/docs/pic/liblinear_js.png b/thirdparty/liblinear/docs/pic/liblinear_js.png new file mode 100755 index 0000000000000000000000000000000000000000..a1ee99b249481ed574c94e018d7e9c75348a85ff Binary files /dev/null and b/thirdparty/liblinear/docs/pic/liblinear_js.png differ diff --git a/thirdparty/liblinear/docs/pic/liblinear_test.png b/thirdparty/liblinear/docs/pic/liblinear_test.png new file mode 100755 index 0000000000000000000000000000000000000000..d0cc8e8b86a7854bc02baf4d795be136843d66cc Binary files /dev/null and b/thirdparty/liblinear/docs/pic/liblinear_test.png differ