Matrix multiplication in c++ in Android Studio

374 Views Asked by At

I'm trying to do matrix multiplication in Android Studio and want to use c++ for the speed benefit. I found the library xtensor and think that it will be useful but I cant get working. I tried putting the header files into the cpp folder but then they dont have access to the base library dependencies and I've been researching for hours now but I couldn't find out exactly what to write in the CMakeLists.txt and how libraries are actually meant to be installed. I'm sorry if this is really obvious but I can't really wrap my head around it.

How can I install the xtensor library in android studio or is there some other way? I wanted to avoid using for loops for the calculation but if there's no other possibility I guess I have to..

1

There are 1 best solutions below

0
On BEST ANSWER

How can I install the xtensor library in android studio or is there some other way? I wanted to avoid using for loops for the calculation but if there's no other possibility I guess I have to..

xtensor project is based on cmake which is supported by AndroidStudio(gradle) so you can easily use it for NDK build.

It takes just a few steps to integrate xtensor into your project (without installing it into the system):

  1. Fetch xtensor and xtl (xtensor depends on xtl) projects and add them to your root cmake, for example:
add_subdirectory(external/xtl)
add_subdirectory(external/xtensor)
  1. Create Findxtl.cmake to support find_package(xtl). It's enough only to set xtl_FOUND:
set(xtl_FOUND TRUE)
  1. And the last step is to link your native library to the xtensor interface library:
add_library(native-lib SHARED native-lib.cpp)
target_link_libraries(native-lib xtensor)

Here an example how it can be done for Android Studio Native C++ Template Project based on "Initialize a 2-D array and compute the sum of one of its rows and a 1-D array" example from xtensor/basic-usage.