carma | Armadillo matrices and Numpy arrays using Pybind11 | Data Manipulation library
kandi X-RAY | carma Summary
kandi X-RAY | carma Summary
CARMA provides fast bidirectional conversions between Numpy arrays and Armadillo matrices, vectors and cubes, much like RcppArmadillo does for R and Armadillo. The library extends the impressive pybind11 library with support for Armadillo. For details on Pybind11 and Armadillo refer to their respective documentation 1, 2.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of carma
carma Key Features
carma Examples and Code Snippets
#include
#include
#include
#include
#include
namespace py = pybind11;
py::tuple ols(arma::mat& X, arma::colvec& y) {
// We borrow the data underlying the numpy arrays
int n = X.n_rows, k = X.n_cols;
arma::colvec coeffs =
mkdir build
cd build
# optionally with -DCMAKE_INSTALL_PREFIX:PATH=
cmake -DCARMA_INSTALL_LIB=ON ..
cmake --build . --config Release --target install
FIND_PACKAGE(carma CONFIG REQUIRED)
TARGET_LINK_LIBRARIES( PRIVATE carma::carma)
ADD_SUBDIRECTORY(extern/carma)
TARGET_LINK_LIBRARIES( PRIVATE carma::carma)
#include
#include
Community Discussions
Trending Discussions on carma
QUESTION
I've worked on this for a couple weeks and can't make a reproducible example outside my codebase. That's why I need help! I'm not sure if this is a problem with pybind11 or Armadillo. It's not a problem with Carma since it happens in situations with no conversion going on.
EDIT: This actually does appear to be a bug in Carma and my MRE is working.
I've been trying to boil it down to an MRE and have been unsuccessful. I will explain what I know here, but since this isn't enough to reproduce the bug, what I need most are some ideas as to where to look. This is basically a very hard-to-reproduce memory corruption error (heap corruption, Windows fatal exception: code 0xc0000374
). It seems to happen when I have a matrix A, not initialized, and assign a matrix to it large enough that Armadillo acquires memory. The crash happens when that memory is released.
I'm on Windows 10, using Armadillo 10.6.2 and pybind11 v2.7.1, compiling using Clang 11.
...ANSWER
Answered 2021-Sep-20 at 21:59Credit to the carma developer, @RUrlus, for the answer:
The problem is due to the bindings module, linked to carma, being linked to a library that hasn't been linked to carma. The external library (mc in the MRE) was allocating memory using the standard malloc
while pybind11 was using Carma's free
on destruction. The mismatch was causing the crash on Windows.
Perhaps in the future there could be a more elegant solution, but for now the workaround is to link external libraries to carma at compile-time, e.g., target_link_libraries(mc PUBLIC armadillo carma)
even if that external library doesn't include or use Carma in any obvious way.
QUESTION
I have a simple example of trying to use carma and pybind11 to go to and from armadillo matrices and numpy arrays based off of this example. Without the printarma() function, the code works i.e. with just wrapping using pybind11 the code compiles and I can run it in python. The problem here seems to be with carma. Here is the code:
...ANSWER
Answered 2020-Sep-26 at 15:00At the end it was two things: the virtual function in the Base class needed to add py::array_t & arr
to it and the semicolon at the end at .def
needed to be deleted along with the m
before .def
. This code compiles and works in python:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install carma
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page