Hello,

I have just published a Nim wrapper for ArrayFire on github: 
[https://github.com/bitstormGER/ArrayFire-Nim](https://github.com/bitstormGER/ArrayFire-Nim)

This is my first Nim project but the wrapper seems quite usable to me.

I hope this helps (ones it is working properly) to make Nim even more 
attractive for scientific computing - my main area of interest. I am currently 
mostly using Python but would love to see more work being done with Nim.

The wrapper is based on the unified backend of ArrayFire so you can change 
backends at runtime. Supported backends are CPU, OpenCL and CUDA - this means 
you have access to GPU accelerated operations and even parallel for loops (see 
gfor in the documentation on github)

To give an idea how code with the wrapper looks - here are some code examples:

Some linear algebra computations - ArrayFire is extremely fast and feature rich
    
    
    var ain = matrix(2,3,@[1'f32, 4'f32, 2'f32, 5'f32, 3'f32, 6'f32])
        var (u,s_vec,vt) = ain.svd()
        
        var s_mat = diag(s_vec ,0, false)
        var in_recon = matmul(u,s_mat, vt[mseq(2), span])
    
    

Computer Vision (translated from a c++ example)
    
    
    setDevice(0)
        info()
        var img_color = loadImage("assets/man.jpg",true)
        let img = colorSpace(img_color, CSpace.GRAY, CSpace.RGB)
        
        img_color /= 255
        
        let feat = fast(img,20.0, 9, true, 0.05)
        
        let hx = feat.getX().to_seq(float)
        let hy = feat.getY().to_seq(float)
        
        let draw_len = 3
        
        for f in 0..<feat.getNumFeatures():
          let x = int(hx[f])
          let y = int(hy[f])
          img_color[y, mseq(int(x)-draw_len, x+draw_len), 0] = 0
          img_color[y, mseq(int(x)-draw_len, x+draw_len), 1] = 1
          img_color[y, mseq(int(x)-draw_len, x+draw_len), 2] = 0
          
          img_color[mseq(y-draw_len, y+draw_len), x, 0] = 0
          img_color[mseq(y-draw_len, y+draw_len), x, 1] = 1
          img_color[mseq(y-draw_len, y+draw_len), x, 2] = 0
        
        echo "Features found: $1" % $feat.getNumFeatures
        
        var wnd : Window
        
        wnd.set_title("FAST Feature Detector")
        
        
        while not wnd.close():
          wnd.image(img_color)
    
    
    

The wrapper requires the C++ backend of Nim and has only been tested on Arch 
linux - I would expect it to work on Linux in general but I did not have time 
to check other OS.

Reply via email to