views:

46

answers:

3

I'm wondering if there is a way to extend ruby Array type to do SIMD & SSE vector calculation.

I mean implement in an low-level language to be used in ruby programs to number crunching tasks.

+2  A: 

I suspect that you would need to write a Ruby C extension. I haven't used that tutorial, but it seems plausible. Just wrap the SIMD and SSE methods you want to use in your extension, et voila! I haven't developed this kind of extension before, so I'm not sure if this kind of operation would incur copying overhead when moving data between Ruby and C. You'd have to investigate that; a quick Google doesn't find any extensions like this already in the wild.

Alterscape
You can add your own data types via C extensions, so if using the builtin array would involve too much copying, he can roll is own.
Marc-André Lafortune
What I'm thinking is if ruby arrays can be typed. If we could create a pure float array or a float matrix to do scientific programming. It seems that ruby arrays is more like a indexed bag of objects.
Anderson
@Anderson: for numerical arrays, there is NArray http://narray.rubyforge.org/
Marc-André Lafortune
A: 

It might be worth exploring Ruby-OpenCL and extending it as necessary.

Nick
Nice, it's something like that I was looking. But using SIMD and SSE operations and in a more natural ruby style.
Anderson
A: 

try using GCC simd intrinsics with RubyInline

banister