- Install Julia version 1.5.3 or above
julia
executable must be in your path.- By-default,
nimjl
will use Julia'sSys.BINDIR
parent directory as the installation folder of Julia. - If you want
nimjl
to use a specific Julia installation, set the environment variableJULIA_PATH
to the root of the installation folder.
- By-default,
- Run
nimble install
ornimble develop
After this steps, $JULIA_PATH/include
should points to Julia header and $JULIA_PATH/lib
should point to libjulia.so
You can also install Julia locally by running nimble install julia
, in that case it will install Julia in the third_party
folder
How to embed Julia w/ C :
-
https://docs.julialang.org/en/v1/manual/embedding/index.html#Working-with-Arrays-1
-
https://github.com/JuliaLang/julia/tree/master/test/embedding
-
Read the Scinim getting-started chapter on Nimjl
-
legacy/
folder contains previous experiment and examples of wrapping in C. -
tests/testfull.nim
is thet test suite -
examples/
contains several examples
Julia is mostly oriented towards numerical computing so Arrays are THE most important data structure to support
Mostly quality-of-life improvements, especially when handling arrays.
- Improve Julia Arrays interop. from Nim.
- Supports complex Arrays
- map / apply / reduce /fold
- Support Julia chaining syntax
- Add support for Enum types
-
Value conversion Nim -> Julia are done by copy.
- Arrays are an exception to this rule and can be created from buffer / are accessible using a buffer.
-
Value conversion Julia -> Nim s always done by copy
- When using Arrays you can access the buffer as
ptr UncheckedArray
of the Julia Arrays withrawData()
. - Using
to(seq[T])
orto(Tensor[T])
perform acopyMem
ofjlArray.rawData()
in your seq/Tensor
- When using Arrays you can access the buffer as
-
Julia allocated arrays only goes up to 3 dimensions (but Arrays can be allocated in Nim)
-
Linux / WSL supports only
- Windows dynamic library linking is different than Linux.
- If you need Windows support, consider opening an issue or a PR :).
- Otherwise, just use WSL
Here is the basic example:
import nimjl
Julia.init() # Initialize Julia VM. Subsequent call will be ignored
var myval = 4.0'f64
# Call Julia function "sqrt" and convert the result to a float
var res = Julia.sqrt(myval).to(float64)
echo res # 2.0
It is now possible to embed Julia files inside a Nim compiled binary to easily distribute Julia code. To make distribution possible, an API to call Pkg.add("...")
has also been added with version number easy to specify.
import nimjl
Julia.init:
Pkg:
add(name="Polynomials", version="3.0.0")
add(name="LinearAlgebra")
add("DSP")
add(name="Wavelets", version="0.9.4")
Embed:
# embed all files with '*.jl' extension in folder ``JuliaToolBox/``
dir("JuliaToolBox/")
# embed all files with '*.jl' extension in the folder of he source file (at compilation) i.e. ``getProjectPath()``
thisDir()
# embed specific file; path should be relative to ``getProjectPath()``
file("localfile.jl")
See examples/ex09_embed_file.nim for a concrete example
Take a look at tests/
or examples/
folder for typical examples.
This project is released under MIT License.