jluna

Julia Wrapper for C++ with Focus on Safety, Elegance, and Ease of Use

https://github.com/clemapfel/jluna

Science Score: 41.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 7 committers (28.6%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.2%) to scientific vocabulary

Keywords

cpp cpp20 julia julia-language julia-wrapper julialang language-interface modern-cpp wrapper wrapper-api wrapper-library
Last synced: 4 months ago · JSON representation ·

Repository

Julia Wrapper for C++ with Focus on Safety, Elegance, and Ease of Use

Basic Info
Statistics
  • Stars: 258
  • Watchers: 4
  • Forks: 13
  • Open Issues: 12
  • Releases: 13
Topics
cpp cpp20 julia julia-language julia-wrapper julialang language-interface modern-cpp wrapper wrapper-api wrapper-library
Created almost 4 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

jluna: A modern Julia Wrapper for C++ (v1.0.0)

Julia is a beautiful language, it is well-designed, and well-documented. Julia's C-API is also well-designed, less beautiful, and much less... documented.
jluna aims to fully wrap the official Julia C-API, replacing it in projects with C++ as the host language, by making accessing Julia's unique strengths through C++ safe, hassle-free, and just as beautiful.


Table of Contents

  1. Introduction
  2. Features
  3. Showcase
  4. Documentation
  5. Dependencies
    4.1 Julia 1.7.0+
    4.2 Supported Compilers: g++, clang++, MSVC
    4.3 CMake 3.12+
  6. Installation
  7. License
  8. Authors

Anouncements

Note: jluna is currently not available for Apple aarch64 architectures, such as those used by the M1 or M2 MacBooks. See here for more information. jluna should still work for Windows 10, 11, Linux, and FreeBSD.


Features

  • expressive, generic syntax
  • create / call / assign Julia-side variables from C++
  • full exception forwarding, verbose error messages with complete stacktrace
  • std types & usertypes can be moved freely between Julia and C++
  • call arbitrary C++ functions from Julia
  • multidimensional, iterable array interface
  • provides a custom thread pool that, unlike the C-API, allows for concurrent interfacing with Julia
  • provides < 5% overhead functions, viable in performance-critical environments
  • complete manual, installation guide, benchmark analysis, inline documentation for IDEs - all written by a human
  • and more!

Showcase

(If you are looking for examples showing best-practice basic usage, please instead consult the manual)

Executing Julia Code

```cpp // execute multi-line Julia code Main.safe_eval(R"( f(x) = x^x^x vec = Int64[1, 2, 3, 4] )");

// call Julia functions with C++ values auto f = Main["f"]; std::cout << (Int64) f(3) << std::endl;

// mutate Julia-side values Main["vec"][2] = 999; Main.safe_eval("println(vec)");

// assign std objects to Julia variables Main["vec"] = std::vector{117, 118, 119, 120}; Main.safe_eval("println(vec)"); 2030534587 [1, 2, 999, 4] ['u', 'v', 'w', 'x'] ```


Array Interface

```cpp // array interface Array matrix = Main.safe_eval("return reshape([i for i in 1:(4*4)], 4, 4)");

// supports multi-dimensional indexing (and array comprehension, not shown here) matrix.at(0, 2) = 999; Main"println";

// even has generator expressions! auto generatedvector = Vector("(Char(i) for i in 97:104)"gen); Main"println"; [1 5 9 13; 2 6 10 14; 999 7 11 15; 4 8 12 16] ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] ```


Calling C++ Functions from Julia

```cpp Main.safeeval("cppfunction = () -> ()"); // forward declaration

// assign C++ lambda to Julia Function Main["cppfunction"] = asjulia_function( -> void { std::cout << "cpp prints: " << in << std::endl; } );

// call lambda, entirely Julia-side Main.safeeval(R"( cppfunction("whatjuliahandsit") )"); cpp prints: whatjuliahandsit

```

Documentation

Documentation, including a step-by-step installation and troubleshooting guide, tutorial, and index of all functions and objects in jluna is available here.


Dependencies

jluna aims to be as modern as is practical. It uses C++20 features extensively and aims to support the newest Julia version, rather than focusing on backwards compatibility.

For jluna you'll need: + Julia 1.7.0 (or newer) + cmake 3.12 (or newer) + C++ Compiler, one of - g++10 (or newer)
- clang++-12 (or newer)
- MSVC 19.34 (or newer)

On Unix, g++ or clang (installed using your package manager) are recommended.
On Windows, either use g++ provided by MinGW or MSVC provided by the Visual Studio C++ build tools.

In either case, make sure the compilers' version is as stated above, as jluna uses modern C++20 features extensively.


Installation & Troubleshooting

A step-by-step guide is available here. It is recommended that you follow this guide, instead of the highly abridged version below.

For IDEs: In many cases, simply opening the cloned jluna project in an IDE (such as VisualStudio, Atom, or CLion) will allow it to automatically set everything up for you. After initialization, simply run "install" from your build menu.

Command Line

Execute, in your bash console, in any public directory:

bash git clone https://github.com/Clemapfel/jluna cd jluna mkdir build cd build cmake .. -DJULIA_BINDIR=$(julia -e "println(Sys.BINDIR)") -DCMAKE_CXX_COMPILER=<C++ Compiler> -DCMAKE_INSTALL_PREFIX=<install directory> Where + <C++ Compiler> is the C++ compiler executable, e.g. g++, clang++, cl.exe, etc. + <install directory> is the desired install directory, omit this option to use the systems default directory

Then: make install ctest --verbose

Which will deposit the library to the specified system folder and run tests to make sure everything works.

Example Usage

For example, installing on a linux machine using g++:

git clone https://github.com/Clemapfel/jluna cd jluna mkdir build cd build cmake .. -DJULIA_BINDIR=$(julia -e "println(Sys.BINDIR)") -DCMAKE_CXX_COMPILER=/usr/bin/g++ sudo make install ctest --verbose Where ommitting DCMAKE_INSTALL_PATH makes CMake choose the default system path. sudo was necessary to write to that path.


Afterward, you can make jluna available to your library using

```cmake

inside your own CMakeLists.txt

findlibrary(jluna REQUIRED NAMES jluna PATHS ) targetlinklibraries( PRIVATE "${jluna}" "${}") `` Where +is the directory specified via-DCMAKEINSTALLPREFIX +is the Julia shared library (usually available in"${JULIABINDIR}/../lib") +` is the name of your library or executable

If any step of this does not work for you, please follow the installation guide instead.


Credits

jluna was designed and written by Clem Cords.

March 2022:

Donations

Jluna was created with no expectation of compensation and made available for free. Consider donating to reward past work and support the continued development of this library:


License & Citation

The current and all prior releases of jluna are supplied under MIT license, available here.

If you would like to cite jluna in your academic publication, you can copy the entry in CITATION.bib to your BibTeX bibliography, then use the \cite{jluna} command anywhere in your LaTeX source code.

Thank you for your consideration, C.

Owner

  • Name: Clem Cords
  • Login: Clemapfel
  • Kind: user
  • Location: Berlin, Germany

Software Engineer: Image Processing, GUI Frameworks | C++ / Julia / Lua

Citation (CITATION.bib)

 @misc{jluna,
  author = {C. Cords},
  title = {jluna: A modern Julia Wrapper for C++},
  url = {https://www.github.com/clemapfel/jluna},
  howpublished = {\url{https://www.clemens-cords.com/jluna}},
  year = {2022},
  note = {v1.0.0}
}

GitHub Events

Total
  • Issues event: 2
  • Watch event: 13
  • Issue comment event: 1
  • Fork event: 1
Last Year
  • Issues event: 2
  • Watch event: 13
  • Issue comment event: 1
  • Fork event: 1

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 635
  • Total Committers: 7
  • Avg Commits per committer: 90.714
  • Development Distribution Score (DDS): 0.044
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
clem c****s@a****m 607
friendlyanon f****n 15
Paul Frivold p****l@k****m 6
Páll Haraldsson P****n@g****m 4
melonedo 4****o 1
Grant Hecht g****c@b****u 1
Connor Fuhrman c****n@e****u 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 37
  • Total pull requests: 34
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 9 days
  • Total issue authors: 25
  • Total pull request authors: 9
  • Average comments per issue: 2.89
  • Average comments per pull request: 0.65
  • Merged pull requests: 30
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 4
  • Pull request authors: 1
  • Average comments per issue: 0.75
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • paulerikf (7)
  • Clemapfel (5)
  • lucwens (2)
  • liuyxpp (2)
  • martinlwtzky (1)
  • chrhck (1)
  • melonedo (1)
  • Taaitaaiger (1)
  • vchuravy (1)
  • jfferson (1)
  • eschnett (1)
  • riatankarsahu (1)
  • cdsousa (1)
  • kouchy (1)
  • robertu94 (1)
Pull Request Authors
  • Clemapfel (25)
  • PallHaraldsson (2)
  • paulerikf (2)
  • connorfuhrman (1)
  • robertu94 (1)
  • melonedo (1)
  • KaiErikNiermann (1)
  • friendlyanon (1)
  • GrantHecht (1)
Top Labels
Issue Labels
acknowledged (24) known issue (5) temporary fix available (5) crash (5) compiler error (3) will_be_accepted (3) cmake error (3) bug (3) high priority (2) help (2) low priority (2) windows (2) question (2) documentation (2) critique (1) duplicate (1) FAQ (1) apple (1) feature request (1)
Pull Request Labels
acknowledged (2) will_be_accepted (1)