MozillaIndia / RustIndia

Rust India Community Repository
MIT License
30 stars 25 forks source link

Implementing Python preprocessing modules in Rust for ML/AI applications #23

Closed kaushiksk closed 7 years ago

kaushiksk commented 7 years ago

I'd like to know of the developments that have been made in this regard. What are the available modules? Which aspects can be contributed on? Also does Rust provide support for Numpy objects?

dvigneshwer commented 7 years ago

Q1. Rust provide support for Numpy objects?

You can create N-dimensional array using the nd-array crate.

Sample code snippet:

  1. Create a new Rust project:

    cargo new --bin sample_matrix
    cd  sample_matrix
    cargo add ndarray
  2. Modifications in src/main.rs

    
    #[macro_use(array)]
    extern crate ndarray;

fn main() { let sample_matrix = array![[1, 2],[3, 4]]; println!("The Zero matrix {}", sample_matrix); }


Output for above snippet:

![image](https://user-images.githubusercontent.com/30098452/28242331-58aaf462-69c6-11e7-9519-9086b0350df6.png)

Q2. Which aspects can be contributed on? 

This is a very interesting area for contribution you can try to incorporate the below code example which basically parallelizes reading of images in a directory to the python rust module recipe in the kit,

extern crate rayon; extern crate Image;

fn load_images(paths: &[PathBuf]) -> Vec { // loads images in parallel thread using par_iter method of rayon crate path.par_iter().map(|path| {Image::load(path)}).collect() }