#julia #ndarray #multidimensional-array #jlrs

jlrs-ndarray

jlrs is a library built around bindings to the Julia C API that enables Julia code to be called from Rust. jlrs can move many kinds of data from Rust to Julia and back, share n-dimensional numerical arrays between languages, call arbitrary functions, and load code from arbitrary Julia source files. jlrs currently supports Linux and Windows.

4 releases (2 breaking)

0.3.0 Mar 25, 2021
0.2.0 Dec 20, 2020
0.1.1 Oct 10, 2020
0.1.0 Oct 10, 2020

#1393 in Math

MIT license

1MB
24K SLoC

Borrow data from Julia arrays as ndarray's ArrayView and ArrayViewMut.

This crate defines a single trait, NdArray, that provides methods that return an immutable or a mutable view of the array data and is implemented by Array and TypedArray from jlrs.

Example:

use jlrs::prelude::*;
use jlrs_ndarray::NdArray;

fn main() {
    let mut julia = unsafe { Julia::init(16).unwrap() };
    julia.dynamic_frame(|_global, frame| {
        let mut data = vec![1usize, 2, 3, 4, 5, 6];
        let slice = &mut data.as_mut_slice();
        let borrowed = Value::borrow_array(frame, slice, (3, 2))?;

        let _array = borrowed.cast::<TypedArray<usize>>()?.array_view(frame)?;

        Ok(())
    }).unwrap();
}

lib.rs:

Borrow data from Julia arrays as ndarray's ArrayView and ArrayViewMut.

This crate defines a single trait, NdArray, that provides methods that return an immutable or a mutable view of the array data and is implemented by Array and TypedArray from jlrs. It's easier to use this trait with TypedArray, you'll likely have to provide type annotations with Array.

Dependencies

~4.5–7MB
~171K SLoC