标签 math 下的文章

安装

安装 xtensor 之前需要先安装依赖 xtl, https://github.com/xtensor-stack/xtl https://github.com/xtensor-stack/xtensor

进入 xtl 源码目录运行命令:

cmake -DCMAKE_INSTALL_PREFIX=/usr
sudo make install

进入 xtensor 源码目录运行命令:

cmake -DCMAKE_INSTALL_PREFIX=/usr
sudo make install

简单使用

工程目录下创建 compile.sh

#!/bin/bash 

mkdir -p build
pushd build
cmake ..
make
make install
popd

相应的 CMakeLists 文件中添加:

set(CMAKE_CXX_STANDARD 14)

如果工程还涉及到 opencv,那么需要添加

    find_package(OpenCV REQUIRED)
    include_directories(${OpenCV_INCLUDE_DIRS})
    link_directories(${OpenCV_LIBRARY_DIRS})

    target_link_libraries(${name} ${OpenCV_LIBS})

如果工程中用到 cjsonobject,需要添加

    include_directories("${PROJECT_SOURCE_DIR}/CJsonObject")

如果工程运行的时候,需要某些库文件,那么可以新建一个 run.sh,里面可以如下添加库,然后运行:

#!/bin/bash

export LD_LIBRARY_PATH=./tengine/linux-arm64-v8a/lib/

./build/install/bin/classification 

最近需要把一些 python 版本的程序转为 c++ 的程序。 python 中使用了很多 numpy 的调用,于是就再找 c++ 的实现。 找了一圈下来,发现最适合的可能就是 xtensor。 github: https://github.com/xtensor-stack/xtensor 使用: https://xtensor.readthedocs.io/en/latest/numpy.html

其他可选:

    The GNU Scientific Library is a GPL software written in C. Thus, it has a C-like allocation and way of programming (pointers, etc.). With the GSLwrap, you can have a C++ way of programming, while still using the GSL. GSL has a BLAS implementation, but you can use ATLAS instead of the default CBLAS, if you want even more performances.

    The boost/uBLAS library is a BSL library, written in C++ and distributed as a boost package. It is a C++-way of implementing the BLAS standard. uBLAS comes with a few linear algebra functions, and there is an experimental binding to ATLAS.

    eigen is a linear algebra library written in C++, distributed under the MPL2 license (starting from version 3.1.1) or LGPL3/GPL2 (older versions). It's a C++ way of programming, but more integrated than the two others (more algorithms and data structures are available). Eigen claim to be faster than the BLAS implementations above, while not following the de-facto standard BLAS API. Eigen does not seem to put a lot of effort on parallel implementation.

    Armadillo is LGPL3 library for C++. It has binding for LAPACK (the library used by numpy). It uses recursive templates and template meta-programming, which is a good point (I don't know if other libraries are doing it also?).

    xtensor is a C++ library that is BSD licensed. It offers A C++ API very similar to that of NumPy. See https://xtensor.readthedocs.io/en/latest/numpy.html for a cheat sheet.

参考: https://stackoverflow.com/questions/11169418/numpy-style-arrays-for-c https://github.com/dpilger26/NumCpp