{"id":15358952,"url":"https://github.com/rurlus/carma","last_synced_at":"2025-10-13T10:06:13.912Z","repository":{"id":39900204,"uuid":"235867993","full_name":"RUrlus/carma","owner":"RUrlus","description":"Converters between Armadillo matrices (C++) and Numpy arrays using Pybind11","archived":false,"fork":false,"pushed_at":"2025-10-01T07:59:47.000Z","size":2036,"stargazers_count":101,"open_issues_count":4,"forks_count":27,"subscribers_count":1,"default_branch":"stable","last_synced_at":"2025-10-13T10:06:12.508Z","etag":null,"topics":["armadillo","c-plus-plus","carma","cpp","numpy","pybind11","python3","rcpparmadillo"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RUrlus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-01-23T19:17:19.000Z","updated_at":"2025-10-06T19:18:37.000Z","dependencies_parsed_at":"2023-12-16T16:24:08.051Z","dependency_job_id":"e7f8b90a-e7e3-48e6-8ada-295847d5a924","html_url":"https://github.com/RUrlus/carma","commit_stats":{"total_commits":395,"total_committers":9,"mean_commits":"43.888888888888886","dds":0.6632911392405063,"last_synced_commit":"3bb34bef9632bab16ae052ad1d753ec5cb286f41"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/RUrlus/carma","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RUrlus%2Fcarma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RUrlus%2Fcarma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RUrlus%2Fcarma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RUrlus%2Fcarma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RUrlus","download_url":"https://codeload.github.com/RUrlus/carma/tar.gz/refs/heads/stable","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RUrlus%2Fcarma/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014668,"owners_count":26085554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["armadillo","c-plus-plus","carma","cpp","numpy","pybind11","python3","rcpparmadillo"],"created_at":"2024-10-01T12:43:25.814Z","updated_at":"2025-10-13T10:06:13.882Z","avatar_url":"https://github.com/RUrlus.png","language":"C++","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"docs/source/carma_logo_small.png\" alt=\"carma_logo\"/\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003e\n  A C++ header only library providing conversions between Numpy arrays and Armadillo matrices.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  |\n  \u003ca href=\"https://carma.readthedocs.io/en/latest/\"\u003eDocumentation\u003c/a\u003e\n  |\n\u003c/p\u003e\n\n[![Linux Build Status](https://github.com/RUrlus/carma/actions/workflows/linux.yml/badge.svg?branch=stable)](https://github.com/RUrlus/carma/actions/workflows/linux.yml)\n[![MacOS Build Status](https://github.com/RUrlus/carma/actions/workflows/macos.yml/badge.svg?branch=stable)](https://github.com/RUrlus/carma/actions/workflows/macos.yml)\n[![Windows Build Status](https://github.com/RUrlus/carma/actions/workflows/windows.yml/badge.svg?branch=stable)](https://github.com/RUrlus/carma/actions/workflows/windows.yml)\n[![Coverage Status](https://coveralls.io/repos/github/RUrlus/carma/badge.svg?branch=stable)](https://coveralls.io/github/RUrlus/carma?branch=stable)\n[![Documentation Status](https://readthedocs.org/projects/carma/badge/?version=latest)](https://carma.readthedocs.io/en/latest/?badge=latest)\n[![License](https://img.shields.io/github/license/RUrlus/carma)](https://github.com/RUrlus/carma/blob/stable/LICENSE)\n[![Release](https://img.shields.io/github/v/release/rurlus/carma)](https://github.com/RUrlus/carma/releases)\n[![DOI](https://zenodo.org/badge/235867993.svg)](https://zenodo.org/badge/latestdoi/235867993)\n\n\n## Introduction\n\nCARMA provides fast bidirectional conversions between [Numpy](https://numpy.org) arrays and [Armadillo](http://arma.sourceforge.net/docs.html) matrices, vectors and cubes, much like [RcppArmadillo](https://github.com/RcppCore/RcppArmadillo) does for R and Armadillo.\n\nThe library extends the impressive [pybind11](https://pybind11.readthedocs.io/en/stable/intro.html) library with support for Armadillo.\nFor details on Pybind11 and Armadillo refer to their respective documentation [1](https://pybind11.readthedocs.io/en/stable/intro.html), [2](http://arma.sourceforge.net/docs.html).\n\n## Installation\nCARMA is a header only library that relies on two other header only libraries, Armadillo and Pybind11.\nIt can be integrated in a CMake build using `ADD_SUBDIRECTORY(\u003cpath_to_carma\u003e)` or installation which provides an interface library target `carma::carma` that has been linked with Python, Numpy, Pybind11 and Armadillo. See [build configuration](https://carma.readthedocs.io/en/stable/building.html) for details.\n\nIt can be installed using:\n```bash\nmkdir build\ncd build\n# optionally with -DCMAKE_INSTALL_PREFIX:PATH=\u003cpath/to/desired/location\u003e\ncmake -DCARMA_INSTALL_LIB=ON ..\ncmake --build . --config Release --target install\n```\n\nYou can than include it in a project using:\n\n```cmake\nFIND_PACKAGE(carma CONFIG REQUIRED)\nTARGET_LINK_LIBRARIES(\u003cyour_target\u003e PRIVATE carma::carma)\n```\n\n### CMake subdirectory\n\nAlternatively you can forgo installing CARMA and directly use it as CMake subdirectory.\nFor Pybind11 and or Armadillo we create target(s) based on user settable version, see [build configuration](https://carma.readthedocs.io/en/stable/building.html), when they are not defined.\n\nTo link with CARMA:\n```cmake\nADD_SUBDIRECTORY(extern/carma)\nTARGET_LINK_LIBRARIES(\u003cyour_target\u003e PRIVATE carma::carma)\n```\nCARMA and Armadillo can then be included using:\n```C++\n#include \u003ccarma\u003e\n#include \u003carmadillo\u003e\n```\n\nCARMA provides a number of configurations that can be set in the `carma_config.cmake` file at the root of the directory or passed to CMake, see [Configuration](https://carma.readthedocs.io/en/stable/configuration.html) and [Build configuration](https://carma.readthedocs.io/en/stable/building.html) documentation sections for details.\n\n## Requirements\n\nNumpy v2.* is supported by CARMA \u003e= v0.8.0 which requires a compiler with support for C++14 and supports:\n\n* Python 3.8 -- 3.12\n* Numpy \u003e= 1.14\n* **Pybind11 \u003e= v2.12.0**\n* Armadillo \u003e= 10.5.2\n\nCARMA \u003c= v0.7 requires a compiler with support for C++14 and supports:\n\n* Python 3.8 -- 3.12\n* **Numpy \u003e= 1.14 \u003c 2.0**\n* **Pybind11 \u003e= v2.6.0 \u003c v2.12.0**\n* Armadillo \u003e= 10.5.2\n\nCARMA makes use of Armadillo's `ARMA_ALIEN_MEM_ALLOC` and `ARMA_ALIEN_MEM_FREE` functionality introduced in version 10.5.2 to use Numpy's (de)allocator.\n\n### Considerations\n\nIn order to achieve fast conversions the default behaviour is avoid copying both from and to Numpy whenever possible and reasonable.\nThis allows very low overhead conversions but it impacts memory safety and requires user vigilance.\n\nIf you intend to return the memory of the input array back as another array, you must make sure to either copy or steal the memory on the conversion in or copy the memory out.\nIf you don't the memory will be aliased by the two Numpy arrays and bad things will happen.\n\nA second consideration is memory layout. Armadillo is optimised for column-major (Fortran order) memory whereas Numpy defaults to row-major (C order).\nThe default behaviour is to automatically convert, read copy, C-order arrays to F-order arrays upon conversion to Armadillo. Users should note that the library will not convert back to C-order when returning.\n\nFor details see the documentation section [Memory Management](https://carma.readthedocs.io/en/latest/memory_management.html).\n\n### Example\n\nOn a high level CARMA provides two ways to work Numpy arrays in Armadillo:\nAutomatic conversion saves a bit on code but provides less flexibility with\nregards to when to copy and when not.\nManual conversion should be used when you need fine grained control.\n\nCombining the two; we use automatic conversion on the conversion in and manual when\ncreating the tuple for the way out.\n\n```cpp\n\n#include \u003ccarma\u003e\n#include \u003carmadillo\u003e\n#include \u003cpybind11/pybind11.h\u003e\n#include \u003cpybind11/numpy.h\u003e\n#include \u003cpybind11/pytypes.h\u003e\n\nnamespace py = pybind11;\n\npy::tuple ols(arma::mat\u0026 X, arma::colvec\u0026 y) {\n    // We borrow the data underlying the numpy arrays\n    int n = X.n_rows, k = X.n_cols;\n\n    arma::colvec coeffs = arma::solve(X, y);\n    arma::colvec resid = y - X * coeffs;\n\n    double sig2 = arma::as_scalar(arma::trans(resid) * resid / (n-k));\n    arma::colvec std_errs = arma::sqrt(sig2 * arma::diagvec( arma::inv(arma::trans(X)*X)) );\n\n    // We take ownership of the memory from the armadillo objects and\n    // return to python as a tuple containing two Numpy arrays.\n    return py::make_tuple(\n        carma::col_to_arr(coeffs),\n        carma::col_to_arr(std_errs)\n    );\n}\n\n// adapted from https://gallery.rcpp.org/articles/fast-linear-model-with-armadillo/\n```\n\nWhich can be called using:\n\n```python\ny = np.linspace(1, 100, num=100) + np.random.normal(0, 0.5, 100)\nX = np.hstack((np.ones(100)[:, None], np.arange(1, 101)[:, None]))\ncoeff, std_err = carma.ols(X, y)\n```\n\nThe repository contains tests, examples and CMake build instructions that can be used as an reference.\n\n### About\n\nThis project was created by Ralph Urlus. Significant improvements to the project have been contributed by [Pascal H.](https://github.com/hpwxf)\n\n### License\n\nCARMA is provided under a Apache 2.0 license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frurlus%2Fcarma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frurlus%2Fcarma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frurlus%2Fcarma/lists"}